You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2018/02/06 14:58:38 UTC

[GitHub] DaanHoogland closed pull request #2380: CLOUDSTACK-8855 Improve Error Message for Host Alert State and reconnect host API.

DaanHoogland closed pull request #2380: CLOUDSTACK-8855 Improve Error Message for Host Alert State and reconnect host API.
URL: https://github.com/apache/cloudstack/pull/2380
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/api/src/com/cloud/alert/Alert.java b/api/src/com/cloud/alert/Alert.java
index f77442068d6..d85dca5b7b0 100644
--- a/api/src/com/cloud/alert/Alert.java
+++ b/api/src/com/cloud/alert/Alert.java
@@ -41,4 +41,6 @@
     boolean getArchived();
 
     String getName();
+
+    String getContent();
 }
diff --git a/api/src/com/cloud/resource/ResourceService.java b/api/src/com/cloud/resource/ResourceService.java
index 854b53591d6..70823084d84 100644
--- a/api/src/com/cloud/resource/ResourceService.java
+++ b/api/src/com/cloud/resource/ResourceService.java
@@ -18,7 +18,6 @@
 
 import java.util.List;
 
-import com.cloud.dc.DataCenter;
 import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
 import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
 import org.apache.cloudstack.api.command.admin.host.AddHostCmd;
@@ -29,6 +28,8 @@
 import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd;
 import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
 
+import com.cloud.dc.DataCenter;
+import com.cloud.exception.AgentUnavailableException;
 import com.cloud.exception.DiscoveryException;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceInUseException;
@@ -41,25 +42,17 @@
     /**
      * Updates a host
      *
-     * @param cmd
-     *            - the command specifying hostId
-     * @return hostObject
-     * @throws NoTransitionException
+     * @param cmd - the command specifying hostId
      */
     Host updateHost(UpdateHostCmd cmd) throws NoTransitionException;
 
     Host cancelMaintenance(CancelMaintenanceCmd cmd);
 
-    Host reconnectHost(ReconnectHostCmd cmd);
+    Host reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException;
 
     /**
      * We will automatically create an Apache CloudStack cluster to attach to the external cluster and return a hyper host to perform
      * host related operation within the cluster
-     *
-     * @param cmd
-     * @return
-     * @throws IllegalArgumentException
-     * @throws DiscoveryException
      */
     List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException, ResourceInUseException;
 
@@ -75,12 +68,6 @@
 
     /**
      * Deletes a host
-     *
-     * @param hostId
-     *            TODO
-     * @param isForced
-     *            TODO
-     *
      * @param true if deleted, false otherwise
      */
     boolean deleteHost(long hostId, boolean isForced, boolean isForceDeleteStorage);
diff --git a/api/src/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java b/api/src/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java
index 5e156372681..ec893b7acb7 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java
@@ -1,3 +1,4 @@
+
 // Licensed to the Apache Software Foundation (ASF) under one
 // or more contributor license agreements.  See the NOTICE file
 // distributed with this work for additional information
@@ -16,8 +17,6 @@
 // under the License.
 package org.apache.cloudstack.api.command.admin.host;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiCommandJobType;
 import org.apache.cloudstack.api.ApiConstants;
@@ -27,13 +26,17 @@
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.HostResponse;
 import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
+import com.cloud.exception.AgentUnavailableException;
+import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.host.Host;
 import com.cloud.user.Account;
+import com.cloud.utils.exception.CloudRuntimeException;
 
 @APICommand(name = "reconnectHost", description = "Reconnects a host.", responseObject = HostResponse.class,
-        requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
+requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
 public class ReconnectHostCmd extends BaseAsyncCmd {
     public static final Logger s_logger = Logger.getLogger(ReconnectHostCmd.class.getName());
 
@@ -101,16 +104,17 @@ public Long getInstanceId() {
     public void execute() {
         try {
             Host result = _resourceService.reconnectHost(this);
-            if (result != null) {
-                HostResponse response = _responseGenerator.createHostResponse(result);
-                response.setResponseName(getCommandName());
-                this.setResponseObject(response);
-            } else {
-                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reconnect host");
-            }
-        } catch (Exception ex) {
-            s_logger.warn("Exception: ", ex);
-            throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
+            HostResponse response = _responseGenerator.createHostResponse(result);
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        }catch (InvalidParameterValueException e) {
+            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
+        }
+        catch (CloudRuntimeException e) {
+            s_logger.warn("Exception: ", e);
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
+        }catch (AgentUnavailableException e) {
+            throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, e.getMessage());
         }
     }
 }
diff --git a/engine/components-api/src/com/cloud/agent/AgentManager.java b/engine/components-api/src/com/cloud/agent/AgentManager.java
index 933c3eaef99..c51970c85f7 100644
--- a/engine/components-api/src/com/cloud/agent/AgentManager.java
+++ b/engine/components-api/src/com/cloud/agent/AgentManager.java
@@ -36,7 +36,7 @@
  */
 public interface AgentManager {
     static final ConfigKey<Integer> Wait = new ConfigKey<Integer>("Advanced", Integer.class, "wait", "1800", "Time in seconds to wait for control commands to return",
-        true);
+            true);
 
     public enum TapAgentsAction {
         Add, Del, Contains,
@@ -143,7 +143,7 @@
 
     public void pullAgentOutMaintenance(long hostId);
 
-    boolean reconnect(long hostId);
+    void reconnect(long hostId) throws AgentUnavailableException;
 
     void rescan();
 
diff --git a/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java b/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
index 7815c76a54e..1ad07d801e7 100644
--- a/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
@@ -180,28 +180,18 @@
     @Inject
     ResourceManager _resourceMgr;
 
-    protected final ConfigKey<Integer> Workers = new ConfigKey<Integer>("Advanced", Integer.class, "workers", "5",
-                    "Number of worker threads handling remote agent connections.", false);
+    protected final ConfigKey<Integer> Workers = new ConfigKey<Integer>("Advanced", Integer.class, "workers", "5", "Number of worker threads handling remote agent connections.", false);
     protected final ConfigKey<Integer> Port = new ConfigKey<Integer>("Advanced", Integer.class, "port", "8250", "Port to listen on for remote agent connections.", false);
     protected final ConfigKey<Integer> PingInterval = new ConfigKey<Integer>("Advanced", Integer.class, "ping.interval", "60",
-                    "Interval to send application level pings to make sure the connection is still working", false);
-    protected final ConfigKey<Float> PingTimeout = new ConfigKey<Float>("Advanced", Float.class, "ping.timeout", "2.5",
-                    "Multiplier to ping.interval before announcing an agent has timed out", true);
-    protected final ConfigKey<Integer> AlertWait = new ConfigKey<Integer>("Advanced", Integer.class, "alert.wait", "1800",
-                    "Seconds to wait before alerting on a disconnected agent", true);
-    protected final ConfigKey<Integer> DirectAgentLoadSize = new ConfigKey<Integer>("Advanced", Integer.class, "direct.agent.load.size", "16",
-                    "The number of direct agents to load each time", false);
-    protected final ConfigKey<Integer> DirectAgentPoolSize = new ConfigKey<Integer>("Advanced", Integer.class, "direct.agent.pool.size", "500",
-                    "Default size for DirectAgentPool", false);
+            "Interval to send application level pings to make sure the connection is still working", false);
+    protected final ConfigKey<Float> PingTimeout = new ConfigKey<Float>("Advanced", Float.class, "ping.timeout", "2.5", "Multiplier to ping.interval before announcing an agent has timed out", true);
+    protected final ConfigKey<Integer> AlertWait = new ConfigKey<Integer>("Advanced", Integer.class, "alert.wait", "1800", "Seconds to wait before alerting on a disconnected agent", true);
+    protected final ConfigKey<Integer> DirectAgentLoadSize = new ConfigKey<Integer>("Advanced", Integer.class, "direct.agent.load.size", "16", "The number of direct agents to load each time", false);
+    protected final ConfigKey<Integer> DirectAgentPoolSize = new ConfigKey<Integer>("Advanced", Integer.class, "direct.agent.pool.size", "500", "Default size for DirectAgentPool", false);
     protected final ConfigKey<Float> DirectAgentThreadCap = new ConfigKey<Float>("Advanced", Float.class, "direct.agent.thread.cap", "1",
-                    "Percentage (as a value between 0 and 1) of direct.agent.pool.size to be used as upper thread cap for a single direct agent to process requests", false);
-    protected final ConfigKey<Boolean> CheckTxnBeforeSending = new ConfigKey<Boolean>(
-                    "Developer",
-                    Boolean.class,
-                    "check.txn.before.sending.agent.commands",
-                    "false",
-                    "This parameter allows developers to enable a check to see if a transaction wraps commands that are sent to the resource.  This is not to be enabled on production systems.",
-                    true);
+            "Percentage (as a value between 0 and 1) of direct.agent.pool.size to be used as upper thread cap for a single direct agent to process requests", false);
+    protected final ConfigKey<Boolean> CheckTxnBeforeSending = new ConfigKey<Boolean>("Developer", Boolean.class, "check.txn.before.sending.agent.commands", "false",
+            "This parameter allows developers to enable a check to see if a transaction wraps commands that are sent to the resource.  This is not to be enabled on production systems.", true);
 
     @Override
     public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
