You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ko...@apache.org on 2013/02/06 09:29:10 UTC

git commit: refs/heads/4.1 - CLOUDSTACK-446 : Host going to alert state, if you are adding already added host Adding an already added host fails with error but in the process incorrectly updates the status of the host to 'Alert'. Put a check to prevent t

Updated Branches:
  refs/heads/4.1 9a9a4abf9 -> 1c88f3c73


CLOUDSTACK-446 : Host going to alert state, if you are adding already added host
Adding an already added host fails with error but in the process incorrectly updates the status of the host to 'Alert'. Put a check to prevent this.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/1c88f3c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/1c88f3c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/1c88f3c7

Branch: refs/heads/4.1
Commit: 1c88f3c732e0946f6a8070ffc6d708ab9919f2fa
Parents: 9a9a4ab
Author: Koushik Das <ko...@citrix.com>
Authored: Tue Nov 6 11:58:30 2012 +0530
Committer: Koushik Das <ko...@citrix.com>
Committed: Wed Feb 6 13:45:48 2013 +0530

----------------------------------------------------------------------
 .../com/cloud/resource/ResourceManagerImpl.java    |   72 ++++++---------
 1 files changed, 27 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1c88f3c7/server/src/com/cloud/resource/ResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java
index f4fa13b..82013d4 100755
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@ -1869,11 +1869,29 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
         return isFirstHost;
     }
 
+    private void markHostAsDisconnected(HostVO host, StartupCommand[] cmds) {
+        if (host == null) { // in case host is null due to some errors, try reloading the host from db
+            if (cmds != null) {
+                StartupCommand firstCmd = cmds[0];
+                host = findHostByGuid(firstCmd.getGuid());
+                if (host == null) {
+                    host = findHostByGuid(firstCmd.getGuidWithoutResource());
+                }
+            }
+        }
+
+        if (host != null) {
+            // Change agent status to Alert, so that host is considered for reconnection next time
+            _agentMgr.agentStatusTransitTo(host, Status.Event.AgentDisconnected, _nodeId);
+        }
+    }
+
     private Host createHostAndAgent(ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags,
             boolean forRebalance) {
         HostVO host = null;
         AgentAttache attache = null;
         StartupCommand[] cmds = null;
+        boolean hostExists = false;
 
         try {
             cmds = resource.initialize();
@@ -1902,10 +1920,9 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
                 if (host == null) {
                     host = findHostByGuid(firstCmd.getGuidWithoutResource());
                 }
-                if (host != null && host.getRemoved() == null) {
-					s_logger.debug("Found the host " + host.getId()
-							+ " by guid: " + firstCmd.getGuid()
-							+ ", old host reconnected as new");
+                if (host != null && host.getRemoved() == null) { // host already added, no need to add again
+                    s_logger.debug("Found the host " + host.getId() + " by guid: " + firstCmd.getGuid() + ", old host reconnected as new");
+                    hostExists = true; // ensures that host status is left unchanged in case of adding same one again
                     return null;
                 }
             }
@@ -1925,35 +1942,16 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
         } catch (Exception e) {
             s_logger.warn("Unable to connect due to ", e);
         } finally {
-            if (attache == null) {
+            if (hostExists) {
                 if (cmds != null) {
                     resource.disconnected();
                 }
-				// In case of some db errors, we may land with the sitaution
-				// that host is null. We need to reload host from db and call
-				// disconnect on it so that it will be loaded for reconnection
-				// next time
-                HostVO tempHost = host;
-				if (tempHost == null) {
+            } else {
+                if (attache == null) {
                     if (cmds != null) {
-                        StartupCommand firstCmd = cmds[0];
-                        tempHost = findHostByGuid(firstCmd.getGuid());
-                        if (tempHost == null) {
-							tempHost = findHostByGuid(firstCmd
-									.getGuidWithoutResource());
-                        }
+                        resource.disconnected();
                     }
-                }
-
-                if (tempHost != null) {
-                    /* Change agent status to Alert */
-					_agentMgr.agentStatusTransitTo(tempHost,
-							Status.Event.AgentDisconnected, _nodeId);
-					/*
-					 * Don't change resource state here since HostVO is already
-					 * in database, which means resource state has had an
-					 * appropriate value
-					 */
+                    markHostAsDisconnected(host, cmds);
                 }
             }
         }
@@ -2060,23 +2058,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
                     if (cmds != null) {
                         resource.disconnected();
                     }
-
-                    // In case of some db errors, we may land with the situation that host is null. We need to reload host from db and call disconnect on it so that it will be loaded for reconnection next time
-                    HostVO tempHost = host;
-                    if (tempHost == null) {
-                        if (cmds != null) {
-                            StartupCommand firstCmd = cmds[0];
-                            tempHost = findHostByGuid(firstCmd.getGuid());
-                            if (tempHost == null) {
-                                tempHost = findHostByGuid(firstCmd.getGuidWithoutResource());
-                            }
-                        }
-                    }
-                    if (tempHost != null) {
-                        /* Change agent status to Alert */
-                        _agentMgr.agentStatusTransitTo(tempHost, Status.Event.AgentDisconnected, _nodeId);
-                        /* Don't change resource state here since HostVO is already in database, which means resource state has had an appropriate value*/
-                    }
+                    markHostAsDisconnected(host, cmds);
                 }
             }
         }