|
20 | 20 | import java.util.Arrays; |
21 | 21 | import java.util.Collections; |
22 | 22 | import java.util.Comparator; |
| 23 | +import java.util.EnumSet; |
23 | 24 | import java.util.HashMap; |
24 | 25 | import java.util.List; |
25 | 26 | import java.util.Map; |
@@ -88,6 +89,14 @@ public List<String> getManagementServerList(final Long hostId, final Long dcId, |
88 | 89 | hostIdList = getOrderedHostIdList(dcId); |
89 | 90 | } |
90 | 91 |
|
| 92 | + // just in case we have a host in creating state make sure it is in the list: |
| 93 | + if (null != hostId && ! hostIdList.contains(hostId)) { |
| 94 | + if (LOG.isTraceEnabled()) { |
| 95 | + LOG.trace("adding requested host to host list as it does not seem to be there; " + hostId); |
| 96 | + } |
| 97 | + hostIdList.add(hostId); |
| 98 | + } |
| 99 | + |
91 | 100 | final org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm algorithm = getAgentMSLBAlgorithm(); |
92 | 101 | final List<String> msList = Arrays.asList(msServerAddresses.replace(" ", "").split(",")); |
93 | 102 | return algorithm.sort(msList, hostIdList, hostId); |
@@ -136,17 +145,54 @@ private List<Host> getAllAgentBasedHosts() { |
136 | 145 | } |
137 | 146 | final List <Host> agentBasedHosts = new ArrayList<>(); |
138 | 147 | for (final Host host : allHosts) { |
139 | | - if (host == null || host.getResourceState() == ResourceState.Creating || host.getResourceState() == ResourceState.Error) { |
140 | | - continue; |
| 148 | + conditionallyAddHost(agentBasedHosts, host); |
| 149 | + } |
| 150 | + return agentBasedHosts; |
| 151 | + } |
| 152 | + |
| 153 | + private void conditionallyAddHost(List<Host> agentBasedHosts, Host host) { |
| 154 | + if (host == null) { |
| 155 | + if (LOG.isTraceEnabled()) { |
| 156 | + LOG.trace("trying to add no host to a list"); |
141 | 157 | } |
142 | | - if (host.getType() == Host.Type.Routing || host.getType() == Host.Type.ConsoleProxy || host.getType() == Host.Type.SecondaryStorage || host.getType() == Host.Type.SecondaryStorageVM) { |
143 | | - if (host.getHypervisorType() != null && host.getHypervisorType() != Hypervisor.HypervisorType.KVM && host.getHypervisorType() != Hypervisor.HypervisorType.LXC) { |
144 | | - continue; |
145 | | - } |
146 | | - agentBasedHosts.add(host); |
| 158 | + return; |
| 159 | + } |
| 160 | + |
| 161 | + EnumSet<ResourceState> allowedStates = EnumSet.of( |
| 162 | + ResourceState.Enabled, |
| 163 | + ResourceState.Maintenance, |
| 164 | + ResourceState.Disabled, |
| 165 | + ResourceState.ErrorInMaintenance, |
| 166 | + ResourceState.PrepareForMaintenance); |
| 167 | + // so the remaining EnumSet<ResourceState> disallowedStates = EnumSet.complementOf(allowedStates) |
| 168 | + // would be {ResourceState.Creating, ResourceState.Error}; |
| 169 | + if (!allowedStates.contains(host.getResourceState())) { |
| 170 | + if (LOG.isTraceEnabled()) { |
| 171 | + LOG.trace(String.format("host is in '%s' state, not adding to the host list, (id = %s)", host.getResourceState(), host.getUuid())); |
147 | 172 | } |
| 173 | + return; |
148 | 174 | } |
149 | | - return agentBasedHosts; |
| 175 | + |
| 176 | + if (host.getType() != Host.Type.Routing |
| 177 | + && host.getType() != Host.Type.ConsoleProxy |
| 178 | + && host.getType() != Host.Type.SecondaryStorage |
| 179 | + && host.getType() != Host.Type.SecondaryStorageVM) { |
| 180 | + if (LOG.isTraceEnabled()) { |
| 181 | + LOG.trace(String.format("host is of wrong type, not adding to the host list, (id = %s, type = %s)", host.getUuid(), host.getType())); |
| 182 | + } |
| 183 | + return; |
| 184 | + } |
| 185 | + |
| 186 | + if (host.getHypervisorType() != null |
| 187 | + && ! (host.getHypervisorType() == Hypervisor.HypervisorType.KVM || host.getHypervisorType() == Hypervisor.HypervisorType.LXC)) { |
| 188 | + |
| 189 | + if (LOG.isTraceEnabled()) { |
| 190 | + LOG.trace(String.format("hypervisor is not the right type, not adding to the host list, (id = %s, hypervisortype = %s)", host.getUuid(), host.getHypervisorType())); |
| 191 | + } |
| 192 | + return; |
| 193 | + } |
| 194 | + |
| 195 | + agentBasedHosts.add(host); |
150 | 196 | } |
151 | 197 |
|
152 | 198 | private org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm getAgentMSLBAlgorithm() { |
|
0 commit comments