From d311f88d35f11b9b3e8d9b9fe5b7fb2a62d20b24 Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Fri, 18 Feb 2022 22:09:00 +0530 Subject: [PATCH] Allow scaling VM to a service offering having different storage tags (#5996) --- .../java/com/cloud/vm/VirtualMachineManagerImpl.java | 9 ++++++--- .../main/java/com/cloud/api/query/QueryManagerImpl.java | 2 +- .../java/com/cloud/storage/VolumeApiServiceImpl.java | 5 ++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java index 477c42a1919..1dd7360d890 100755 --- a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java @@ -45,6 +45,7 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import javax.persistence.EntityExistsException; +import com.cloud.storage.VolumeApiServiceImpl; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; import org.apache.cloudstack.annotation.AnnotationService; import org.apache.cloudstack.annotation.dao.AnnotationDao; @@ -3765,9 +3766,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final List currentTags = StringUtils.csvTagsToList(currentDiskOffering.getTags()); final List newTags = StringUtils.csvTagsToList(newDiskOffering.getTags()); - if (!newTags.containsAll(currentTags)) { - throw new InvalidParameterValueException("Unable to upgrade virtual machine; the current service offering " + " should have tags as subset of " + - "the new service offering tags. Current service offering tags: " + currentTags + "; " + "new service " + "offering tags: " + newTags); + if (VolumeApiServiceImpl.MatchStoragePoolTagsWithDiskOffering.valueIn(vmInstance.getDataCenterId())) { + if (!VolumeApiServiceImpl.doesNewDiskOfferingHasTagsAsOldDiskOffering(currentDiskOffering, newDiskOffering)) { + throw new InvalidParameterValueException("Unable to upgrade virtual machine; the current service offering " + " should have tags as subset of " + + "the new service offering tags. Current service offering tags: " + currentTags + "; " + "new service " + "offering tags: " + newTags); + } } } diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java index d6a3ab6474a..0ae776bddef 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -3267,7 +3267,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q if (currentVmOffering != null) { DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(currentVmOffering.getDiskOfferingId()); List storageTags = com.cloud.utils.StringUtils.csvTagsToList(diskOffering.getTags()); - if (!storageTags.isEmpty()) { + if (!storageTags.isEmpty() && VolumeApiServiceImpl.MatchStoragePoolTagsWithDiskOffering.value()) { SearchBuilder sb = _srvOfferingJoinDao.createSearchBuilder(); for(String tag : storageTags) { sb.and(tag, sb.entity().getTags(), Op.FIND_IN_SET); diff --git a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java index bad3806e892..6ff6b56ccbb 100644 --- a/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java @@ -1910,10 +1910,9 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic } _configMgr.checkDiskOfferingAccess(_accountMgr.getActiveAccountById(volume.getAccountId()), newDiskOffering, _dcDao.findById(volume.getDataCenterId())); - if (newDiskOffering.getDiskSize() > 0 && !newDiskOffering.isComputeOnly()) { newSize[0] = (Long) newDiskOffering.getDiskSize(); - } else if (newDiskOffering.isCustomized()) { + } else if (newDiskOffering.isCustomized() && !newDiskOffering.isComputeOnly()) { if (newSize[0] == null) { throw new InvalidParameterValueException("The new disk offering requires that a size be specified."); } @@ -3049,7 +3048,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic return CollectionUtils.isSubCollection(Arrays.asList(newDiskOfferingTagsAsStringArray), Arrays.asList(storageTagsAsStringArray)); } - public boolean doesNewDiskOfferingHasTagsAsOldDiskOffering(DiskOfferingVO oldDO, DiskOfferingVO newDO) { + public static boolean doesNewDiskOfferingHasTagsAsOldDiskOffering(DiskOfferingVO oldDO, DiskOfferingVO newDO) { String[] oldDOStorageTags = oldDO.getTagsArray(); String[] newDOStorageTags = newDO.getTagsArray(); if (oldDOStorageTags.length == 0) {