sureshanaparti commented on a change in pull request #5029:
URL: https://github.com/apache/cloudstack/pull/5029#discussion_r635217201



##########
File path: server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
##########
@@ -6194,22 +6194,16 @@ public VirtualMachine 
migrateVirtualMachineWithVolume(Long vmId, Host destinatio
 
         HypervisorCapabilitiesVO capabilities = 
_hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(srcHost.getHypervisorType(),
 srcHost.getHypervisorVersion());
 
-        if (capabilities == null && 
HypervisorType.KVM.equals(srcHost.getHypervisorType())) {
-            List<HypervisorCapabilitiesVO> lstHypervisorCapabilities = 
_hypervisorCapabilitiesDao.listAllByHypervisorType(HypervisorType.KVM);
-
-            if (lstHypervisorCapabilities != null) {
-                for (HypervisorCapabilitiesVO hypervisorCapabilities : 
lstHypervisorCapabilities) {
-                    if (hypervisorCapabilities.isStorageMotionSupported()) {
-                        capabilities = hypervisorCapabilities;
-
-                        break;
-                    }
-                }
+        if (capabilities == null) {
+            if (!HypervisorType.KVM.equals(srcHost.getHypervisorType())) {
+                throw new CloudRuntimeException(String.format("Cannot migrate 
VM with storage, as the capabilities are not found for the hypervisor %s with 
version %s", srcHost.getHypervisorType(), srcHost.getHypervisorVersion()));
             }
-        }
+            List<HypervisorCapabilitiesVO> lstHypervisorCapabilities = 
_hypervisorCapabilitiesDao.listAllByHypervisorType(HypervisorType.KVM);
 
-        if (!capabilities.isStorageMotionSupported()) {
-            throw new CloudRuntimeException("Migration with storage isn't 
supported on hypervisor " + srcHost.getHypervisorType() + " of version " + 
srcHost.getHypervisorVersion());
+            capabilities = 
lstHypervisorCapabilities.stream().filter(hvCapabilities -> 
hvCapabilities.isStorageMotionSupported()).findAny()
+            .orElseThrow(() -> new 
CloudRuntimeException(String.format("Migration with storage isn't supported on 
hypervisor %s of version %s", srcHost.getHypervisorType(), 
srcHost.getHypervisorVersion())));

Review comment:
       > @sureshanaparti, actually here we have 2 cases in which exception 
could be thrown
   > 1 - if the `lstHypervisorCapabilities` is empty, then I could use your 
suggestion
   > 2 - if `!isStorageMotionSupported`, then the message should be left 
"Migration with storage isn't supported on hypervisor..."
   > Should I think for a common message for both cases?
   
   @slavkap when `lstHypervisorCapabilities` (for KVM) is not empty, and any of 
the capabilities for KVM (other than that hypervisor version) are checked for 
storage motion support. If no such capabilities exists, then i think, still it 
means there are no capabilities for that hypervisor and version (and you can 
use the same message as the first one).




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