diff --git a/server/src/com/cloud/agent/manager/AgentMonitor.java b/server/src/com/cloud/agent/manager/AgentMonitor.java index 97c0411d4e6..c019a76eaa8 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 _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 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 sc = SearchCriteria2.create(HostVO.class); sc.addAnd(sc.getEntity().getResourceState(), Op.IN, ResourceState.PrepareForMaintenance, ResourceState.ErrorInMaintenance); List 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 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); } } }