-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Allow to configure root disk size via Service Offering (diskoffering of type Service). #4341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -894,7 +894,7 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep | |
| DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId()); | ||
| DiskOfferingVO newDiskOffering = null; | ||
|
|
||
| if (cmd.getNewDiskOfferingId() != null && volume.getDiskOfferingId() != cmd.getNewDiskOfferingId()) { | ||
| if (cmd.getNewDiskOfferingId() != null) { | ||
| newDiskOffering = _diskOfferingDao.findById(cmd.getNewDiskOfferingId()); | ||
| } | ||
|
|
||
|
|
@@ -913,6 +913,12 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep | |
|
|
||
| // if we are to use the existing disk offering | ||
| if (newDiskOffering == null) { | ||
| if (volume.getVolumeType().equals(Volume.Type.ROOT) && diskOffering.getDiskSize() > 0) { | ||
| throw new InvalidParameterValueException( | ||
| "Failed to resize Root volume. The service offering of this Volume has been configured with a root disk size; " | ||
| + "on such case a Root Volume can only be resized when changing to another Service Offering with a Root disk size. " | ||
| + "For more details please check out the Official Resizing Volumes documentation."); | ||
| } | ||
| newSize = cmd.getSize(); | ||
| newHypervisorSnapshotReserve = volume.getHypervisorSnapshotReserve(); | ||
|
|
||
|
|
@@ -958,10 +964,6 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep | |
| throw new InvalidParameterValueException("Requested disk offering has been removed."); | ||
| } | ||
|
|
||
| if (!DiskOfferingVO.Type.Disk.equals(newDiskOffering.getType())) { | ||
| throw new InvalidParameterValueException("Requested disk offering type is invalid."); | ||
| } | ||
|
|
||
| if (diskOffering.getTags() != null) { | ||
| if (!StringUtils.areTagsEqual(diskOffering.getTags(), newDiskOffering.getTags())) { | ||
| throw new InvalidParameterValueException("The tags on the new and old disk offerings must match."); | ||
|
|
@@ -972,7 +974,9 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep | |
|
|
||
| _configMgr.checkDiskOfferingAccess(_accountMgr.getActiveAccountById(volume.getAccountId()), newDiskOffering, _dcDao.findById(volume.getDataCenterId())); | ||
|
|
||
| if (newDiskOffering.isCustomized()) { | ||
| if (newDiskOffering.getDiskSize() > 0 && DiskOfferingVO.Type.Service.equals(newDiskOffering.getType())) { | ||
| newSize = newDiskOffering.getDiskSize(); | ||
| } else if (newDiskOffering.isCustomized()) { | ||
| newSize = cmd.getSize(); | ||
|
|
||
| if (newSize == null) { | ||
|
|
@@ -989,9 +993,9 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep | |
| newSize = newDiskOffering.getDiskSize(); | ||
| } | ||
|
|
||
| if (!volume.getSize().equals(newSize) && !volume.getVolumeType().equals(Volume.Type.DATADISK)) { | ||
| throw new InvalidParameterValueException("Only data volumes can be resized via a new disk offering."); | ||
| } | ||
| Long instanceId = volume.getInstanceId(); | ||
| VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(instanceId); | ||
| checkIfVolumeIsRootAndVmIsRunning(newSize, volume, vmInstanceVO); | ||
|
|
||
| if (newDiskOffering.isCustomizedIops() != null && newDiskOffering.isCustomizedIops()) { | ||
| newMinIops = cmd.getMinIops() != null ? cmd.getMinIops() : volume.getMinIops(); | ||
|
|
@@ -1140,6 +1144,13 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep | |
| shrinkOk); | ||
| } | ||
|
|
||
| private void checkIfVolumeIsRootAndVmIsRunning(Long newSize, VolumeVO volume, VMInstanceVO vmInstanceVO) { | ||
| if (!volume.getSize().equals(newSize) && volume.getVolumeType().equals(Volume.Type.ROOT) && !State.Stopped.equals(vmInstanceVO.getState())) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any specific reason why we are not allowing resizing when vm is running?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ravening good question. This was done to avoid users thinking that the service offering was updated correctly. Unfortunatelly, it is necessary to Stop/Start the VM, otherwise IOps updates would not take effect, for example. Considering that this is a service offering update command, then we need to take such situations into account. Additionally, not all operation systems support dynamic memory scaling. |
||
| throw new InvalidParameterValueException(String.format("Cannot resize ROOT volume [%s] when VM is not on Stopped State. VM %s is in state %.", volume.getName(), vmInstanceVO | ||
| .getInstanceName(), vmInstanceVO.getState())); | ||
| } | ||
| } | ||
|
|
||
| private void validateIops(Long minIops, Long maxIops) { | ||
| if ((minIops == null && maxIops != null) || (minIops != null && maxIops == null)) { | ||
| throw new InvalidParameterValueException("Either 'miniops' and 'maxiops' must both be provided or neither must be provided."); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An optimization suggestion here. You can write below one liner since
rootDiskSizeInBytesis not used anywhere elseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ravening that does not make any difference. The JVM feeds its bytecodes to the Just-In-Time compiler (JIT) which will already take care of doing such optimization (among many others).
I did that way because of 2 reasons, one tecnical and the other a personal option: (i) in case of remote debugging connected via JVM it helps on changing a variable value in runtime; (ii) I prefer that way for code readability.