Skip to content

Commit bea1dad

Browse files
author
Mike Tutkowski
committed
More ideas for PR 2761
1 parent 07279b4 commit bea1dad

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,7 +2320,7 @@ private void buildMapUsingUserInformation(VirtualMachineProfile profile, Host ta
23202320
StoragePoolVO targetPool = _storagePoolDao.findById(poolId);
23212321
StoragePoolVO currentPool = _storagePoolDao.findById(volume.getPoolId());
23222322

2323-
executeManagedStorageChecksWhenTargetStoragePoolProvided(currentPool, targetPool, volume);
2323+
executeManagedStorageChecks(currentPool, targetPool, volume);
23242324
if (_poolHostDao.findByPoolHost(targetPool.getId(), targetHost.getId()) == null) {
23252325
throw new CloudRuntimeException(
23262326
String.format("Cannot migrate the volume [%s] to the storage pool [%s] while migrating VM [%s] to target host [%s]. The host does not have access to the storage pool entered.",
@@ -2341,12 +2341,22 @@ private void createStoragePoolMappingsForVolumes(VirtualMachineProfile profile,
23412341
for (Volume volume : allVolumes) {
23422342
StoragePoolVO currentPool = _storagePoolDao.findById(volume.getPoolId());
23432343

2344-
executeManagedStorageChecksWhenTargetStoragePoolNotProvided(targetHost, currentPool, volume);
2345-
if (ScopeType.HOST.equals(currentPool.getScope()) || isStorageCrossClusterMigration(targetHost, currentPool)) {
2346-
createVolumeToStoragePoolMappingIfPossible(profile, targetHost, volumeToPoolObjectMap, volume, currentPool);
2347-
} else {
2344+
if (currentPool.isManaged()) {
2345+
if (_poolHostDao.findByPoolHost(currentPool.getId(), targetHost.getId()) == null) {
2346+
throw new CloudRuntimeException(
2347+
String.format("Cannot migrate the volume [%s] to the storage pool [%s] while migrating VM [%s] to target host [%s]. The host does not have access " +
2348+
"to the storage pool entered.", volume.getUuid(), currentPool.getUuid(), profile.getUuid(), targetHost.getUuid()));
2349+
}
2350+
23482351
volumeToPoolObjectMap.put(volume, currentPool);
23492352
}
2353+
else {
2354+
if (ScopeType.HOST.equals(currentPool.getScope()) || isStorageCrossClusterMigration(targetHost, currentPool)) {
2355+
createVolumeToStoragePoolMappingIfPossible(profile, targetHost, volumeToPoolObjectMap, volume, currentPool);
2356+
} else {
2357+
volumeToPoolObjectMap.put(volume, currentPool);
2358+
}
2359+
}
23502360
}
23512361
}
23522362

@@ -2357,7 +2367,7 @@ private void createStoragePoolMappingsForVolumes(VirtualMachineProfile profile,
23572367
* <li> Cross cluster migration with cluster-wide storage pool. Volumes in managed storage cannot be migrated out of their current pool. Therefore, an exception is thrown.
23582368
* </ul>
23592369
*/
2360-
protected void executeManagedStorageChecksWhenTargetStoragePoolProvided(StoragePoolVO currentPool, StoragePoolVO targetPool, Volume volume) {
2370+
protected void executeManagedStorageChecks(StoragePoolVO currentPool, StoragePoolVO targetPool, Volume volume) {
23612371
if (!currentPool.isManaged()) {
23622372
return;
23632373
}
@@ -2368,17 +2378,6 @@ protected void executeManagedStorageChecksWhenTargetStoragePoolProvided(StorageP
23682378
"[volumeId=%s, currentStoragePoolId=%s, targetStoragePoolId=%s].", volume.getUuid(), currentPool.getUuid(), targetPool.getUuid()));
23692379
}
23702380

2371-
protected void executeManagedStorageChecksWhenTargetStoragePoolNotProvided(Host targetHost, StoragePoolVO currentPool, Volume volume) {
2372-
if (!currentPool.isManaged()) {
2373-
return;
2374-
}
2375-
if (ScopeType.ZONE.equals(currentPool.getScope())) {
2376-
return;
2377-
}
2378-
throw new CloudRuntimeException(String.format("Currently, you can only 'migrate' a volume on managed storage if its storage pool is zone wide " +
2379-
"[volumeId=%s, storageId=%s, targetHostId=%s].", volume.getUuid(), currentPool.getUuid(), targetHost.getUuid()));
2380-
}
2381-
23822381
/**
23832382
* Return true if the VM migration is a cross cluster migration. To execute that, we check if the volume current storage pool cluster is different from the target host cluster.
23842383
*/

0 commit comments

Comments
 (0)