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



##########
File path: 
plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java
##########
@@ -138,11 +144,83 @@ private boolean isOnVmware(DataObject srcData, DataObject 
destData) {
                 && 
HypervisorType.VMware.equals(destData.getTO().getHypervisorType());
     }
 
-    private Pair<Long, String> 
getHostIdForVmAndHostGuidInTargetCluster(DataObject srcData, DataObject 
destData) {
-        StoragePool sourcePool = (StoragePool) srcData.getDataStore();
-        ScopeType sourceScopeType = 
srcData.getDataStore().getScope().getScopeType();
-        StoragePool targetPool = (StoragePool) destData.getDataStore();
-        ScopeType targetScopeType = 
destData.getDataStore().getScope().getScopeType();
+    private Pair<Long, Long> findClusterAndHostIdForVm(VirtualMachine 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 = volDao.findByInstanceAndType(vm.getId(), 
Volume.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);
+    }

Review comment:
       thanks @harikrishna-patnala. Done.




-- 
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:
us...@infra.apache.org


Reply via email to