Skip to content

Commit d311f88

Browse files
authored
Allow scaling VM to a service offering having different storage tags (#5996)
1 parent 72a77d5 commit d311f88

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import javax.naming.ConfigurationException;
4646
import javax.persistence.EntityExistsException;
4747

48+
import com.cloud.storage.VolumeApiServiceImpl;
4849
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
4950
import org.apache.cloudstack.annotation.AnnotationService;
5051
import org.apache.cloudstack.annotation.dao.AnnotationDao;
@@ -3765,9 +3766,11 @@ public void checkIfCanUpgrade(final VirtualMachine vmInstance, final ServiceOffe
37653766

37663767
final List<String> currentTags = StringUtils.csvTagsToList(currentDiskOffering.getTags());
37673768
final List<String> newTags = StringUtils.csvTagsToList(newDiskOffering.getTags());
3768-
if (!newTags.containsAll(currentTags)) {
3769-
throw new InvalidParameterValueException("Unable to upgrade virtual machine; the current service offering " + " should have tags as subset of " +
3770-
"the new service offering tags. Current service offering tags: " + currentTags + "; " + "new service " + "offering tags: " + newTags);
3769+
if (VolumeApiServiceImpl.MatchStoragePoolTagsWithDiskOffering.valueIn(vmInstance.getDataCenterId())) {
3770+
if (!VolumeApiServiceImpl.doesNewDiskOfferingHasTagsAsOldDiskOffering(currentDiskOffering, newDiskOffering)) {
3771+
throw new InvalidParameterValueException("Unable to upgrade virtual machine; the current service offering " + " should have tags as subset of " +
3772+
"the new service offering tags. Current service offering tags: " + currentTags + "; " + "new service " + "offering tags: " + newTags);
3773+
}
37713774
}
37723775
}
37733776

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3267,7 +3267,7 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
32673267
if (currentVmOffering != null) {
32683268
DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(currentVmOffering.getDiskOfferingId());
32693269
List<String> storageTags = com.cloud.utils.StringUtils.csvTagsToList(diskOffering.getTags());
3270-
if (!storageTags.isEmpty()) {
3270+
if (!storageTags.isEmpty() && VolumeApiServiceImpl.MatchStoragePoolTagsWithDiskOffering.value()) {
32713271
SearchBuilder<ServiceOfferingJoinVO> sb = _srvOfferingJoinDao.createSearchBuilder();
32723272
for(String tag : storageTags) {
32733273
sb.and(tag, sb.entity().getTags(), Op.FIND_IN_SET);

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,10 +1910,9 @@ private void validateVolumeResizeWithNewDiskOfferingAndLoad(VolumeVO volume, Dis
19101910
}
19111911

19121912
_configMgr.checkDiskOfferingAccess(_accountMgr.getActiveAccountById(volume.getAccountId()), newDiskOffering, _dcDao.findById(volume.getDataCenterId()));
1913-
19141913
if (newDiskOffering.getDiskSize() > 0 && !newDiskOffering.isComputeOnly()) {
19151914
newSize[0] = (Long) newDiskOffering.getDiskSize();
1916-
} else if (newDiskOffering.isCustomized()) {
1915+
} else if (newDiskOffering.isCustomized() && !newDiskOffering.isComputeOnly()) {
19171916
if (newSize[0] == null) {
19181917
throw new InvalidParameterValueException("The new disk offering requires that a size be specified.");
19191918
}
@@ -3049,7 +3048,7 @@ public boolean doesTargetStorageSupportDiskOffering(StoragePool destPool, String
30493048
return CollectionUtils.isSubCollection(Arrays.asList(newDiskOfferingTagsAsStringArray), Arrays.asList(storageTagsAsStringArray));
30503049
}
30513050

3052-
public boolean doesNewDiskOfferingHasTagsAsOldDiskOffering(DiskOfferingVO oldDO, DiskOfferingVO newDO) {
3051+
public static boolean doesNewDiskOfferingHasTagsAsOldDiskOffering(DiskOfferingVO oldDO, DiskOfferingVO newDO) {
30533052
String[] oldDOStorageTags = oldDO.getTagsArray();
30543053
String[] newDOStorageTags = newDO.getTagsArray();
30553054
if (oldDOStorageTags.length == 0) {

0 commit comments

Comments
 (0)