Skip to content

Commit d751ca5

Browse files
review comments
1 parent 9fc8ef1 commit d751ca5

File tree

1 file changed

+67
-50
lines changed

1 file changed

+67
-50
lines changed

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

Lines changed: 67 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,27 +1050,7 @@ protected boolean handleDisconnectWithoutInvestigation(final AgentAttache attach
10501050
}
10511051

10521052
logger.debug("Acquired lock on host {}, to process agent disconnection", host != null? host : hostId);
1053-
try {
1054-
logger.info("Host {} is disconnecting with event {}", attache, event);
1055-
Status nextStatus;
1056-
if (host == null) {
1057-
logger.warn("Can't find host with {} ({})", hostId, attache);
1058-
nextStatus = Status.Removed;
1059-
} else {
1060-
nextStatus = getNextStatusOnDisconnection(host, event);
1061-
caService.purgeHostCertificate(host);
1062-
}
1063-
logger.debug("Deregistering link for {} with state {}", attache, nextStatus);
1064-
1065-
removeAgent(attache, nextStatus);
1066-
1067-
if (host != null && transitState) {
1068-
// update the state for host in DB as per the event
1069-
disconnectAgent(host, event, _nodeId);
1070-
}
1071-
} finally {
1072-
joinLock.unlock();
1073-
}
1053+
disconnectHostAgent(attache, event, host, transitState, joinLock);
10741054
result = true;
10751055
} finally {
10761056
joinLock.releaseRef();
@@ -1079,6 +1059,33 @@ protected boolean handleDisconnectWithoutInvestigation(final AgentAttache attach
10791059
return result;
10801060
}
10811061

1062+
private void disconnectHostAgent(final AgentAttache attache, final Status.Event event, final HostVO host, final boolean transitState, final GlobalLock joinLock) {
1063+
try {
1064+
logger.info("Host {} is disconnecting with event {}", attache, event);
1065+
final long hostId = attache.getId();
1066+
Status nextStatus;
1067+
if (host == null) {
1068+
logger.warn("Can't find host with {} ({})", hostId, attache);
1069+
nextStatus = Status.Removed;
1070+
} else {
1071+
nextStatus = getNextStatusOnDisconnection(host, event);
1072+
caService.purgeHostCertificate(host);
1073+
}
1074+
logger.debug("Deregistering link for {} with state {}", attache, nextStatus);
1075+
1076+
removeAgent(attache, nextStatus);
1077+
1078+
if (host != null && transitState) {
1079+
// update the state for host in DB as per the event
1080+
disconnectAgent(host, event, _nodeId);
1081+
}
1082+
} finally {
1083+
if (joinLock != null) {
1084+
joinLock.unlock();
1085+
}
1086+
}
1087+
}
1088+
10821089
protected boolean handleDisconnectWithInvestigation(final AgentAttache attache, Status.Event event) {
10831090
final long hostId = attache.getId();
10841091
HostVO host = _hostDao.findById(hostId);
@@ -1347,20 +1354,7 @@ protected AgentAttache createAttacheForConnect(final HostVO host, final Link lin
13471354
return attache;
13481355
}
13491356

1350-
private AgentAttache sendReadyAndGetAttache(HostVO host, ReadyCommand ready, Link link, StartupCommand[] startup) throws ConnectionException {
1351-
final List<String> agentMSHostList = new ArrayList<>();
1352-
String lbAlgorithm = null;
1353-
if (startup != null && startup.length > 0) {
1354-
final String agentMSHosts = startup[0].getMsHostList();
1355-
if (StringUtils.isNotEmpty(agentMSHosts)) {
1356-
String[] msHosts = agentMSHosts.split("@");
1357-
if (msHosts.length > 1) {
1358-
lbAlgorithm = msHosts[1];
1359-
}
1360-
agentMSHostList.addAll(Arrays.asList(msHosts[0].split(",")));
1361-
}
1362-
}
1363-
ready.setArch(host.getArch().getType());
1357+
private AgentAttache sendReadyAndGetAttache(HostVO host, ReadyCommand ready, Link link, StartupCommand[] startupCmds) throws ConnectionException {
13641358
AgentAttache attache;
13651359
GlobalLock joinLock = getHostJoinLock(host.getId());
13661360
try {
@@ -1369,26 +1363,49 @@ private AgentAttache sendReadyAndGetAttache(HostVO host, ReadyCommand ready, Lin
13691363
}
13701364

13711365
logger.debug("Acquired lock on host {}, to process agent connection", host);
1372-
try {
1373-
if (!indirectAgentLB.compareManagementServerListAndLBAlgorithm(host.getId(), host.getDataCenterId(), agentMSHostList, lbAlgorithm)) {
1374-
final List<String> newMSList = indirectAgentLB.getManagementServerList(host.getId(), host.getDataCenterId(), null);
1375-
ready.setMsHostList(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);
1366+
attache = connectHostAgent(host, ready, link, startupCmds, joinLock);
1367+
} finally {
1368+
joinLock.releaseRef();
1369+
}
1370+
1371+
return attache;
1372+
}
1373+
1374+
private AgentAttache connectHostAgent(HostVO host, ReadyCommand ready, Link link, StartupCommand[] startupCmds, GlobalLock joinLock) throws ConnectionException {
1375+
AgentAttache attache;
1376+
try {
1377+
final List<String> agentMSHostList = new ArrayList<>();
1378+
String lbAlgorithm = null;
1379+
if (startupCmds != null && startupCmds.length > 0) {
1380+
final String agentMSHosts = startupCmds[0].getMsHostList();
1381+
if (StringUtils.isNotEmpty(agentMSHosts)) {
1382+
String[] msHosts = agentMSHosts.split("@");
1383+
if (msHosts.length > 1) {
1384+
lbAlgorithm = msHosts[1];
1385+
}
1386+
agentMSHostList.addAll(Arrays.asList(msHosts[0].split(",")));
13791387
}
1388+
}
13801389

1381-
final List<String> avoidMsList = _mshostDao.listNonUpStateMsIPs();
1382-
ready.setAvoidMsHostList(avoidMsList);
1383-
ready.setLbCheckInterval(indirectAgentLB.getLBPreferredHostCheckInterval(host.getClusterId()));
1390+
if (!indirectAgentLB.compareManagementServerListAndLBAlgorithm(host.getId(), host.getDataCenterId(), agentMSHostList, lbAlgorithm)) {
1391+
final List<String> newMSList = indirectAgentLB.getManagementServerList(host.getId(), host.getDataCenterId(), null);
1392+
ready.setMsHostList(newMSList);
1393+
String newLBAlgorithm = indirectAgentLB.getLBAlgorithmName();
1394+
ready.setLbAlgorithm(newLBAlgorithm);
1395+
logger.debug("Agent's management server host list or lb algorithm is not up to date, sending list and algorithm update: {}, {}", newMSList, newLBAlgorithm);
1396+
}
1397+
1398+
final List<String> avoidMsList = _mshostDao.listNonUpStateMsIPs();
1399+
ready.setAvoidMsHostList(avoidMsList);
1400+
ready.setLbCheckInterval(indirectAgentLB.getLBPreferredHostCheckInterval(host.getClusterId()));
1401+
ready.setArch(host.getArch().getType());
13841402

1385-
attache = createAttacheForConnect(host, link);
1386-
attache = notifyMonitorsOfConnection(attache, startup, false);
1387-
} finally {
1403+
attache = createAttacheForConnect(host, link);
1404+
attache = notifyMonitorsOfConnection(attache, startupCmds, false);
1405+
} finally {
1406+
if (joinLock != null) {
13881407
joinLock.unlock();
13891408
}
1390-
} finally {
1391-
joinLock.releaseRef();
13921409
}
13931410

13941411
return attache;

0 commit comments

Comments
 (0)