sathvikaragi commented on code in PR #14752:
URL: https://github.com/apache/cloudstack/pull/14752#discussion_r4752758345
##########
server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java:
##########
@@ -1410,16 +1410,9 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws
ResourceAllocationExcep
}
if (volumeMigrateRequired) {
- MigrateVolumeCmd migrateVolumeCmd = new
MigrateVolumeCmd(volume.getId(),
suitableStoragePoolsWithEnoughSpace.get(0).getId(), newDiskOfferingId, true);
- try {
- Volume result = migrateVolume(migrateVolumeCmd);
- volume = (result != null) ?
_volsDao.findById(result.getId()) : null;
- if (volume == null) {
- throw new CloudRuntimeException(String.format("Volume
resize operation failed for volume ID: %s as migration failed to storage pool
%s accommodating new size", volume.getUuid(),
suitableStoragePoolsWithEnoughSpace.get(0).getId()));
- }
- } catch (Exception e) {
- throw new CloudRuntimeException(String.format("Volume
resize operation failed for volume ID: %s as migration failed to storage pool
%s accommodating new size", volume.getUuid(),
suitableStoragePoolsWithEnoughSpace.get(0).getId()));
- }
+ StoragePool destPool =
suitableStoragePoolsWithEnoughSpace.get(0);
+ volume = migrateVolumeToPool(volume, destPool,
newDiskOfferingId,
+ String.format("Volume resize operation failed for
volume ID: %s as migration failed to storage pool %s accommodating new size",
volume.getUuid(), destPool));
Review Comment:
destPool is passed directly as %s which calls toString() on the
StoragePoolVO object this may produce a verbose string . Consider using
destPool.getId() or name.
##########
server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java:
##########
@@ -2251,16 +2244,9 @@ public Volume changeDiskOfferingForVolumeInternal(Long
volumeId, Long newDiskOff
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
String.format("Volume change offering operation failed for volume: %s as no
suitable pool(s) with enough space found for volume migration.", volume));
}
Collections.shuffle(suitableStoragePoolsWithEnoughSpace);
- MigrateVolumeCmd migrateVolumeCmd = new
MigrateVolumeCmd(volume.getId(),
suitableStoragePoolsWithEnoughSpace.get(0).getId(), newDiskOffering.getId(),
true);
- try {
- Volume result = migrateVolume(migrateVolumeCmd);
- volume = (result != null) ?
_volsDao.findById(result.getId()) : null;
- if (volume == null) {
- throw new CloudRuntimeException(String.format("Volume
change offering operation failed for volume: %s migration failed to storage
pool %s", volume, suitableStoragePools.get(0)));
- }
- } catch (Exception e) {
- throw new CloudRuntimeException(String.format("Volume
change offering operation failed for volume: %s migration failed to storage
pool %s due to %s", volume, suitableStoragePools.get(0), e.getMessage()));
- }
+ StoragePool destPool =
suitableStoragePoolsWithEnoughSpace.get(0);
+ volume = migrateVolumeToPool(volume, destPool,
newDiskOffering.getId(),
+ String.format("Volume change offering operation failed
for volume: %s migration failed to storage pool %s", volume, destPool));
Review Comment:
destPool and volume are passed directly as %s which calls toString() on the
StoragePoolVO object this may produce a verbose string . Consider using
destPool.getId() or name.
##########
server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java:
##########
@@ -2284,6 +2270,20 @@ public Volume changeDiskOfferingForVolumeInternal(Long
volumeId, Long newDiskOff
}
}
+ private VolumeVO migrateVolumeToPool(VolumeVO volume, StoragePool
destPool, Long newDiskOfferingId, String failureMessage) {
+ Volume result;
+ try {
+ result = migrateVolume(new MigrateVolumeCmd(volume.getId(),
destPool.getId(), newDiskOfferingId, true));
+ } catch (Exception e) {
+ throw new CloudRuntimeException(String.format("%s due to %s",
failureMessage, ObjectUtils.defaultIfNull(e.getMessage(),
e.getClass().getSimpleName())), e);
Review Comment:
Some exceptions return an empty string from getMessage() rather than null.
ObjectUtils.defaultIfNull won't catch that case and the error message would end
with "due to ". Suggest using StringUtils.defaultIfBlank() instead it handles
both null and empty
--
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]