agent: Compare indirect agent lb algorithm when cloudstack agent connects (#4335)

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

Fixes: #3895
This commit is contained in:
Wei Zhou 2020-09-23 09:18:16 +02:00 committed by GitHub
parent 766eab8cab
commit 534dd475d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -1080,10 +1080,15 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
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(",")));
}
}
@ -1091,7 +1096,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
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());

View File

@ -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

View File

@ -98,10 +98,13 @@ public class IndirectAgentLBServiceImpl extends ComponentLifecycleBase implement
}
@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);