Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -88,6 +89,14 @@ public List<String> getManagementServerList(final Long hostId, final Long dcId,
hostIdList = getOrderedHostIdList(dcId);
}

// just in case we have a host in creating state make sure it is in the list:
if (null != hostId && ! hostIdList.contains(hostId)) {
if (LOG.isTraceEnabled()) {
LOG.trace("adding requested host to host list as it does not seem to be there; " + hostId);
}
hostIdList.add(hostId);
}

final org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm algorithm = getAgentMSLBAlgorithm();
final List<String> msList = Arrays.asList(msServerAddresses.replace(" ", "").split(","));
return algorithm.sort(msList, hostIdList, hostId);
Expand Down Expand Up @@ -136,17 +145,54 @@ private List<Host> getAllAgentBasedHosts() {
}
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) {
Comment thread
DaanHoogland marked this conversation as resolved.
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;
}

EnumSet<ResourceState> allowedStates = EnumSet.of(
ResourceState.Enabled,
ResourceState.Maintenance,
ResourceState.Disabled,
ResourceState.ErrorInMaintenance,
ResourceState.PrepareForMaintenance);
// so the remaining EnumSet<ResourceState> disallowedStates = EnumSet.complementOf(allowedStates)
// would be {ResourceState.Creating, ResourceState.Error};
if (!allowedStates.contains(host.getResourceState())) {
if (LOG.isTraceEnabled()) {
LOG.trace(String.format("host is in '%s' state, not adding to the host list, (id = %s)", host.getResourceState(), host.getUuid()));
}
return;
}
return agentBasedHosts;

if (host.getType() != Host.Type.Routing
&& host.getType() != Host.Type.ConsoleProxy
&& host.getType() != Host.Type.SecondaryStorage
&& host.getType() != Host.Type.SecondaryStorageVM) {
if (LOG.isTraceEnabled()) {
LOG.trace(String.format("host is of wrong type, not adding to the host list, (id = %s, type = %s)", host.getUuid(), host.getType()));
}
return;
}

if (host.getHypervisorType() != null
&& ! (host.getHypervisorType() == Hypervisor.HypervisorType.KVM || host.getHypervisorType() == Hypervisor.HypervisorType.LXC)) {

if (LOG.isTraceEnabled()) {
LOG.trace(String.format("hypervisor is not the right type, not adding to the host list, (id = %s, hypervisortype = %s)", host.getUuid(), host.getHypervisorType()));
}
return;
}

agentBasedHosts.add(host);
}

private org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm getAgentMSLBAlgorithm() {
Expand Down