Skip to content

Commit 3f263d8

Browse files
Agent connection improvements
1 parent 1574013 commit 3f263d8

3 files changed

Lines changed: 36 additions & 24 deletions

File tree

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

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,15 +1040,19 @@ protected Status getNextStatusOnDisconnection(Host host, final Status.Event even
10401040

10411041
protected boolean handleDisconnectWithoutInvestigation(final AgentAttache attache, final Status.Event event, final boolean transitState, final boolean removeAgent) {
10421042
final long hostId = attache.getId();
1043-
1043+
final HostVO host = _hostDao.findById(hostId);
10441044
boolean result = false;
10451045
GlobalLock joinLock = getHostJoinLock(hostId);
1046-
if (joinLock.lock(60)) {
1046+
try {
1047+
if (!joinLock.lock(60)) {
1048+
logger.debug("Unable to acquire lock on host {} to process agent disconnection", host != null? host : hostId);
1049+
return result;
1050+
}
1051+
1052+
logger.debug("Acquired lock on host {}, to process agent disconnection", host != null? host : hostId);
10471053
try {
1048-
logger.info("Host {} is disconnecting with event {}",
1049-
attache, event);
1054+
logger.info("Host {} is disconnecting with event {}", attache, event);
10501055
Status nextStatus;
1051-
final HostVO host = _hostDao.findById(hostId);
10521056
if (host == null) {
10531057
logger.warn("Can't find host with {} ({})", hostId, attache);
10541058
nextStatus = Status.Removed;
@@ -1068,8 +1072,10 @@ protected boolean handleDisconnectWithoutInvestigation(final AgentAttache attach
10681072
joinLock.unlock();
10691073
}
10701074
result = true;
1075+
} finally {
1076+
joinLock.releaseRef();
10711077
}
1072-
joinLock.releaseRef();
1078+
10731079
return result;
10741080
}
10751081

@@ -1357,29 +1363,34 @@ private AgentAttache sendReadyAndGetAttache(HostVO host, ReadyCommand ready, Lin
13571363
ready.setArch(host.getArch().getType());
13581364
AgentAttache attache;
13591365
GlobalLock joinLock = getHostJoinLock(host.getId());
1360-
if (joinLock.lock(60)) {
1361-
try {
1366+
try {
1367+
if (!joinLock.lock(60)) {
1368+
throw new ConnectionException(true, String.format("Unable to acquire lock on host %s, to process agent connection", host));
1369+
}
13621370

1363-
if (!indirectAgentLB.compareManagementServerList(host.getId(), host.getDataCenterId(), agentMSHostList, lbAlgorithm)) {
1371+
logger.debug("Acquired lock on host {}, to process agent connection", host);
1372+
try {
1373+
if (!indirectAgentLB.compareManagementServerListAndLBAlorithm(host.getId(), host.getDataCenterId(), agentMSHostList, lbAlgorithm)) {
13641374
final List<String> newMSList = indirectAgentLB.getManagementServerList(host.getId(), host.getDataCenterId(), null);
13651375
ready.setMsHostList(newMSList);
1366-
final List<String> avoidMsList = _mshostDao.listNonUpStateMsIPs();
1367-
ready.setAvoidMsHostList(avoidMsList);
1368-
ready.setLbAlgorithm(indirectAgentLB.getLBAlgorithmName());
1369-
ready.setLbCheckInterval(indirectAgentLB.getLBPreferredHostCheckInterval(host.getClusterId()));
1370-
logger.debug("Agent's management server host list is not up to date, sending list update: {}", newMSList);
1376+
String newLBAlgorithm = indirectAgentLB.getLBAlgorithmName();
1377+
ready.setLbAlgorithm(newLBAlgorithm);
1378+
logger.debug("Agent's management server host list or lb algorithm is not up to date, sending list and algorithm update: {}, {}", newMSList, newLBAlgorithm);
13711379
}
13721380

1381+
final List<String> avoidMsList = _mshostDao.listNonUpStateMsIPs();
1382+
ready.setAvoidMsHostList(avoidMsList);
1383+
ready.setLbCheckInterval(indirectAgentLB.getLBPreferredHostCheckInterval(host.getClusterId()));
1384+
13731385
attache = createAttacheForConnect(host, link);
13741386
attache = notifyMonitorsOfConnection(attache, startup, false);
13751387
} finally {
13761388
joinLock.unlock();
13771389
}
1378-
} else {
1379-
throw new ConnectionException(true,
1380-
String.format("Unable to acquire lock on host %s", host));
1390+
} finally {
1391+
joinLock.releaseRef();
13811392
}
1382-
joinLock.releaseRef();
1393+
13831394
return attache;
13841395
}
13851396

@@ -1821,11 +1832,11 @@ protected boolean isHostOwnerSwitched(final HostVO host) {
18211832
return false;
18221833
}
18231834

1824-
private void disconnectInternal(final long hostId, final Status.Event event, final boolean invstigate) {
1835+
private void disconnectInternal(final long hostId, final Status.Event event, final boolean investigate) {
18251836
final AgentAttache attache = findAttache(hostId);
18261837

18271838
if (attache != null) {
1828-
if (!invstigate) {
1839+
if (!investigate) {
18291840
disconnectWithoutInvestigation(attache, event);
18301841
} else {
18311842
disconnectWithInvestigation(attache, event);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ public interface IndirectAgentLB {
4848
List<String> getManagementServerList(Long hostId, Long dcId, List<Long> orderedHostIdList, String lbAlgorithm);
4949

5050
/**
51-
* Compares received management server list against expected list for a host in a zone.
51+
* Compares received management server list against expected list for a host in a zone and LB algorithm.
5252
* @param hostId host id
5353
* @param dcId zone id
5454
* @param receivedMSHosts received management server list
55-
* @return true if mgmtHosts is up to date, false if not
55+
* @param lbAlgorithm received LB algorithm
56+
* @return true if mgmtHosts and LB algorithm are up to date, false if not
5657
*/
57-
boolean compareManagementServerList(Long hostId, Long dcId, List<String> receivedMSHosts, String lbAlgorithm);
58+
boolean compareManagementServerListAndLBAlorithm(Long hostId, Long dcId, List<String> receivedMSHosts, String lbAlgorithm);
5859

5960
/**
6061
* Returns the configure LB algorithm

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public List<String> getManagementServerList(final Long hostId, final Long dcId,
149149
}
150150

151151
@Override
152-
public boolean compareManagementServerList(final Long hostId, final Long dcId, final List<String> receivedMSHosts, final String lbAlgorithm) {
152+
public boolean compareManagementServerListAndLBAlorithm(final Long hostId, final Long dcId, final List<String> receivedMSHosts, final String lbAlgorithm) {
153153
if (receivedMSHosts == null || receivedMSHosts.isEmpty()) {
154154
return false;
155155
}

0 commit comments

Comments
 (0)