Fix changeOfferingForVolume API to consider storage type in the disk offering (#6377)

This commit is contained in:
Harikrishna 2022-05-13 16:51:15 +05:30 committed by GitHub
parent ea37d757d3
commit 57ecdf9ea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 9 deletions

View File

@ -405,7 +405,7 @@ public interface ManagementService {
*/ */
Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolume(Long volumeId); Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolume(Long volumeId);
Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolumeInternal(Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool); Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolumeInternal(Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool, boolean bypassStorageTypeCheck);
String[] listEventTypes(); String[] listEventTypes();

View File

@ -117,7 +117,7 @@ public class ChangeOfferingForVolumeCmd extends BaseAsyncCmd implements UserCmd
} }
public boolean getAutoMigrate() { public boolean getAutoMigrate() {
return autoMigrate == null ? true : autoMigrate; return autoMigrate == null ? false : autoMigrate;
} }
public boolean isShrinkOk() { public boolean isShrinkOk() {

View File

@ -1526,7 +1526,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
@Override @Override
public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolume(final Long volumeId) { public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolume(final Long volumeId) {
Pair<List<? extends StoragePool>, List<? extends StoragePool>> allPoolsAndSuitablePoolsPair = listStoragePoolsForMigrationOfVolumeInternal(volumeId, null, null, null, null, false); Pair<List<? extends StoragePool>, List<? extends StoragePool>> allPoolsAndSuitablePoolsPair = listStoragePoolsForMigrationOfVolumeInternal(volumeId, null, null, null, null, false, true);
List<? extends StoragePool> allPools = allPoolsAndSuitablePoolsPair.first(); List<? extends StoragePool> allPools = allPoolsAndSuitablePoolsPair.first();
List<? extends StoragePool> suitablePools = allPoolsAndSuitablePoolsPair.second(); List<? extends StoragePool> suitablePools = allPoolsAndSuitablePoolsPair.second();
List<StoragePool> avoidPools = new ArrayList<>(); List<StoragePool> avoidPools = new ArrayList<>();
@ -1542,7 +1542,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools); return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
} }
public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolumeInternal(final Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool) { public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolumeInternal(final Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool, boolean bypassStorageTypeCheck) {
final Account caller = getCaller(); final Account caller = getCaller();
if (!_accountMgr.isRootAdmin(caller.getId())) { if (!_accountMgr.isRootAdmin(caller.getId())) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
@ -1623,7 +1623,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
} }
if (vm != null) { if (vm != null) {
suitablePools = findAllSuitableStoragePoolsForVm(volume, diskOfferingId, newSize, newMinIops, newMaxIops, vm, vmHost, avoid, suitablePools = findAllSuitableStoragePoolsForVm(volume, diskOfferingId, newSize, newMinIops, newMaxIops, vm, vmHost, avoid,
CollectionUtils.isNotEmpty(clusters) ? clusters.get(0) : null, hypervisorType); CollectionUtils.isNotEmpty(clusters) ? clusters.get(0) : null, hypervisorType, bypassStorageTypeCheck);
} else { } else {
suitablePools = findAllSuitableStoragePoolsForDetachedVolume(volume, diskOfferingId, allPools); suitablePools = findAllSuitableStoragePoolsForDetachedVolume(volume, diskOfferingId, allPools);
} }
@ -1714,7 +1714,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
* *
* Side note: the idea behind this method is to provide power for administrators of manually overriding deployments defined by CloudStack. * Side note: the idea behind this method is to provide power for administrators of manually overriding deployments defined by CloudStack.
*/ */
private List<StoragePool> findAllSuitableStoragePoolsForVm(final VolumeVO volume, Long diskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, VMInstanceVO vm, Host vmHost, ExcludeList avoid, Cluster srcCluster, HypervisorType hypervisorType) { private List<StoragePool> findAllSuitableStoragePoolsForVm(final VolumeVO volume, Long diskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, VMInstanceVO vm, Host vmHost, ExcludeList avoid, Cluster srcCluster, HypervisorType hypervisorType, boolean bypassStorageTypeCheck) {
List<StoragePool> suitablePools = new ArrayList<>(); List<StoragePool> suitablePools = new ArrayList<>();
Long clusterId = null; Long clusterId = null;
Long podId = null; Long podId = null;
@ -1736,7 +1736,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
} }
for (StoragePoolAllocator allocator : _storagePoolAllocators) { for (StoragePoolAllocator allocator : _storagePoolAllocators) {
List<StoragePool> pools = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL, true); List<StoragePool> pools = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL, bypassStorageTypeCheck);
if (CollectionUtils.isEmpty(pools)) { if (CollectionUtils.isEmpty(pools)) {
continue; continue;
} }

View File

@ -1765,7 +1765,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
StoragePoolVO existingStoragePool = _storagePoolDao.findById(volume.getPoolId()); StoragePoolVO existingStoragePool = _storagePoolDao.findById(volume.getPoolId());
Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForMigrationOfVolumeInternal(volume.getId(), newDiskOffering.getId(), newSize, newMinIops, newMaxIops, true); Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForMigrationOfVolumeInternal(volume.getId(), newDiskOffering.getId(), newSize, newMinIops, newMaxIops, true, false);
List<? extends StoragePool> suitableStoragePools = poolsPair.second(); List<? extends StoragePool> suitableStoragePools = poolsPair.second();
if (!suitableStoragePools.stream().anyMatch(p -> (p.getId() == existingStoragePool.getId()))) { if (!suitableStoragePools.stream().anyMatch(p -> (p.getId() == existingStoragePool.getId()))) {

View File

@ -794,7 +794,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
continue; continue;
} }
LOGGER.debug(String.format("Volume %s needs to be migrated", volumeVO.getUuid())); LOGGER.debug(String.format("Volume %s needs to be migrated", volumeVO.getUuid()));
Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForMigrationOfVolumeInternal(profile.getVolumeId(), null, null, null, null, false); Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForMigrationOfVolumeInternal(profile.getVolumeId(), null, null, null, null, false, true);
if (CollectionUtils.isEmpty(poolsPair.first()) && CollectionUtils.isEmpty(poolsPair.second())) { if (CollectionUtils.isEmpty(poolsPair.first()) && CollectionUtils.isEmpty(poolsPair.second())) {
cleanupFailedImportVM(vm); cleanupFailedImportVM(vm);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("VM import failed for unmanaged vm: %s during volume ID: %s migration as no suitable pool(s) found", userVm.getInstanceName(), volumeVO.getUuid())); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("VM import failed for unmanaged vm: %s during volume ID: %s migration as no suitable pool(s) found", userVm.getInstanceName(), volumeVO.getUuid()));