Updated Branches:
  refs/heads/4.1 917d6242e -> 96a98f5a7

CLOUDSTACK-1367 NPE noticed in logs while AgentMonitor is monitoring the host 
ping interval

Added null check. If the host is not found, we dont ping anymore.


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

Branch: refs/heads/4.1
Commit: 96a98f5a71533e7f577b88f0b6116671b97c380a
Parents: 917d624
Author: Prachi Damle <[email protected]>
Authored: Thu Feb 21 17:39:09 2013 -0800
Committer: Prachi Damle <[email protected]>
Committed: Thu Feb 21 17:42:20 2013 -0800

----------------------------------------------------------------------
 .../src/com/cloud/agent/manager/AgentMonitor.java  |   32 +++++++++-----
 1 files changed, 20 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/96a98f5a/server/src/com/cloud/agent/manager/AgentMonitor.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/agent/manager/AgentMonitor.java 
b/server/src/com/cloud/agent/manager/AgentMonitor.java
index 97c0411..c019a76 100755
--- a/server/src/com/cloud/agent/manager/AgentMonitor.java
+++ b/server/src/com/cloud/agent/manager/AgentMonitor.java
@@ -71,7 +71,7 @@ public class AgentMonitor extends Thread implements Listener {
     private ConnectionConcierge _concierge;
     @Inject ClusterDao _clusterDao;
     @Inject ResourceManager _resourceMgr;
-    
+
     // private ConnectionConcierge _concierge;
     private Map<Long, Long> _pingMap;
 
@@ -104,7 +104,7 @@ public class AgentMonitor extends Thread implements 
Listener {
 
     /**
      * Check if the agent is behind on ping
-     * 
+     *
      * @param agentId
      *            agent or host id.
      * @return null if the agent is not kept here. true if behind; false if 
not.
@@ -144,21 +144,29 @@ public class AgentMonitor extends Thread implements 
Listener {
                        SearchCriteriaService<HostVO, HostVO> sc = 
SearchCriteria2.create(HostVO.class);
                        sc.addAnd(sc.getEntity().getId(), Op.EQ, agentId);
                        HostVO h = sc.find();
-                       ResourceState resourceState = h.getResourceState();
-                       if (resourceState == ResourceState.Disabled || 
resourceState == ResourceState.Maintenance || resourceState == 
ResourceState.ErrorInMaintenance) {
-                               /* Host is in non-operation state, so no 
investigation and direct put agent to Disconnected */
-                               status_Logger.debug("Ping timeout but host " + 
agentId + " is in resource state of " + resourceState + ", so no 
investigation");
-                               
_agentMgr.disconnectWithoutInvestigation(agentId, Event.ShutdownRequested);
-                       } else {
-                               status_Logger.debug("Ping timeout for host " + 
agentId + ", do invstigation");
-                               _agentMgr.disconnectWithInvestigation(agentId, 
Event.PingTimeout);
+                    if (h != null) {
+                        ResourceState resourceState = h.getResourceState();
+                        if (resourceState == ResourceState.Disabled || 
resourceState == ResourceState.Maintenance
+                                || resourceState == 
ResourceState.ErrorInMaintenance) {
+                            /*
+                             * Host is in non-operation state, so no
+                             * investigation and direct put agent to
+                             * Disconnected
+                             */
+                            status_Logger.debug("Ping timeout but host " + 
agentId + " is in resource state of "
+                                    + resourceState + ", so no investigation");
+                            _agentMgr.disconnectWithoutInvestigation(agentId, 
Event.ShutdownRequested);
+                        } else {
+                            status_Logger.debug("Ping timeout for host " + 
agentId + ", do invstigation");
+                            _agentMgr.disconnectWithInvestigation(agentId, 
Event.PingTimeout);
+                        }
                        }
                 }
 
                 SearchCriteriaService<HostVO, HostVO> sc = 
SearchCriteria2.create(HostVO.class);
                 sc.addAnd(sc.getEntity().getResourceState(), Op.IN, 
ResourceState.PrepareForMaintenance, ResourceState.ErrorInMaintenance);
                 List<HostVO> hosts = sc.list();
-                
+
                 for (HostVO host : hosts) {
                     long hostId = host.getId();
                     DataCenterVO dcVO = 
_dcDao.findById(host.getDataCenterId());
@@ -170,7 +178,7 @@ public class AgentMonitor extends Thread implements 
Listener {
                         List<VMInstanceVO> vosMigrating = 
_vmDao.listVmsMigratingFromHost(hostId);
                         if (vos.isEmpty() && vosMigrating.isEmpty()) {
                             _alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, 
host.getDataCenterId(), host.getPodId(), "Migration Complete for host " + 
hostDesc, "Host [" + hostDesc + "] is ready for maintenance");
-                            _resourceMgr.resourceStateTransitTo(host, 
ResourceState.Event.InternalEnterMaintenance, _msId);   
+                            _resourceMgr.resourceStateTransitTo(host, 
ResourceState.Event.InternalEnterMaintenance, _msId);
                         }
                     }
                 }

Reply via email to