use of org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd in project cloudstack by apache.
the class KubernetesClusterResourceModifierActionWorker method resizeNodeVolume.
protected void resizeNodeVolume(final UserVm vm) throws ManagementServerException {
try {
if (vm.getHypervisorType() == Hypervisor.HypervisorType.VMware && templateDao.findById(vm.getTemplateId()).isDeployAsIs()) {
List<VolumeVO> vmVols = volumeDao.findByInstance(vm.getId());
for (VolumeVO volumeVO : vmVols) {
if (volumeVO.getVolumeType() == Volume.Type.ROOT) {
ResizeVolumeCmd resizeVolumeCmd = new ResizeVolumeCmd();
resizeVolumeCmd = ComponentContext.inject(resizeVolumeCmd);
Field f = resizeVolumeCmd.getClass().getDeclaredField("size");
Field f1 = resizeVolumeCmd.getClass().getDeclaredField("id");
f.setAccessible(true);
f1.setAccessible(true);
f1.set(resizeVolumeCmd, volumeVO.getId());
f.set(resizeVolumeCmd, kubernetesCluster.getNodeRootDiskSize());
volumeService.resizeVolume(resizeVolumeCmd);
}
}
}
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new ManagementServerException(String.format("Failed to resize volume of VM in the Kubernetes cluster : %s", kubernetesCluster.getName()), e);
}
}
use of org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd in project cloudstack by apache.
the class UserVmManagerImpl method prepareResizeVolumeCmd.
/**
* Prepares the Resize Volume Command and verifies if the disk offering from the new service offering can be resized.
* <br>
* If the Service Offering was configured with a root disk size (size > 0) then it can only resize to an offering with a larger disk
* or to an offering with a root size of zero, which is the default behavior.
*/
protected ResizeVolumeCmd prepareResizeVolumeCmd(VolumeVO rootVolume, DiskOfferingVO currentRootDiskOffering, DiskOfferingVO newRootDiskOffering) {
if (rootVolume == null) {
throw new InvalidParameterValueException("Could not find Root volume for the VM while preparing the Resize Volume Command.");
}
if (currentRootDiskOffering == null) {
throw new InvalidParameterValueException("Could not find Disk Offering matching the provided current Root Offering ID.");
}
if (newRootDiskOffering == null) {
throw new InvalidParameterValueException("Could not find Disk Offering matching the provided Offering ID for resizing Root volume.");
}
ResizeVolumeCmd resizeVolumeCmd = new ResizeVolumeCmd(rootVolume.getId(), newRootDiskOffering.getMinIops(), newRootDiskOffering.getMaxIops());
long newNewOfferingRootSizeInBytes = newRootDiskOffering.getDiskSize();
long newNewOfferingRootSizeInGiB = newNewOfferingRootSizeInBytes / GiB_TO_BYTES;
long currentRootDiskOfferingGiB = currentRootDiskOffering.getDiskSize() / GiB_TO_BYTES;
if (newNewOfferingRootSizeInBytes > currentRootDiskOffering.getDiskSize()) {
resizeVolumeCmd = new ResizeVolumeCmd(rootVolume.getId(), newRootDiskOffering.getMinIops(), newRootDiskOffering.getMaxIops(), newRootDiskOffering.getId());
s_logger.debug(String.format("Preparing command to resize VM Root disk from %d GB to %d GB; current offering: %s, new offering: %s.", currentRootDiskOfferingGiB, newNewOfferingRootSizeInGiB, currentRootDiskOffering.getName(), newRootDiskOffering.getName()));
} else if (newNewOfferingRootSizeInBytes > 0l && newNewOfferingRootSizeInBytes < currentRootDiskOffering.getDiskSize()) {
throw new InvalidParameterValueException(String.format("Failed to resize Root volume. The new Service Offering [id: %d, name: %s] has a smaller disk size [%d GB] than the current disk [%d GB].", newRootDiskOffering.getId(), newRootDiskOffering.getName(), newNewOfferingRootSizeInGiB, currentRootDiskOfferingGiB));
}
return resizeVolumeCmd;
}
use of org.apache.cloudstack.api.command.user.volume.ResizeVolumeCmd in project cloudstack by apache.
the class UserVmManagerImplTest method prepareAndRunResizeVolumeTest.
private void prepareAndRunResizeVolumeTest(Long expectedOfferingId, long expectedMinIops, long expectedMaxIops, DiskOfferingVO currentRootDiskOffering, DiskOfferingVO newRootDiskOffering) {
long rootVolumeId = 1l;
VolumeVO rootVolumeOfVm = Mockito.mock(VolumeVO.class);
Mockito.when(rootVolumeOfVm.getId()).thenReturn(rootVolumeId);
ResizeVolumeCmd resizeVolumeCmd = userVmManagerImpl.prepareResizeVolumeCmd(rootVolumeOfVm, currentRootDiskOffering, newRootDiskOffering);
Assert.assertEquals(rootVolumeId, resizeVolumeCmd.getId().longValue());
Assert.assertEquals(expectedOfferingId, resizeVolumeCmd.getNewDiskOfferingId());
Assert.assertEquals(expectedMinIops, resizeVolumeCmd.getMinIops().longValue());
Assert.assertEquals(expectedMaxIops, resizeVolumeCmd.getMaxIops().longValue());
}
Aggregations