rhtyd commented on a change in pull request #3795: Agent lb on svm URL: https://github.com/apache/cloudstack/pull/3795#discussion_r363753350
########## File path: server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java ########## @@ -136,17 +146,54 @@ public int compare(Long x, Long y) { } final List <Host> agentBasedHosts = new ArrayList<>(); for (final Host host : allHosts) { - if (host == null || host.getResourceState() == ResourceState.Creating || host.getResourceState() == ResourceState.Error) { - continue; + conditionallyAddHost(agentBasedHosts, host); + } + return agentBasedHosts; + } + + private void conditionallyAddHost(List<Host> agentBasedHosts, Host host) { + if (host == null) { + if (LOG.isTraceEnabled()) { + LOG.trace("trying to add no host to a list"); } - if (host.getType() == Host.Type.Routing || host.getType() == Host.Type.ConsoleProxy || host.getType() == Host.Type.SecondaryStorage || host.getType() == Host.Type.SecondaryStorageVM) { - if (host.getHypervisorType() != null && host.getHypervisorType() != Hypervisor.HypervisorType.KVM && host.getHypervisorType() != Hypervisor.HypervisorType.LXC) { - continue; - } - agentBasedHosts.add(host); + return; + } + + ResourceState[] allowedStates = new ResourceState[]{ + ResourceState.Enabled, + ResourceState.Maintenance, + ResourceState.Disabled, + ResourceState.ErrorInMaintenance, + ResourceState.PrepareForMaintenance + }; + // so the remaining ResourceState[] disallowedStates = new ResourceState[]{ResourceState.Creating, ResourceState.Error}; + if (binarySearch(allowedStates, host.getResourceState()) < 0) { Review comment: @DaanHoogland premature optimisation is... nope there won't be a lot of performance gain. If you have to you can use `Collections.binarySearch()` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services