Skip to content

Commit e6f51c6

Browse files
committed
Added proper error msgs and reformat code
Add better conditions when check for hypervisor capabilities, and added proper error messages
1 parent 3435a76 commit e6f51c6

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6201,21 +6201,15 @@ public VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinatio
62016201

62026202
HypervisorCapabilitiesVO capabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(srcHost.getHypervisorType(), srcHost.getHypervisorVersion());
62036203

6204-
if (capabilities == null && HypervisorType.KVM.equals(srcHost.getHypervisorType())) {
6205-
List<HypervisorCapabilitiesVO> lstHypervisorCapabilities = _hypervisorCapabilitiesDao.listAllByHypervisorType(HypervisorType.KVM);
6206-
6207-
if (lstHypervisorCapabilities != null) {
6208-
for (HypervisorCapabilitiesVO hypervisorCapabilities : lstHypervisorCapabilities) {
6209-
if (hypervisorCapabilities.isStorageMotionSupported()) {
6210-
capabilities = hypervisorCapabilities;
6211-
6212-
break;
6213-
}
6214-
}
6204+
if (capabilities == null) {
6205+
if (!HypervisorType.KVM.equals(srcHost.getHypervisorType())) {
6206+
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()));
62156207
}
6216-
}
6208+
List<HypervisorCapabilitiesVO> lstHypervisorCapabilities = _hypervisorCapabilitiesDao.listAllByHypervisorType(HypervisorType.KVM);
62176209

6218-
if (capabilities == null || !capabilities.isStorageMotionSupported()) {
6210+
capabilities = lstHypervisorCapabilities.stream().filter(hvCapabilities -> hvCapabilities.isStorageMotionSupported()).findAny()
6211+
.orElseThrow(() -> new CloudRuntimeException(String.format("Migration with storage isn't supported on hypervisor %s of version %s", srcHost.getHypervisorType(), srcHost.getHypervisorVersion())));
6212+
} else if (!capabilities.isStorageMotionSupported()) {
62196213
throw new CloudRuntimeException(String.format("Migration with storage isn't supported on hypervisor %s of version %s", srcHost.getHypervisorType(), srcHost.getHypervisorVersion()));
62206214
}
62216215

0 commit comments

Comments
 (0)