Skip to content

Commit 023af4a

Browse files
committed
<fix>[storage]: get volume accountUuid without null check
Resolves: ZSTAC-45747 Change-Id: I77777973716e6b6c7a6c766470756f7873706f7a
1 parent f78be58 commit 023af4a

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;
@@ -784,6 +784,7 @@ private void expunge(final Completion completion) {
784784
}
785785

786786
final VolumeInventory inv = getSelfInventory();
787+
String accountUuid = self.getAccountUuid();
787788
pluginRgty.getExtensionList(VolumeBeforeExpungeExtensionPoint.class).forEach(ext -> ext.volumePreExpunge(inv));
788789
FlowChain chain = FlowChainBuilder.newShareFlowChain();
789790
chain.setName("expunge-volume");
@@ -871,7 +872,6 @@ public void handle(Map data) {
871872
CollectionUtils.safeForEach(pluginRgty.getExtensionList(VolumeAfterExpungeExtensionPoint.class), arg -> arg.volumeAfterExpunge(inv));
872873

873874
VolumeInventory volumeInventory = getSelfInventory();
874-
String accountUuid = acntMgr.getOwnerAccountUuidOfResource(self.getUuid());
875875
dbf.remove(self);
876876
cleanupVolumeEO(self.getUuid());
877877
completion.success();
@@ -1203,12 +1203,12 @@ public void rollback(FlowRollback trigger, Map data) {
12031203
@Override
12041204
public void handle(Map data) {
12051205
VolumeStatus oldStatus = self.getStatus();
1206+
String accountUuid = self.getAccountUuid();
12061207

12071208
if (deletionPolicy == VolumeDeletionPolicy.Direct) {
12081209
callVmJustBeforeDeleteFromDbExtensionPoint();
12091210
self.setStatus(VolumeStatus.Deleted);
12101211
self = dbf.updateAndRefresh(self);
1211-
String accountUuid = acntMgr.getOwnerAccountUuidOfResource(self.getUuid());
12121212
VolumeInventory volumeInventory = getSelfInventory();
12131213
dbf.remove(self);
12141214
cleanupVolumeEO(self.getUuid());
@@ -1225,7 +1225,6 @@ public void handle(Map data) {
12251225
callVmJustBeforeDeleteFromDbExtensionPoint();
12261226
VolumeInventory inventory = getSelfInventory();
12271227
inventory.setStatus(VolumeStatus.Deleted.toString());
1228-
String accountUuid = acntMgr.getOwnerAccountUuidOfResource(self.getUuid());
12291228
dbf.remove(self);
12301229
new FireVolumeCanonicalEvent().fireVolumeStatusChangedEvent(oldStatus, inventory, accountUuid);
12311230
} else {
@@ -1417,7 +1416,7 @@ public void run(final SyncTaskChain chain) {
14171416
if (deletionPolicy == VolumeDeletionPolicy.DBOnly) {
14181417
callVmJustBeforeDeleteFromDbExtensionPoint();
14191418
VolumeInventory inventory = getSelfInventory();
1420-
String accountUuid = acntMgr.getOwnerAccountUuidOfResource(self.getUuid());
1419+
String accountUuid = self.getAccountUuid();
14211420
dbf.remove(self);
14221421
new FireVolumeCanonicalEvent().fireVolumeStatusChangedEvent(self.getStatus(), inventory, accountUuid);
14231422
}

0 commit comments

Comments
 (0)