Skip to content

Commit 534dd47

Browse files
authored
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
1 parent 766eab8 commit 534dd47

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,18 +1080,23 @@ private AgentAttache handleConnectedAgent(final Link link, final StartupCommand[
10801080
ReadyCommand ready = null;
10811081
try {
10821082
final List<String> agentMSHostList = new ArrayList<>();
1083+
String lbAlgorithm = null;
10831084
if (startup != null && startup.length > 0) {
10841085
final String agentMSHosts = startup[0].getMsHostList();
10851086
if (!Strings.isNullOrEmpty(agentMSHosts)) {
1086-
agentMSHostList.addAll(Arrays.asList(agentMSHosts.split(",")));
1087+
String[] msHosts = agentMSHosts.split("@");
1088+
if (msHosts.length > 1) {
1089+
lbAlgorithm = msHosts[1];
1090+
}
1091+
agentMSHostList.addAll(Arrays.asList(msHosts[0].split(",")));
10871092
}
10881093
}
10891094

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

1094-
if (!indirectAgentLB.compareManagementServerList(host.getId(), host.getDataCenterId(), agentMSHostList)) {
1099+
if (!indirectAgentLB.compareManagementServerList(host.getId(), host.getDataCenterId(), agentMSHostList, lbAlgorithm)) {
10951100
final List<String> newMSList = indirectAgentLB.getManagementServerList(host.getId(), host.getDataCenterId(), null);
10961101
ready.setMsHostList(newMSList);
10971102
ready.setLbAlgorithm(indirectAgentLB.getLBAlgorithmName());

framework/agent-lb/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLB.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public interface IndirectAgentLB {
3737
* @param receivedMSHosts received management server list
3838
* @return true if mgmtHosts is up to date, false if not
3939
*/
40-
boolean compareManagementServerList(Long hostId, Long dcId, List<String> receivedMSHosts);
40+
boolean compareManagementServerList(Long hostId, Long dcId, List<String> receivedMSHosts, String lbAlgorithm);
4141

4242
/**
4343
* Returns the configure LB algorithm

server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ public List<String> getManagementServerList(final Long hostId, final Long dcId,
9898
}
9999

100100
@Override
101-
public boolean compareManagementServerList(final Long hostId, final Long dcId, final List<String> receivedMSHosts) {
101+
public boolean compareManagementServerList(final Long hostId, final Long dcId, final List<String> receivedMSHosts, final String lbAlgorithm) {
102102
if (receivedMSHosts == null || receivedMSHosts.size() < 1) {
103103
return false;
104104
}
105+
if (getLBAlgorithmName() != lbAlgorithm) {
106+
return false;
107+
}
105108
final List<String> expectedMSList = getManagementServerList(hostId, dcId, null);
106109
final org.apache.cloudstack.agent.lb.IndirectAgentLBAlgorithm algorithm = getAgentMSLBAlgorithm();
107110
return algorithm.compare(expectedMSList, receivedMSHosts);

0 commit comments

Comments
 (0)