Skip to content

Commit b07f591

Browse files
committed
address Suresh's comments
1 parent 30bdc38 commit b07f591

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3206,7 +3206,7 @@ protected boolean checkPoolforSpace(StoragePool pool, long allocatedSizeWithTemp
32063206
return false;
32073207
}
32083208
if (!AllowVolumeReSizeBeyondAllocation.valueIn(pool.getDataCenterId())) {
3209-
s_logger.debug(String.format("Skipping the pool %s as %s is false", pool, AllowVolumeReSizeBeyondAllocation.key()));
3209+
logger.debug(String.format("Skipping the pool %s as %s is false", pool, AllowVolumeReSizeBeyondAllocation.key()));
32103210
return false;
32113211
}
32123212

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,16 +1286,26 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep
12861286
}
12871287

12881288
Long newDiskOfferingId = newDiskOffering != null ? newDiskOffering.getId() : diskOffering.getId();
1289-
Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForSystemMigrationOfVolume(volume.getId(), newDiskOfferingId, currentSize, newMinIops, newMaxIops, true, false);
1290-
List<? extends StoragePool> suitableStoragePools = poolsPair.second();
12911289

12921290
boolean volumeMigrateRequired = false;
1291+
List<? extends StoragePool> suitableStoragePoolsWithEnoughSpace = null;
12931292
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
12941293
if (!storageMgr.storagePoolHasEnoughSpaceForResize(storagePool, currentSize, newSize)) {
1295-
volumeMigrateRequired = true;
12961294
if (!autoMigrateVolume) {
1297-
throw new CloudRuntimeException(String.format("Failed to resize volume %s since the storage pool does not have enough space to resize volume %s, automigrate is set to false but volume needs to migrated.", volume.getUuid(), volume.getName()));
1295+
throw new CloudRuntimeException(String.format("Failed to resize volume %s since the storage pool does not have enough space to accommodate new size for the volume %s, try with automigrate set to true in order to check in the other suitable pools for the new size and then migrate & resize volume there.", volume.getUuid(), volume.getName()));
1296+
}
1297+
Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForSystemMigrationOfVolume(volume.getId(), newDiskOfferingId, currentSize, newMinIops, newMaxIops, true, false);
1298+
List<? extends StoragePool> suitableStoragePools = poolsPair.second();
1299+
if (CollectionUtils.isEmpty(poolsPair.first()) && CollectionUtils.isEmpty(poolsPair.second())) {
1300+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Volume resize failed for volume ID: %s as no suitable pool(s) found for migrating to support new disk offering or new size", volume.getUuid()));
12981301
}
1302+
final Long newSizeFinal = newSize;
1303+
suitableStoragePoolsWithEnoughSpace = suitableStoragePools.stream().filter(pool -> storageMgr.storagePoolHasEnoughSpaceForResize(pool, 0L, newSizeFinal)).collect(Collectors.toList());
1304+
if (CollectionUtils.isEmpty(suitableStoragePoolsWithEnoughSpace)) {
1305+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Volume resize failed for volume ID: %s as no suitable pool(s) with enough space found.", volume.getUuid()));
1306+
}
1307+
Collections.shuffle(suitableStoragePoolsWithEnoughSpace);
1308+
volumeMigrateRequired = true;
12991309
}
13001310

13011311
boolean volumeResizeRequired = false;
@@ -1311,24 +1321,15 @@ public VolumeVO resizeVolume(ResizeVolumeCmd cmd) throws ResourceAllocationExcep
13111321
}
13121322

13131323
if (volumeMigrateRequired) {
1314-
if (CollectionUtils.isEmpty(poolsPair.first()) && CollectionUtils.isEmpty(poolsPair.second())) {
1315-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Volume resize operation failed for volume ID: %s as no suitable pool(s) found for migrating to support new disk offering or new size", volume.getUuid()));
1316-
}
1317-
final Long newSizeFinal = newSize;
1318-
List<? extends StoragePool> suitableStoragePoolsWithEnoughSpace = suitableStoragePools.stream().filter(pool -> storageMgr.storagePoolHasEnoughSpaceForResize(pool, 0L, newSizeFinal)).collect(Collectors.toList());
1319-
if (CollectionUtils.isEmpty(suitableStoragePoolsWithEnoughSpace)) {
1320-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Volume resize operation failed for volume ID: %s as no suitable pool(s) with enough space found for volume migration.", volume.getUuid()));
1321-
}
1322-
Collections.shuffle(suitableStoragePoolsWithEnoughSpace);
13231324
MigrateVolumeCmd migrateVolumeCmd = new MigrateVolumeCmd(volume.getId(), suitableStoragePoolsWithEnoughSpace.get(0).getId(), newDiskOfferingId, true);
13241325
try {
13251326
Volume result = migrateVolume(migrateVolumeCmd);
13261327
volume = (result != null) ? _volsDao.findById(result.getId()) : null;
13271328
if (volume == null) {
1328-
throw new CloudRuntimeException(String.format("Volume resize operation failed for volume ID: %s migration failed to storage pool %s", volume.getUuid(), suitableStoragePools.get(0).getId()));
1329+
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()));
13291330
}
13301331
} catch (Exception e) {
1331-
throw new CloudRuntimeException(String.format("Volume resize operation failed for volume ID: %s migration failed to storage pool %s due to %s", volume.getUuid(), suitableStoragePools.get(0).getId(), e.getMessage()));
1332+
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()));
13321333
}
13331334
}
13341335

0 commit comments

Comments
 (0)