Skip to content

Commit 57ecdf9

Browse files
Fix changeOfferingForVolume API to consider storage type in the disk offering (apache#6377)
1 parent ea37d75 commit 57ecdf9

5 files changed

Lines changed: 9 additions & 9 deletions

File tree

‎api/src/main/java/com/cloud/server/ManagementService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public interface ManagementService {
405405
*/
406406
Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolume(Long volumeId);
407407

408-
Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolumeInternal(Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool);
408+
Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolumeInternal(Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool, boolean bypassStorageTypeCheck);
409409

410410
String[] listEventTypes();
411411

‎api/src/main/java/org/apache/cloudstack/api/command/user/volume/ChangeOfferingForVolumeCmd.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public Long getMaxIops() {
117117
}
118118

119119
public boolean getAutoMigrate() {
120-
return autoMigrate == null ? true : autoMigrate;
120+
return autoMigrate == null ? false : autoMigrate;
121121
}
122122

123123
public boolean isShrinkOk() {

‎server/src/main/java/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ private boolean hasSuitablePoolsForVolume(final VolumeVO volume, final Host host
15261526
@Override
15271527
public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolume(final Long volumeId) {
15281528

1529-
Pair<List<? extends StoragePool>, List<? extends StoragePool>> allPoolsAndSuitablePoolsPair = listStoragePoolsForMigrationOfVolumeInternal(volumeId, null, null, null, null, false);
1529+
Pair<List<? extends StoragePool>, List<? extends StoragePool>> allPoolsAndSuitablePoolsPair = listStoragePoolsForMigrationOfVolumeInternal(volumeId, null, null, null, null, false, true);
15301530
List<? extends StoragePool> allPools = allPoolsAndSuitablePoolsPair.first();
15311531
List<? extends StoragePool> suitablePools = allPoolsAndSuitablePoolsPair.second();
15321532
List<StoragePool> avoidPools = new ArrayList<>();
@@ -1542,7 +1542,7 @@ public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStorag
15421542
return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
15431543
}
15441544

1545-
public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolumeInternal(final Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool) {
1545+
public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStoragePoolsForMigrationOfVolumeInternal(final Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool, boolean bypassStorageTypeCheck) {
15461546
final Account caller = getCaller();
15471547
if (!_accountMgr.isRootAdmin(caller.getId())) {
15481548
if (s_logger.isDebugEnabled()) {
@@ -1623,7 +1623,7 @@ public Pair<List<? extends StoragePool>, List<? extends StoragePool>> listStorag
16231623
}
16241624
if (vm != null) {
16251625
suitablePools = findAllSuitableStoragePoolsForVm(volume, diskOfferingId, newSize, newMinIops, newMaxIops, vm, vmHost, avoid,
1626-
CollectionUtils.isNotEmpty(clusters) ? clusters.get(0) : null, hypervisorType);
1626+
CollectionUtils.isNotEmpty(clusters) ? clusters.get(0) : null, hypervisorType, bypassStorageTypeCheck);
16271627
} else {
16281628
suitablePools = findAllSuitableStoragePoolsForDetachedVolume(volume, diskOfferingId, allPools);
16291629
}
@@ -1714,7 +1714,7 @@ private List<? extends StoragePool> getAllStoragePoolCompatibleWithVolumeSourceS
17141714
*
17151715
* Side note: the idea behind this method is to provide power for administrators of manually overriding deployments defined by CloudStack.
17161716
*/
1717-
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) {
1717+
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) {
17181718
List<StoragePool> suitablePools = new ArrayList<>();
17191719
Long clusterId = null;
17201720
Long podId = null;
@@ -1736,7 +1736,7 @@ private List<StoragePool> findAllSuitableStoragePoolsForVm(final VolumeVO volume
17361736
}
17371737

17381738
for (StoragePoolAllocator allocator : _storagePoolAllocators) {
1739-
List<StoragePool> pools = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL, true);
1739+
List<StoragePool> pools = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL, bypassStorageTypeCheck);
17401740
if (CollectionUtils.isEmpty(pools)) {
17411741
continue;
17421742
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ private Volume changeDiskOfferingForVolumeInternal(VolumeVO volume, Long newDisk
17651765

17661766
StoragePoolVO existingStoragePool = _storagePoolDao.findById(volume.getPoolId());
17671767

1768-
Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForMigrationOfVolumeInternal(volume.getId(), newDiskOffering.getId(), newSize, newMinIops, newMaxIops, true);
1768+
Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForMigrationOfVolumeInternal(volume.getId(), newDiskOffering.getId(), newSize, newMinIops, newMaxIops, true, false);
17691769
List<? extends StoragePool> suitableStoragePools = poolsPair.second();
17701770

17711771
if (!suitableStoragePools.stream().anyMatch(p -> (p.getId() == existingStoragePool.getId()))) {

‎server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ private UserVm migrateImportedVM(HostVO sourceHost, VirtualMachineTemplate templ
794794
continue;
795795
}
796796
LOGGER.debug(String.format("Volume %s needs to be migrated", volumeVO.getUuid()));
797-
Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForMigrationOfVolumeInternal(profile.getVolumeId(), null, null, null, null, false);
797+
Pair<List<? extends StoragePool>, List<? extends StoragePool>> poolsPair = managementService.listStoragePoolsForMigrationOfVolumeInternal(profile.getVolumeId(), null, null, null, null, false, true);
798798
if (CollectionUtils.isEmpty(poolsPair.first()) && CollectionUtils.isEmpty(poolsPair.second())) {
799799
cleanupFailedImportVM(vm);
800800
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()));

0 commit comments

Comments
 (0)