cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject [08/15] git commit: updated refs/heads/master to 527d6ee
Date Mon, 29 Jun 2015 08:43:46 GMT
Formatting the code of the AgentManagerImpl class

Signed-off-by: wilderrodrigues <wrodrigues@schubergphilis.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4690c3d8
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4690c3d8
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4690c3d8

Branch: refs/heads/master
Commit: 4690c3d844602ffa570c49078c21f41cd83a3903
Parents: b6f1298
Author: wilderrodrigues <wrodrigues@schubergphilis.com>
Authored: Thu Jun 25 11:03:06 2015 +0200
Committer: wilderrodrigues <wrodrigues@schubergphilis.com>
Committed: Mon Jun 29 09:59:10 2015 +0200

----------------------------------------------------------------------
 .../cloud/agent/manager/AgentManagerImpl.java   | 366 ++++++++++---------
 1 file changed, 184 insertions(+), 182 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4690c3d8/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java b/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
index addf482..eff1f01 100644
--- a/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java
@@ -38,8 +38,6 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.framework.config.ConfigKey;
 import org.apache.cloudstack.framework.config.Configurable;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
@@ -47,6 +45,7 @@ import org.apache.cloudstack.framework.jobs.AsyncJob;
 import org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext;
 import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
+import org.apache.log4j.Logger;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.Listener;
@@ -203,12 +202,12 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
 
         s_logger.info("Ping Timeout is " + PingTimeout.value());
 
-        int threads = DirectAgentLoadSize.value();
+        final int threads = DirectAgentLoadSize.value();
 
         _nodeId = ManagementServerNode.getManagementServerId();
         s_logger.info("Configuring AgentManagerImpl. management server node id(msid): " + _nodeId);
 
-        long lastPing = (System.currentTimeMillis() >> 10) - (long)(PingTimeout.value() * PingInterval.value());
+        final long lastPing = (System.currentTimeMillis() >> 10) - (long)(PingTimeout.value() * PingInterval.value());
         _hostDao.markHostsAsDisconnected(_nodeId, lastPing);
 
         registerForHostEvents(new BehindOnPingListener(), true, true, false);
@@ -239,12 +238,12 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     }
 
     @Override
