Skip to content

Commit 94c1109

Browse files
author
Daniel Augusto Veronezi Salvador
committed
Merge branch 'fix-npe-on-list-disk-offering-with-vmid' into '4.20.0.0-scclouds'
Correção de NPE ao listar _disk offerings_ utilizando o parâmetro `virtualmachineid` Closes #3226 See merge request scclouds/scclouds!1345
2 parents af6487b + d0e0265 commit 94c1109

4 files changed

Lines changed: 21 additions & 15 deletions

File tree

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import com.cloud.exception.StorageUnavailableException;
3333
import com.cloud.storage.ScopeType;
3434
import com.cloud.storage.StoragePoolStatus;
35+
import com.cloud.storage.VolumeVO;
36+
import org.apache.cloudstack.context.CallContext;
3537
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
3638
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
3739
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
@@ -412,4 +414,20 @@ protected void logEndOfSearch(List<StoragePool> storagePoolList) {
412414
Arrays.toString(storagePoolList.toArray()));
413415
}
414416

417+
protected long getAccountIdFromProfile(DiskProfile diskProfile, VirtualMachineProfile virtualMachineProfile) {
418+
long volumeId = diskProfile.getVolumeId();
419+
VolumeVO volumeVo = volumeDao.findById(volumeId);
420+
421+
if (volumeVo != null) {
422+
return volumeVo.getAccountId();
423+
}
424+
425+
logger.debug("Volume [{}] not found. We will try to get the account ID from the virtual machine profile.", volumeId, virtualMachineProfile.getUuid());
426+
if (virtualMachineProfile.getVirtualMachine() != null) {
427+
return virtualMachineProfile.getVirtualMachine().getAccountId();
428+
}
429+
430+
logger.debug("No virtual machine or volume were found. The calling account will be inferred as the volume owner.");
431+
return CallContext.current().getCallingAccountId();
432+
}
415433
}

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import javax.naming.ConfigurationException;
2626

2727
import com.cloud.storage.VolumeApiServiceImpl;
28-
import com.cloud.storage.VolumeVO;
2928
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
3029
import org.springframework.stereotype.Component;
3130

@@ -78,10 +77,7 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
7877
logDisabledStoragePools(dcId, podId, clusterId, ScopeType.CLUSTER);
7978
}
8079

81-
long volumeId = dskCh.getVolumeId();
82-
VolumeVO volumeVo = volumeDao.findById(volumeId);
83-
84-
long accountId = volumeVo.getAccountId();
80+
long accountId = getAccountIdFromProfile(dskCh, vmProfile);
8581

8682
List<StoragePoolVO> pools = storagePoolDao.findPoolsByTags(dcId, podId, clusterId, dskCh.getTags(), true, VolumeApiServiceImpl.storageTagRuleExecutionTimeout.value());
8783
pools.addAll(tagAsRuleHelper.findStoragePoolByScopeAndRuleTags(dcId, podId, clusterId, ScopeType.CLUSTER, List.of(dskCh.getTags()), accountId));

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import javax.inject.Inject;
2525
import javax.naming.ConfigurationException;
2626

27-
import com.cloud.storage.VolumeVO;
2827
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
2928
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
3029
import org.springframework.stereotype.Component;
@@ -100,10 +99,7 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
10099
return null;
101100
}
102101

103-
long volumeId = dskCh.getVolumeId();
104-
VolumeVO volumeVo = volumeDao.findById(volumeId);
105-
106-
long accountId = volumeVo.getAccountId();
102+
long accountId = getAccountIdFromProfile(dskCh, vmProfile);
107103

108104
List<StoragePoolVO> availablePools =
109105
storagePoolDao.findLocalStoragePoolsByTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), dskCh.getTags(), true, keyword);

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import javax.inject.Inject;
2626

27-
import com.cloud.storage.VolumeVO;
2827
import org.springframework.stereotype.Component;
2928

3029
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
@@ -61,10 +60,7 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
6160
logDisabledStoragePools(plan.getDataCenterId(), null, null, ScopeType.ZONE);
6261
}
6362

64-
long volumeId = dskCh.getVolumeId();
65-
VolumeVO volumeVo = volumeDao.findById(volumeId);
66-
67-
long accountId = volumeVo.getAccountId();
63+
long accountId = getAccountIdFromProfile(dskCh, vmProfile);
6864

6965
List<StoragePool> suitablePools = new ArrayList<>();
7066
List<StoragePoolVO> storagePools = storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), dskCh.getTags(), true);

0 commit comments

Comments
 (0)