use of org.apache.cloudstack.api.command.user.volume.ChangeOfferingForVolumeCmd in project cloudstack by apache.
the class UserVmManagerImpl method changeDiskOfferingForRootVolume.
private void changeDiskOfferingForRootVolume(Long vmId, DiskOfferingVO newDiskOffering, Map<String, String> customParameters) throws ResourceAllocationException {
List<VolumeVO> vols = _volsDao.findReadyAndAllocatedRootVolumesByInstance(vmId);
for (final VolumeVO rootVolumeOfVm : vols) {
DiskOfferingVO currentRootDiskOffering = _diskOfferingDao.findById(rootVolumeOfVm.getDiskOfferingId());
HypervisorType hypervisorType = _volsDao.getHypervisorType(rootVolumeOfVm.getId());
if (HypervisorType.Simulator != hypervisorType) {
Long minIopsInNewDiskOffering = null;
Long maxIopsInNewDiskOffering = null;
boolean autoMigrate = false;
boolean shrinkOk = false;
if (customParameters.containsKey(ApiConstants.MIN_IOPS)) {
minIopsInNewDiskOffering = Long.parseLong(customParameters.get(ApiConstants.MIN_IOPS));
}
if (customParameters.containsKey(ApiConstants.MAX_IOPS)) {
minIopsInNewDiskOffering = Long.parseLong(customParameters.get(ApiConstants.MAX_IOPS));
}
if (customParameters.containsKey(ApiConstants.AUTO_MIGRATE)) {
autoMigrate = Boolean.parseBoolean(customParameters.get(ApiConstants.AUTO_MIGRATE));
}
if (customParameters.containsKey(ApiConstants.SHRINK_OK)) {
shrinkOk = Boolean.parseBoolean(customParameters.get(ApiConstants.SHRINK_OK));
}
ChangeOfferingForVolumeCmd changeOfferingForVolumeCmd = new ChangeOfferingForVolumeCmd(rootVolumeOfVm.getId(), newDiskOffering.getId(), minIopsInNewDiskOffering, maxIopsInNewDiskOffering, autoMigrate, shrinkOk);
Volume result = _volumeService.changeDiskOfferingForVolume(changeOfferingForVolumeCmd);
if (result == null) {
throw new CloudRuntimeException("Failed to change disk offering of the root volume");
}
} else if (newDiskOffering.getDiskSize() > 0 && currentRootDiskOffering.getDiskSize() != newDiskOffering.getDiskSize()) {
throw new InvalidParameterValueException("Hypervisor " + hypervisorType + " does not support volume resize");
}
}
}
Aggregations