-    public Task create(Task.Type type, Link link, byte[] data) {
+    public Task create(final Task.Type type, final Link link, final byte[] data) {
         return new AgentHandler(type, link, data);
     }
 
     @Override
-    public int registerForHostEvents(final Listener listener, boolean connections, boolean commands, boolean priority) {
+    public int registerForHostEvents(final Listener listener, final boolean connections, final boolean commands, final boolean priority) {
         synchronized (_hostMonitors) {
             _monitorId++;
             if (connections) {
@@ -269,7 +268,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     }
 
     @Override
-    public int registerForInitialConnects(final StartupCommandProcessor creator, boolean priority) {
+    public int registerForInitialConnects(final StartupCommandProcessor creator, final boolean priority) {
         synchronized (_hostMonitors) {
             _monitorId++;
             if (priority) {
@@ -287,10 +286,10 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         _hostMonitors.remove(id);
     }
 
-    private AgentControlAnswer handleControlCommand(AgentAttache attache, final AgentControlCommand cmd) {
+    private AgentControlAnswer handleControlCommand(final AgentAttache attache, final AgentControlCommand cmd) {
         AgentControlAnswer answer = null;
 
-        for (Pair<Integer, Listener> listener : _cmdMonitors) {
+        for (final Pair<Integer, Listener> listener : _cmdMonitors) {
             answer = listener.second().processControlCommand(attache.getId(), cmd);
 
             if (answer != null) {
@@ -302,22 +301,22 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         return new AgentControlAnswer(cmd);
     }
 
-    public void handleCommands(AgentAttache attache, final long sequence, final Command[] cmds) {
-        for (Pair<Integer, Listener> listener : _cmdMonitors) {
-            boolean processed = listener.second().processCommands(attache.getId(), sequence, cmds);
+    public void handleCommands(final AgentAttache attache, final long sequence, final Command[] cmds) {
+        for (final Pair<Integer, Listener> listener : _cmdMonitors) {
+            final boolean processed = listener.second().processCommands(attache.getId(), sequence, cmds);
             if (s_logger.isTraceEnabled()) {
                 s_logger.trace("SeqA " + attache.getId() + "-" + sequence + ": " + (processed ? "processed" : "not processed") + " by " + listener.getClass());
             }
         }
     }
 
-    public void notifyAnswersToMonitors(long agentId, long seq, Answer[] answers) {
-        for (Pair<Integer, Listener> listener : _cmdMonitors) {
+    public void notifyAnswersToMonitors(final long agentId, final long seq, final Answer[] answers) {
+        for (final Pair<Integer, Listener> listener : _cmdMonitors) {
             listener.second().processAnswers(agentId, seq, answers);
         }
     }
 
-    public AgentAttache findAttache(long hostId) {
+    public AgentAttache findAttache(final long hostId) {
         AgentAttache attache = null;
         synchronized (_agents) {
             attache = _agents.get(hostId);
@@ -326,12 +325,12 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     }
 
     @Override
-    public Answer sendTo(Long dcId, HypervisorType type, Command cmd) {
-        List<ClusterVO> clusters = _clusterDao.listByDcHyType(dcId, type.toString());
+    public Answer sendTo(final Long dcId, final HypervisorType type, final Command cmd) {
+        final List<ClusterVO> clusters = _clusterDao.listByDcHyType(dcId, type.toString());
         int retry = 0;
-        for (ClusterVO cluster : clusters) {
-            List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), null, dcId);
-            for (HostVO host : hosts) {
+        for (final ClusterVO cluster : clusters) {
+            final List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), null, dcId);
+            for (final HostVO host : hosts) {
                 retry++;
                 if (retry > _retry) {
                     return null;
@@ -339,9 +338,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
                 Answer answer = null;
                 try {
 
-                    long targetHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(host.getId(), cmd);
+                    final long targetHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(host.getId(), cmd);
                     answer = easySend(targetHostId, cmd);
-                } catch (Exception e) {
+                } catch (final Exception e) {
                 }
                 if (answer != null) {
                     return answer;
@@ -356,16 +355,16 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     }
 
     @Override
-    public Answer send(Long hostId, Command cmd) throws AgentUnavailableException, OperationTimedoutException {
-        Commands cmds = new Commands(Command.OnError.Stop);
+    public Answer send(final Long hostId, final Command cmd) throws AgentUnavailableException, OperationTimedoutException {
+        final Commands cmds = new Commands(Command.OnError.Stop);
         cmds.addCommand(cmd);
         send(hostId, cmds, cmd.getWait());
-        Answer[] answers = cmds.getAnswers();
+        final Answer[] answers = cmds.getAnswers();
         if (answers != null && !(answers[0] instanceof UnsupportedAnswer)) {
             return answers[0];
         }
 
-        if (answers != null && (answers[0] instanceof UnsupportedAnswer)) {
+        if (answers != null && answers[0] instanceof UnsupportedAnswer) {
             s_logger.warn("Unsupported Command: " + answers[0].getDetails());
             return answers[0];
         }
@@ -375,19 +374,20 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
 
     @DB
     protected boolean noDbTxn() {
-        TransactionLegacy txn = TransactionLegacy.currentTxn();
+        final TransactionLegacy txn = TransactionLegacy.currentTxn();
         return !txn.dbTxnStarted();
     }
 
-    private static void tagCommand(Command cmd) {
-        AsyncJobExecutionContext context = AsyncJobExecutionContext.getCurrent();
+    private static void tagCommand(final Command cmd) {
+        final AsyncJobExecutionContext context = AsyncJobExecutionContext.getCurrent();
         if (context != null && context.getJob() != null) {
-            AsyncJob job = context.getJob();
+            final AsyncJob job = context.getJob();
 
-            if (job.getRelated() != null && !job.getRelated().isEmpty())
+            if (job.getRelated() != null && !job.getRelated().isEmpty()) {
                 cmd.setContextParam("job", "job-" + job.getRelated() + "/" + "job-" + job.getId());
-            else
+            } else {
                 cmd.setContextParam("job", "job-" + job.getId());
+            }
         }
     }
 
@@ -395,15 +395,16 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
      * @param commands
      * @return
      */
-    private Command[] checkForCommandsAndTag(Commands commands) {
-        Command[] cmds = commands.toCommands();
+    private Command[] checkForCommandsAndTag(final Commands commands) {
+        final Command[] cmds = commands.toCommands();
 
         assert cmds.length > 0 : "Ask yourself this about a hundred times.  Why am I  sending zero length commands?";
 
         setEmptyAnswers(commands, cmds);
 
-        for (Command cmd : cmds)
+        for (final Command cmd : cmds) {
             tagCommand(cmd);
+        }
         return cmds;
     }
 
@@ -411,14 +412,14 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
      * @param commands
      * @param cmds
      */
-    private void setEmptyAnswers(Commands commands, Command[] cmds) {
+    private void setEmptyAnswers(final Commands commands, final Command[] cmds) {
         if (cmds.length == 0) {
             commands.setAnswers(new Answer[0]);
         }
     }
 
     @Override
-    public Answer[] send(Long hostId, Commands commands, int timeout) throws AgentUnavailableException, OperationTimedoutException {
+    public Answer[] send(final Long hostId, final Commands commands, int timeout) throws AgentUnavailableException, OperationTimedoutException {
         assert hostId != null : "Who's not checking the agent id before sending?  ... (finger wagging)";
         if (hostId == null) {
             throw new AgentUnavailableException(-1);
@@ -438,31 +439,31 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
             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!";
         }
 
-        Command[] cmds = checkForCommandsAndTag(commands);
+        final Command[] cmds = checkForCommandsAndTag(commands);
 
         final AgentAttache agent = getAttache(hostId);
         if (agent == null || agent.isClosed()) {
             throw new AgentUnavailableException("agent not logged into this management server", hostId);
         }
 
-        Request req = new Request(hostId, agent.getName(), _nodeId, cmds, commands.stopOnError(), true);
+        final Request req = new Request(hostId, agent.getName(), _nodeId, cmds, commands.stopOnError(), true);
         req.setSequence(agent.getNextSequence());
-        Answer[] answers = agent.send(req, timeout);
+        final Answer[] answers = agent.send(req, timeout);
         notifyAnswersToMonitors(hostId, req.getSequence(), answers);
         commands.setAnswers(answers);
         return answers;
     }
 
-    protected Status investigate(AgentAttache agent) {
-        Long hostId = agent.getId();
-        HostVO host = _hostDao.findById(hostId);
+    protected Status investigate(final AgentAttache agent) {
+        final Long hostId = agent.getId();
+        final HostVO host = _hostDao.findById(hostId);
         if (host != null && host.getType() != null && !host.getType().isVirtual()) {
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("checking if agent (" + hostId + ") is alive");
             }
-            Answer answer = easySend(hostId, new CheckHealthCommand());
+            final Answer answer = easySend(hostId, new CheckHealthCommand());
             if (answer != null && answer.getResult()) {
-                Status status = Status.Up;
+                final Status status = Status.Up;
                 if (s_logger.isDebugEnabled()) {
                     s_logger.debug("agent (" + hostId + ") responded to checkHeathCommand, reporting that agent is " + status);
                 }
@@ -477,7 +478,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         if (hostId == null) {
             return null;
         }
-        AgentAttache agent = findAttache(hostId);
+        final AgentAttache agent = findAttache(hostId);
         if (agent == null) {
             s_logger.debug("Unable to find agent for " + hostId);
             throw new AgentUnavailableException("Unable to find agent ", hostId);
@@ -487,26 +488,26 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     }
 
     @Override
-    public long send(Long hostId, Commands commands, Listener listener) throws AgentUnavailableException {
+    public long send(final Long hostId, final Commands commands, final Listener listener) throws AgentUnavailableException {
         final AgentAttache agent = getAttache(hostId);
         if (agent.isClosed()) {
             throw new AgentUnavailableException("Agent " + agent.getId() + " is closed", agent.getId());
         }
 
-        Command[] cmds = checkForCommandsAndTag(commands);
+        final Command[] cmds = checkForCommandsAndTag(commands);
 
-        Request req = new Request(hostId, agent.getName(), _nodeId, cmds, commands.stopOnError(), true);
+        final Request req = new Request(hostId, agent.getName(), _nodeId, cmds, commands.stopOnError(), true);
         req.setSequence(agent.getNextSequence());
 
         agent.send(req, listener);
         return req.getSequence();
     }
 
-    public void removeAgent(AgentAttache attache, Status nextState) {
+    public void removeAgent(final AgentAttache attache, final Status nextState) {
         if (attache == null) {
             return;
         }
-        long hostId = attache.getId();
+        final long hostId = attache.getId();
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Remove Agent : " + hostId);
         }
@@ -527,7 +528,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
             removed.disconnect(nextState);
         }
 
-        for (Pair<Integer, Listener> monitor : _hostMonitors) {
+        for (final Pair<Integer, Listener> monitor : _hostMonitors) {
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Sending Disconnect to listener: " + monitor.second().getClass().getName());
             }
@@ -535,19 +536,19 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         }
     }
 
-    protected AgentAttache notifyMonitorsOfConnection(AgentAttache attache, final StartupCommand[] cmd, boolean forRebalance) throws ConnectionException {
-        long hostId = attache.getId();
-        HostVO host = _hostDao.findById(hostId);
-        for (Pair<Integer, Listener> monitor : _hostMonitors) {
+    protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, final StartupCommand[] cmd, final boolean forRebalance) throws ConnectionException {
+        final long hostId = attache.getId();
+        final HostVO host = _hostDao.findById(hostId);
+        for (final Pair<Integer, Listener> monitor : _hostMonitors) {
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Sending Connect to listener: " + monitor.second().getClass().getSimpleName());
             }
             for (int i = 0; i < cmd.length; i++) {
                 try {
                     monitor.second().processConnect(host, cmd[i], forRebalance);
-                } catch (Exception e) {
+                } catch (final Exception e) {
                     if (e instanceof ConnectionException) {
-                        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());
@@ -572,9 +573,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
             }
         }
 
-        Long dcId = host.getDataCenterId();
-        ReadyCommand ready = new ReadyCommand(dcId, host.getId());
-        Answer answer = easySend(hostId, ready);
+        final Long dcId = host.getDataCenterId();
+        final ReadyCommand ready = new ReadyCommand(dcId, host.getId());
+        final Answer answer = easySend(hostId, ready);
         if (answer == null || !answer.getResult()) {
             // this is tricky part for secondary storage
             // make it as disconnected, wait for secondary storage VM to be up
@@ -601,39 +602,39 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     }
 
     public void startDirectlyConnectedHosts() {
-        List<HostVO> hosts = _resourceMgr.findDirectlyConnectedHosts();
-        for (HostVO host : hosts) {
+        final List<HostVO> hosts = _resourceMgr.findDirectlyConnectedHosts();
+        for (final HostVO host : hosts) {
             loadDirectlyConnectedHost(host, false);
         }
     }
 
-    private ServerResource loadResourcesWithoutHypervisor(HostVO host) {
-        String resourceName = host.getResource();
+    private ServerResource loadResourcesWithoutHypervisor(final HostVO host) {
+        final String resourceName = host.getResource();
         ServerResource resource = null;
         try {
-            Class<?> clazz = Class.forName(resourceName);
-            Constructor<?> constructor = clazz.getConstructor();
+            final Class<?> clazz = Class.forName(resourceName);
+            final Constructor<?> constructor = clazz.getConstructor();
             resource = (ServerResource)constructor.newInstance();
-        } catch (ClassNotFoundException e) {
+        } catch (final ClassNotFoundException e) {
             s_logger.warn("Unable to find class " + host.getResource(), e);
-        } catch (InstantiationException e) {
+        } catch (final InstantiationException e) {
             s_logger.warn("Unablet to instantiate class " + host.getResource(), e);
-        } catch (IllegalAccessException e) {
+        } catch (final IllegalAccessException e) {
             s_logger.warn("Illegal access " + host.getResource(), e);
-        } catch (SecurityException e) {
+        } catch (final SecurityException e) {
             s_logger.warn("Security error on " + host.getResource(), e);
-        } catch (NoSuchMethodException e) {
+        } catch (final NoSuchMethodException e) {
             s_logger.warn("NoSuchMethodException error on " + host.getResource(), e);
-        } catch (IllegalArgumentException e) {
+        } catch (final IllegalArgumentException e) {
             s_logger.warn("IllegalArgumentException error on " + host.getResource(), e);
-        } catch (InvocationTargetException e) {
+        } catch (final InvocationTargetException e) {
             s_logger.warn("InvocationTargetException error on " + host.getResource(), e);
         }
 
         if (resource != null) {
             _hostDao.loadDetails(host);
 
-            HashMap<String, Object> params = new HashMap<String, Object>(host.getDetails().size() + 5);
+            final HashMap<String, Object> params = new HashMap<String, Object>(host.getDetails().size() + 5);
             params.putAll(host.getDetails());
 
             params.put("guid", host.getGuid());
@@ -644,7 +645,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
             if (host.getClusterId() != null) {
                 params.put("cluster", Long.toString(host.getClusterId()));
                 String guid = null;
-                ClusterVO cluster = _clusterDao.findById(host.getClusterId());
+                final ClusterVO cluster = _clusterDao.findById(host.getClusterId());
                 if (cluster.getGuid() == null) {
                     guid = host.getDetail("pool");
                 } else {
@@ -660,7 +661,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
 
             try {
                 resource.configure(host.getName(), params);
-            } catch (ConfigurationException e) {
+            } catch (final ConfigurationException e) {
                 s_logger.warn("Unable to configure resource due to " + e.getMessage());
                 return null;
             }
@@ -677,12 +678,12 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     public void rescan() {
     }
 
-    protected boolean loadDirectlyConnectedHost(HostVO host, boolean forRebalance) {
+    protected boolean loadDirectlyConnectedHost(final HostVO host, final boolean forRebalance) {
         boolean initialized = false;
         ServerResource resource = null;
         try {
             //load the respective discoverer
-            Discoverer discoverer = _resourceMgr.getMatchingDiscover(host.getHypervisorType());
+            final Discoverer discoverer = _resourceMgr.getMatchingDiscover(host.getHypervisorType());
             if (discoverer == null) {
                 s_logger.info("Could not to find a Discoverer to load the resource: " + host.getId() + " for hypervisor type: " + host.getHypervisorType());
                 resource = loadResourcesWithoutHypervisor(host);
@@ -706,19 +707,19 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
 
         if (forRebalance) {
             tapLoadingAgents(host.getId(), TapAgentsAction.Add);
-            Host h = _resourceMgr.createHostAndAgent(host.getId(), resource, host.getDetails(), false, null, true);
+            final Host h = _resourceMgr.createHostAndAgent(host.getId(), resource, host.getDetails(), false, null, true);
             tapLoadingAgents(host.getId(), TapAgentsAction.Del);
 
-            return (h == null ? false : true);
+            return h == null ? false : true;
         } else {
             _executor.execute(new SimulateStartTask(host.getId(), resource, host.getDetails()));
             return true;
         }
     }
 
-    protected AgentAttache createAttacheForDirectConnect(Host host, ServerResource resource) throws ConnectionException {
+    protected AgentAttache createAttacheForDirectConnect(final Host host, final ServerResource resource) throws ConnectionException {
         s_logger.debug("create DirectAgentAttache for " + host.getId());
-        DirectAgentAttache attache = new DirectAgentAttache(this, host.getId(), host.getName(), resource, host.isInMaintenanceStates());
+        final DirectAgentAttache attache = new DirectAgentAttache(this, host.getId(), host.getName(), resource, host.isInMaintenanceStates());
 
         AgentAttache old = null;
         synchronized (_agents) {
@@ -759,12 +760,12 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         return true;
     }
 
-    protected boolean handleDisconnectWithoutInvestigation(AgentAttache attache, Status.Event event, boolean transitState, boolean removeAgent) {
-        long hostId = attache.getId();
+    protected boolean handleDisconnectWithoutInvestigation(final AgentAttache attache, final Status.Event event, final boolean transitState, final boolean removeAgent) {
+        final long hostId = attache.getId();
 
         s_logger.info("Host " + hostId + " is disconnecting with event " + event);
         Status nextStatus = null;
-        HostVO host = _hostDao.findById(hostId);
+        final HostVO host = _hostDao.findById(hostId);
         if (host == null) {
             s_logger.warn("Can't find host with " + hostId);
             nextStatus = Status.Removed;
@@ -778,8 +779,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
             } else {
                 try {
                     nextStatus = currentStatus.getNextStatus(event);
-                } catch (NoTransitionException e) {
-                    String err = "Cannot find next status for " + event + " as current status is " + currentStatus + " for agent " + hostId;
+                } catch (final NoTransitionException e) {
+                    final String err = "Cannot find next status for " + event + " as current status is " + currentStatus + " for agent " + hostId;
                     s_logger.debug(err);
                     throw new CloudRuntimeException(err);
                 }
@@ -803,15 +804,15 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         return true;
     }
 
-    protected boolean handleDisconnectWithInvestigation(AgentAttache attache, Status.Event event) {
-        long hostId = attache.getId();
+    protected boolean handleDisconnectWithInvestigation(final AgentAttache attache, Status.Event event) {
+        final long hostId = attache.getId();
         HostVO host = _hostDao.findById(hostId);
 
         if (host != null) {
             Status nextStatus = null;
             try {
                 nextStatus = host.getStatus().getNextStatus(event);
-            } catch (NoTransitionException ne) {
+            } catch (final 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!
@@ -835,7 +836,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
 
                 if (determinedState == Status.Down) {
                     s_logger.error("Host is down: " + host.getId() + "-" + host.getName() + ".  Starting HA on the VMs");
-                    if ((host.getType() != Host.Type.SecondaryStorage) && (host.getType() != Host.Type.ConsoleProxy)) {
+                    if (host.getType() != Host.Type.SecondaryStorage && host.getType() != Host.Type.ConsoleProxy) {
                         _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host disconnected, " + host.getId(),
                                 "Host is down: " + host.getId() + "-" + host.getName() + ".  Starting HA on the VMs");
                     }
@@ -848,7 +849,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
                 } else if (determinedState == Status.Disconnected) {
                     s_logger.warn("Agent is disconnected but the host is still up: " + host.getId() + "-" + host.getName());
                     if (currentStatus == Status.Disconnected) {
-                        if (((System.currentTimeMillis() >> 10) - host.getLastPinged()) > AlertWait.value()) {
+                        if ((System.currentTimeMillis() >> 10) - host.getLastPinged() > AlertWait.value()) {
                             s_logger.warn("Host " + host.getId() + " has been disconnected pass the time it should be disconnected.");
                             event = Status.Event.WaitedTooLong;
                         } else {
@@ -856,10 +857,10 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
                             return false;
                         }
                     } else if (currentStatus == Status.Up) {
-                        DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
-                        HostPodVO podVO = _podDao.findById(host.getPodId());
-                        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)) {
+                        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();
+                        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, HA will begin on the VMs");
                         }
@@ -867,9 +868,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
                     }
                 } else {
                     // if we end up here we are in alert state, send an alert
-                    DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
-                    HostPodVO podVO = _podDao.findById(host.getPodId());
-                    String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
+                    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(), "Host in ALERT state, " + hostDesc,
                             "In availability zone " + host.getDataCenterId() + ", " + host.getId() + "-" + host.getName()
                             + " disconnect due to event " + event + ", ms can't determine the host status" );
@@ -914,12 +915,12 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     @Override
     public Answer easySend(final Long hostId, final Command cmd) {
         try {
-            Host h = _hostDao.findById(hostId);
+            final Host h = _hostDao.findById(hostId);
             if (h == null || h.getRemoved() != null) {
                 s_logger.debug("Host with id " + hostId + " doesn't exist");
                 return null;
             }
-            Status status = h.getStatus();
+            final Status status = h.getStatus();
             if (!status.equals(Status.Up) && !status.equals(Status.Connecting)) {
                 s_logger.debug("Can not send command " + cmd + " due to Host " + hostId + " is not up");
                 return null;
@@ -949,9 +950,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     }
 
     @Override
-    public Answer[] send(final Long hostId, Commands cmds) throws AgentUnavailableException, OperationTimedoutException {
+    public Answer[] send(final Long hostId, final Commands cmds) throws AgentUnavailableException, OperationTimedoutException {
         int wait = 0;
-        for (Command cmd : cmds) {
+        for (final Command cmd : cmds) {
             if (cmd.getWait() > wait) {
                 wait = cmd.getWait();
             }
@@ -979,7 +980,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
             return false;
         }
 
-        AgentAttache attache = findAttache(hostId);
+        final 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;
@@ -989,7 +990,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         return true;
     }
 
-    public boolean executeUserRequest(long hostId, Event event) throws AgentUnavailableException {
+    public boolean executeUserRequest(final long hostId, final Event event) throws AgentUnavailableException {
         if (event == Event.AgentDisconnected) {
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Received agent disconnect event for host " + hostId);
@@ -1007,13 +1008,13 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     }
 
     @Override
-    public boolean isAgentAttached(long hostId) {
+    public boolean isAgentAttached(final long hostId) {
         return findAttache(hostId) != null;
     }
 
-    protected AgentAttache createAttacheForConnect(HostVO host, Link link) throws ConnectionException {
+    protected AgentAttache createAttacheForConnect(final HostVO host, final Link link) throws ConnectionException {
         s_logger.debug("create ConnectedAgentAttache for " + host.getId());
-        AgentAttache attache = new ConnectedAgentAttache(this, host.getId(), host.getName(), link, host.isInMaintenanceStates());
+        final AgentAttache attache = new ConnectedAgentAttache(this, host.getId(), host.getName(), link, host.isInMaintenanceStates());
         link.attach(attache);
 
         AgentAttache old = null;
@@ -1027,17 +1028,17 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         return attache;
     }
 
-    private AgentAttache handleConnectedAgent(final Link link, final StartupCommand[] startup, Request request) {
+    private AgentAttache handleConnectedAgent(final Link link, final StartupCommand[] startup, final Request request) {
         AgentAttache attache = null;
         ReadyCommand ready = null;
         try {
-            HostVO host = _resourceMgr.createHostVOForConnectedAgent(startup);
+            final HostVO host = _resourceMgr.createHostVOForConnectedAgent(startup);
             if (host != null) {
                 ready = new ReadyCommand(host.getDataCenterId(), host.getId());
                 attache = createAttacheForConnect(host, link);
                 attache = notifyMonitorsOfConnection(attache, startup, false);
             }
-        } catch (Exception e) {
+        } catch (final Exception e) {
             s_logger.debug("Failed to handle host connection: " + e.toString());
             ready = new ReadyCommand(null);
             ready.setDetails(e.toString());
@@ -1054,7 +1055,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
             } else {
                 easySend(attache.getId(), ready);
             }
-        } catch (Exception e) {
+        } catch (final Exception e) {
             s_logger.debug("Failed to send ready command:" + e.toString());
         }
         return attache;
@@ -1065,7 +1066,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         Map<String, String> details;
         long id;
 
-        public SimulateStartTask(long id, ServerResource resource, Map<String, String> details) {
+        public SimulateStartTask(final long id, final ServerResource resource, final Map<String, String> details) {
             this.id = id;
             this.resource = resource;
             this.details = details;
@@ -1080,7 +1081,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
 
                 if (tapLoadingAgents(id, TapAgentsAction.Add)) {
                     try {
-                        AgentAttache agentattache = findAttache(id);
+                        final AgentAttache agentattache = findAttache(id);
                         if (agentattache == null) {
                             s_logger.debug("Creating agent for host " + id);
                             _resourceMgr.createHostAndAgent(id, resource, details, false, null, false);
@@ -1094,7 +1095,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
                 } else {
                     s_logger.debug("Agent creation already getting processed in another thread for host " + id + ", ignore this");
                 }
-            } catch (Exception e) {
+            } catch (final Exception e) {
                 s_logger.warn("Unable to simulate start on resource " + id + " name " + resource.getName(), e);
             }
         }
@@ -1105,7 +1106,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         Command[] _cmds;
         Request _request;
 
-        HandleAgentConnectTask(Link link, final Command[] cmds, final Request request) {
+        HandleAgentConnectTask(final Link link, final Command[] cmds, final Request request) {
             _link = link;
             _cmds = cmds;
             _request = request;
@@ -1114,26 +1115,26 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         @Override
         protected void runInContext() {
             _request.logD("Processing the first command ");
-            StartupCommand[] startups = new StartupCommand[_cmds.length];
+            final StartupCommand[] startups = new StartupCommand[_cmds.length];
             for (int i = 0; i < _cmds.length; i++) {
                 startups[i] = (StartupCommand)_cmds[i];
             }
 
-            AgentAttache attache = handleConnectedAgent(_link, startups, _request);
+            final AgentAttache attache = handleConnectedAgent(_link, startups, _request);
             if (attache == null) {
                 s_logger.warn("Unable to create attache for agent: " + _request);
             }
         }
     }
 
-    protected void connectAgent(Link link, final Command[] cmds, final Request request) {
+    protected void connectAgent(final Link link, final Command[] cmds, final Request request) {
         //send startupanswer to agent in the very beginning, so agent can move on without waiting for the answer for an undetermined time, if we put this logic into another thread pool.
-        StartupAnswer[] answers = new StartupAnswer[cmds.length];
+        final StartupAnswer[] answers = new StartupAnswer[cmds.length];
         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)) {
+            if (cmd instanceof StartupRoutingCommand || cmd instanceof StartupProxyCommand || cmd instanceof StartupSecondaryStorageCommand ||
+                    cmd instanceof StartupStorageCommand) {
                 answers[i] = new StartupAnswer((StartupCommand)cmds[i], 0, getPingInterval());
                 break;
             }
@@ -1142,19 +1143,19 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         response = new Response(request, answers[0], _nodeId, -1);
         try {
             link.send(response.toBytes());
-        } catch (ClosedChannelException e) {
+        } catch (final ClosedChannelException e) {
             s_logger.debug("Failed to send startupanswer: " + e.toString());
         }
         _connectExecutor.execute(new HandleAgentConnectTask(link, cmds, request));
     }
 
     public class AgentHandler extends Task {
-        public AgentHandler(Task.Type type, Link link, byte[] data) {
+        public AgentHandler(final Task.Type type, final Link link, final byte[] data) {
             super(type, link, data);
         }
 
         protected void processRequest(final Link link, final Request request) {
-            AgentAttache attache = (AgentAttache)link.attachment();
+            final AgentAttache attache = (AgentAttache)link.attachment();
             final Command[] cmds = request.getCommands();
             Command cmd = cmds[0];
             boolean logD = true;
@@ -1220,21 +1221,21 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
                     } else {
                         handleCommands(attache, request.getSequence(), new Command[] {cmd});
                         if (cmd instanceof PingCommand) {
-                            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) {
-                                boolean gatewayAccessible = ((PingRoutingCommand)cmd).isGatewayAccessible();
-                                HostVO host = _hostDao.findById(Long.valueOf(cmdHostId));
+                                final boolean gatewayAccessible = ((PingRoutingCommand)cmd).isGatewayAccessible();
+                                final HostVO host = _hostDao.findById(Long.valueOf(cmdHostId));
 
                                 if (host != null) {
                                     if (!gatewayAccessible) {
                                         // alert that host lost connection to
                                         // gateway (cannot ping the default route)
-                                        DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
-                                        HostPodVO podVO = _podDao.findById(host.getPodId());
-                                        String hostDesc =
+                                        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_ROUTING, host.getDataCenterId(), host.getPodId(),
@@ -1250,7 +1251,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
                             }
                             answer = new PingAnswer((PingCommand)cmd);
                         } else if (cmd instanceof ReadyAnswer) {
-                            HostVO host = _hostDao.findById(attache.getId());
+                            final HostVO host = _hostDao.findById(attache.getId());
                             if (host == null) {
                                 if (s_logger.isDebugEnabled()) {
                                     s_logger.debug("Cant not find host " + attache.getId());
@@ -1268,7 +1269,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
                 answers[i] = answer;
             }
 
-            Response response = new Response(request, answers, _nodeId, attache.getId());
+            final Response response = new Response(request, answers, _nodeId, attache.getId());
             if (s_logger.isDebugEnabled()) {
                 if (logD) {
                     s_logger.debug("SeqA " + attache.getId() + "-" + response.getSequence() + ": Sending " + response);
@@ -1294,7 +1295,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
 
         @Override
         protected void doTask(final Task task) throws Exception {
-            TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
+            final TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
             try {
                 final Type type = task.getType();
                 if (type == Task.Type.DATA) {
@@ -1331,13 +1332,14 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     protected AgentManagerImpl() {
     }
 
-    public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) {
+    public boolean tapLoadingAgents(final Long hostId, final TapAgentsAction action) {
         synchronized (_loadingAgents) {
             if (action == TapAgentsAction.Add) {
-                if (_loadingAgents.contains(hostId))
+                if (_loadingAgents.contains(hostId)) {
                     return false;
-                else
+                } else {
                     _loadingAgents.add(hostId);
+                }
             } else if (action == TapAgentsAction.Del) {
                 _loadingAgents.remove(hostId);
             } else if (action == TapAgentsAction.Contains) {
@@ -1350,12 +1352,12 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     }
 
     @Override
-    public boolean agentStatusTransitTo(HostVO host, Status.Event e, long msId) {
+    public boolean agentStatusTransitTo(final HostVO host, final Status.Event e, final long msId) {
         try {
             _agentStatusLock.lock();
             if (status_logger.isDebugEnabled()) {
-                ResourceState state = host.getResourceState();
-                StringBuilder msg = new StringBuilder("Transition:");
+                final ResourceState state = host.getResourceState();
+                final StringBuilder msg = new StringBuilder("Transition:");
                 msg.append("[Resource state = ").append(state);
                 msg.append(", Agent event = ").append(e.toString());
                 msg.append(", Host id = ").append(host.getId()).append(", name = " + host.getName()).append("]");
@@ -1365,7 +1367,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
             host.setManagementServerId(msId);
             try {
                 return _statusStateMachine.transitTo(host, e, host.getId(), _hostDao);
-            } catch (NoTransitionException e1) {
+            } 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 + "," +
@@ -1376,7 +1378,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         }
     }
 
-    public boolean disconnectAgent(HostVO host, Status.Event e, long msId) {
+    public boolean disconnectAgent(final HostVO host, final Status.Event e, final long msId) {
         host.setDisconnectedOn(new Date());
         if (e.equals(Status.Event.Remove)) {
             host.setGuid(null);
@@ -1386,16 +1388,16 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         return agentStatusTransitTo(host, e, msId);
     }
 
-    protected void disconnectWithoutInvestigation(AgentAttache attache, final Status.Event event) {
+    protected void disconnectWithoutInvestigation(final AgentAttache attache, final Status.Event event) {
         _executor.submit(new DisconnectTask(attache, event, false));
     }
 
-    public void disconnectWithInvestigation(AgentAttache attache, final Status.Event event) {
+    public void disconnectWithInvestigation(final AgentAttache attache, final Status.Event event) {
         _executor.submit(new DisconnectTask(attache, event, true));
     }
 
     protected boolean isHostOwnerSwitched(final long hostId) {
-        HostVO host = _hostDao.findById(hostId);
+        final HostVO host = _hostDao.findById(hostId);
         if (host == null) {
             s_logger.warn("Can't find the host " + hostId);
             return false;
@@ -1403,15 +1405,15 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         return isHostOwnerSwitched(host);
     }
 
-    protected boolean isHostOwnerSwitched(HostVO host) {
+    protected boolean isHostOwnerSwitched(final HostVO host) {
         if (host.getStatus() == Status.Up && host.getManagementServerId() != null && host.getManagementServerId() != _nodeId) {
             return true;
         }
         return false;
     }
 
-    private void disconnectInternal(final long hostId, final Status.Event event, boolean invstigate) {
-        AgentAttache attache = findAttache(hostId);
+    private void disconnectInternal(final long hostId, final Status.Event event, final boolean invstigate) {
+        final AgentAttache attache = findAttache(hostId);
 
         if (attache != null) {
             if (!invstigate) {
@@ -1426,7 +1428,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
                 return;
             }
 
-            HostVO host = _hostDao.findById(hostId);
+            final HostVO host = _hostDao.findById(hostId);
             if (host != null && host.getRemoved() == null) {
                 disconnectAgent(host, event, _nodeId);
             }
@@ -1443,11 +1445,11 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     }
 
     @Override
-    public boolean handleDirectConnectAgent(Host host, StartupCommand[] cmds, ServerResource resource, boolean forRebalance) throws ConnectionException {
+    public boolean handleDirectConnectAgent(final Host host, final StartupCommand[] cmds, final ServerResource resource, final boolean forRebalance) throws ConnectionException {
         AgentAttache attache;
 
         attache = createAttacheForDirectConnect(host, resource);
-        StartupAnswer[] answers = new StartupAnswer[cmds.length];
+        final StartupAnswer[] answers = new StartupAnswer[cmds.length];
         for (int i = 0; i < answers.length; i++) {
             answers[i] = new StartupAnswer(cmds[i], attache.getId(), PingInterval.value());
         }
@@ -1458,8 +1460,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     }
 
     @Override
-    public void pullAgentToMaintenance(long hostId) {
-        AgentAttache attache = findAttache(hostId);
+    public void pullAgentToMaintenance(final long hostId) {
+        final AgentAttache attache = findAttache(hostId);
         if (attache != null) {
             attache.setMaintenanceMode(true);
             // Now cancel all of the commands except for the active one.
@@ -1468,8 +1470,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
     }
 
     @Override
-    public void pullAgentOutMaintenance(long hostId) {
-        AgentAttache attache = findAttache(hostId);
+    public void pullAgentOutMaintenance(final long hostId) {
+        final AgentAttache attache = findAttache(hostId);
         if (attache != null) {
             attache.setMaintenanceMode(false);
         }
@@ -1487,11 +1489,11 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         return _directAgentThreadCap;
     }
 
-    public Long getAgentPingTime(long agentId) {
+    public Long getAgentPingTime(final long agentId) {
         return _pingMap.get(agentId);
     }
 
-    public void pingBy(long agentId) {
+    public void pingBy(final long agentId) {
         // Update PingMap with the latest time if agent entry exists in the PingMap
         if (_pingMap.replace(agentId, InaccurateClock.getTimeInSeconds()) == null) {
             s_logger.info("PingMap for agent: " + agentId + " will not be updated because agent is no longer in the PingMap");
@@ -1504,13 +1506,13 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
             s_logger.trace("Agent Monitor is started.");
 
             try {
-                List<Long> behindAgents = findAgentsBehindOnPing();
-                for (Long agentId : behindAgents) {
-                    QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
+                final List<Long> behindAgents = findAgentsBehindOnPing();
+                for (final Long agentId : behindAgents) {
+                    final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
                     sc.and(sc.entity().getId(), Op.EQ, agentId);
-                    HostVO h = sc.find();
+                    final HostVO h = sc.find();
                     if (h != null) {
-                        ResourceState resourceState = h.getResourceState();
+                        final ResourceState resourceState = h.getResourceState();
                         if (resourceState == ResourceState.Disabled || resourceState == ResourceState.Maintenance || resourceState == ResourceState.ErrorInMaintenance) {
                             /*
                              * Host is in non-operation state, so no
@@ -1520,7 +1522,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
                             status_logger.debug("Ping timeout but host " + agentId + " is in resource state of " + resourceState + ", so no investigation");
                             disconnectWithoutInvestigation(agentId, Event.ShutdownRequested);
                         } else {
-                            HostVO host = _hostDao.findById(agentId);
+                            final HostVO host = _hostDao.findById(agentId);
                             if (host != null && (host.getType() == Host.Type.ConsoleProxy || host.getType() == Host.Type.SecondaryStorageVM
                                     || host.getType() == Host.Type.SecondaryStorageCmdExecutor)) {
 
@@ -1534,20 +1536,20 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
                     }
                 }
 
-                QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
+                final QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
                 sc.and(sc.entity().getResourceState(), Op.IN, ResourceState.PrepareForMaintenance, ResourceState.ErrorInMaintenance);
-                List<HostVO> hosts = sc.list();
+                final List<HostVO> hosts = sc.list();
 
-                for (HostVO host : hosts) {
+                for (final HostVO host : hosts) {
                     if (_resourceMgr.checkAndMaintain(host.getId())) {
-                        DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
-                        HostPodVO podVO = _podDao.findById(host.getPodId());
-                        String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
+                        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");
                     }
                 }
-            } catch (Throwable th) {
+            } catch (final Throwable th) {
                 s_logger.error("Caught the following exception: ", th);
             }
 
@@ -1555,9 +1557,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         }
 
         protected List<Long> findAgentsBehindOnPing() {
-            List<Long> agentsBehind = new ArrayList<Long>();
-            long cutoffTime = InaccurateClock.getTimeInSeconds() - getTimeout();
-            for (Map.Entry<Long, Long> entry : _pingMap.entrySet()) {
+            final List<Long> agentsBehind = new ArrayList<Long>();
+            final long cutoffTime = InaccurateClock.getTimeInSeconds() - getTimeout();
+            for (final Map.Entry<Long, Long> entry : _pingMap.entrySet()) {
                 if (entry.getValue() < cutoffTime) {
                     agentsBehind.add(entry.getKey());
                 }
@@ -1578,14 +1580,14 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         }
 
         @Override
-        public boolean processAnswers(long agentId, long seq, Answer[] answers) {
+        public boolean processAnswers(final long agentId, final long seq, final Answer[] answers) {
             return false;
         }
 
         @Override
-        public boolean processCommands(long agentId, long seq, Command[] commands) {
-            boolean processed = false;
-            for (Command cmd : commands) {
+        public boolean processCommands(final long agentId, final long seq, final Command[] commands) {
+            final boolean processed = false;
+            for (final Command cmd : commands) {
                 if (cmd instanceof PingCommand) {
                     pingBy(agentId);
                 }
@@ -1594,12 +1596,12 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         }
 
         @Override
-        public AgentControlAnswer processControlCommand(long agentId, AgentControlCommand cmd) {
+        public AgentControlAnswer processControlCommand(final long agentId, final AgentControlCommand cmd) {
             return null;
         }
 
         @Override
-        public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) {
+        public void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance) {
             if (host.getType().equals(Host.Type.TrafficMonitor) || host.getType().equals(Host.Type.SecondaryStorage)) {
                 return;
             }
@@ -1609,13 +1611,13 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
         }
 
         @Override
-        public boolean processDisconnect(long agentId, Status state) {
+        public boolean processDisconnect(final long agentId, final Status state) {
             _pingMap.remove(agentId);
             return true;
         }
 
         @Override
-        public boolean processTimeout(long agentId, long seq) {
+        public boolean processTimeout(final long agentId, final long seq) {
             return true;
         }
 


Mime
View raw message