Skip to content

Commit c052916

Browse files
author
gitlab
committed
Merge branch 'fix-45747@@2' into 'master'
<fix>[storage]: get volume accountUuid without null check See merge request zstackio/zstack!3494
2 parents cd35b78 + 023af4a commit c052916

5 files changed

Lines changed: 44 additions & 16 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.zstack.core.aspect;
2+
3+
import org.zstack.core.db.Q;
4+
import org.zstack.header.aspect.OwnedByAccountAspect;
5+
import org.zstack.header.core.StaticInit;
6+
import org.zstack.header.identity.AccountResourceRefVO;
7+
import org.zstack.header.identity.AccountResourceRefVO_;
8+
9+
import java.util.function.Function;
10+
11+
public class AspectCompleter {
12+
@StaticInit
13+
static void staticinit() {
14+
OwnedByAccountAspect.setAccountUuidGetter(new Function<String, String>() {
15+
@Override
16+
public String apply(String s) {
17+
return Q.New(AccountResourceRefVO.class).select(AccountResourceRefVO_.accountUuid)
18+
.eq(AccountResourceRefVO_.resourceUuid, s).findValue();
19+
}
20+
});
21+
}
22+
}

core/src/main/java/org/zstack/core/aspect/EncryptColumnAspect.aj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import java.lang.reflect.Field;
1616
* @Date: 2021/12/2
1717
*/
1818
public aspect EncryptColumnAspect {
19-
private static final CLogger logger = Utils.getLogger(OwnedByAccountAspect.class);
19+
private static final CLogger logger = Utils.getLogger(EncryptColumnAspect.class);
2020

2121
@Autowired
2222
protected PluginRegistry pluginRegistry;

core/src/main/java/org/zstack/core/aspect/OwnedByAccountAspect.aj renamed to header/src/main/java/org/zstack/header/aspect/OwnedByAccountAspect.aj

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
package org.zstack.core.aspect;
1+
package org.zstack.header.aspect;
22

3-
import org.zstack.header.identity.AccountResourceRefVO;
4-
import org.zstack.header.identity.AccountResourceRefVO_;
3+
import org.zstack.header.identity.OwnedByAccount;
54
import org.zstack.header.vo.ResourceVO;
6-
import org.zstack.core.db.Q;
75
import org.zstack.utils.Utils;
86
import org.zstack.utils.logging.CLogger;
9-
import org.zstack.header.identity.OwnedByAccount;
7+
108
import javax.persistence.EntityManager;
9+
import java.util.function.Function;
1110

1211
public aspect OwnedByAccountAspect {
1312
private static final CLogger logger = Utils.getLogger(OwnedByAccountAspect.class);
1413

15-
Object around(OwnedByAccount oa) : this(oa) && execution(String OwnedByAccount+.getAccountUuid()) {
14+
private static Function<String, String> accountUuidGetter;
15+
16+
public static Function<String, String> getAccountUuidGetter() {
17+
return accountUuidGetter;
18+
}
19+
20+
public static void setAccountUuidGetter(Function<String, String> accountUuidGetter) {
21+
OwnedByAccountAspect.accountUuidGetter = accountUuidGetter;
22+
}
23+
24+
Object around(OwnedByAccount oa) : this(oa) && execution(java.lang.String OwnedByAccount+.getAccountUuid()) {
1625
Object accountUuid = proceed(oa);
1726

1827
if (accountUuid == null) {
19-
accountUuid = Q.New(AccountResourceRefVO.class).select(AccountResourceRefVO_.accountUuid)
20-
.eq(AccountResourceRefVO_.resourceUuid, ((ResourceVO)oa).getUuid()).findValue();
21-
oa.setAccountUuid((String)accountUuid);
28+
accountUuid = accountUuidGetter.apply(((ResourceVO) oa).getUuid());
2229
}
2330

2431
return accountUuid;

core/src/main/java/org/zstack/core/aspect/OwnedByAccountAspectHelper.java renamed to header/src/main/java/org/zstack/header/aspect/OwnedByAccountAspectHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.zstack.core.aspect;
1+
package org.zstack.header.aspect;
22

33
import org.zstack.header.identity.AccountConstant;
44
import org.zstack.header.identity.AccountResourceRefVO;

storage/src/main/java/org/zstack/storage/volume/VolumeBase.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import org.zstack.header.image.ImageInventory;
3434
import org.zstack.header.image.ImagePlatform;
3535
import org.zstack.header.image.ImageVO;
36-
import org.zstack.header.message.*;
3736
import org.zstack.header.message.APIDeleteMessage.DeletionMode;
37+
import org.zstack.header.message.*;
3838
import org.zstack.header.storage.primary.*;
3939
import org.zstack.header.storage.snapshot.*;
4040
import org.zstack.header.storage.snapshot.group.MemorySnapshotGroupExtensionPoint;
@@ -786,6 +786,7 @@ private void expunge(final Completion completion) {
786786
}
787787

788788
final VolumeInventory inv = getSelfInventory();
789+
String accountUuid = self.getAccountUuid();
789790
pluginRgty.getExtensionList(VolumeBeforeExpungeExtensionPoint.class).forEach(ext -> ext.volumePreExpunge(inv));
790791
FlowChain chain = FlowChainBuilder.newShareFlowChain();
791792
chain.setName("expunge-volume");
@@ -873,7 +874,6 @@ public void handle(Map data) {
873874
CollectionUtils.safeForEach(pluginRgty.getExtensionList(VolumeAfterExpungeExtensionPoint.class), arg -> arg.volumeAfterExpunge(inv));
874875

875876
VolumeInventory volumeInventory = getSelfInventory();
876-
String accountUuid = acntMgr.getOwnerAccountUuidOfResource(self.getUuid());
877877
dbf.remove(self);
878878
cleanupVolumeEO(self.getUuid());
879879
completion.success();
@@ -1205,12 +1205,12 @@ public void rollback(FlowRollback trigger, Map data) {
12051205
@Override
12061206
public void handle(Map data) {
12071207
VolumeStatus oldStatus = self.getStatus();
1208+
String accountUuid = self.getAccountUuid();
12081209

12091210
if (deletionPolicy == VolumeDeletionPolicy.Direct) {
12101211
callVmJustBeforeDeleteFromDbExtensionPoint();
12111212
self.setStatus(VolumeStatus.Deleted);
12121213
self = dbf.updateAndRefresh(self);
1213-
String accountUuid = acntMgr.getOwnerAccountUuidOfResource(self.getUuid());
12141214
VolumeInventory volumeInventory = getSelfInventory();
12151215
dbf.remove(self);
12161216
cleanupVolumeEO(self.getUuid());
@@ -1227,7 +1227,6 @@ public void handle(Map data) {
12271227
callVmJustBeforeDeleteFromDbExtensionPoint();
12281228
VolumeInventory inventory = getSelfInventory();
12291229
inventory.setStatus(VolumeStatus.Deleted.toString());
1230-
String accountUuid = acntMgr.getOwnerAccountUuidOfResource(self.getUuid());
12311230
dbf.remove(self);
12321231
new FireVolumeCanonicalEvent().fireVolumeStatusChangedEvent(oldStatus, inventory, accountUuid);
12331232
} else {
@@ -1419,7 +1418,7 @@ public void run(final SyncTaskChain chain) {
14191418
if (deletionPolicy == VolumeDeletionPolicy.DBOnly) {
14201419
callVmJustBeforeDeleteFromDbExtensionPoint();
14211420
VolumeInventory inventory = getSelfInventory();
1422-
String accountUuid = acntMgr.getOwnerAccountUuidOfResource(self.getUuid());
1421+
String accountUuid = self.getAccountUuid();
14231422
dbf.remove(self);
14241423
new FireVolumeCanonicalEvent().fireVolumeStatusChangedEvent(self.getStatus(), inventory, accountUuid);
14251424
}

0 commit comments

Comments
 (0)