bhouse-nexthop commented on code in PR #14752:
URL: https://github.com/apache/cloudstack/pull/14752#discussion_r4754589955


##########
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:
   I'd keep the object here. `StoragePoolVO.toString()` only prints the id, 
uuid, name and pool type (`StoragePool 
{"id":..,"uuid":"..","name":"..","poolType":".."}`), so it stays short, and the 
pools in this list can also be a `PrimaryDataStoreImpl`, whose `toString()` 
delegates to the same method. The name and uuid are what an operator needs to 
find the pool, which the bare id doesn't give them. The volume in the same 
message is printed the same way.



##########
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:
   Good catch, thanks. Changed to `StringUtils.defaultIfBlank`, so an empty 
message now falls back to the exception's class name as well, and added 
`testResizeVolumeNamesTheExceptionWhenMigrationFailureHasNoMessage` for it 
(77ee0def88).



##########
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:
   Same as the other thread: `toString()` on the pool prints only its id, uuid, 
name and pool type, so I've kept the object for the name and uuid.



-- 
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]

Reply via email to