Skip to content

Commit 133ddad

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 cad9a05 commit 133ddad

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
@@ -6194,21 +6194,15 @@ public VirtualMachine migrateVirtualMachineWithVolume(Long vmId, Host destinatio
61946194

61956195
HypervisorCapabilitiesVO capabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(srcHost.getHypervisorType(), srcHost.getHypervisorVersion());
61966196

6197-
if (capabilities == null && HypervisorType.KVM.equals(srcHost.getHypervisorType())) {
6198-
List<HypervisorCapabilitiesVO> lstHypervisorCapabilities = _hypervisorCapabilitiesDao.listAllByHypervisorType(HypervisorType.KVM);
6199-
6200-
if (lstHypervisorCapabilities != null) {
6201-
for (HypervisorCapabilitiesVO hypervisorCapabilities : lstHypervisorCapabilities) {
6202-
if (hypervisorCapabilities.isStorageMotionSupported()) {
6203-
capabilities = hypervisorCapabilities;
6204-
6205-
break;
6206-
}
6207-
}
6197+
if (capabilities == null) {
6198+
if (!HypervisorType.KVM.equals(srcHost.getHypervisorType())) {
6199+
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()));
62086200
}
6209-
}
6201+
List<HypervisorCapabilitiesVO> lstHypervisorCapabilities = _hypervisorCapabilitiesDao.listAllByHypervisorType(HypervisorType.KVM);
62106202

6211-
if (capabilities == null || !capabilities.isStorageMotionSupported()) {
6203+
capabilities = lstHypervisorCapabilities.stream().filter(hvCapabilities -> hvCapabilities.isStorageMotionSupported()).findAny()
6204+
.orElseThrow(() -> new CloudRuntimeException(String.format("Migration with storage isn't supported on hypervisor %s of version %s", srcHost.getHypervisorType(), srcHost.getHypervisorVersion())));
6205+
} else if (!capabilities.isStorageMotionSupported()) {
62126206
throw new CloudRuntimeException(String.format("Migration with storage isn't supported on hypervisor %s of version %s", srcHost.getHypervisorType(), srcHost.getHypervisorVersion()));
62136207
}
62146208

0 commit comments

Comments
 (0)