Skip to content

Commit 63acfa1

Browse files
author
Fabrício Duarte
committed
Merge branch 'fix-npe-volume-creation-from-snap' into '4.20.0.0-scclouds'
Correção em NPE ao criar volume a partir de snapshot de volume Closes #3180 See merge request scclouds/scclouds!1324
2 parents a789a31 + 5f7dae6 commit 63acfa1

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

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

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

2727
import com.cloud.storage.VolumeApiServiceImpl;
28+
import com.cloud.storage.VolumeVO;
2829
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
2930
import org.springframework.stereotype.Component;
3031

@@ -77,8 +78,13 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
7778
logDisabledStoragePools(dcId, podId, clusterId, ScopeType.CLUSTER);
7879
}
7980

81+
long volumeId = dskCh.getVolumeId();
82+
VolumeVO volumeVo = volumeDao.findById(volumeId);
83+
84+
long accountId = volumeVo.getAccountId();
85+
8086
List<StoragePoolVO> pools = storagePoolDao.findPoolsByTags(dcId, podId, clusterId, dskCh.getTags(), true, VolumeApiServiceImpl.storageTagRuleExecutionTimeout.value());
81-
pools.addAll(tagAsRuleHelper.findStoragePoolByScopeAndRuleTags(dcId, podId, clusterId, ScopeType.CLUSTER, List.of(dskCh.getTags()), vmProfile.getVirtualMachine().getAccountId()));
87+
pools.addAll(tagAsRuleHelper.findStoragePoolByScopeAndRuleTags(dcId, podId, clusterId, ScopeType.CLUSTER, List.of(dskCh.getTags()), accountId));
8288
logger.debug(String.format("Found pools [%s] that match with tags [%s].", pools, Arrays.toString(dskCh.getTags())));
8389

8490
// add remaining pools in cluster, that did not match tags, to avoid set

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

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

27+
import com.cloud.storage.VolumeVO;
2728
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
2829
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
2930
import org.springframework.stereotype.Component;
@@ -98,9 +99,15 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
9899
logger.debug("LocalStoragePoolAllocator is returning null since both the host ID and pod ID are null. That means this should be a zone wide primary storage deployment.");
99100
return null;
100101
}
102+
103+
long volumeId = dskCh.getVolumeId();
104+
VolumeVO volumeVo = volumeDao.findById(volumeId);
105+
106+
long accountId = volumeVo.getAccountId();
107+
101108
List<StoragePoolVO> availablePools =
102109
storagePoolDao.findLocalStoragePoolsByTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), dskCh.getTags(), true, keyword);
103-
availablePools.addAll(tagAsRuleHelper.findStoragePoolByScopeAndRuleTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), ScopeType.HOST, List.of(dskCh.getTags()), vmProfile.getVirtualMachine().getAccountId()));
110+
availablePools.addAll(tagAsRuleHelper.findStoragePoolByScopeAndRuleTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), ScopeType.HOST, List.of(dskCh.getTags()), accountId));
104111
for (StoragePoolVO pool : availablePools) {
105112
if (suitablePools.size() == returnUpTo) {
106113
break;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import javax.inject.Inject;
2626

27+
import com.cloud.storage.VolumeVO;
2728
import org.springframework.stereotype.Component;
2829

2930
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
@@ -60,9 +61,14 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
6061
logDisabledStoragePools(plan.getDataCenterId(), null, null, ScopeType.ZONE);
6162
}
6263

64+
long volumeId = dskCh.getVolumeId();
65+
VolumeVO volumeVo = volumeDao.findById(volumeId);
66+
67+
long accountId = volumeVo.getAccountId();
68+
6369
List<StoragePool> suitablePools = new ArrayList<>();
6470
List<StoragePoolVO> storagePools = storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), dskCh.getTags(), true);
65-
storagePools.addAll(tagAsRuleHelper.findStoragePoolByScopeAndRuleTags(plan.getDataCenterId(), null, null, ScopeType.ZONE, List.of(dskCh.getTags()), vmProfile.getVirtualMachine().getAccountId()));
71+
storagePools.addAll(tagAsRuleHelper.findStoragePoolByScopeAndRuleTags(plan.getDataCenterId(), null, null, ScopeType.ZONE, List.of(dskCh.getTags()), accountId));
6672
if (storagePools.isEmpty()) {
6773
logger.debug(String.format("Could not find any zone wide storage pool that matched with any of the following tags [%s].", Arrays.toString(dskCh.getTags())));
6874
storagePools = new ArrayList<>();

0 commit comments

Comments
 (0)