@@ -246,7 +236,7 @@ protected int getPingInterval() {
     }
 
     protected long getTimeout() {
-        return (long) (Math.ceil(PingTimeout.value() * PingInterval.value()));
+        return (long)(Math.ceil(PingTimeout.value() * PingInterval.value()));
     }
 
     @Override
@@ -443,8 +433,7 @@ private void setEmptyAnswers(final Commands commands, final Command[] cmds) {
         if (CheckTxnBeforeSending.value()) {
             if (!noDbTxn()) {
                 throw new CloudRuntimeException("We do not allow transactions to be wrapped around commands sent to be executed on remote agents.  "
-                                + "We cannot predict how long it takes a command to complete.  "
-                                + "The transaction may be rolled back because the connection took too long.");
+                        + "We cannot predict how long it takes a command to complete.  " + "The transaction may be rolled back because the connection took too long.");
             }
         } else {
             assert noDbTxn() : "I know, I know.  Why are we so strict as to not allow txn across an agent call?  ...  Why are we so cruel ... Why are we such a dictator .... Too bad... Sorry...but NO AGENT COMMANDS WRAPPED WITHIN DB TRANSACTIONS!";
@@ -571,15 +560,13 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
                     monitor.second().processConnect(host, cmd[i], forRebalance);
                 } catch (final Exception e) {
                     if (e instanceof ConnectionException) {
-                        final ConnectionException ce = (ConnectionException) e;
+                        final ConnectionException ce = (ConnectionException)e;
                         if (ce.isSetupError()) {
-                            s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId +
-                                            " due to " + e.getMessage());
+                            s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage());
                             handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
                             throw ce;
                         } else {
-                            s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId +
-                                            " due to " + e.getMessage());
+                            s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + e.getMessage());
                             handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
                             return attache;
                         }
@@ -587,8 +574,7 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
                         handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true);
                         throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
                     } else {
-                        s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId +
-                                        " due to " + e.getMessage(), e);
+                        s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage(), e);
                         handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
                         throw new CloudRuntimeException("Unable to connect " + attache.getId(), e);
                     }
@@ -641,7 +627,7 @@ private ServerResource loadResourcesWithoutHypervisor(final HostVO host) {
         try {
             final Class<?> clazz = Class.forName(resourceName);
             final Constructor<?> constructor = clazz.getConstructor();
-            resource = (ServerResource) constructor.newInstance();
+            resource = (ServerResource)constructor.newInstance();
         } catch (final ClassNotFoundException e) {
             s_logger.warn("Unable to find class " + host.getResource(), e);
         } catch (final InstantiationException e) {
@@ -895,7 +881,7 @@ protected boolean handleDisconnectWithInvestigation(final AgentAttache attache,
                         final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
                         if (host.getType() != Host.Type.SecondaryStorage && host.getType() != Host.Type.ConsoleProxy) {
                             _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host disconnected, " + hostDesc,
-                                            "If the agent for host [" + hostDesc + "] is not restarted within " + AlertWait + " seconds, host will go to Alert state");
+                                    "If the agent for host [" + hostDesc + "] is not restarted within " + AlertWait + " seconds, host will go to Alert state");
                         }
                         event = Status.Event.AgentDisconnected;
                     }
@@ -906,7 +892,7 @@ protected boolean handleDisconnectWithInvestigation(final AgentAttache attache,
                     final String podName = podVO != null ? podVO.getName() : "NO POD";
                     final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podName;
                     _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host in ALERT state, " + hostDesc,
-                                    "In availability zone " + host.getDataCenterId() + ", host is in alert state: " + host.getId() + "-" + host.getName());
+                            "In availability zone " + host.getDataCenterId() + ", host is in alert state: " + host.getId() + "-" + host.getName());
                 }
             } else {
                 s_logger.debug("The next status of agent " + host.getId() + " is not Alert, no need to investigate what happened");
@@ -994,33 +980,30 @@ public Answer easySend(final Long hostId, final Command cmd) {
     }
 
     @Override
-    public boolean reconnect(final long hostId) {
-        HostVO host;
+    public void reconnect(final long hostId) throws AgentUnavailableException {
+        HostVO host = _hostDao.findById(hostId);
+        if (host == null) {
+            throw new CloudRuntimeException("Unable to find host: " + hostId);
+        }
 
-        host = _hostDao.findById(hostId);
-        if (host == null || host.getRemoved() != null) {
-            s_logger.warn("Unable to find host " + hostId);
-            return false;
+        if (host.getRemoved() != null) {
+            throw new CloudRuntimeException("Host has already been removed: " + hostId);
         }
 
         if (host.getStatus() == Status.Disconnected) {
-            s_logger.info("Host is already disconnected, no work to be done");
-            return true;
+            s_logger.debug("Host is already disconnected, no work to be done: " + hostId);
+            return;
         }
 
         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;
+            throw new CloudRuntimeException("Unable to disconnect host because it is not in the correct state: host=" + hostId + "; Status=" + host.getStatus());
         }
 
-        final AgentAttache attache = findAttache(hostId);
+        AgentAttache attache = findAttache(hostId);
         if (attache == null) {
-            s_logger.info("Unable to disconnect host because it is not connected to this server: " + hostId);
-            return false;
+            throw new CloudRuntimeException("Unable to disconnect host because it is not connected to this server: " + hostId);
         }
-
         disconnectWithoutInvestigation(attache, Event.ShutdownRequested);
-        return true;
     }
 
     @Override
@@ -1056,8 +1039,15 @@ public boolean executeUserRequest(final long hostId, final Event event) throws A
                 handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true);
             }
             return true;
-        } else if (event == Event.ShutdownRequested) {
-            return reconnect(hostId);
+        }
+        if (event == Event.ShutdownRequested) {
+            try {
+                reconnect(hostId);
+            } catch (CloudRuntimeException e) {
+                s_logger.debug("Error on shutdown request for hostID: " + hostId, e);
+                return false;
+            }
+            return true;
         }
         return false;
     }
