mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Agent lb on svm (#3795)
* add host if needed * allow for test with null-host * full coverage of states * EnumSet.contains instead of Arrays.binarySearch
This commit is contained in:
parent
54cc73af08
commit
6ebd02e7af
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||
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;
|
||||
@ -88,6 +89,14 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
|
||||
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);
|
||||
@ -136,19 +145,56 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
|
||||
}
|
||||
final List <Host> agentBasedHosts = new ArrayList<>();
|
||||
for (final Host host : allHosts) {
|
||||
if (host == null || host.getResourceState() == ResourceState.Creating || host.getResourceState() == ResourceState.Error) {
|
||||
continue;
|
||||
}
|
||||
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);
|
||||
}
|
||||
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");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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() {
|
||||
final String algorithm = getLBAlgorithmName();
|
||||
if (algorithmMap.containsKey(algorithm)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user