DaanHoogland commented on code in PR #8089:
URL: https://github.com/apache/cloudstack/pull/8089#discussion_r1367083735


##########
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);

Review Comment:
   ```suggestion
                       s_logger.warn(String.format("Can't find host with %d", 
hostId));
   ```



##########
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);

Review Comment:
   ```suggestion
                   s_logger.debug(String.format("The next status of agent %s is 
%s, current status is %s", host.getUuid(), nextstatus, currentStatus));
   ```



##########
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);

Review Comment:
   ```suggestion
                   s_logger.debug(String.format("Host %s is already %s", 
host.getUuid(), currentStatus);
   ```



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

Reply via email to