DaanHoogland commented on a change in pull request #6005:
URL: https://github.com/apache/cloudstack/pull/6005#discussion_r809885469
##########
File path:
engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
##########
@@ -92,7 +92,7 @@ public VolumeInfo getVolume() {
AsyncCallFuture<VolumeApiResult> resize(VolumeInfo volume);
- void resizeVolumeOnHypervisor(long volumeId, long newSize, long
destHostId, String instanceName);
+ void resizeVolumeOnHypervisor(long volumeId, long currentSize, long
newSize, long destHostId, String instanceName);
Review comment:
why is the parameter be called `currentSize` needed? seems like
`newSize` is enough.
##########
File path: server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
##########
@@ -364,7 +379,27 @@ public VolumeVO uploadVolume(UploadVolumeCmd cmd) throws
ResourceAllocationExcep
RegisterVolumePayload payload = new
RegisterVolumePayload(cmd.getUrl(), cmd.getChecksum(), cmd.getFormat());
vol.addPayload(payload);
- volService.registerVolume(vol, store);
+ try {
+ AsyncCallFuture<VolumeApiResult> future =
volService.registerVolume(vol, store);
+ VolumeApiResult result = future.get();
+ if (result.isFailed()) {
+ s_logger.warn("Failed to resize the volume " + volume);
+ String details = "";
+ if (result.getResult() != null &&
!result.getResult().isEmpty()) {
+ details = result.getResult();
+ }
+ throw new CloudRuntimeException(details);
+ }
+ volume = _volsDao.findById(vol.getId());
+ if (!Objects.equals(sizeInGB, vol.getSize())) {
+ if (sizeInGB !=null) {
+ volume.setSize(sizeInGB * GiB_TO_BYTES);
+ _volsDao.persist(volume);
+ }
+ }
+ } catch (Exception e) {
+ throw new CloudRuntimeException(String.format("Failed to register
volume due to - %s", e.getMessage()), e);
+ }
Review comment:
can you extract?
##########
File path: server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
##########
@@ -353,9 +354,23 @@ public VolumeVO uploadVolume(UploadVolumeCmd cmd) throws
ResourceAllocationExcep
String format = cmd.getFormat();
Long diskOfferingId = cmd.getDiskOfferingId();
String imageStoreUuid = cmd.getImageStoreUuid();
+ Long sizeInGB = cmd.getSize();
+
DataStore store = _tmpltMgr.getImageStore(imageStoreUuid, zoneId);
validateVolume(caller, ownerId, zoneId, volumeName, url, format,
diskOfferingId);
+ DiskOfferingVO diskOffering =
_diskOfferingDao.findById(diskOfferingId);
+ if (diskOffering != null && diskOffering.isCustomized()) {
+ if (sizeInGB == null) {
+ throw new InvalidParameterValueException("This disk offering
requires a custom size specified");
+ }
+ Long customDiskOfferingMaxSize =
VolumeOrchestrationService.CustomDiskOfferingMaxSize.value();
+ Long customDiskOfferingMinSize =
VolumeOrchestrationService.CustomDiskOfferingMinSize.value();
+
+ if ((sizeInGB < customDiskOfferingMinSize) || (sizeInGB >
customDiskOfferingMaxSize)) {
+ throw new InvalidParameterValueException("Volume size: " +
sizeInGB + "GB is out of allowed range. Max: " + customDiskOfferingMaxSize + "
Min:" + customDiskOfferingMinSize);
+ }
+ }
Review comment:
can you extract this and give a good merthod name?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]