nvazquez commented on a change in pull request #4758:
URL: https://github.com/apache/cloudstack/pull/4758#discussion_r612876821



##########
File path: 
plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java
##########
@@ -210,7 +173,7 @@ private VirtualMachine getVolumeVm(DataObject srcData) {
     private Pair<Long, String> 
getHostIdForVmAndHostGuidInTargetClusterForAttachedVm(VirtualMachine vm,
                                                                                
      StoragePool targetPool,
                                                                                
      ScopeType targetScopeType) {
-        Pair<Long, Long> clusterAndHostId = findClusterAndHostIdForVm(vm);
+        Pair<Long, Long> clusterAndHostId = 
vmManager.findClusterAndHostIdForVm(vm);

Review comment:
       With the above comment, this should be passing vm.getId() instead

##########
File path: 
engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java
##########
@@ -2294,43 +2294,6 @@ private void markVolumesInPool(VMInstanceVO vm, 
StoragePool destPool, Answer[] h
         }
     }
 
-    private Pair<Long, Long> findClusterAndHostIdForVm(VMInstanceVO vm) {
-        Long hostId = vm.getHostId();
-        Long clusterId = null;
-        // OfflineVmwareMigration: probably this is null when vm is stopped
-        if(hostId == null) {
-            hostId = vm.getLastHostId();
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug(String.format("host id is null, using last host 
id %d", hostId) );
-            }
-        }
-        if (hostId == null) {
-            List<VolumeVO> volumes = 
_volsDao.findByInstanceAndType(vm.getId(), Type.ROOT);
-            if (CollectionUtils.isNotEmpty(volumes)) {
-                for (VolumeVO rootVolume : volumes) {
-                    if (rootVolume.getPoolId() != null) {
-                        StoragePoolVO pool = 
_storagePoolDao.findById(rootVolume.getPoolId());
-                        if (pool != null && pool.getClusterId() != null) {
-                            clusterId = pool.getClusterId();
-                            List<HostVO> hosts = 
_hostDao.findHypervisorHostInCluster(pool.getClusterId());
-                            if (CollectionUtils.isNotEmpty(hosts)) {
-                                hostId = hosts.get(0).getId();
-                                break;
-                            }
-                        }
-                    }
-                }
-            }
-        }
-        if (clusterId == null && hostId != null) {
-            HostVO host = _hostDao.findById(hostId);
-            if (host != null) {
-                clusterId = host.getClusterId();
-            }
-        }
-        return new Pair<>(clusterId, hostId);
-    }
-
     private void migrateThroughHypervisorOrStorage(StoragePool destPool, 
VMInstanceVO vm) throws StorageUnavailableException, 
InsufficientCapacityException {
         final VirtualMachineProfile profile = new 
VirtualMachineProfileImpl(vm);
         Pair<Long, Long> vmClusterAndHost = findClusterAndHostIdForVm(vm);

Review comment:
       With the above comment, this should be receiving vm.getId() instead

##########
File path: engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java
##########
@@ -255,4 +256,10 @@ static String getHypervisorHostname(String name) {
     boolean unmanage(String vmUuid);
 
     UserVm restoreVirtualMachine(long vmId, Long newTemplateId) throws 
ResourceUnavailableException, InsufficientCapacityException;
+
+    Pair<Long, Long> findClusterAndHostIdForVmFromVolumes(long vmId);
+
+    Pair<Long, Long> findClusterAndHostIdForVm(VirtualMachine vm);
+
+    Pair<Long, Long> findClusterAndHostIdForVm(long vmId);

Review comment:
       As methods are related, why not leaving only this one and make the first 
two methods as private on the implementation?




-- 
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.

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


Reply via email to