DaanHoogland commented on code in PR #7606:
URL: https://github.com/apache/cloudstack/pull/7606#discussion_r1241846080
##########
server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java:
##########
@@ -1185,59 +1187,49 @@ public UserVmResponse
importUnmanagedInstance(ImportUnmanagedInstanceCmd cmd) {
List<HostVO> hosts =
resourceManager.listHostsInClusterByStatus(clusterId, Status.Up);
UserVm userVm = null;
List<String> additionalNameFilters = getAdditionalNameFilters(cluster);
+ List<String> managedVms = new ArrayList<>(additionalNameFilters);
+ managedVms.addAll(getHostsManagedVms(hosts));
for (HostVO host : hosts) {
- if (host.isInMaintenanceStates()) {
- continue;
- }
- List<String> managedVms = new ArrayList<>();
- managedVms.addAll(additionalNameFilters);
- managedVms.addAll(getHostManagedVms(host));
- GetUnmanagedInstancesCommand command = new
GetUnmanagedInstancesCommand(instanceName);
- command.setManagedInstancesNames(managedVms);
- Answer answer = agentManager.easySend(host.getId(), command);
- if (!(answer instanceof GetUnmanagedInstancesAnswer)) {
- continue;
- }
- GetUnmanagedInstancesAnswer unmanagedInstancesAnswer =
(GetUnmanagedInstancesAnswer) answer;
- HashMap<String, UnmanagedInstanceTO> unmanagedInstances =
unmanagedInstancesAnswer.getUnmanagedInstances();
+ HashMap<String, UnmanagedInstanceTO> unmanagedInstances =
getUnmanagedInstancesForHost(host, cmd.getName(), managedVms);
if (MapUtils.isEmpty(unmanagedInstances)) {
continue;
}
Set<String> names = unmanagedInstances.keySet();
for (String name : names) {
- if (instanceName.equals(name)) {
- UnmanagedInstanceTO unmanagedInstance =
unmanagedInstances.get(name);
- if (unmanagedInstance == null) {
- throw new
ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Unable to
retrieve details for unmanaged VM: %s", name));
+ if (!instanceName.equals(name)) {
Review Comment:
we can extract the larger part of this block, from the `continue` here and
the `break` just before the end of the loop.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]