@@ -1173,7 +1163,7 @@ protected void runInContext() {
             _request.logD("Processing the first command ");
             final StartupCommand[] startups = new StartupCommand[_cmds.length];
             for (int i = 0; i < _cmds.length; i++) {
-                startups[i] = (StartupCommand) _cmds[i];
+                startups[i] = (StartupCommand)_cmds[i];
             }
 
             final AgentAttache attache = handleConnectedAgent(_link, startups, _request);
@@ -1190,9 +1180,8 @@ protected void connectAgent(final Link link, final Command[] cmds, final Request
         Command cmd;
         for (int i = 0; i < cmds.length; i++) {
             cmd = cmds[i];
-            if (cmd instanceof StartupRoutingCommand || cmd instanceof StartupProxyCommand || cmd instanceof StartupSecondaryStorageCommand ||
-                            cmd instanceof StartupStorageCommand) {
-                answers[i] = new StartupAnswer((StartupCommand) cmds[i], 0, getPingInterval());
+            if (cmd instanceof StartupRoutingCommand || cmd instanceof StartupProxyCommand || cmd instanceof StartupSecondaryStorageCommand || cmd instanceof StartupStorageCommand) {
+                answers[i] = new StartupAnswer((StartupCommand)cmds[i], 0, getPingInterval());
                 break;
             }
         }
@@ -1212,7 +1201,7 @@ public AgentHandler(final Task.Type type, final Link link, final byte[] data) {
         }
 
         protected void processRequest(final Link link, final Request request) {
-            final AgentAttache attache = (AgentAttache) link.attachment();
+            final AgentAttache attache = (AgentAttache)link.attachment();
             final Command[] cmds = request.getCommands();
             Command cmd = cmds[0];
             boolean logD = true;
@@ -1251,22 +1240,21 @@ protected void processRequest(final Link link, final Request request) {
                 Answer answer = null;
                 try {
                     if (cmd instanceof StartupRoutingCommand) {
-                        final StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
+                        final StartupRoutingCommand startup = (StartupRoutingCommand)cmd;
                         answer = new StartupAnswer(startup, attache.getId(), getPingInterval());
                     } else if (cmd instanceof StartupProxyCommand) {
-                        final StartupProxyCommand startup = (StartupProxyCommand) cmd;
+                        final StartupProxyCommand startup = (StartupProxyCommand)cmd;
                         answer = new StartupAnswer(startup, attache.getId(), getPingInterval());
                     } else if (cmd instanceof StartupSecondaryStorageCommand) {
-                        final StartupSecondaryStorageCommand startup = (StartupSecondaryStorageCommand) cmd;
+                        final StartupSecondaryStorageCommand startup = (StartupSecondaryStorageCommand)cmd;
                         answer = new StartupAnswer(startup, attache.getId(), getPingInterval());
                     } else if (cmd instanceof StartupStorageCommand) {
-                        final StartupStorageCommand startup = (StartupStorageCommand) cmd;
+                        final StartupStorageCommand startup = (StartupStorageCommand)cmd;
                         answer = new StartupAnswer(startup, attache.getId(), getPingInterval());
                     } else if (cmd instanceof ShutdownCommand) {
-                        final ShutdownCommand shutdown = (ShutdownCommand) cmd;
+                        final ShutdownCommand shutdown = (ShutdownCommand)cmd;
                         final String reason = shutdown.getReason();
-                        s_logger.info("Host " + attache.getId() + " has informed us that it is shutting down with reason " + reason + " and detail " +
-                                        shutdown.getDetail());
+                        s_logger.info("Host " + attache.getId() + " has informed us that it is shutting down with reason " + reason + " and detail " + shutdown.getDetail());
                         if (reason.equals(ShutdownCommand.Update)) {
                             // disconnectWithoutInvestigation(attache, Event.UpdateNeeded);
                             throw new CloudRuntimeException("Agent update not implemented");
@@ -1275,16 +1263,16 @@ protected void processRequest(final Link link, final Request request) {
                         }
                         return;
                     } else if (cmd instanceof AgentControlCommand) {
-                        answer = handleControlCommand(attache, (AgentControlCommand) cmd);
+                        answer = handleControlCommand(attache, (AgentControlCommand)cmd);
                     } else {
-                        handleCommands(attache, request.getSequence(), new Command[] { cmd });
+                        handleCommands(attache, request.getSequence(), new Command[] {cmd});
                         if (cmd instanceof PingCommand) {
-                            final long cmdHostId = ((PingCommand) cmd).getHostId();
+                            final long cmdHostId = ((PingCommand)cmd).getHostId();
 
                             // if the router is sending a ping, verify the
                             // gateway was pingable
                             if (cmd instanceof PingRoutingCommand) {
-                                final boolean gatewayAccessible = ((PingRoutingCommand) cmd).isGatewayAccessible();
+                                final boolean gatewayAccessible = ((PingRoutingCommand)cmd).isGatewayAccessible();
                                 final HostVO host = _hostDao.findById(Long.valueOf(cmdHostId));
 
                                 if (host != null) {
@@ -1293,22 +1281,18 @@ protected void processRequest(final Link link, final Request request) {
                                         // gateway (cannot ping the default route)
                                         final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
                                         final HostPodVO podVO = _podDao.findById(host.getPodId());
-                                        final String hostDesc =
-                                                        "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: "
-                                                                        + podVO.getName();
+                                        final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
 
-                                        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId(),
-                                                        "Host lost connection to gateway, " + hostDesc, "Host [" + hostDesc +
-                                                                        "] lost connection to gateway (default route) and is possibly having network connection issues.");
+                                        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId(), "Host lost connection to gateway, " + hostDesc,
+                                                "Host [" + hostDesc + "] lost connection to gateway (default route) and is possibly having network connection issues.");
                                     } else {
                                         _alertMgr.clearAlert(AlertManager.AlertType.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId());
                                     }
                                 } else {
-                                    s_logger.debug("Not processing " + PingRoutingCommand.class.getSimpleName() + " for agent id=" + cmdHostId +
-                                                    "; can't find the host in the DB");
+                                    s_logger.debug("Not processing " + PingRoutingCommand.class.getSimpleName() + " for agent id=" + cmdHostId + "; can't find the host in the DB");
                                 }
                             }
-                            answer = new PingAnswer((PingCommand) cmd);
+                            answer = new PingAnswer((PingCommand)cmd);
                         } else if (cmd instanceof ReadyAnswer) {
                             final HostVO host = _hostDao.findById(attache.getId());
                             if (host == null) {
@@ -1344,7 +1328,7 @@ protected void processRequest(final Link link, final Request request) {
         }
 
         protected void processResponse(final Link link, final Response response) {
-            final AgentAttache attache = (AgentAttache) link.attachment();
+            final AgentAttache attache = (AgentAttache)link.attachment();
             if (attache == null) {
                 s_logger.warn("Unable to process: " + response);
             } else if (!attache.processAnswers(response.getSequence(), response)) {
@@ -1362,7 +1346,7 @@ protected void doTask(final Task task) throws TaskExecutionException {
                     try {
                         final Request event = Request.parse(data);
                         if (event instanceof Response) {
-                            processResponse(task.getLink(), (Response) event);
+                            processResponse(task.getLink(), (Response)event);
                         } else {
                             processRequest(task.getLink(), event);
                         }
@@ -1377,7 +1361,7 @@ protected void doTask(final Task task) throws TaskExecutionException {
                 } else if (type == Task.Type.CONNECT) {
                 } else if (type == Task.Type.DISCONNECT) {
                     final Link link = task.getLink();
-                    final AgentAttache attache = (AgentAttache) link.attachment();
+                    final AgentAttache attache = (AgentAttache)link.attachment();
                     if (attache != null) {
                         disconnectWithInvestigation(attache, Event.AgentDisconnected);
                     } else {
@@ -1431,10 +1415,8 @@ public boolean agentStatusTransitTo(final HostVO host, final Status.Event e, fin
             try {
                 return _statusStateMachine.transitTo(host, e, host.getId(), _hostDao);
             } catch (final NoTransitionException e1) {
-                status_logger.debug("Cannot transit agent status with event " + e + " for host " + host.getId() + ", name=" + host.getName() +
-                                ", mangement server id is " + msId);
-                throw new CloudRuntimeException("Cannot transit agent status with event " + e + " for host " + host.getId() + ", mangement server id is " + msId + "," +
-                                e1.getMessage());
+                status_logger.debug("Cannot transit agent status with event " + e + " for host " + host.getId() + ", name=" + host.getName() + ", mangement server id is " + msId);
+                throw new CloudRuntimeException("Cannot transit agent status with event " + e + " for host " + host.getId() + ", mangement server id is " + msId + "," + e1.getMessage());
             }
         } finally {
             _agentStatusLock.unlock();
@@ -1498,6 +1480,7 @@ private void disconnectInternal(final long hostId, final Status.Event event, fin
         }
     }
 
+    @Override
     public void disconnectWithInvestigation(final long hostId, final Status.Event event) {
         disconnectInternal(hostId, event, true);
     }
@@ -1508,8 +1491,7 @@ public void disconnectWithoutInvestigation(final long hostId, final Status.Event
     }
 
     @Override
-    public boolean handleDirectConnectAgent(final Host host, final StartupCommand[] cmds, final ServerResource resource,
-            final boolean forRebalance, boolean newHost) throws ConnectionException {
+    public boolean handleDirectConnectAgent(final Host host, final StartupCommand[] cmds, final ServerResource resource, final boolean forRebalance, boolean newHost) throws ConnectionException {
         AgentAttache attache;
 
         attache = createAttacheForDirectConnect(host, resource);
@@ -1590,8 +1572,8 @@ protected void runInContext() {
                             disconnectWithoutInvestigation(agentId, Event.ShutdownRequested);
                         } else {
                             final HostVO host = _hostDao.findById(agentId);
-                            if (host != null && (host.getType() == Host.Type.ConsoleProxy || host.getType() == Host.Type.SecondaryStorageVM
-                                            || host.getType() == Host.Type.SecondaryStorageCmdExecutor)) {
+                            if (host != null
+                                    && (host.getType() == Host.Type.ConsoleProxy || host.getType() == Host.Type.SecondaryStorageVM || host.getType() == Host.Type.SecondaryStorageCmdExecutor)) {
 
                                 s_logger.warn("Disconnect agent for CPVM/SSVM due to physical connection close. host: " + host.getId());
                                 disconnectWithoutInvestigation(agentId, Event.ShutdownRequested);
@@ -1612,8 +1594,8 @@ protected void runInContext() {
                         final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
                         final HostPodVO podVO = _podDao.findById(host.getPodId());
                         final String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
-                        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Migration Complete for host " + hostDesc, "Host ["
-                                        + hostDesc + "] is ready for maintenance");
+                        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Migration Complete for host " + hostDesc,
+                                "Host [" + hostDesc + "] is ready for maintenance");
                     }
                 }
             } catch (final Throwable th) {
@@ -1714,8 +1696,7 @@ public String getConfigComponentName() {
 
     @Override
     public ConfigKey<?>[] getConfigKeys() {
-        return new ConfigKey<?>[] { CheckTxnBeforeSending, Workers, Port, PingInterval, PingTimeout, Wait, AlertWait, DirectAgentLoadSize, DirectAgentPoolSize,
-                        DirectAgentThreadCap };
+        return new ConfigKey<?>[] {CheckTxnBeforeSending, Workers, Port, PingInterval, PingTimeout, Wait, AlertWait, DirectAgentLoadSize, DirectAgentPoolSize, DirectAgentThreadCap};
     }
 
     protected class SetHostParamsListener implements Listener {
@@ -1745,20 +1726,20 @@ public void processHostAdded(long hostId) {
 
         @Override
         public void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance) {
-        if (cmd instanceof StartupRoutingCommand) {
-            if (((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.KVM || ((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.LXC) {
-                Map<String, String> params = new HashMap<String, String>();
-                params.put("router.aggregation.command.each.timeout", _configDao.getValue("router.aggregation.command.each.timeout"));
+            if (cmd instanceof StartupRoutingCommand) {
+                if (((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.KVM || ((StartupRoutingCommand)cmd).getHypervisorType() == HypervisorType.LXC) {
+                    Map<String, String> params = new HashMap<String, String>();
+                    params.put("router.aggregation.command.each.timeout", _configDao.getValue("router.aggregation.command.each.timeout"));
 
-                try {
-                    SetHostParamsCommand cmds = new SetHostParamsCommand(params);
-                    Commands c = new Commands(cmds);
-                    send(host.getId(), c, this);
-                } catch (AgentUnavailableException e) {
-                    s_logger.debug("Failed to send host params on host: " + host.getId());
+                    try {
+                        SetHostParamsCommand cmds = new SetHostParamsCommand(params);
+                        Commands c = new Commands(cmds);
+                        send(host.getId(), c, this);
+                    } catch (AgentUnavailableException e) {
+                        s_logger.debug("Failed to send host params on host: " + host.getId());
+                    }
                 }
             }
-        }
 
         }
 
diff --git a/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
index 0b9899eb9e0..f680be53dec 100644
--- a/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/agent/manager/ClusteredAgentManagerImpl.java
@@ -46,12 +46,12 @@
 import org.apache.cloudstack.framework.config.ConfigDepot;
 import org.apache.cloudstack.framework.config.ConfigKey;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.ha.dao.HAConfigDao;
 import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.managed.context.ManagedContextTimerTask;
+import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
 import org.apache.cloudstack.utils.security.SSLUtils;
-import org.apache.cloudstack.ha.dao.HAConfigDao;
-import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.api.Answer;
@@ -134,14 +134,12 @@ protected ClusteredAgentManagerImpl() {
         super();
     }
 
-    protected final ConfigKey<Boolean> EnableLB = new ConfigKey<Boolean>(Boolean.class, "agent.lb.enabled", "Advanced", "false",
-            "Enable agent load balancing between management server nodes", true);
+    protected final ConfigKey<Boolean> EnableLB = new ConfigKey<Boolean>(Boolean.class, "agent.lb.enabled", "Advanced", "false", "Enable agent load balancing between management server nodes", true);
     protected final ConfigKey<Double> ConnectedAgentThreshold = new ConfigKey<Double>(Double.class, "agent.load.threshold", "Advanced", "0.7",
             "What percentage of the agents can be held by one management server before load balancing happens", true);
-    protected final ConfigKey<Integer> LoadSize = new ConfigKey<Integer>(Integer.class, "direct.agent.load.size", "Advanced", "16",
-            "How many agents to connect to in each round", true);
-    protected final ConfigKey<Integer> ScanInterval = new ConfigKey<Integer>(Integer.class, "direct.agent.scan.interval", "Advanced", "90",
-            "Interval between scans to load agents", false, ConfigKey.Scope.Global, 1000);
+    protected final ConfigKey<Integer> LoadSize = new ConfigKey<Integer>(Integer.class, "direct.agent.load.size", "Advanced", "16", "How many agents to connect to in each round", true);
+    protected final ConfigKey<Integer> ScanInterval = new ConfigKey<Integer>(Integer.class, "direct.agent.scan.interval", "Advanced", "90", "Interval between scans to load agents", false,
+            ConfigKey.Scope.Global, 1000);
 
     @Override
     public boolean configure(final String name, final Map<String, Object> xmlParams) throws ConfigurationException {
@@ -342,8 +340,7 @@ public boolean executeUserRequest(final long hostId, final Event event) throws A
                     final HostTransferMapVO transferVO = _hostTransferDao.findById(hostId);
                     if (transferVO != null) {
                         if (transferVO.getFutureOwner() == _nodeId && transferVO.getState() == HostTransferState.TransferStarted) {
-                            s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId + " as the host is being connected to " +
-                                    _nodeId);
+                            s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId + " as the host is being connected to " + _nodeId);
                             return true;
                         }
                     }
@@ -352,8 +349,7 @@ public boolean executeUserRequest(final long hostId, final Event event) throws A
                 // don't process disconnect if the disconnect came for the host via delayed cluster notification,
                 // but the host has already reconnected to the current management server
                 if (!attache.forForward()) {
-                    s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId +
-                            " as the host is directly connected to the current management server " + _nodeId);
+                    s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId + " as the host is directly connected to the current management server " + _nodeId);
                     return true;
                 }
 
@@ -367,19 +363,15 @@ public boolean executeUserRequest(final long hostId, final Event event) throws A
     }
 
     @Override
-    public boolean reconnect(final long hostId) {
-        Boolean result;
-        try {
-            result = propagateAgentEvent(hostId, Event.ShutdownRequested);
-            if (result != null) {
-                return result;
-            }
-        } catch (final AgentUnavailableException e) {
-            s_logger.debug("cannot propagate agent reconnect because agent is not available", e);
-            return false;
-        }
+    public void reconnect(final long hostId) throws CloudRuntimeException, AgentUnavailableException {
+        Boolean result = propagateAgentEvent(hostId, Event.ShutdownRequested);
+        if (result == null) {
+            super.reconnect(hostId);
 
-        return super.reconnect(hostId);
+        }
+        if (!result) {
+            throw new CloudRuntimeException("Failed to propagating agent change request event:" + Event.ShutdownRequested + " to host:" + hostId);
+        }
     }
 
     public void notifyNodesInCluster(final AgentAttache attache) {
@@ -398,18 +390,18 @@ public void notifyNodesInClusterToScheduleHostScanTask() {
     }
 
     protected static void logT(final byte[] bytes, final String msg) {
-        s_logger.trace("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " +
-                (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
+        s_logger.trace("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": "
+                + (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
     }
 
     protected static void logD(final byte[] bytes, final String msg) {
-        s_logger.debug("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " +
-                (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
+        s_logger.debug("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": "
+                + (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
     }
 
     protected static void logI(final byte[] bytes, final String msg) {
-        s_logger.info("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " +
-                (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
+        s_logger.info("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": "
+                + (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg);
     }
 
     public boolean routeToPeer(final String peer, final byte[] bytes) {
@@ -443,8 +435,7 @@ public boolean routeToPeer(final String peer, final byte[] bytes) {
                     logI(bytes, "Unable to route to peer: " + Request.parse(bytes).toString() + " due to " + e.getMessage());
                 } catch (ClassNotFoundException | UnsupportedVersionException ex) {
                     // Request.parse thrown exception when we try to log it, log as much as we can
-                    logI(bytes, "Unable to route to peer due to" + e.getMessage()
-                            + ". Also caught exception when parsing request: " + ex.getMessage());
+                    logI(bytes, "Unable to route to peer due to" + e.getMessage() + ". Also caught exception when parsing request: " + ex.getMessage());
                 }
             }
         }
@@ -489,8 +480,7 @@ public SocketChannel connectToPeer(final String peerName, final SocketChannel pr
                 try {
                     prevCh.close();
                 } catch (final Exception e) {
-                    s_logger.info("[ignored]"
-                            + "failed to get close resource for previous channel Socket: " + e.getLocalizedMessage());
+                    s_logger.info("[ignored]" + "failed to get close resource for previous channel Socket: " + e.getLocalizedMessage());
                 }
             }
             if (ch == null || ch == prevCh) {
@@ -597,7 +587,7 @@ public boolean stop() {
                     s_logger.info("Closing: " + ch.toString());
                     ch.close();
                 } catch (final IOException e) {
-                    s_logger.info("[ignored] error on closing channel: " +ch.toString(), e);
+                    s_logger.info("[ignored] error on closing channel: " + ch.toString(), e);
                 }
             }
         }
@@ -770,8 +760,7 @@ public void removeAgent(final AgentAttache attache, final Status nextState) {
     }
 
     @Override
-    public boolean executeRebalanceRequest(final long agentId, final long currentOwnerId, final long futureOwnerId, final Event event) throws AgentUnavailableException,
-    OperationTimedoutException {
+    public boolean executeRebalanceRequest(final long agentId, final long currentOwnerId, final long futureOwnerId, final Event event) throws AgentUnavailableException, OperationTimedoutException {
         boolean result = false;
         if (event == Event.RequestAgentRebalance) {
             return setToWaitForRebalance(agentId, currentOwnerId, futureOwnerId);
@@ -837,8 +826,8 @@ public void startRebalanceAgents() {
             avLoad = allManagedAgents.size() / allMS.size();
         } else {
             if (s_logger.isDebugEnabled()) {
-                s_logger.debug("There are no hosts to rebalance in the system. Current number of active management server nodes in the system is " + allMS.size() +
-                        "; number of managed agents is " + allManagedAgents.size());
+                s_logger.debug("There are no hosts to rebalance in the system. Current number of active management server nodes in the system is " + allMS.size() + "; number of managed agents is "
+                        + allManagedAgents.size());
             }
             return;
         }
@@ -991,8 +980,7 @@ protected void runInContext() {
                                 // remove the host from re-balance list and delete from op_host_transfer DB
                                 // no need to do anything with the real attache as we haven't modified it yet
                                 final Date cutTime = DateUtil.currentGMTTime();
-                                final HostTransferMapVO transferMap =
-                                        _hostTransferDao.findActiveHostTransferMapByHostId(hostId, new Date(cutTime.getTime() - rebalanceTimeOut));
+                                final HostTransferMapVO transferMap = _hostTransferDao.findActiveHostTransferMapByHostId(hostId, new Date(cutTime.getTime() - rebalanceTimeOut));
 
                                 if (transferMap == null) {
                                     s_logger.debug("Timed out waiting for the host id=" + hostId + " to be ready to transfer, skipping rebalance for the host");
@@ -1010,8 +998,7 @@ protected void runInContext() {
 
                                 final ManagementServerHostVO ms = _mshostDao.findByMsid(transferMap.getFutureOwner());
                                 if (ms != null && ms.getState() != ManagementServerHost.State.Up) {
-                                    s_logger.debug("Can't transfer host " + hostId + " as it's future owner is not in UP state: " + ms +
-                                            ", skipping rebalance for the host");
+                                    s_logger.debug("Can't transfer host " + hostId + " as it's future owner is not in UP state: " + ms + ", skipping rebalance for the host");
                                     iterator.remove();
                                     _hostTransferDao.completeAgentTransfer(hostId);
                                     continue;
@@ -1027,8 +1014,8 @@ protected void runInContext() {
                                     }
 
                                 } else {
-                                    s_logger.debug("Agent " + hostId + " can't be transfered yet as its request queue size is " + attache.getQueueSize() +
-                                            " and listener queue size is " + attache.getNonRecurringListenersSize());
+                                    s_logger.debug("Agent " + hostId + " can't be transfered yet as its request queue size is " + attache.getQueueSize() + " and listener queue size is "
+                                            + attache.getNonRecurringListenersSize());
                                 }
                             }
                         } else {
@@ -1094,8 +1081,7 @@ protected boolean rebalanceHost(final long hostId, final long currentOwnerId, fi
 
                 if (result) {
                     if (s_logger.isDebugEnabled()) {
-                        s_logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId +
-                                " as a part of rebalance process");
+                        s_logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process");
                     }
                     result = loadDirectlyConnectedHost(host, true);
                 } else {
@@ -1103,17 +1089,15 @@ protected boolean rebalanceHost(final long hostId, final long currentOwnerId, fi
                 }
 
             } catch (final Exception ex) {
-                s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId +
-                        " as a part of rebalance process due to:", ex);
+                s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process due to:",
+                        ex);
                 result = false;
             }
 
             if (result) {
-                s_logger.debug("Successfully loaded directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId +
-                        " as a part of rebalance process");
+                s_logger.debug("Successfully loaded directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process");
             } else {
-                s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId +
-                        " as a part of rebalance process");
+                s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process");
             }
         }
 
@@ -1144,8 +1128,7 @@ protected void finishRebalance(final long hostId, final long futureOwnerId, fina
             // 2) Get all transfer requests and route them to peer
             Request requestToTransfer = forwardAttache.getRequestToTransfer();
             while (requestToTransfer != null) {
-                s_logger.debug("Forwarding request " + requestToTransfer.getSequence() + " held in transfer attache " + hostId + " from the management server " +
-                        _nodeId + " to " + futureOwnerId);
+                s_logger.debug("Forwarding request " + requestToTransfer.getSequence() + " held in transfer attache " + hostId + " from the management server " + _nodeId + " to " + futureOwnerId);
                 final boolean routeResult = routeToPeer(Long.toString(futureOwnerId), requestToTransfer.getBytes());
                 if (!routeResult) {
                     logD(requestToTransfer.getBytes(), "Failed to route request to peer");
@@ -1198,8 +1181,8 @@ protected boolean startRebalance(final long hostId) {
                 if (attache == null) {
                     s_logger.warn("Attache for the agent " + hostId + " no longer exists on management server " + _nodeId + ", can't start host rebalancing");
                 } else {
-                    s_logger.warn("Attache for the agent " + hostId + " has request queue size= " + attache.getQueueSize() + " and listener queue size " +
-                            attache.getNonRecurringListenersSize() + ", can't start host rebalancing");
+                    s_logger.warn("Attache for the agent " + hostId + " has request queue size= " + attache.getQueueSize() + " and listener queue size " + attache.getNonRecurringListenersSize()
+                    + ", can't start host rebalancing");
                 }
                 return false;
             }
@@ -1255,8 +1238,9 @@ private String handleScheduleHostScanTaskCommand(final ScheduleHostScanTaskComma
         } catch (final Exception e) {
             // Scheduling host scan task in peer MS is a best effort operation during host add, regular host scan
             // happens at fixed intervals anyways. So handling any exceptions that may be thrown
-            s_logger.warn("Exception happened while trying to schedule host scan task on mgmt server " + _clusterMgr.getSelfPeerName() +
-                    ", ignoring as regular host scan happens at fixed interval anyways", e);
+            s_logger.warn(
+                    "Exception happened while trying to schedule host scan task on mgmt server " + _clusterMgr.getSelfPeerName() + ", ignoring as regular host scan happens at fixed interval anyways",
+                    e);
             return null;
         }
 
@@ -1372,15 +1356,15 @@ public String dispatch(final ClusterServicePdu pdu) {
                     final String jsonReturn = _gson.toJson(answers);
 
                     if (s_logger.isDebugEnabled()) {
-                        s_logger.debug("Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " +
-                                (System.currentTimeMillis() - startTick) + " ms, return result: " + jsonReturn);
+                        s_logger.debug("Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " + (System.currentTimeMillis() - startTick) + " ms, return result: "
+                                + jsonReturn);
                     }
 
                     return jsonReturn;
                 } else {
                     if (s_logger.isDebugEnabled()) {
-                        s_logger.debug("Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " +
-                                (System.currentTimeMillis() - startTick) + " ms, return null result");
+                        s_logger.debug(
+                                "Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " + (System.currentTimeMillis() - startTick) + " ms, return null result");
                     }
                 }
             } catch (final AgentUnavailableException e) {
diff --git a/engine/schema/resources/META-INF/db/schema-41000to41100.sql b/engine/schema/resources/META-INF/db/schema-41000to41100.sql
index 5d51b47a994..50884b2e4fa 100644
--- a/engine/schema/resources/META-INF/db/schema-41000to41100.sql
+++ b/engine/schema/resources/META-INF/db/schema-41000to41100.sql
@@ -516,3 +516,6 @@ UPDATE `cloud`.`vm_template` SET guest_os_id=99 WHERE id=8;
 
 -- Network External Ids
 ALTER TABLE `cloud`.`networks` ADD `external_id` varchar(255);
+
+--[CLOUDSTACK-9846] Make provision to store content and subject for Alerts in separate columns.
+ALTER TABLE `cloud.`alert` ADD COLUMN `content` VARCHAR(5000);
\ No newline at end of file
diff --git a/engine/schema/src/com/cloud/alert/AlertVO.java b/engine/schema/src/com/cloud/alert/AlertVO.java
index 70ef469f52b..1f2cd9d8c60 100644
--- a/engine/schema/src/com/cloud/alert/AlertVO.java
+++ b/engine/schema/src/com/cloud/alert/AlertVO.java
@@ -53,6 +53,9 @@
     @Column(name = "subject", length = 999)
     private String subject;
 
+    @Column(name = "content", length = 5000)
+    private String content;
+
     @Column(name = "sent_count")
     private int sentCount = 0;
 
@@ -191,4 +194,13 @@ public String getName() {
     public void setName(String name) {
         this.name = name;
     }
+
+    @Override
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
 }
diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
index 38a836d2d6d..1df16404d39 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
@@ -28,12 +28,6 @@
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.log4j.Logger;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import com.google.gson.Gson;
-
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.ServerApiException;
@@ -41,6 +35,9 @@
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
 import org.apache.cloudstack.region.gslb.GslbServiceProvider;
+import org.apache.log4j.Logger;
+import org.json.JSONException;
+import org.json.JSONObject;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
@@ -84,6 +81,7 @@
 import com.cloud.deploy.DeploymentPlan;
 import com.cloud.event.ActionEvent;
 import com.cloud.event.EventTypes;
+import com.cloud.exception.AgentUnavailableException;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.InsufficientNetworkCapacityException;
@@ -154,10 +152,11 @@
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.ReservationContext;
 import com.cloud.vm.VirtualMachineProfile;
+import com.google.gson.Gson;
 
 public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl
-        implements LoadBalancingServiceProvider, NetscalerLoadBalancerElementService, ExternalLoadBalancerDeviceManager,
-        IpDeployer, StaticNatServiceProvider, GslbServiceProvider {
+implements LoadBalancingServiceProvider, NetscalerLoadBalancerElementService, ExternalLoadBalancerDeviceManager,
+IpDeployer, StaticNatServiceProvider, GslbServiceProvider {
 
     private static final Logger s_logger = Logger.getLogger(NetscalerElement.class);
     public static final AutoScaleCounterType AutoScaleCounterSnmp = new AutoScaleCounterType("snmp");
@@ -218,7 +217,7 @@ private boolean canHandle(Network config, Service service) {
 
         boolean handleInAdvanceZone = (zone.getNetworkType() == NetworkType.Advanced
                 && (config.getGuestType() == Network.GuestType.Isolated
-                        || config.getGuestType() == Network.GuestType.Shared)
+                || config.getGuestType() == Network.GuestType.Shared)
                 && config.getTrafficType() == TrafficType.Guest);
         boolean handleInBasicZone = (zone.getNetworkType() == NetworkType.Basic
                 && config.getGuestType() == Network.GuestType.Shared && config.getTrafficType() == TrafficType.Guest);
@@ -242,7 +241,7 @@ private boolean isBasicZoneNetwok(Network config) {
     @Override
     public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest,
             ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException,
-                    InsufficientNetworkCapacityException {
+    InsufficientNetworkCapacityException {
 
         if (!canHandle(guestConfig, Service.Lb)) {
             return false;
@@ -271,7 +270,7 @@ public boolean implement(Network guestConfig, NetworkOffering offering, DeployDe
             throw new ResourceUnavailableException(
                     "There are no NetScaler load balancer devices with the free capacity for implementing this network : "
                             + e.getMessage(),
-                    DataCenter.class, guestConfig.getDataCenterId());
+                            DataCenter.class, guestConfig.getDataCenterId());
         }
     }
 
@@ -286,7 +285,6 @@ public HostVO allocateNCCResourceForNetwork(Network guestConfig) throws Configur
         Map<String, String> _configs;
         List<NetScalerControlCenterVO> ncc = _netscalerControlCenterDao.listAll();
         HostVO hostVO = null;
-        Map<String, Object> params;
         if (ncc.size() > 0) {
             NetScalerControlCenterVO nccVO = ncc.get(0);
             String ipAddress = nccVO.getNccip();
@@ -414,7 +412,7 @@ public boolean manageGuestNetworkWithNetscalerControlCenter(boolean add, Network
     @Override
     public boolean prepare(Network config, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest,
             ReservationContext context) throws ConcurrentOperationException, InsufficientNetworkCapacityException,
-                    ResourceUnavailableException {
+    ResourceUnavailableException {
         return true;
     }
 
@@ -593,45 +591,45 @@ public ExternalLoadBalancerDeviceVO addNetscalerLoadBalancer(AddNetscalerLoadBal
         boolean dedicatedUse = (configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED) != null)
                 ? Boolean.parseBoolean(configParams.get(ApiConstants.LOAD_BALANCER_DEVICE_DEDICATED)) : false;
 
-        if (dedicatedUse && !deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())) {
-            String msg = "Only Netscaler VPX load balancers can be specified for dedicated use";
-            s_logger.debug(msg);
-            throw new InvalidParameterValueException(msg);
-        }
+                if (dedicatedUse && !deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())) {
+                    String msg = "Only Netscaler VPX load balancers can be specified for dedicated use";
+                    s_logger.debug(msg);
+                    throw new InvalidParameterValueException(msg);
+                }
 
-        if (cmd.isGslbProvider()) {
+                if (cmd.isGslbProvider()) {
 
-            if (!deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())
-                    && !deviceName.equals(NetworkDevice.NetscalerMPXLoadBalancer.getName())) {
-                String msg = "Only Netscaler VPX or MPX load balancers can be specified as GSLB service provider";
-                s_logger.debug(msg);
-                throw new InvalidParameterValueException(msg);
-            }
+                    if (!deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName())
+                            && !deviceName.equals(NetworkDevice.NetscalerMPXLoadBalancer.getName())) {
+                        String msg = "Only Netscaler VPX or MPX load balancers can be specified as GSLB service provider";
+                        s_logger.debug(msg);
+                        throw new InvalidParameterValueException(msg);
+                    }
 
-            if (cmd.getSitePublicIp() == null || cmd.getSitePrivateIp() == null) {
-                String msg = "Public and Privae IP needs to provided for NetScaler that will be GSLB provider";
-                s_logger.debug(msg);
-                throw new InvalidParameterValueException(msg);
-            }
+                    if (cmd.getSitePublicIp() == null || cmd.getSitePrivateIp() == null) {
+                        String msg = "Public and Privae IP needs to provided for NetScaler that will be GSLB provider";
+                        s_logger.debug(msg);
+                        throw new InvalidParameterValueException(msg);
+                    }
 
-            if (dedicatedUse) {
-                throw new InvalidParameterValueException(
-                        "NetScaler provisioned to be GSLB service provider can only be configured for shared usage.");
-            }
+                    if (dedicatedUse) {
+                        throw new InvalidParameterValueException(
+                                "NetScaler provisioned to be GSLB service provider can only be configured for shared usage.");
+                    }
 
-        }
+                }
 
-        if (cmd.isExclusiveGslbProvider() && !cmd.isGslbProvider()) {
-            throw new InvalidParameterValueException(
-                    "NetScaler can be provisioned to be exclusive GSLB service provider"
-                            + " only if its being configured as GSLB service provider also.");
-        }
+                if (cmd.isExclusiveGslbProvider() && !cmd.isGslbProvider()) {
+                    throw new InvalidParameterValueException(
+                            "NetScaler can be provisioned to be exclusive GSLB service provider"
+                                    + " only if its being configured as GSLB service provider also.");
+                }
 
-        ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(),
-                cmd.getUsername(), cmd.getPassword(), deviceName, new NetscalerResource(), cmd.isGslbProvider(),
-                cmd.isExclusiveGslbProvider(), cmd.getSitePublicIp(), cmd.getSitePrivateIp());
+                ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(),
+                        cmd.getUsername(), cmd.getPassword(), deviceName, new NetscalerResource(), cmd.isGslbProvider(),
+                        cmd.isExclusiveGslbProvider(), cmd.getSitePublicIp(), cmd.getSitePrivateIp());
 
-        return lbDeviceVO;
+                return lbDeviceVO;
     }
 
     @Override
@@ -759,7 +757,11 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
         });
         HostVO host = _hostDao.findById(lbDeviceVo.getHostId());
 
-        _agentMgr.reconnect(host.getId());
+        try {
+            _agentMgr.reconnect(host.getId());
+        } catch (AgentUnavailableException e) {
+            s_logger.warn("failed to reconnect host " + host, e);
+        }
         return lbDeviceVo;
     }
 
@@ -858,8 +860,9 @@ public boolean deleteServicePackageOffering(DeleteServicePackageOfferingCmd cmd)
         boolean flag=false;
         try {
             result = _netscalerServicePackageDao.findByUuid(cmd.getId());
-            if (result == null)
+            if (result == null) {
                 throw new CloudRuntimeException("Record does not Exists in the Table");
+            }
 
             if(_networkOfferingDao.isUsingServicePackage(result.getUuid()))
             {
@@ -869,10 +872,11 @@ public boolean deleteServicePackageOffering(DeleteServicePackageOfferingCmd cmd)
             flag = _netscalerServicePackageDao.remove(result.getId());
 
         } catch (Exception e) {
-            if (e instanceof InvalidParameterValueException)
+            if (e instanceof InvalidParameterValueException) {
                 throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
-            else
-               throw e;
+            } else {
+                throw e;
+            }
 
         }
         return flag;
@@ -884,18 +888,19 @@ public boolean deleteServicePackageOffering(DeleteServicePackageOfferingCmd cmd)
     public boolean deleteNetscalerControlCenter(DeleteNetscalerControlCenterCmd cmd) throws CloudRuntimeException {
 
         NetScalerControlCenterVO result = _netscalerControlCenterDao.findByUuid(cmd.getId());
-        if (result == null)
+        if (result == null) {
             throw new CloudRuntimeException("External Netscaler Control Center Table does not contain record with this ID");
-        else {
+        } else {
             //ID list of Network Offering which are not removed and have service Package Uuid field not null.
             List<Long> servicePackageId_list = _networkOfferingDao.listNetworkOfferingID();
 
             if (servicePackageId_list.size() != 0) {
                 //VO list of Networks  which are using Network Offering.
                 List<NetworkVO> networkVO_list = _networkDao.listNetworkVO(servicePackageId_list);
-                if (networkVO_list != null && networkVO_list.size() != 0)
+                if (networkVO_list != null && networkVO_list.size() != 0) {
                     throw new CloudRuntimeException(
                             "ServicePackages published by NetScalerControlCenter are being used by NetworkOfferings. Try deleting NetworkOffering with ServicePackages and then delete NetScalerControlCenter.");
+                }
             }
         }
         try {
@@ -1466,8 +1471,9 @@ public NetScalerServicePackageResponse registerNetscalerServicePackage(RegisterS
     @DB
     public NetScalerControlCenterVO registerNetscalerControlCenter(RegisterNetscalerControlCenterCmd cmd) {
 
-        if (_netscalerControlCenterDao.listAll() != null && _netscalerControlCenterDao.listAll().size() != 0)
+        if (_netscalerControlCenterDao.listAll() != null && _netscalerControlCenterDao.listAll().size() != 0) {
             throw new CloudRuntimeException("One Netscaler Control Center already exist in the DataBase. At a time only one Netscaler Control Center is allowed");
+        }
 
         final RegisterNetscalerControlCenterCmd cmdinfo = cmd;
         String ipAddress = cmd.getIpaddress();
@@ -1511,7 +1517,7 @@ public NetScalerControlCenterVO doInTransaction(TransactionStatus status) {
         Long serviceOfferingId = cmd.getServiceOfferingId();
         DeploymentPlan plan = new DataCenterDeployment(dest.getDataCenter().getId());
         try {
-             resp =  _netScalerVMManager.deployNsVpx(cmd.getAccount(), dest, plan, serviceOfferingId, templateId);
+            resp =  _netScalerVMManager.deployNsVpx(cmd.getAccount(), dest, plan, serviceOfferingId, templateId);
         } catch (InsufficientCapacityException e) {
             e.printStackTrace();
         }
@@ -1520,7 +1526,7 @@ public NetScalerControlCenterVO doInTransaction(TransactionStatus status) {
 
     @Override
     public VirtualRouter stopNetscalerServiceVm(Long id, boolean forced, Account callingAccount, long callingUserId) throws ConcurrentOperationException,
-            ResourceUnavailableException {
+    ResourceUnavailableException {
         return _netScalerVMManager.stopNetScalerVm(id, forced, callingAccount, callingUserId);
     }
 }
\ No newline at end of file
diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java
index a58a4f8b0f9..449d452de1f 100644
--- a/server/src/com/cloud/alert/AlertManagerImpl.java
+++ b/server/src/com/cloud/alert/AlertManagerImpl.java
@@ -39,12 +39,6 @@
 import javax.mail.internet.InternetAddress;
 import javax.naming.ConfigurationException;
 
-import org.apache.log4j.Logger;
-
-import com.sun.mail.smtp.SMTPMessage;
-import com.sun.mail.smtp.SMTPSSLTransport;
-import com.sun.mail.smtp.SMTPTransport;
-
 import org.apache.cloudstack.framework.config.ConfigDepot;
 import org.apache.cloudstack.framework.config.ConfigKey;
 import org.apache.cloudstack.framework.config.Configurable;
@@ -52,6 +46,7 @@
 import org.apache.cloudstack.managed.context.ManagedContextTimerTask;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.log4j.Logger;
 
 import com.cloud.alert.dao.AlertDao;
 import com.cloud.api.ApiDBUtils;
@@ -85,6 +80,9 @@
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
 import com.cloud.utils.db.SearchCriteria;
+import com.sun.mail.smtp.SMTPMessage;
+import com.sun.mail.smtp.SMTPSSLTransport;
+import com.sun.mail.smtp.SMTPTransport;
 
 public class AlertManagerImpl extends ManagerBase implements AlertManager, Configurable {
     private static final Logger s_logger = Logger.getLogger(AlertManagerImpl.class.getName());
@@ -205,8 +203,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
         String capacityCheckPeriodStr = configs.get("capacity.check.period");
         if (capacityCheckPeriodStr != null) {
             _capacityCheckPeriod = Long.parseLong(capacityCheckPeriodStr);
-            if (_capacityCheckPeriod <= 0)
+            if (_capacityCheckPeriod <= 0) {
                 _capacityCheckPeriod = Long.parseLong(Config.CapacityCheckPeriod.getDefaultValue());
+            }
         }
 
         _timer = new Timer("CapacityChecker");
@@ -589,7 +588,7 @@ private void generateEmailAlert(DataCenterVO dc, HostPodVO pod, ClusterVO cluste
             alertType = AlertManager.AlertType.ALERT_TYPE_LOCAL_STORAGE;
             break;
 
-        //Pod Level
+            //Pod Level
         case Capacity.CAPACITY_TYPE_PRIVATE_IP:
             msgSubject = "System Alert: Number of unallocated private IPs is low in pod " + pod.getName() + " of availability zone " + dc.getName();
             totalStr = Double.toString(totalCapacity);
@@ -598,7 +597,7 @@ private void generateEmailAlert(DataCenterVO dc, HostPodVO pod, ClusterVO cluste
             alertType = AlertManager.AlertType.ALERT_TYPE_PRIVATE_IP;
             break;
 
-        //Zone Level
+            //Zone Level
         case Capacity.CAPACITY_TYPE_SECONDARY_STORAGE:
             msgSubject = "System Alert: Low Available Secondary Storage in availability zone " + dc.getName();
             totalStr = formatBytesToMegabytes(totalCapacity);
@@ -746,22 +745,22 @@ protected PasswordAuthentication getPasswordAuthentication() {
 
         // TODO:  make sure this handles SSL transport (useAuth is true) and regular
         public void sendAlert(AlertType alertType, long dataCenterId, Long podId, Long clusterId, String subject, String content) throws MessagingException,
-                UnsupportedEncodingException {
+        UnsupportedEncodingException {
             s_alertsLogger.warn("AlertType:: " + alertType + " | dataCenterId:: " + dataCenterId + " | podId:: " +
                     podId + " | clusterId:: " + clusterId + " | message:: " + subject);
             AlertVO alert = null;
             if ((alertType != AlertManager.AlertType.ALERT_TYPE_HOST) &&
-                (alertType != AlertManager.AlertType.ALERT_TYPE_USERVM) &&
-                (alertType != AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER) &&
-                (alertType != AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY) &&
-                (alertType != AlertManager.AlertType.ALERT_TYPE_SSVM) &&
-                (alertType != AlertManager.AlertType.ALERT_TYPE_STORAGE_MISC) &&
-                (alertType != AlertManager.AlertType.ALERT_TYPE_MANAGMENT_NODE) &&
-                (alertType != AlertManager.AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED) &&
-                (alertType != AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED) &&
-                (alertType != AlertManager.AlertType.ALERT_TYPE_OOBM_AUTH_ERROR) &&
-                (alertType != AlertManager.AlertType.ALERT_TYPE_HA_ACTION) &&
-                (alertType != AlertManager.AlertType.ALERT_TYPE_CA_CERT)) {
+                    (alertType != AlertManager.AlertType.ALERT_TYPE_USERVM) &&
+                    (alertType != AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER) &&
+                    (alertType != AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY) &&
+                    (alertType != AlertManager.AlertType.ALERT_TYPE_SSVM) &&
+                    (alertType != AlertManager.AlertType.ALERT_TYPE_STORAGE_MISC) &&
+                    (alertType != AlertManager.AlertType.ALERT_TYPE_MANAGMENT_NODE) &&
+                    (alertType != AlertManager.AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED) &&
+                    (alertType != AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED) &&
+                    (alertType != AlertManager.AlertType.ALERT_TYPE_OOBM_AUTH_ERROR) &&
+                    (alertType != AlertManager.AlertType.ALERT_TYPE_HA_ACTION) &&
+                    (alertType != AlertManager.AlertType.ALERT_TYPE_CA_CERT)) {
                 alert = _alertDao.getLastAlert(alertType.getType(), dataCenterId, podId, clusterId);
             }
 
@@ -770,6 +769,7 @@ public void sendAlert(AlertType alertType, long dataCenterId, Long podId, Long c
                 AlertVO newAlert = new AlertVO();
                 newAlert.setType(alertType.getType());
                 newAlert.setSubject(subject);
+                newAlert.setContent(content);
                 newAlert.setClusterId(clusterId);
                 newAlert.setPodId(podId);
                 newAlert.setDataCenterId(dataCenterId);
diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java
index c9916e90130..69e5fad2e21 100755
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@ -29,10 +29,6 @@
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
 import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
@@ -49,6 +45,9 @@
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
@@ -74,7 +73,6 @@
 import com.cloud.capacity.dao.CapacityDao;
 import com.cloud.cluster.ClusterManager;
 import com.cloud.configuration.Config;
-import com.cloud.configuration.ConfigurationManager;
 import com.cloud.dc.ClusterDetailsDao;
 import com.cloud.dc.ClusterDetailsVO;
 import com.cloud.dc.ClusterVO;
@@ -248,8 +246,6 @@ public void setDiscoverers(final List<? extends Discoverer> discoverers) {
     @Inject
     private VMTemplateDao _templateDao;
     @Inject
-    private ConfigurationManager _configMgr;
-    @Inject
     private ClusterVSMMapDao _clusterVSMMapDao;
 
     private final long _nodeId = ManagementServerNode.getManagementServerId();
@@ -609,7 +605,7 @@ public Discoverer getMatchingDiscover(final Hypervisor.HypervisorType hypervisor
 
     private List<HostVO> discoverHostsFull(final Long dcId, final Long podId, Long clusterId, final String clusterName, String url, String username, String password,
             final String hypervisorType, final List<String> hostTags, final Map<String, String> params, final boolean deferAgentCreation) throws IllegalArgumentException, DiscoveryException,
-            InvalidParameterValueException {
+    InvalidParameterValueException {
         URI uri = null;
 
         // Check if the zone exists in the system
@@ -835,7 +831,6 @@ protected boolean doDeleteHost(final long hostId, final boolean isForced, final
         }
         // Get storage pool host mappings here because they can be removed as a
         // part of handleDisconnect later
-        // TODO: find out the bad boy, what's a buggy logic!
         final List<StoragePoolHostVO> pools = _storagePoolHostDao.listByHostIdIncludingRemoved(hostId);
 
         final ResourceStateAdapter.DeleteHostAnswer answer =
@@ -1165,15 +1160,16 @@ public Host cancelMaintenance(final CancelMaintenanceCmd cmd) {
     }
 
     @Override
-    public Host reconnectHost(final ReconnectHostCmd cmd) {
-        final Long hostId = cmd.getId();
+    public Host reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException {
+        Long hostId = cmd.getId();
 
-        final HostVO host = _hostDao.findById(hostId);
+        HostVO host = _hostDao.findById(hostId);
         if (host == null) {
             throw new InvalidParameterValueException("Host with id " + hostId.toString() + " doesn't exist");
         }
 
-        return _agentMgr.reconnect(hostId) ? host : null;
+        _agentMgr.reconnect(hostId);
+        return host;
     }
 
     @Override
@@ -2309,7 +2305,6 @@ public boolean executeUserRequest(final long hostId, final ResourceState.Event e
         } else if (event == ResourceState.Event.AdminCancelMaintenance) {
             return doCancelMaintenance(hostId);
         } else if (event == ResourceState.Event.DeleteHost) {
-            /* TODO: Ask alex why we assume the last two parameters are false */
             return doDeleteHost(hostId, false, false);
         } else if (event == ResourceState.Event.Unmanaged) {
             return doUmanageHost(hostId);
@@ -2328,7 +2323,7 @@ private boolean doUmanageHost(final long hostId) {
         }
 
         if (host.getHypervisorType() == HypervisorType.KVM || host.getHypervisorType() == HypervisorType.LXC) {
-            final MaintainAnswer answer = (MaintainAnswer)_agentMgr.easySend(hostId, new MaintainCommand());
+            _agentMgr.easySend(hostId, new MaintainCommand());
         }
 
         _agentMgr.disconnectWithoutInvestigation(hostId, Event.ShutdownRequested);
@@ -2378,10 +2373,6 @@ public boolean updateClusterPassword(final UpdateHostPasswordCmd command) {
         final List<HostVO> hosts = listAllHostsInCluster(command.getClusterId());
         for (final HostVO host : hosts) {
             try {
-                /*
-                 * FIXME: this is a buggy logic, check with alex. Shouldn't
-                 * return if propagation return non null
-                 */
                 final Boolean result = propagateResourceEvent(host.getId(), ResourceState.Event.UpdatePassword);
                 if (result != null) {
                     return result;
@@ -2834,11 +2825,4 @@ public Boolean doInTransaction(final TransactionStatus status) {
             return false;
         }
     }
-
-    @Override
-    public boolean start() {
-        // TODO Auto-generated method stub
-        return super.start();
-    }
-
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services