JoaoJandre commented on code in PR #6833:
URL: https://github.com/apache/cloudstack/pull/6833#discussion_r1002108208


##########
plugins/hypervisors/xenserver/src/main/java/org/apache/cloudstack/storage/motion/XenServerStorageMotionStrategy.java:
##########
@@ -310,80 +443,80 @@ private void 
handleManagedVolumesAfterFailedMigration(Map<VolumeInfo, DataStore>
     private Answer migrateVmWithVolumesAcrossCluster(VMInstanceVO vm, 
VirtualMachineTO to, Host srcHost, Host destHost, Map<VolumeInfo, DataStore> 
volumeToPool)
             throws AgentUnavailableException {
         // Initiate migration of a virtual machine with its volumes.
+        verifyNoSnapshotsOnManagedStorageVolumes(volumeToPool);
 
-        try {
-            verifyNoSnapshotsOnManagedStorageVolumes(volumeToPool);
-
-            List<Pair<VolumeTO, String>> volumeToStorageUuid = new 
ArrayList<>();
+        List<Pair<VolumeTO, String>> volumeToStorageUuid = new ArrayList<>();
 
-            for (Map.Entry<VolumeInfo, DataStore> entry : 
volumeToPool.entrySet()) {
-                VolumeInfo volumeInfo = entry.getKey();
-                StoragePool storagePool = 
storagePoolDao.findById(volumeInfo.getPoolId());
-                VolumeTO volumeTo = new VolumeTO(volumeInfo, storagePool);
+        for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) 
{
+            VolumeInfo volumeInfo = entry.getKey();
+            StoragePool storagePool = 
storagePoolDao.findById(volumeInfo.getPoolId());
+            VolumeTO volumeTo = new VolumeTO(volumeInfo, storagePool);
 
-                if (storagePool.isManaged()) {
-                    String iqn = handleManagedVolumePreMigration(volumeInfo, 
storagePool, destHost);
+            if (storagePool.isManaged()) {
+                String iqn = handleManagedVolumePreMigration(volumeInfo, 
storagePool, destHost);
 
-                    volumeToStorageUuid.add(new Pair<>(volumeTo, iqn));
-                }
-                else {
-                    StoragePool pool = (StoragePool)entry.getValue();
-                    String srNameLabel = 
CitrixHelper.getSRNameLabel(pool.getUuid(), pool.getPoolType(), pool.getPath());
-                    volumeToStorageUuid.add(new Pair<>(volumeTo, srNameLabel));
-                }
+                volumeToStorageUuid.add(new Pair<>(volumeTo, iqn));
             }
+            else {
+                StoragePool pool = (StoragePool) entry.getValue();
+                String srNameLabel = 
CitrixHelper.getSRNameLabel(pool.getUuid(), pool.getPoolType(), pool.getPath());
+                volumeToStorageUuid.add(new Pair<>(volumeTo, srNameLabel));
+            }
+        }
 
-            // Migration across cluster needs to be done in three phases.
-            // 1. Send a migrate receive command to the destination host so 
that it is ready to receive a vm.
-            // 2. Send a migrate send command to the source host. This 
actually migrates the vm to the destination.
-            // 3. Complete the process. Update the volume details.
+        // Migration across cluster needs to be done in three phases.
+        // 1. Send a migrate receive command to the destination host so that 
it is ready to receive a vm.
+        // 2. Send a migrate send command to the source host. This actually 
migrates the vm to the destination.
+        // 3. Complete the process. Update the volume details.
+        MigrateWithStorageCompleteAnswer answer;
+        try {
+            answer = migrateVolumeAcrossCluster(to, srcHost, destHost, 
volumeToStorageUuid);
+        } catch (OperationTimedoutException e) {
+            s_logger.error("Error while migrating vm " + vm + " to host " + 
destHost, e);
+            throw new AgentUnavailableException("Operation timed out on 
storage motion for " + vm, destHost.getId());
+        } catch (CloudRuntimeException e) {
+            s_logger.error("Error on vm " + vm + " " + e.getMessage());
+            handleManagedVolumesAfterFailedMigration(volumeToPool, destHost);
+            throw e;
+        }
 
-            MigrateWithStorageReceiveCommand receiveCmd = new 
MigrateWithStorageReceiveCommand(to, volumeToStorageUuid);
-            MigrateWithStorageReceiveAnswer receiveAnswer = 
(MigrateWithStorageReceiveAnswer)agentMgr.send(destHost.getId(), receiveCmd);
+        // s_logger.error("Migration with storage of vm " + vm + " to host " + 
destHost + " failed.");

Review Comment:
   ```suggestion
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to