|
26 | 26 | import java.util.HashSet; |
27 | 27 | import java.util.List; |
28 | 28 | import java.util.Map; |
| 29 | +import java.util.Objects; |
29 | 30 | import java.util.Optional; |
30 | 31 | import java.util.Set; |
31 | 32 | import java.util.UUID; |
@@ -1795,12 +1796,6 @@ private Volume changeDiskOfferingForVolumeInternal(VolumeVO volume, Long newDisk |
1795 | 1796 | boolean volumeMigrateRequired = false; |
1796 | 1797 | boolean volumeResizeRequired = false; |
1797 | 1798 |
|
1798 | | - // Skip the Disk offering change on Volume if Disk Offering is the same and is linked to a custom Service Offering |
1799 | | - if(isNewDiskOfferingTheSameAndCustomServiceOffering(existingDiskOffering, newDiskOffering)) { |
1800 | | - s_logger.debug(String.format("Scaling CPU and/or Memory of VM with custom service offering. New disk offering stills the same. Skipping the Disk offering change on Volume %s.", volume.getUuid())); |
1801 | | - return volume; |
1802 | | - } |
1803 | | - |
1804 | 1799 | // VALIDATIONS |
1805 | 1800 | Long[] updateNewSize = {newSize}; |
1806 | 1801 | Long[] updateNewMinIops = {newMinIops}; |
@@ -1907,19 +1902,6 @@ private boolean compareEqualsIncludingNullOrZero(Long a, Long b) { |
1907 | 1902 | return a.equals(b); |
1908 | 1903 | } |
1909 | 1904 |
|
1910 | | - /** |
1911 | | - * Returns true if the new disk offering is the same than current offering, and the respective Service offering is a custom (constraint or unconstraint) offering. |
1912 | | - */ |
1913 | | - protected boolean isNewDiskOfferingTheSameAndCustomServiceOffering(DiskOfferingVO existingDiskOffering, DiskOfferingVO newDiskOffering) { |
1914 | | - if (newDiskOffering.getId() == existingDiskOffering.getId()) { |
1915 | | - ServiceOfferingVO serviceOffering = _serviceOfferingDao.findServiceOfferingByComputeOnlyDiskOffering(newDiskOffering.getId()); |
1916 | | - if (serviceOffering != null && serviceOffering.isCustomized()) { |
1917 | | - return true; |
1918 | | - } |
1919 | | - } |
1920 | | - return false; |
1921 | | - } |
1922 | | - |
1923 | 1905 | private VolumeVO resizeVolumeInternal(VolumeVO volume, DiskOfferingVO newDiskOffering, Long currentSize, Long newSize, Long newMinIops, Long newMaxIops, Integer newHypervisorSnapshotReserve, boolean shrinkOk) throws ResourceAllocationException { |
1924 | 1906 | UserVmVO userVm = _userVmDao.findById(volume.getInstanceId()); |
1925 | 1907 | HypervisorType hypervisorType = _volsDao.getHypervisorType(volume.getId()); |
@@ -2031,30 +2013,8 @@ private void validateVolumeResizeWithNewDiskOfferingAndLoad(VolumeVO volume, Dis |
2031 | 2013 | throw new InvalidParameterValueException("Requested disk offering has been removed."); |
2032 | 2014 | } |
2033 | 2015 |
|
2034 | | - if (newDiskOffering.getId() == existingDiskOffering.getId()) { |
2035 | | - throw new InvalidParameterValueException(String.format("Volume %s already have the new disk offering %s provided.", volume.getUuid(), existingDiskOffering.getUuid())); |
2036 | | - } |
2037 | | - |
2038 | | - if (existingDiskOffering.getDiskSizeStrictness() != newDiskOffering.getDiskSizeStrictness()) { |
2039 | | - throw new InvalidParameterValueException("Disk offering size strictness does not match with new disk offering."); |
2040 | | - } |
2041 | | - |
2042 | | - if (MatchStoragePoolTagsWithDiskOffering.valueIn(volume.getDataCenterId())) { |
2043 | | - if (!doesNewDiskOfferingHasTagsAsOldDiskOffering(existingDiskOffering, newDiskOffering)) { |
2044 | | - throw new InvalidParameterValueException(String.format("Selected disk offering %s does not have tags as in existing disk offering of volume %s", existingDiskOffering.getUuid(), volume.getUuid())); |
2045 | | - } |
2046 | | - } |
2047 | | - |
2048 | | - Long instanceId = volume.getInstanceId(); |
2049 | | - VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(instanceId); |
2050 | | - if (volume.getVolumeType().equals(Volume.Type.ROOT)) { |
2051 | | - ServiceOfferingVO serviceOffering = _serviceOfferingDao.findById(vmInstanceVO.getServiceOfferingId()); |
2052 | | - if (serviceOffering != null && serviceOffering.getDiskOfferingStrictness()) { |
2053 | | - throw new InvalidParameterValueException(String.format("Cannot resize ROOT volume [%s] with new disk offering since existing disk offering is strictly assigned to the ROOT volume.", volume.getName())); |
2054 | | - } |
2055 | | - } |
2056 | | - |
2057 | 2016 | _configMgr.checkDiskOfferingAccess(_accountMgr.getActiveAccountById(volume.getAccountId()), newDiskOffering, _dcDao.findById(volume.getDataCenterId())); |
| 2017 | + |
2058 | 2018 | if (newDiskOffering.getDiskSize() > 0 && !newDiskOffering.isComputeOnly()) { |
2059 | 2019 | newSize[0] = (Long) newDiskOffering.getDiskSize(); |
2060 | 2020 | } else if (newDiskOffering.isCustomized() && !newDiskOffering.isComputeOnly()) { |
@@ -2084,10 +2044,41 @@ private void validateVolumeResizeWithNewDiskOfferingAndLoad(VolumeVO volume, Dis |
2084 | 2044 | if (existingDiskOffering.getDiskSizeStrictness() && !(volume.getSize().equals(newSize[0]))) { |
2085 | 2045 | throw new InvalidParameterValueException(String.format("Resize volume for %s is not allowed since disk offering's size is fixed", volume.getName())); |
2086 | 2046 | } |
| 2047 | + |
| 2048 | + Long instanceId = volume.getInstanceId(); |
| 2049 | + VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(instanceId); |
| 2050 | + |
| 2051 | + checkIfVolumeCanResizeWithNewDiskOffering(volume, existingDiskOffering, newDiskOffering, newSize[0], vmInstanceVO); |
2087 | 2052 | checkIfVolumeIsRootAndVmIsRunning(newSize[0], volume, vmInstanceVO); |
2088 | 2053 |
|
2089 | 2054 | } |
2090 | 2055 |
|
| 2056 | + private void checkIfVolumeCanResizeWithNewDiskOffering(VolumeVO volume, DiskOfferingVO existingDiskOffering, DiskOfferingVO newDiskOffering, Long newSize, VMInstanceVO vmInstanceVO) { |
| 2057 | + if (existingDiskOffering.getId() == newDiskOffering.getId() && |
| 2058 | + (!newDiskOffering.isCustomized() || (newDiskOffering.isCustomized() && Objects.equals(volume.getSize(), newSize << 30)))) { |
| 2059 | + throw new InvalidParameterValueException(String.format("Volume %s is already having disk offering %s", volume, newDiskOffering.getUuid())); |
| 2060 | + } |
| 2061 | + |
| 2062 | + if (existingDiskOffering.getDiskSizeStrictness() != newDiskOffering.getDiskSizeStrictness()) { |
| 2063 | + throw new InvalidParameterValueException("Disk offering size strictness does not match with new disk offering."); |
| 2064 | + } |
| 2065 | + |
| 2066 | + if (MatchStoragePoolTagsWithDiskOffering.valueIn(volume.getDataCenterId()) && !doesNewDiskOfferingHasTagsAsOldDiskOffering(existingDiskOffering, newDiskOffering)) { |
| 2067 | + throw new InvalidParameterValueException(String.format("Selected disk offering %s does not have tags as in existing disk offering of volume %s", existingDiskOffering.getUuid(), volume.getUuid())); |
| 2068 | + } |
| 2069 | + |
| 2070 | + if (volume.getVolumeType().equals(Volume.Type.ROOT)) { |
| 2071 | + ServiceOfferingVO serviceOffering = _serviceOfferingDao.findById(vmInstanceVO.getServiceOfferingId()); |
| 2072 | + if (serviceOffering != null && serviceOffering.getDiskOfferingStrictness()) { |
| 2073 | + throw new InvalidParameterValueException(String.format("Cannot resize ROOT volume [%s] with new disk offering since existing disk offering is strictly assigned to the ROOT volume.", volume.getName())); |
| 2074 | + } |
| 2075 | + } |
| 2076 | + |
| 2077 | + if (existingDiskOffering.getDiskSizeStrictness() && !(volume.getSize().equals(newSize))) { |
| 2078 | + throw new InvalidParameterValueException(String.format("Resize volume for %s is not allowed since disk offering's size is fixed", volume.getName())); |
| 2079 | + } |
| 2080 | + } |
| 2081 | + |
2091 | 2082 | private void validateVolumeResizeWithSize(VolumeVO volume, long currentSize, Long newSize, boolean shrinkOk) throws ResourceAllocationException { |
2092 | 2083 |
|
2093 | 2084 | // if the caller is looking to change the size of the volume |
|
0 commit comments