vishesh92 commented on code in PR #8089:
URL: https://github.com/apache/cloudstack/pull/8089#discussion_r1368218394
##########
engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java:
##########
@@ -798,49 +799,65 @@ public boolean stop() {
return true;
}
+ protected Status getNextStatusOnDisconnection(Host host, final
Status.Event event) {
+ final Status currentStatus = host.getStatus();
+ Status nextStatus;
+ if (currentStatus == Status.Down || currentStatus == Status.Alert ||
currentStatus == Status.Removed) {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Host " + host.getId() + " is already " +
currentStatus);
+ }
+ nextStatus = currentStatus;
+ } else {
+ try {
+ nextStatus = currentStatus.getNextStatus(event);
+ } catch (final NoTransitionException e) {
+ final String err = "Cannot find next status for " + event + "
as current status is " + currentStatus + " for agent " + host.getId();
+ s_logger.debug(err);
+ throw new CloudRuntimeException(err);
+ }
+
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("The next status of agent " + host.getId() +
"is " + nextStatus + ", current status is " + currentStatus);
+ }
+ }
+ return nextStatus;
+ }
+
protected boolean handleDisconnectWithoutInvestigation(final AgentAttache
attache, final Status.Event event, final boolean transitState, final boolean
removeAgent) {
final long hostId = attache.getId();
- s_logger.info("Host " + hostId + " is disconnecting with event " +
event);
- Status nextStatus = null;
- final HostVO host = _hostDao.findById(hostId);
- if (host == null) {
- s_logger.warn("Can't find host with " + hostId);
- nextStatus = Status.Removed;
- } else {
- final Status currentStatus = host.getStatus();
- if (currentStatus == Status.Down || currentStatus == Status.Alert
|| currentStatus == Status.Removed) {
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Host " + hostId + " is already " +
currentStatus);
- }
- nextStatus = currentStatus;
- } else {
- try {
- nextStatus = currentStatus.getNextStatus(event);
- } catch (final NoTransitionException e) {
- final String err = "Cannot find next status for " + event
+ " as current status is " + currentStatus + " for agent " + hostId;
- s_logger.debug(err);
- throw new CloudRuntimeException(err);
+ boolean result = false;
+ GlobalLock joinLock = getHostJoinLock(hostId);
+ if (joinLock.lock(60)) {
+ try {
+ s_logger.info("Host " + hostId + " is disconnecting with event
" + event);
+ Status nextStatus = null;
+ final HostVO host = _hostDao.findById(hostId);
+ if (host == null) {
+ s_logger.warn("Can't find host with " + hostId);
+ nextStatus = Status.Removed;
+ } else {
+ nextStatus = getNextStatusOnDisconnection(host, event);
+ caService.purgeHostCertificate(host);
}
if (s_logger.isDebugEnabled()) {
- s_logger.debug("The next status of agent " + hostId + "is
" + nextStatus + ", current status is " + currentStatus);
+ s_logger.debug("Deregistering link for " + hostId + " with
state " + nextStatus);
}
- }
- caService.purgeHostCertificate(host);
- }
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Deregistering link for " + hostId + " with state "
+ nextStatus);
- }
+ removeAgent(attache, nextStatus);
- removeAgent(attache, nextStatus);
- // update the DB
- if (host != null && transitState) {
- disconnectAgent(host, event, _nodeId);
+ // update the DB
Review Comment:
IMO, yes. The comment should be more detailed instead.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]