Skip to content

Commit 47bdcd7

Browse files
Allow resize and automigrate of root volume if required in all cases of service offering change
1 parent ec91836 commit 47bdcd7

1 file changed

Lines changed: 18 additions & 28 deletions

File tree

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,13 +1197,7 @@ private UserVm upgradeStoppedVirtualMachine(Long vmId, Long svcOffId, Map<String
11971197
}
11981198
ServiceOfferingVO currentServiceOffering = _offeringDao.findByIdIncludingRemoved(vmInstance.getId(), vmInstance.getServiceOfferingId());
11991199

1200-
if (currentServiceOffering.getDiskOfferingStrictness() != newServiceOffering.getDiskOfferingStrictness()) {
1201-
throw new InvalidParameterValueException("Unable to upgrade VM, since disk offering strictness flag is not same for new service offering and old service offering");
1202-
}
1203-
1204-
if (currentServiceOffering.getDiskOfferingStrictness() && currentServiceOffering.getDiskOfferingId() != newServiceOffering.getDiskOfferingId()) {
1205-
throw new InvalidParameterValueException("Unable to Scale VM, since disk offering id associated with the old service offering is not same for new service offering");
1206-
}
1200+
validateDiskOfferingChecks(currentServiceOffering, newServiceOffering);
12071201

12081202
int newCpu = newServiceOffering.getCpu();
12091203
int newMemory = newServiceOffering.getRamSize();
@@ -1225,11 +1219,11 @@ private UserVm upgradeStoppedVirtualMachine(Long vmId, Long svcOffId, Map<String
12251219

12261220
// Check if the new service offering can be applied to vm instance
12271221
_accountMgr.checkAccess(owner, newServiceOffering, _dcDao.findById(vmInstance.getDataCenterId()));
1228-
DiskOfferingVO currentDiskOffering = _diskOfferingDao.findById(currentServiceOffering.getDiskOfferingId());
1222+
1223+
// resize and migrate the root volume if required
12291224
DiskOfferingVO newDiskOffering = _diskOfferingDao.findById(newServiceOffering.getDiskOfferingId());
1230-
if (currentDiskOffering.isComputeOnly() && newDiskOffering.isComputeOnly()) {
1231-
changeDiskOfferingForRootVolume(vmId, newDiskOffering, customParameters);
1232-
}
1225+
changeDiskOfferingForRootVolume(vmId, newDiskOffering, customParameters);
1226+
12331227
_itMgr.upgradeVmDb(vmId, newServiceOffering, currentServiceOffering);
12341228

12351229
// Increment or decrement CPU and Memory count accordingly.
@@ -1887,20 +1881,7 @@ private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingI
18871881
throw new InvalidParameterValueException("Unable to Scale VM: since dynamic scaling enabled flag is not same for new service offering and old service offering");
18881882
}
18891883

1890-
if (currentServiceOffering.getDiskOfferingStrictness() != newServiceOffering.getDiskOfferingStrictness()) {
1891-
throw new InvalidParameterValueException("Unable to Scale VM, since disk offering strictness flag is not same for new service offering and old service offering");
1892-
}
1893-
1894-
if (currentServiceOffering.getDiskOfferingStrictness() && currentServiceOffering.getDiskOfferingId() != newServiceOffering.getDiskOfferingId()) {
1895-
throw new InvalidParameterValueException("Unable to Scale VM, since disk offering id associated with the old service offering is not same for new service offering");
1896-
}
1897-
1898-
DiskOfferingVO currentDiskOffering = _diskOfferingDao.findById(currentServiceOffering.getDiskOfferingId());
1899-
DiskOfferingVO newDiskOffering = _diskOfferingDao.findById(newServiceOffering.getDiskOfferingId());
1900-
1901-
if (Boolean.compare(currentDiskOffering.isComputeOnly(), newDiskOffering.isComputeOnly()) != 0) {
1902-
throw new InvalidParameterValueException("Unable to scale VM, since compute only flags on old and new service offerings are not same");
1903-
}
1884+
validateDiskOfferingChecks(currentServiceOffering, newServiceOffering);
19041885

19051886
int newCpu = newServiceOffering.getCpu();
19061887
int newMemory = newServiceOffering.getRamSize();
@@ -1998,9 +1979,8 @@ private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingI
19981979
}
19991980

20001981
// #3 resize or migrate the root volume if required
2001-
if (currentDiskOffering.isComputeOnly() && newDiskOffering.isComputeOnly()) {
2002-
changeDiskOfferingForRootVolume(vmId, newDiskOffering, customParameters);
2003-
}
1982+
DiskOfferingVO newDiskOffering = _diskOfferingDao.findById(newServiceOffering.getDiskOfferingId());
1983+
changeDiskOfferingForRootVolume(vmId, newDiskOffering, customParameters);
20041984

20051985
// #4 scale the vm now
20061986
vmInstance = _vmInstanceDao.findById(vmId);
@@ -2026,6 +2006,16 @@ private boolean upgradeRunningVirtualMachine(Long vmId, Long newServiceOfferingI
20262006
return success;
20272007
}
20282008

2009+
private void validateDiskOfferingChecks(ServiceOfferingVO currentServiceOffering, ServiceOfferingVO newServiceOffering) {
2010+
if (currentServiceOffering.getDiskOfferingStrictness() != newServiceOffering.getDiskOfferingStrictness()) {
2011+
throw new InvalidParameterValueException("Unable to Scale VM, since disk offering strictness flag is not same for new service offering and old service offering");
2012+
}
2013+
2014+
if (currentServiceOffering.getDiskOfferingStrictness() && currentServiceOffering.getDiskOfferingId() != newServiceOffering.getDiskOfferingId()) {
2015+
throw new InvalidParameterValueException("Unable to Scale VM, since disk offering id associated with the old service offering is not same for new service offering");
2016+
}
2017+
}
2018+
20292019
private void changeDiskOfferingForRootVolume(Long vmId, DiskOfferingVO newDiskOffering, Map<String, String> customParameters) throws ResourceAllocationException {
20302020

20312021
List<VolumeVO> vols = _volsDao.findReadyAndAllocatedRootVolumesByInstance(vmId);

0 commit comments

Comments
 (0)