mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
server: Prevent NPE if hypervisor's capabilities are null (#5029)
If the hypervisor's capabilities are null, CloudRuntimeException will be thrown; Format the error message.
This commit is contained in:
parent
c6ba3d1bea
commit
d47e273329
@ -6201,22 +6201,16 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
||||
|
||||
HypervisorCapabilitiesVO capabilities = _hypervisorCapabilitiesDao.findByHypervisorTypeAndVersion(srcHost.getHypervisorType(), srcHost.getHypervisorVersion());
|
||||
|
||||
if (capabilities == null && HypervisorType.KVM.equals(srcHost.getHypervisorType())) {
|
||||
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 (lstHypervisorCapabilities != null) {
|
||||
for (HypervisorCapabilitiesVO hypervisorCapabilities : lstHypervisorCapabilities) {
|
||||
if (hypervisorCapabilities.isStorageMotionSupported()) {
|
||||
capabilities = hypervisorCapabilities;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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("Cannot migrate VM with storage, as the capabilities are not found for the hypervisor %s with version %s", srcHost.getHypervisorType(), srcHost.getHypervisorVersion())));
|
||||
} else if (!capabilities.isStorageMotionSupported()) {
|
||||
throw new CloudRuntimeException(String.format("Migration with storage isn't supported on hypervisor %s of version %s", srcHost.getHypervisorType(), srcHost.getHypervisorVersion()));
|
||||
}
|
||||
|
||||
// Check if destination host is up.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user