Updated Branches: refs/heads/master ddcad148e -> bd4661e46
CLOUDSTACK-1137: force reconnect to a disconnected host throws error. Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/bd4661e4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/bd4661e4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/bd4661e4 Branch: refs/heads/master Commit: bd4661e46746a5f597ce72e1b8c9ad3962cede90 Parents: ddcad14 Author: Min Chen <[email protected]> Authored: Thu Feb 14 17:56:04 2013 -0800 Committer: Min Chen <[email protected]> Committed: Thu Feb 14 17:57:41 2013 -0800 ---------------------------------------------------------------------- .../com/cloud/agent/manager/AgentManagerImpl.java | 19 +++++++++----- 1 files changed, 12 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bd4661e4/server/src/com/cloud/agent/manager/AgentManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java index 2286dab..3b5d433 100755 --- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java +++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java @@ -230,7 +230,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl @Override public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException { - + final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params); _port = NumbersUtil.parseInt(configs.get("port"), 8250); final int workers = NumbersUtil.parseInt(configs.get("workers"), 5); @@ -778,7 +778,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl if (host != null) { agentStatusTransitTo(host, Event.AgentDisconnected, _nodeId); } - } + } } if (forRebalance) { @@ -895,7 +895,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } catch (NoTransitionException ne) { /* Agent may be currently in status of Down, Alert, Removed, namely there is no next status for some events. * Why this can happen? Ask God not me. I hate there was no piece of comment for code handling race condition. - * God knew what race condition the code dealt with! + * God knew what race condition the code dealt with! */ } @@ -1046,6 +1046,11 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl return false; } + if (host.getStatus() == Status.Disconnected) { + s_logger.info("Host is already disconnected, no work to be done"); + return true; + } + if (host.getStatus() != Status.Up && host.getStatus() != Status.Alert && host.getStatus() != Status.Rebalancing) { s_logger.info("Unable to disconnect host because it is not in the correct state: host=" + hostId + "; Status=" + host.getStatus()); return false; @@ -1197,12 +1202,12 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } } Response response = null; - response = new Response(request, answers[0], _nodeId, -1); + response = new Response(request, answers[0], _nodeId, -1); try { link.send(response.toBytes()); } catch (ClosedChannelException e) { s_logger.debug("Failed to send startupanswer: " + e.toString()); - } + } _connectExecutor.execute(new HandleAgentConnectTask(link, cmds, request)); } @@ -1405,7 +1410,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } else { throw new CloudRuntimeException("Unkonwn TapAgentsAction " + action); } - } + } return true; } @@ -1508,7 +1513,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl attache.setMaintenanceMode(true); // Now cancel all of the commands except for the active one. attache.cancelAllCommands(Status.Disconnected, false); - } + } } @Override
