sureshanaparti commented on code in PR #9787: URL: https://github.com/apache/cloudstack/pull/9787#discussion_r1802983952
########## server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java: ########## @@ -1781,18 +1788,54 @@ private Map<String, String> createParamsForRemoveClonedInstance(String vcenter, return params; } - private HostVO selectInstanceConversionKVMHostInCluster(Cluster destinationCluster, Long convertInstanceHostId) { + private HostVO selectKVMHostForImportingInCluster(Cluster destinationCluster, Long importInstanceHostId) { + if (importInstanceHostId != null) { + HostVO selectedHost = hostDao.findById(importInstanceHostId); + if (selectedHost == null) { + String msg = String.format("Cannot find host with ID %s", importInstanceHostId); + LOGGER.error(msg); + throw new CloudRuntimeException(msg); + } + if (selectedHost.getResourceState() != ResourceState.Enabled || + selectedHost.getStatus() != Status.Up || selectedHost.getType() != Host.Type.Routing || + destinationCluster.getDataCenterId() != selectedHost.getDataCenterId() || + selectedHost.getClusterId() != destinationCluster.getId() + ) { + String msg = String.format( + "Cannot import the converted instance on the host %s as it is not a running and Enabled host", + selectedHost.getName()); + LOGGER.error(msg); + throw new CloudRuntimeException(msg); + } + return selectedHost; + } + + List<HostVO> hosts = hostDao.listByClusterAndHypervisorType(destinationCluster.getId(), destinationCluster.getHypervisorType()); + if (CollectionUtils.isNotEmpty(hosts)) { + return hosts.get(new Random().nextInt(hosts.size())); + } + + String err = String.format( + "Could not find any suitable %s host in cluster %s to import the converted instance", + destinationCluster.getHypervisorType(), destinationCluster.getName()); + LOGGER.error(err); + throw new CloudRuntimeException(err); + } + + private HostVO selectKVMHostForConversionInCluster(Cluster destinationCluster, Long convertInstanceHostId) { if (convertInstanceHostId != null) { HostVO selectedHost = hostDao.findById(convertInstanceHostId); if (selectedHost == null) { String msg = String.format("Cannot find host with ID %s", convertInstanceHostId); Review Comment: ```suggestion String msg = String.format("Cannot find host with ID %s for conversion", convertInstanceHostId); ``` -- 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. To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org