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.
This commit is contained in:
Prachi Damle 2013-02-21 17:39:09 -08:00
parent 1689062334
commit 6823adb3ac
1 changed files with 20 additions and 12 deletions

View File

@ -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);
}
}
}