You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2021/07/02 09:19:30 UTC

[GitHub] [cloudstack] DaanHoogland commented on a change in pull request #4378: server: Optional destination host when migrate a vm

DaanHoogland commented on a change in pull request #4378:
URL: https://github.com/apache/cloudstack/pull/4378#discussion_r662869903



##########
File path: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
##########
@@ -5895,8 +5897,46 @@ public VirtualMachine migrateVirtualMachine(Long vmId, Host destinationHost) thr
             throw new InvalidParameterValueException("Cannot migrate VM, host with id: " + srcHostId + " for VM not found");
         }
 
+        DeployDestination dest = null;
+        if (destinationHost == null) {
+            vm.setLastHostId(null); // Last host does not have higher priority in vm migration
+            final ServiceOfferingVO offering = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
+            final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offering, null, null);
+            final Host host = _hostDao.findById(srcHostId);
+            final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), null, null, null);
+            ExcludeList excludes = new ExcludeList();
+            excludes.addHost(srcHostId);
+            try {
+                dest = _planningMgr.planDeployment(profile, plan, excludes, null);
+            } catch (final AffinityConflictException e2) {
+                s_logger.warn("Unable to create deployment, affinity rules associted to the VM conflict", e2);
+                throw new CloudRuntimeException("Unable to create deployment, affinity rules associted to the VM conflict");
+            } catch (final InsufficientServerCapacityException e3) {
+                throw new CloudRuntimeException("Unable to find a server to migrate the vm to");
+            }
+        } else {
+            dest = checkVmMigrationDestination(vm, srcHost, destinationHost);
+        }
 
-        if (destinationHost.getId() == srcHostId) {
+        // If no suitable destination found then throw exception
+        if (dest == null) {
+            throw new CloudRuntimeException("Unable to find suitable destination to migrate VM " + vm.getInstanceName());
+        }
+
+        UserVmVO uservm = _vmDao.findById(vmId);
+        if (uservm != null) {
+            collectVmDiskStatistics(uservm);
+            collectVmNetworkStatistics(uservm);
+        }
+        _itMgr.migrate(vm.getUuid(), srcHostId, dest);

Review comment:
       sorry, this wasn't clear and also is far less interesting but you could
   ```suggestion
       private void collectStatisticsBeforeMigration(Long vmId)
           UserVmVO uservm = _vmDao.findById(vmId);
           if (uservm != null) {
               collectVmDiskStatistics(uservm);
               collectVmNetworkStatistics(uservm);
           }
       }
   ```
   or 
   ```suggestion
       private void collectStatisticsAndMigrate(Long vmId)
       {
           UserVmVO uservm = _vmDao.findById(vmId);
           if (uservm != null) {
               collectVmDiskStatistics(uservm);
               collectVmNetworkStatistics(uservm);
           }
           _itMgr.migrate(vm.getUuid(), srcHostId, dest);
       }
   ```




-- 
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: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org