Skip to content

Commit

Permalink
agent: Compare indirect agent lb algorithm when cloudstack agent conn…
Browse files Browse the repository at this point in the history
…ects (apache#4335)

Compare not only the list of management servers but also the lb algorithm when agent connects.

Fixes: apache#3895
  • Loading branch information
ustcweizhou authored Sep 23, 2020
1 parent 766eab8 commit 534dd47
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1080,18 +1080,23 @@ private AgentAttache handleConnectedAgent(final Link link, final StartupCommand[
ReadyCommand ready = null;
try {
final List<String> agentMSHostList = new ArrayList<>();
String lbAlgorithm = null;
if (startup != null && startup.length > 0) {
final String agentMSHosts = startup[0].getMsHostList();
if (!Strings.isNullOrEmpty(agentMSHosts)) {
agentMSHostList.addAll(Arrays.asList(agentMSHosts.split(",")));
String[] msHosts = agentMSHosts.split("@");
if (msHosts.length > 1) {
lbAlgorithm = msHosts[1];
}
agentMSHostList.addAll(Arrays.asList(msHosts[0].split(",")));
}
}

final HostVO host = _resourceMgr.createHostVOForConnectedAgent(startup);
if (host != null) {
ready = new ReadyCommand(host.getDataCenterId(), host.getId());

if (!indirectAgentLB.compareManagementServerList(host.getId(), host.getDataCenterId(), agentMSHostList)) {
if (!indirectAgentLB.compareManagementServerList(host.getId(), host.getDataCenterId(), agentMSHostList, lbAlgorithm)) {
final List<String> newMSList = indirectAgentLB.getManagementServerList(host.getId(), host.getDataCenterId(), null);
ready.setMsHostList(newMSList);
ready.setLbAlgorithm(indirectAgentLB.getLBAlgorithmName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface IndirectAgentLB {
* @param receivedMSHosts received management server list
* @return true if mgmtHosts is up to date, false if not
*/
boolean compareManagementServerList(Long hostId, Long dcId, List<String> receivedMSHosts);
boolean compareManagementServerList(Long hostId, Long dcId, List<String> receivedMSHosts, String lbAlgorithm);

/**
* Returns the configure LB algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,13 @@ public List<String> getManagementServerList(final Long hostId, final Long dcId,
}

@Override
public boolean compareManagementServerList(final Long hostId, final Long dcId, final List<String> receivedMSHosts) {
public boolean compareManagementServerList(final Long hostId, final Long dcId, final List<String> receivedMSHosts, final String lbAlgorithm) {
if (receivedMSHosts == null || receivedMSHosts.size() < 1) {
return false;
}
if (getLBAlgorithmName() != lbAlgorithm) {
return false;
}
final List<String> expectedMSList = getManagementServerList(hostId, dcId, null);
final org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm algorithm = getAgentMSLBAlgorithm();
return algorithm.compare(expectedMSList, receivedMSHosts);
Expand Down

0 comments on commit 534dd47

Please sign in to comment.