You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add managed storage pool constraints to MigrateWithVolume API method (#2761)
* Add managed storage pool constraints to MigrateWithVolume API method
* Apply mike's suggestions
* Apply Mike's suggestion in a second review
* Mike's suggestions
* Confused bit
* just executeManagedStorageChecks
* Created methods `executeManagedStorageChecksWhenTargetStoragePoolNotProvided` and `executeManagedStorageChecksWhenTargetStoragePoolProvided`
* improve "executeManagedStorageChecksWhenTargetStoragePoolNotProvided"
* Fix "findVolumesThatWereNotMappedByTheUser" method
* Applu Mike's suggestion to improve "createMappingVolumeAndStoragePool" method
* Unit tests to cover modified code
@@ -2286,31 +2286,52 @@ protected void migrate(final VMInstanceVO vm, final long srcHostId, final Deploy
2286
2286
}
2287
2287
2288
2288
/**
2289
-
* Create the mapping of volumes and storage pools. If the user did not enter a mapping on her/his own, we create one using {@link #getDefaultMappingOfVolumesAndStoragePoolForMigration(VirtualMachineProfile, Host)}.
2290
-
* If the user provided a mapping, we use whatever the user has provided (check the method {@link #createMappingVolumeAndStoragePoolEnteredByUser(VirtualMachineProfile, Host, Map)}).
2289
+
* We create the mapping of volumes and storage pool to migrate the VMs according to the information sent by the user.
2290
+
* If the user did not enter a complete mapping, the volumes that were left behind will be auto mapped using {@link #createStoragePoolMappingsForVolumes(VirtualMachineProfile, Host, Map, List)}
if (!volumeToStoragePoolObjectMap.containsKey(volume)) {
2309
+
volumesNotMapped.add(volume);
2310
+
}
2311
+
}
2312
+
returnvolumesNotMapped;
2313
+
}
2314
+
2315
+
/**
2316
+
* Builds the map of storage pools and volumes with the information entered by the user. Before creating the an entry we validate if the migration is feasible checking if the migration is allowed and if the target host can access the defined target storage pool.
if (_poolHostDao.findByPoolHost(targetPool.getId(), host.getId()) == null) {
2313
-
thrownewCloudRuntimeException(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.", volume.getUuid(), targetPool.getUuid(), profile.getUuid(), host.getUuid()));
if (_poolHostDao.findByPoolHost(targetPool.getId(), targetHost.getId()) == null) {
2332
+
thrownewCloudRuntimeException(
2333
+
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.",
* We create the default mapping of volumes and storage pools for the migration of the VM to the target host.
2325
-
* If the current storage pool of one of the volumes is using local storage in the host, it then needs to be migrated to a local storage in the target host.
2326
-
* Otherwise, we do not need to migrate, and the volume can be kept in its current storage pool.
2345
+
* Executes the managed storage checks for the mapping<volume, storage pool> entered by the user. The checks execute by this method are the following.
2346
+
* <ul>
2347
+
* <li> If the current storage pool of the volume is not a managed storage, we do not need to validate anything here.
2348
+
* <li> If the current storage pool is a managed storage and the target storage pool ID is different from the current one, we throw an exception.
thrownewCloudRuntimeException(String.format("Currently, a volume on managed storage can only be 'migrated' to itself " + "[volumeId=%s, currentStoragePoolId=%s, targetStoragePoolId=%s].",
* Executes the managed storage checks for the volumes that the user has not entered a mapping of <volume, storage pool>. The following checks are performed.
2381
+
* <ul>
2382
+
* <li> If the current storage pool is not a managed storage, we do not need to proceed with this method;
2383
+
* <li> We check if the target host has access to the current managed storage pool. If it does not have an exception will be thrown.
if (_poolHostDao.findByPoolHost(currentPool.getId(), targetHost.getId()) == null) {
2391
+
thrownewCloudRuntimeException(String.format("The target host does not have access to the volume's managed storage pool. [volumeId=%s, storageId=%s, targetHostId=%s].", volume.getUuid(),
2392
+
currentPool.getUuid(), targetHost.getUuid()));
2393
+
}
2394
+
}
2395
+
2396
+
/**
2397
+
* 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.
thrownewCloudRuntimeException(String.format("There is not storage pools available at the target host [%s] to migrate volume [%s]", targetHost.getUuid(), volume.getUuid()));
thrownewCloudRuntimeException(String.format("There is not storage pools avaliable at the target host [%s] to migrate volume [%s]", targetHost.getUuid(), volume.getUuid()));
if (!canTargetHostAccessVolumeStoragePool && !volumeToPoolObjectMap.containsKey(volume)) {
2369
-
thrownewCloudRuntimeException(String.format("Cannot find a storage pool which is available for volume [%s] while migrating virtual machine [%s] to host [%s]", volume.getUuid(),
2370
-
profile.getUuid(), targetHost.getUuid()));
2429
+
if (!canTargetHostAccessVolumeCurrentStoragePool) {
* We use {@link StoragePoolAllocator} objects to find local storage pools connected to the targetHost where we would be able to allocate the given volume.
2435
+
* We use {@link StoragePoolAllocator} objects to find storage pools connected to the targetHost where we would be able to allocate the given volume.
0 commit comments