From 0c750aa8faaebf6d426a5b5fc65f7865c419ac79 Mon Sep 17 00:00:00 2001 From: anthony Date: Sat, 9 Oct 2010 17:34:36 -0700 Subject: [PATCH] bug 6462: notifyMonitorsOfConnection of handleDirectConnect may fail, but it still returns the removed attach, and lauch ping task status 6462: resolved fixed --- .../cloud/agent/manager/AgentManagerImpl.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index cd8cf1f5007..7e94163a6b5 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -482,9 +482,9 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory { AgentAttache attache = createAttache(id, server, resource); if (!resource.IsRemoteAgent()) - notifyMonitorsOfConnection(attache, startup); + attache = notifyMonitorsOfConnection(attache, startup); else { - _hostDao.updateStatus(server, Event.AgentConnected, _nodeId); + _hostDao.updateStatus(server, Event.AgentConnected, _nodeId); } return attache; } @@ -896,14 +896,12 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory { if (s_logger.isDebugEnabled()) { s_logger.debug("Deregistering link for " + hostId + " with state " + nextState); } + + _hostDao.disconnect(host, event, _nodeId); + synchronized (_agents) { AgentAttache removed = _agents.remove(hostId); - if (removed != null && removed != attache) { // NOTE: == is intentionally used here. - _agents.put(removed.getId(), removed); - } } - - _hostDao.disconnect(host, event, _nodeId); host = _hostDao.findById(host.getId()); if (host.getStatus() == Status.Alert || host.getStatus() == Status.Down) { _haMgr.scheduleRestartForVmsOnHost(host); @@ -920,7 +918,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory { return true; } - protected void notifyMonitorsOfConnection(AgentAttache attache, final StartupCommand[] cmd) { + protected AgentAttache notifyMonitorsOfConnection(AgentAttache attache, final StartupCommand[] cmd) { long hostId = attache.getId(); HostVO host = _hostDao.findById(hostId); for (Pair monitor : _hostMonitors) { @@ -931,7 +929,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory { if (!monitor.second().processConnect(host, cmd[i])) { s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId); handleDisconnect(attache, Event.AgentDisconnected, false); - return; + return null; } } } @@ -941,11 +939,12 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory { Answer answer = easySend(hostId, ready); if (answer == null) { handleDisconnect(attache, Event.AgentDisconnected, false); - return; + return null; } _hostDao.updateStatus(host, Event.Ready, _nodeId); attache.ready(); + return attache; } @Override @@ -1597,7 +1596,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory { AgentAttache attache = createAttache(id, server, link); - notifyMonitorsOfConnection(attache, startup); + attache = notifyMonitorsOfConnection(attache, startup); return attache; }