|
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; |
@@ -1741,12 +1742,6 @@ private Volume changeDiskOfferingForVolumeInternal(VolumeVO volume, Long newDisk |
1741 | 1742 | boolean volumeMigrateRequired = false; |
1742 | 1743 | boolean volumeResizeRequired = false; |
1743 | 1744 |
|
1744 | | - // Skip the Disk offering change on Volume if Disk Offering is the same and is linked to a custom Service Offering |
1745 | | - if(isNewDiskOfferingTheSameAndCustomServiceOffering(existingDiskOffering, newDiskOffering)) { |
1746 | | - 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())); |
1747 | | - return volume; |
1748 | | - } |
1749 | | - |
1750 | 1745 | // VALIDATIONS |
1751 | 1746 | Long[] updateNewSize = {newSize}; |
1752 | 1747 | Long[] updateNewMinIops = {newMinIops}; |
@@ -1853,19 +1848,6 @@ private boolean compareEqualsIncludingNullOrZero(Long a, Long b) { |
1853 | 1848 | return a.equals(b); |
1854 | 1849 | } |
1855 | 1850 |
|
1856 | | - /** |
1857 | | - * 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. |
1858 | | - */ |
1859 | | - protected boolean isNewDiskOfferingTheSameAndCustomServiceOffering(DiskOfferingVO existingDiskOffering, DiskOfferingVO newDiskOffering) { |
1860 | | - if (newDiskOffering.getId() == existingDiskOffering.getId()) { |
1861 | | - ServiceOfferingVO serviceOffering = _serviceOfferingDao.findServiceOfferingByComputeOnlyDiskOffering(newDiskOffering.getId()); |
1862 | | - if (serviceOffering != null && serviceOffering.isCustomized()) { |
1863 | | - return true; |
1864 | | - } |
1865 | | - } |
1866 | | - return false; |
1867 | | - } |
1868 | | - |
1869 | 1851 | private VolumeVO resizeVolumeInternal(VolumeVO volume, DiskOfferingVO newDiskOffering, Long currentSize, Long newSize, Long newMinIops, Long newMaxIops, Integer newHypervisorSnapshotReserve, boolean shrinkOk) throws ResourceAllocationException { |
1870 | 1852 | UserVmVO userVm = _userVmDao.findById(volume.getInstanceId()); |
1871 | 1853 | HypervisorType hypervisorType = _volsDao.getHypervisorType(volume.getId()); |
@@ -1965,30 +1947,6 @@ private void validateVolumeResizeWithNewDiskOfferingAndLoad(VolumeVO volume, Dis |
1965 | 1947 | throw new InvalidParameterValueException("Requested disk offering has been removed."); |
1966 | 1948 | } |
1967 | 1949 |
|
1968 | | - if (newDiskOffering.getId() == existingDiskOffering.getId()) { |
1969 | | - throw new InvalidParameterValueException(String.format("Volume %s already have the new disk offering %s provided.", volume.getUuid(), existingDiskOffering.getUuid())); |
1970 | | - } |
1971 | | - |
1972 | | - if (existingDiskOffering.getDiskSizeStrictness() != newDiskOffering.getDiskSizeStrictness()) { |
1973 | | - throw new InvalidParameterValueException("Disk offering size strictness does not match with new disk offering."); |
1974 | | - } |
1975 | | - |
1976 | | - if (MatchStoragePoolTagsWithDiskOffering.valueIn(volume.getDataCenterId())) { |
1977 | | - if (!doesNewDiskOfferingHasTagsAsOldDiskOffering(existingDiskOffering, newDiskOffering)) { |
1978 | | - 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())); |
1979 | | - } |
1980 | | - } |
1981 | | - |
1982 | | - Long instanceId = volume.getInstanceId(); |
1983 | | - VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(instanceId); |
1984 | | - if (volume.getVolumeType().equals(Volume.Type.ROOT)) { |
1985 | | - ServiceOfferingVO serviceOffering = _serviceOfferingDao.findById(vmInstanceVO.getServiceOfferingId()); |
1986 | | - if (serviceOffering != null && serviceOffering.getDiskOfferingStrictness()) { |
1987 | | - 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())); |
1988 | | - } |
1989 | | - } |
1990 | | - |
1991 | | - _configMgr.checkDiskOfferingAccess(_accountMgr.getActiveAccountById(volume.getAccountId()), newDiskOffering, _dcDao.findById(volume.getDataCenterId())); |
1992 | 1950 | if (newDiskOffering.getDiskSize() > 0 && !newDiskOffering.isComputeOnly()) { |
1993 | 1951 | newSize[0] = (Long) newDiskOffering.getDiskSize(); |
1994 | 1952 | } else if (newDiskOffering.isCustomized() && !newDiskOffering.isComputeOnly()) { |
@@ -2022,6 +1980,31 @@ private void validateVolumeResizeWithNewDiskOfferingAndLoad(VolumeVO volume, Dis |
2022 | 1980 | newHypervisorSnapshotReserve[0] = volume.getHypervisorSnapshotReserve() != null ? newDiskOffering.getHypervisorSnapshotReserve() : null; |
2023 | 1981 | } |
2024 | 1982 |
|
| 1983 | + if (existingDiskOffering.getId() == newDiskOffering.getId() && |
| 1984 | + (!newDiskOffering.isCustomized() || (newDiskOffering.isCustomized() && Objects.equals(volume.getSize(), newSize[0] << 30)))) { |
| 1985 | + throw new InvalidParameterValueException(String.format("Volume %s is already having disk offering %s", volume, newDiskOffering.getUuid())); |
| 1986 | + } |
| 1987 | + |
| 1988 | + if (existingDiskOffering.getDiskSizeStrictness() != newDiskOffering.getDiskSizeStrictness()) { |
| 1989 | + throw new InvalidParameterValueException("Disk offering size strictness does not match with new disk offering."); |
| 1990 | + } |
| 1991 | + |
| 1992 | + if (MatchStoragePoolTagsWithDiskOffering.valueIn(volume.getDataCenterId())) { |
| 1993 | + if (!doesNewDiskOfferingHasTagsAsOldDiskOffering(existingDiskOffering, newDiskOffering)) { |
| 1994 | + 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())); |
| 1995 | + } |
| 1996 | + } |
| 1997 | + Long instanceId = volume.getInstanceId(); |
| 1998 | + VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(instanceId); |
| 1999 | + if (volume.getVolumeType().equals(Volume.Type.ROOT)) { |
| 2000 | + ServiceOfferingVO serviceOffering = _serviceOfferingDao.findById(vmInstanceVO.getServiceOfferingId()); |
| 2001 | + if (serviceOffering != null && serviceOffering.getDiskOfferingStrictness()) { |
| 2002 | + 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())); |
| 2003 | + } |
| 2004 | + } |
| 2005 | + |
| 2006 | + _configMgr.checkDiskOfferingAccess(_accountMgr.getActiveAccountById(volume.getAccountId()), newDiskOffering, _dcDao.findById(volume.getDataCenterId())); |
| 2007 | + |
2025 | 2008 | if (existingDiskOffering.getDiskSizeStrictness() && !(volume.getSize().equals(newSize[0]))) { |
2026 | 2009 | throw new InvalidParameterValueException(String.format("Resize volume for %s is not allowed since disk offering's size is fixed", volume.getName())); |
2027 | 2010 | } |
|
0 commit comments