cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [1/6] git commit: updated refs/heads/master to 791f9df
Date Thu, 19 Nov 2015 16:59:36 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master fe2917e91 -> 791f9dfe5


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1cf57f74/plugins/hypervisors/hyperv/src/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/hyperv/src/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java b/plugins/hypervisors/hyperv/src/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java
index 17c5708..bd001ce 100644
--- a/plugins/hypervisors/hyperv/src/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java
+++ b/plugins/hypervisors/hyperv/src/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java
@@ -43,6 +43,7 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.cloudstack.storage.command.CopyCommand;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.http.HttpResponse;
@@ -62,11 +63,6 @@ import org.apache.http.impl.conn.BasicClientConnectionManager;
 import org.apache.http.util.EntityUtils;
 import org.apache.log4j.Logger;
 
-import com.google.gson.Gson;
-import com.google.gson.reflect.TypeToken;
-
-import org.apache.cloudstack.storage.command.CopyCommand;
-
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.CheckRouterAnswer;
 import com.cloud.agent.api.CheckRouterCommand;
@@ -156,6 +152,8 @@ import com.cloud.utils.ssh.SshHelper;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachine.PowerState;
 import com.cloud.vm.VirtualMachineName;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 
 
 /**
@@ -207,13 +205,13 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
     public final StartupCommand[] initialize() {
         // assert
         if (!_configureCalled) {
-            String errMsg = this.getClass().getName() + " requires configure() be called before" + " initialize()";
+            final String errMsg = this.getClass().getName() + " requires configure() be called before" + " initialize()";
             s_logger.error(errMsg);
         }
 
         // Create default StartupRoutingCommand, then customise
-        StartupRoutingCommand defaultStartRoutCmd =
-            new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.Hyperv, RouterPrivateIpStrategy.HostLocal);
+        final StartupRoutingCommand defaultStartRoutCmd =
+                new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.Hyperv, RouterPrivateIpStrategy.HostLocal);
 
         // Identity within the data centre is decided by CloudStack kernel,
         // and passed via ServerResource.configure()
@@ -234,20 +232,20 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         // comes from the host itself. CloudStack sanity checks network
         // configuration
         // and uses capacity info for resource allocation.
-        Command[] startCmds = requestStartupCommand(new Command[] {defaultStartRoutCmd});
+        final Command[] startCmds = requestStartupCommand(new Command[] {defaultStartRoutCmd});
 
         // TODO: may throw, is this okay?
-        StartupRoutingCommand startCmd = (StartupRoutingCommand)startCmds[0];
+        final StartupRoutingCommand startCmd = (StartupRoutingCommand)startCmds[0];
 
         // Assert that host identity is consistent with existing values.
         if (startCmd == null) {
-            String errMsg = String.format("Host %s (IP %s)" + "did not return a StartupRoutingCommand", _name, _agentIp);
+            final String errMsg = String.format("Host %s (IP %s)" + "did not return a StartupRoutingCommand", _name, _agentIp);
             s_logger.error(errMsg);
             // TODO: valid to return null, or should we throw?
             return null;
         }
         if (!startCmd.getDataCenter().equals(defaultStartRoutCmd.getDataCenter())) {
-            String errMsg =
+            final String errMsg =
                     String.format("Host %s (IP %s) changed zone/data center.  Was " + defaultStartRoutCmd.getDataCenter() + " NOW its " + startCmd.getDataCenter(), _name,
                             _agentIp);
             s_logger.error(errMsg);
@@ -255,26 +253,26 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             return null;
         }
         if (!startCmd.getPod().equals(defaultStartRoutCmd.getPod())) {
-            String errMsg = String.format("Host %s (IP %s) changed pod.  Was " + defaultStartRoutCmd.getPod() + " NOW its " + startCmd.getPod(), _name, _agentIp);
+            final String errMsg = String.format("Host %s (IP %s) changed pod.  Was " + defaultStartRoutCmd.getPod() + " NOW its " + startCmd.getPod(), _name, _agentIp);
             s_logger.error(errMsg);
             // TODO: valid to return null, or should we throw?
             return null;
         }
         if (!startCmd.getCluster().equals(defaultStartRoutCmd.getCluster())) {
-            String errMsg =
+            final String errMsg =
                     String.format("Host %s (IP %s) changed cluster.  Was " + defaultStartRoutCmd.getCluster() + " NOW its " + startCmd.getCluster(), _name, _agentIp);
             s_logger.error(errMsg);
             // TODO: valid to return null, or should we throw?
             return null;
         }
         if (!startCmd.getGuid().equals(defaultStartRoutCmd.getGuid())) {
-            String errMsg = String.format("Host %s (IP %s) changed guid.  Was " + defaultStartRoutCmd.getGuid() + " NOW its " + startCmd.getGuid(), _name, _agentIp);
+            final String errMsg = String.format("Host %s (IP %s) changed guid.  Was " + defaultStartRoutCmd.getGuid() + " NOW its " + startCmd.getGuid(), _name, _agentIp);
             s_logger.error(errMsg);
             // TODO: valid to return null, or should we throw?
             return null;
         }
         if (!startCmd.getPrivateIpAddress().equals(defaultStartRoutCmd.getPrivateIpAddress())) {
-            String errMsg =
+            final String errMsg =
                     String.format("Host %s (IP %s) IP address.  Was " + defaultStartRoutCmd.getPrivateIpAddress() + " NOW its " + startCmd.getPrivateIpAddress(), _name,
                             _agentIp);
             s_logger.error(errMsg);
@@ -282,7 +280,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             return null;
         }
         if (!startCmd.getName().equals(defaultStartRoutCmd.getName())) {
-            String errMsg = String.format("Host %s (IP %s) name.  Was " + startCmd.getName() + " NOW its " + defaultStartRoutCmd.getName(), _name, _agentIp);
+            final String errMsg = String.format("Host %s (IP %s) name.  Was " + startCmd.getName() + " NOW its " + defaultStartRoutCmd.getName(), _name, _agentIp);
             s_logger.error(errMsg);
             // TODO: valid to return null, or should we throw?
             return null;
@@ -301,8 +299,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             storePoolCmd = (StartupStorageCommand)startCmds[1];
             // TODO: is this assertion required?
             if (storePoolCmd == null) {
-                String frmtStr = "Host %s (IP %s) sent incorrect Command, " + "second parameter should be a " + "StartupStorageCommand";
-                String errMsg = String.format(frmtStr, _name, _agentIp);
+                final String frmtStr = "Host %s (IP %s) sent incorrect Command, " + "second parameter should be a " + "StartupStorageCommand";
+                final String errMsg = String.format(frmtStr, _name, _agentIp);
                 s_logger.error(errMsg);
                 // TODO: valid to return null, or should we throw?
                 return null;
@@ -316,13 +314,13 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
 
     @Override
     public final PingCommand getCurrentStatus(final long id) {
-        PingCommand pingCmd = new PingRoutingCommand(getType(), id, getHostVmStateReport());
+        final PingCommand pingCmd = new PingRoutingCommand(getType(), id, getHostVmStateReport());
 
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Ping host " + _name + " (IP " + _agentIp + ")");
         }
 
-        Answer pingAns = executeRequest(pingCmd);
+        final Answer pingAns = executeRequest(pingCmd);
 
         if (pingAns == null || !pingAns.getResult()) {
             s_logger.info("Cannot ping host " + _name + " (IP " + _agentIp + "), pingAns (blank means null) is:" + pingAns);
@@ -335,12 +333,12 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         URI agentUri = null;
         try {
             agentUri = new URI("https", null, _agentIp, _port, "/api/HypervResource/" + HOST_VM_STATE_REPORT_COMMAND, null, null);
-        } catch (URISyntaxException e) {
-            String errMsg = "Could not generate URI for Hyper-V agent";
+        } catch (final URISyntaxException e) {
+            final String errMsg = "Could not generate URI for Hyper-V agent";
             s_logger.error(errMsg, e);
             return null;
         }
-        String incomingCmd = postHttpRequest("{}", agentUri);
+        final String incomingCmd = postHttpRequest("{}", agentUri);
 
         if (incomingCmd == null) {
             return null;
@@ -349,8 +347,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         try {
             result = s_gson.fromJson(incomingCmd, new TypeToken<ArrayList<HashMap<String, String>>>() {
             }.getType());
-        } catch (Exception ex) {
-            String errMsg = "Failed to deserialize Command[] " + incomingCmd;
+        } catch (final Exception ex) {
+            final String errMsg = "Failed to deserialize Command[] " + incomingCmd;
             s_logger.error(errMsg, ex);
         }
         s_logger.debug("HostVmStateReportCommand received response "
@@ -367,13 +365,13 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
 
     protected HashMap<String, HostVmStateReportEntry> getHostVmStateReport() {
         final HashMap<String, HostVmStateReportEntry> vmStates = new HashMap<String, HostVmStateReportEntry>();
-        ArrayList<Map<String, String>> vmList = requestHostVmStateReport();
+        final ArrayList<Map<String, String>> vmList = requestHostVmStateReport();
         if (vmList == null) {
             return null;
         }
 
-        for (Map<String, String> vmMap : vmList) {
-            String name = (String)vmMap.keySet().toArray()[0];
+        for (final Map<String, String> vmMap : vmList) {
+            final String name = (String)vmMap.keySet().toArray()[0];
             vmStates.put(name, new HostVmStateReportEntry(PowerState.valueOf(vmMap.get(name)), _guid));
         }
         return vmStates;
@@ -388,17 +386,17 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         // http://docs.oracle.com/javase/1.5.0/docs/api/java/net/URI.html
         URI agentUri = null;
         try {
-            String cmdName = StartupCommand.class.getName();
+            final String cmdName = StartupCommand.class.getName();
             agentUri =
                     new URI("https", null, _agentIp, _port,
                             "/api/HypervResource/" + cmdName, null, null);
-        } catch (URISyntaxException e) {
+        } catch (final URISyntaxException e) {
             // TODO add proper logging
-            String errMsg = "Could not generate URI for Hyper-V agent";
+            final String errMsg = "Could not generate URI for Hyper-V agent";
             s_logger.error(errMsg, e);
             return null;
         }
-        String incomingCmd = postHttpRequest(s_gson.toJson(cmd), agentUri);
+        final String incomingCmd = postHttpRequest(s_gson.toJson(cmd), agentUri);
 
         if (incomingCmd == null) {
             return null;
@@ -406,8 +404,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         Command[] result = null;
         try {
             result = s_gson.fromJson(incomingCmd, Command[].class);
-        } catch (Exception ex) {
-            String errMsg = "Failed to deserialize Command[] " + incomingCmd;
+        } catch (final Exception ex) {
+            final String errMsg = "Failed to deserialize Command[] " + incomingCmd;
             s_logger.error(errMsg, ex);
         }
         s_logger.debug("requestStartupCommand received response " + s_gson.toJson(result));
@@ -424,16 +422,16 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         // Using java.net.URI, see
         // http://docs.oracle.com/javase/1.5.0/docs/api/java/net/URI.html
         URI agentUri = null;
-        Class<? extends Command> clazz = cmd.getClass();
+        final Class<? extends Command> clazz = cmd.getClass();
         Answer answer = null;
         try {
-            String cmdName = cmd.getClass().getName();
+            final String cmdName = cmd.getClass().getName();
             agentUri =
                     new URI("https", null, _agentIp, _port,
                             "/api/HypervResource/" + cmdName, null, null);
-        } catch (URISyntaxException e) {
+        } catch (final URISyntaxException e) {
             // TODO add proper logging
-            String errMsg = "Could not generate URI for Hyper-V agent";
+            final String errMsg = "Could not generate URI for Hyper-V agent";
             s_logger.error(errMsg, e);
             return null;
         }
@@ -494,10 +492,10 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         }
         else {
             if (clazz == StartCommand.class) {
-                VirtualMachineTO vmSpec = ((StartCommand)cmd).getVirtualMachine();
+                final VirtualMachineTO vmSpec = ((StartCommand)cmd).getVirtualMachine();
                 if (vmSpec.getType() != VirtualMachine.Type.User) {
                     if (s_hypervMgr != null) {
-                        String secondary = s_hypervMgr.prepareSecondaryStorageStore(Long.parseLong(_zoneId));
+                        final String secondary = s_hypervMgr.prepareSecondaryStorageStore(Long.parseLong(_zoneId));
                         if (secondary != null) {
                             ((StartCommand)cmd).setSecondaryStorage(secondary);
                         }
@@ -508,14 +506,14 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             }
 
             // Send the cmd to hyperv agent.
-            String ansStr = postHttpRequest(s_gson.toJson(cmd), agentUri);
+            final String ansStr = postHttpRequest(s_gson.toJson(cmd), agentUri);
             if (ansStr == null) {
                 return Answer.createUnsupportedCommandAnswer(cmd);
             }
             // Only Answer instances are returned by remote agents.
             // E.g. see Response.getAnswers()
-            Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
-            String logResult = cleanPassword(s_gson.toJson(result));
+            final Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
+            final String logResult = cleanPassword(s_gson.toJson(result));
             s_logger.debug("executeRequest received response " + logResult);
             if (result.length > 0) {
                 return result[0];
@@ -524,15 +522,15 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         return answer;
     }
 
-    private Answer execute(CopyCommand cmd) {
+    private Answer execute(final CopyCommand cmd) {
         URI agentUri = null;
         try {
-            String cmdName = cmd.getClass().getName();
+            final String cmdName = cmd.getClass().getName();
             agentUri =
                     new URI("https", null, _agentIp, _port,
                             "/api/HypervResource/" + cmdName, null, null);
-        } catch (URISyntaxException e) {
-            String errMsg = "Could not generate URI for Hyper-V agent";
+        } catch (final URISyntaxException e) {
+            final String errMsg = "Could not generate URI for Hyper-V agent";
             s_logger.error(errMsg, e);
             return null;
         }
@@ -540,13 +538,13 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         cleanPassword(cmd.getDestTO().getDataStore());
 
         // Send the cmd to hyperv agent.
-        String ansStr = postHttpRequest(s_gson.toJson(cmd), agentUri);
+        final String ansStr = postHttpRequest(s_gson.toJson(cmd), agentUri);
         if (ansStr == null) {
             return Answer.createUnsupportedCommandAnswer(cmd);
         }
 
-        Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
-        String logResult = cleanPassword(s_gson.toJson(result));
+        final Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
+        final String logResult = cleanPassword(s_gson.toJson(result));
         s_logger.debug("executeRequest received response " + logResult);
         if (result.length > 0) {
             return result[0];
@@ -555,79 +553,79 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         return null;
     }
 
-    private void cleanPassword(DataStoreTO dataStoreTO) {
+    private void cleanPassword(final DataStoreTO dataStoreTO) {
         if (dataStoreTO instanceof NfsTO) {
-            NfsTO nfsTO = (NfsTO)dataStoreTO;
-            String url = nfsTO.getUrl();
+            final NfsTO nfsTO = (NfsTO)dataStoreTO;
+            final String url = nfsTO.getUrl();
             if (url.contains("cifs") && url.contains("password")) {
                 nfsTO.setUrl(url.substring(0, url.indexOf('?')));
             }
         }
     }
 
-    private PlugNicAnswer execute(PlugNicCommand cmd) {
+    private PlugNicAnswer execute(final PlugNicCommand cmd) {
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Executing resource PlugNicCommand " + s_gson.toJson(cmd));
         }
 
         try {
 
-            String vmName = cmd.getVmName();
-            NicTO nic = cmd.getNic();
-            URI broadcastUri = nic.getBroadcastUri();
+            final String vmName = cmd.getVmName();
+            final NicTO nic = cmd.getNic();
+            final URI broadcastUri = nic.getBroadcastUri();
             if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
                 throw new InternalErrorException("Unable to assign a public IP to a VIF on network " + nic.getBroadcastUri());
             }
-            String vlanId = BroadcastDomainType.getValue(broadcastUri);
+            final String vlanId = BroadcastDomainType.getValue(broadcastUri);
             int publicNicInfo = -1;
             publicNicInfo = getVmFreeNicIndex(vmName);
             if (publicNicInfo > 0) {
                 modifyNicVlan(vmName, vlanId, publicNicInfo, true, cmd.getNic().getName());
                 return new PlugNicAnswer(cmd, true, "success");
             }
-            String msg = " Plug Nic failed for the vm as it has reached max limit of NICs to be added";
+            final String msg = " Plug Nic failed for the vm as it has reached max limit of NICs to be added";
             s_logger.warn(msg);
             return new PlugNicAnswer(cmd, false, msg);
 
-        } catch (Exception e) {
+        } catch (final Exception e) {
             s_logger.error("Unexpected exception: ", e);
             return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + e.toString());
         }
     }
 
 
-    private UnPlugNicAnswer execute(UnPlugNicCommand cmd) {
+    private UnPlugNicAnswer execute(final UnPlugNicCommand cmd) {
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Executing resource UnPlugNicCommand " + s_gson.toJson(cmd));
         }
 
         try {
-            String vmName = cmd.getVmName();
-            NicTO nic = cmd.getNic();
-            URI broadcastUri = nic.getBroadcastUri();
+            final String vmName = cmd.getVmName();
+            final NicTO nic = cmd.getNic();
+            final URI broadcastUri = nic.getBroadcastUri();
             if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
                 throw new InternalErrorException("Unable to unassign a public IP to a VIF on network " + nic.getBroadcastUri());
             }
-            String vlanId = BroadcastDomainType.getValue(broadcastUri);
+            final String vlanId = BroadcastDomainType.getValue(broadcastUri);
             int publicNicInfo = -1;
             publicNicInfo = getVmNics(vmName, vlanId);
             if (publicNicInfo > 0) {
                 modifyNicVlan(vmName, "2", publicNicInfo, false, "");
             }
             return new UnPlugNicAnswer(cmd, true, "success");
-        } catch (Exception e) {
+        } catch (final Exception e) {
             s_logger.error("Unexpected exception: ", e);
             return new UnPlugNicAnswer(cmd, false, "Unable to execute unPlugNicCommand due to " + e.toString());
         }
     }
 
     @Override
-    public ExecutionResult executeInVR(String routerIP, String script, String args) {
+    public ExecutionResult executeInVR(final String routerIP, final String script, final String args) {
         return executeInVR(routerIP, script, args, 120);
     }
 
     @Override
-    public ExecutionResult executeInVR(String routerIP, String script, String args, int timeout) {
+    public ExecutionResult executeInVR(final String routerIP, final String script, final String args, final int timeout) {
         Pair<Boolean, String> result;
 
         //TODO: Password should be masked, cannot output to log directly
@@ -638,8 +636,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         try {
             result = SshHelper.sshExecute(routerIP, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/" + script + " " + args,
                     60000, 60000, timeout * 1000);
-        } catch (Exception e) {
-            String msg = "Command failed due to " + e ;
+        } catch (final Exception e) {
+            final String msg = "Command failed due to " + e ;
             s_logger.error(msg);
             result = new Pair<Boolean, String>(false, msg);
         }
@@ -650,11 +648,11 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
     }
 
     @Override
-    public ExecutionResult createFileInVR(String routerIp, String filePath, String fileName, String content) {
-        File keyFile = getSystemVMKeyFile();
+    public ExecutionResult createFileInVR(final String routerIp, final String filePath, final String fileName, final String content) {
+        final File keyFile = getSystemVMKeyFile();
         try {
             SshHelper.scpTo(routerIp, 3922, "root", keyFile, null, filePath, content.getBytes(Charset.forName("UTF-8")), fileName, null);
-        } catch (Exception e) {
+        } catch (final Exception e) {
             s_logger.warn("Fail to create file " + filePath + fileName + " in VR " + routerIp, e);
             return new ExecutionResult(false, e.getMessage());
         }
@@ -662,7 +660,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
     }
 
     @Override
-    public ExecutionResult prepareCommand(NetworkElementCommand cmd) {
+    public ExecutionResult prepareCommand(final NetworkElementCommand cmd) {
         //Update IP used to access router
         cmd.setRouterAccessIp(getRouterSshControlIp(cmd));
         assert cmd.getRouterAccessIp() != null;
@@ -681,22 +679,22 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         return new ExecutionResult(true, null);
     }
 
-    private ExecutionResult prepareNetworkElementCommand(IpAssocCommand cmd) {
+    private ExecutionResult prepareNetworkElementCommand(final IpAssocCommand cmd) {
         try {
 
-            IpAddressTO[] ips = cmd.getIpAddresses();
-            String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
-            String controlIp = getRouterSshControlIp(cmd);
+            final IpAddressTO[] ips = cmd.getIpAddresses();
+            final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
+            final String controlIp = getRouterSshControlIp(cmd);
 
-            for (IpAddressTO ip : ips) {
+            for (final IpAddressTO ip : ips) {
                 /**
                  * TODO support other networks
                  */
-                URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
+                final URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
                 if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
                     throw new InternalErrorException("Unable to assign a public IP to a VIF on network " + ip.getBroadcastUri());
                 }
-                String vlanId = BroadcastDomainType.getValue(broadcastUri);
+                final String vlanId = BroadcastDomainType.getValue(broadcastUri);
                 int publicNicInfo = -1;
                 publicNicInfo = getVmNics(routerName, vlanId);
 
@@ -709,7 +707,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                 }
 
                 if (addVif) {
-                    Pair<Integer, String> nicdevice = findRouterFreeEthDeviceIndex(controlIp);
+                    final Pair<Integer, String> nicdevice = findRouterFreeEthDeviceIndex(controlIp);
                     publicNicInfo = nicdevice.first();
                     if (publicNicInfo > 0) {
                         modifyNicVlan(routerName, vlanId, nicdevice.second());
@@ -720,7 +718,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                     }
                     else {
                         // we didn't find any eth device available in VR to configure the ip range with new VLAN
-                        String msg = "No Nic is available on DomR VIF to associate/disassociate IP with.";
+                        final String msg = "No Nic is available on DomR VIF to associate/disassociate IP with.";
                         s_logger.error(msg);
                         throw new InternalErrorException(msg);
                     }
@@ -730,29 +728,29 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                     ip.setNicDevId(publicNicInfo);
                 }
             }
-        } catch (Throwable e) {
+        } catch (final Throwable e) {
             s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e);
             return new ExecutionResult(false, e.toString());
         }
         return new ExecutionResult(true, null);
     }
 
-    protected ExecutionResult prepareNetworkElementCommand(SetupGuestNetworkCommand cmd) {
-        NicTO nic = cmd.getNic();
-        String domrName =
+    protected ExecutionResult prepareNetworkElementCommand(final SetupGuestNetworkCommand cmd) {
+        final NicTO nic = cmd.getNic();
+        final String domrName =
                 cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
 
         try {
-            URI broadcastUri = nic.getBroadcastUri();
-            String vlanId = BroadcastDomainType.getValue(broadcastUri);
-            int ethDeviceNum = getVmNics(domrName, vlanId);
+            final URI broadcastUri = nic.getBroadcastUri();
+            final String vlanId = BroadcastDomainType.getValue(broadcastUri);
+            final int ethDeviceNum = getVmNics(domrName, vlanId);
             if (ethDeviceNum > 0) {
                 nic.setDeviceId(ethDeviceNum);
             } else {
                 return new ExecutionResult(false, "Prepare SetupGuestNetwork failed due to unable to find the nic");
             }
-        } catch (Exception e) {
-            String msg = "Prepare SetupGuestNetwork failed due to " + e.toString();
+        } catch (final Exception e) {
+            final String msg = "Prepare SetupGuestNetwork failed due to " + e.toString();
             s_logger.warn(msg, e);
             return new ExecutionResult(false, msg);
         }
@@ -760,17 +758,17 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
     }
 
 
-    private ExecutionResult prepareNetworkElementCommand(IpAssocVpcCommand cmd) {
-        String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
+    private ExecutionResult prepareNetworkElementCommand(final IpAssocVpcCommand cmd) {
+        final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
 
         try {
-            IpAddressTO[] ips = cmd.getIpAddresses();
-            for (IpAddressTO ip : ips) {
-                URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
+            final IpAddressTO[] ips = cmd.getIpAddresses();
+            for (final IpAddressTO ip : ips) {
+                final URI broadcastUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
                 if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
                     throw new InternalErrorException("Invalid Broadcast URI " + ip.getBroadcastUri());
                 }
-                String vlanId = BroadcastDomainType.getValue(broadcastUri);
+                final String vlanId = BroadcastDomainType.getValue(broadcastUri);
                 int publicNicInfo = -1;
                 publicNicInfo = getVmNics(routerName, vlanId);
                 if (publicNicInfo < 0) {
@@ -784,7 +782,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
 
                 ip.setNicDevId(publicNicInfo);
             }
-        } catch (Exception e) {
+        } catch (final Exception e) {
             s_logger.error("Prepare Ip Assoc failure on applying one ip due to exception:  ", e);
             return new ExecutionResult(false, e.toString());
         }
@@ -792,43 +790,43 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         return new ExecutionResult(true, null);
     }
 
-    protected ExecutionResult prepareNetworkElementCommand(SetSourceNatCommand cmd) {
-        String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
-        IpAddressTO pubIp = cmd.getIpAddress();
+    protected ExecutionResult prepareNetworkElementCommand(final SetSourceNatCommand cmd) {
+        final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
+        final IpAddressTO pubIp = cmd.getIpAddress();
 
         try {
-            String broadcastUri = pubIp.getBroadcastUri();
-            String vlanId = BroadcastDomainType.getValue(broadcastUri);
-            int ethDeviceNum = getVmNics(routerName, vlanId);
+            final String broadcastUri = pubIp.getBroadcastUri();
+            final String vlanId = BroadcastDomainType.getValue(broadcastUri);
+            final int ethDeviceNum = getVmNics(routerName, vlanId);
             if (ethDeviceNum > 0) {
                 pubIp.setNicDevId(ethDeviceNum);
             } else {
                 return new ExecutionResult(false, "Prepare Ip SNAT failed due to unable to find the nic");
             }
-        } catch (Exception e) {
-            String msg = "Prepare Ip SNAT failure due to " + e.toString();
+        } catch (final Exception e) {
+            final String msg = "Prepare Ip SNAT failure due to " + e.toString();
             s_logger.error(msg, e);
             return new ExecutionResult(false, e.toString());
         }
         return new ExecutionResult(true, null);
     }
 
-    private ExecutionResult prepareNetworkElementCommand(SetNetworkACLCommand cmd) {
-        NicTO nic = cmd.getNic();
-        String routerName =
+    private ExecutionResult prepareNetworkElementCommand(final SetNetworkACLCommand cmd) {
+        final NicTO nic = cmd.getNic();
+        final String routerName =
                 cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
 
         try {
-            URI broadcastUri = nic.getBroadcastUri();
-            String vlanId = BroadcastDomainType.getValue(broadcastUri);
-            int ethDeviceNum = getVmNics(routerName, vlanId);
+            final URI broadcastUri = nic.getBroadcastUri();
+            final String vlanId = BroadcastDomainType.getValue(broadcastUri);
+            final int ethDeviceNum = getVmNics(routerName, vlanId);
             if (ethDeviceNum > 0) {
                 nic.setDeviceId(ethDeviceNum);
             } else {
                 return new ExecutionResult(false, "Prepare SetNetworkACL failed due to unable to find the nic");
             }
-        } catch (Exception e) {
-            String msg = "Prepare SetNetworkACL failed due to " + e.toString();
+        } catch (final Exception e) {
+            final String msg = "Prepare SetNetworkACL failed due to " + e.toString();
             s_logger.error(msg, e);
             return new ExecutionResult(false, msg);
         }
@@ -836,13 +834,13 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
     }
 
     @Override
-    public ExecutionResult cleanupCommand(NetworkElementCommand cmd) {
+    public ExecutionResult cleanupCommand(final NetworkElementCommand cmd) {
         return new ExecutionResult(true, null);
     }
 
     protected Answer execute(final RemoteAccessVpnCfgCommand cmd) {
-        String controlIp = getRouterSshControlIp(cmd);
-        StringBuffer argsBuf = new StringBuffer();
+        final String controlIp = getRouterSshControlIp(cmd);
+        final StringBuffer argsBuf = new StringBuffer();
         if (cmd.isCreate()) {
             argsBuf.append(" -r ").append(cmd.getIpRange()).append(" -p ").append(cmd.getPresharedKey()).append(" -s ").append(cmd.getVpnServerIp()).append(" -l ").append(cmd.getLocalIp())
             .append(" -c ");
@@ -859,7 +857,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                 s_logger.debug("Executing /opt/cloud/bin/vpn_lt2p.sh ");
             }
 
-            Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vpn_l2tp.sh " + argsBuf.toString());
+            final Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vpn_l2tp.sh " + argsBuf.toString());
 
             if (!result.first()) {
                 s_logger.error("RemoteAccessVpnCfg command on domR failed, message: " + result.second());
@@ -871,12 +869,12 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                 s_logger.info("RemoteAccessVpnCfg command on domain router " + argsBuf.toString() + " completed");
             }
 
-        } catch (Throwable e) {
+        } catch (final Throwable e) {
             if (e instanceof RemoteException) {
                 s_logger.warn(e.getMessage());
             }
 
-            String msg = "RemoteAccessVpnCfg command failed due to " + e.getMessage();
+            final String msg = "RemoteAccessVpnCfg command failed due to " + e.getMessage();
             s_logger.error(msg, e);
             return new Answer(cmd, false, msg);
         }
@@ -886,9 +884,9 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
 
     protected Answer execute(final VpnUsersCfgCommand cmd) {
 
-        String controlIp = getRouterSshControlIp(cmd);
-        for (VpnUsersCfgCommand.UsernamePassword userpwd : cmd.getUserpwds()) {
-            StringBuffer argsBuf = new StringBuffer();
+        final String controlIp = getRouterSshControlIp(cmd);
+        for (final VpnUsersCfgCommand.UsernamePassword userpwd : cmd.getUserpwds()) {
+            final StringBuffer argsBuf = new StringBuffer();
             if (!userpwd.isAdd()) {
                 argsBuf.append(" -U ").append(userpwd.getUsername());
             } else {
@@ -901,19 +899,19 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                     s_logger.debug("Executing /opt/cloud/bin/vpn_lt2p.sh ");
                 }
 
-                Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vpn_l2tp.sh " + argsBuf.toString());
+                final Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vpn_l2tp.sh " + argsBuf.toString());
 
                 if (!result.first()) {
                     s_logger.error("VpnUserCfg command on domR failed, message: " + result.second());
 
                     return new Answer(cmd, false, "VpnUserCfg command failed due to " + result.second());
                 }
-            } catch (Throwable e) {
+            } catch (final Throwable e) {
                 if (e instanceof RemoteException) {
                     s_logger.warn(e.getMessage());
                 }
 
-                String msg = "VpnUserCfg command failed due to " + e.getMessage();
+                final String msg = "VpnUserCfg command failed due to " + e.getMessage();
                 s_logger.error(msg, e);
                 return new Answer(cmd, false, msg);
             }
@@ -921,21 +919,21 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
 
         return new Answer(cmd);
     }
-    private SetStaticRouteAnswer execute(SetStaticRouteCommand cmd) {
+    private SetStaticRouteAnswer execute(final SetStaticRouteCommand cmd) {
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Executing resource SetStaticRouteCommand: " + s_gson.toJson(cmd));
         }
 
         boolean endResult = true;
 
-        String controlIp = getRouterSshControlIp(cmd);
+        final String controlIp = getRouterSshControlIp(cmd);
         String args = "";
-        String[] results = new String[cmd.getStaticRoutes().length];
+        final String[] results = new String[cmd.getStaticRoutes().length];
         int i = 0;
 
         // Extract and build the arguments for the command to be sent to the VR.
-        String[] rules = cmd.generateSRouteRules();
-        StringBuilder sb = new StringBuilder();
+        final String[] rules = cmd.generateSRouteRules();
+        final StringBuilder sb = new StringBuilder();
 
         for (int j = 0; j < rules.length; j++) {
             sb.append(rules[j]).append(',');
@@ -944,11 +942,12 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
 
         // Send over the command for execution, via ssh, to the VR.
         try {
-            Pair<Boolean, String> result =
+            final Pair<Boolean, String> result =
                     SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vpc_staticroute.sh " + args);
 
-            if (s_logger.isDebugEnabled())
+            if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Executing script on domain router " + controlIp + ": /opt/cloud/bin/vpc_staticroute.sh " + args);
+            }
 
             if (!result.first()) {
                 s_logger.error("SetStaticRouteCommand failure on setting one rule. args: " + args);
@@ -957,7 +956,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             } else {
                 results[i++] = null;
             }
-        } catch (Throwable e) {
+        } catch (final Throwable e) {
             s_logger.error("SetStaticRouteCommand(args: " + args + ") failed on setting one rule due to " + e);
             results[i++] = "Failed";
             endResult = false;
@@ -966,7 +965,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
 
     }
 
-    protected CheckS2SVpnConnectionsAnswer execute(CheckS2SVpnConnectionsCommand cmd) {
+    protected CheckS2SVpnConnectionsAnswer execute(final CheckS2SVpnConnectionsCommand cmd) {
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Executing resource CheckS2SVpnConnectionsCommand: " + s_gson.toJson(cmd));
             s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /opt/cloud/bin/checkbatchs2svpn.sh ");
@@ -974,9 +973,9 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
 
         Pair<Boolean, String> result;
         try {
-            String controlIp = getRouterSshControlIp(cmd);
-            StringBuilder cmdline = new StringBuilder("/opt/cloud/bin/checkbatchs2svpn.sh ");
-            for (String ip : cmd.getVpnIps()) {
+            final String controlIp = getRouterSshControlIp(cmd);
+            final StringBuilder cmdline = new StringBuilder("/opt/cloud/bin/checkbatchs2svpn.sh ");
+            for (final String ip : cmd.getVpnIps()) {
                 cmdline.append(" ");
                 cmdline.append(ip);
             }
@@ -993,20 +992,20 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("check site-to-site vpn connections command on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed");
             }
-        } catch (Throwable e) {
-            String msg = "CheckS2SVpnConnectionsCommand failed due to " + e;
+        } catch (final Throwable e) {
+            final String msg = "CheckS2SVpnConnectionsCommand failed due to " + e;
             s_logger.error(msg, e);
             return new CheckS2SVpnConnectionsAnswer(cmd, false, "CheckS2SVpnConneciontsCommand failed");
         }
         return new CheckS2SVpnConnectionsAnswer(cmd, true, result.second());
     }
 
-    protected Answer execute(Site2SiteVpnCfgCommand cmd) {
+    protected Answer execute(final Site2SiteVpnCfgCommand cmd) {
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Executing resource Site2SiteVpnCfgCommand " + s_gson.toJson(cmd));
         }
 
-        String routerIp = getRouterSshControlIp(cmd);
+        final String routerIp = getRouterSshControlIp(cmd);
 
         String args = "";
         if (cmd.isCreate()) {
@@ -1060,24 +1059,24 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("setup site 2 site vpn on router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed");
             }
-        } catch (Throwable e) {
-            String msg = "Setup site2site VPN falied due to " + e.getMessage();
+        } catch (final Throwable e) {
+            final String msg = "Setup site2site VPN falied due to " + e.getMessage();
             s_logger.error(msg, e);
             return new Answer(cmd, false, "Setup site2site VPN failed due to " + e.getMessage());
         }
         return new Answer(cmd, true, result.second());
     }
 
-    protected SetSourceNatAnswer execute(SetSourceNatCommand cmd) {
+    protected SetSourceNatAnswer execute(final SetSourceNatCommand cmd) {
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Executing resource SetSourceNatCommand " + s_gson.toJson(cmd));
         }
 
-        String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
-        String routerIp = getRouterSshControlIp(cmd);
-        IpAddressTO pubIp = cmd.getIpAddress();
+        final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
+        final String routerIp = getRouterSshControlIp(cmd);
+        final IpAddressTO pubIp = cmd.getIpAddress();
         try {
-            int ethDeviceNum = findRouterEthDeviceIndex(routerName, routerIp, pubIp.getVifMacAddress());
+            final int ethDeviceNum = findRouterEthDeviceIndex(routerName, routerIp, pubIp.getVifMacAddress());
             String args = "";
             args += " -A ";
             args += " -l ";
@@ -1086,35 +1085,35 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             args += " -c ";
             args += "eth" + ethDeviceNum;
 
-            Pair<Boolean, String> result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vpc_snat.sh " + args);
+            final Pair<Boolean, String> result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vpc_snat.sh " + args);
 
             if (!result.first()) {
-                String msg = "SetupGuestNetworkCommand on domain router " + routerIp + " failed. message: " + result.second();
+                final String msg = "SetupGuestNetworkCommand on domain router " + routerIp + " failed. message: " + result.second();
                 s_logger.error(msg);
 
                 return new SetSourceNatAnswer(cmd, false, msg);
             }
 
             return new SetSourceNatAnswer(cmd, true, "success");
-        } catch (Exception e) {
-            String msg = "Ip SNAT failure due to " + e.toString();
+        } catch (final Exception e) {
+            final String msg = "Ip SNAT failure due to " + e.toString();
             s_logger.error(msg, e);
             return new SetSourceNatAnswer(cmd, false, msg);
         }
     }
 
-    protected Answer execute(SetPortForwardingRulesCommand cmd) {
+    protected Answer execute(final SetPortForwardingRulesCommand cmd) {
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Executing resource SetPortForwardingRulesCommand: " + s_gson.toJson(cmd));
         }
 
-        String controlIp = getRouterSshControlIp(cmd);
+        final String controlIp = getRouterSshControlIp(cmd);
         String args = "";
-        String[] results = new String[cmd.getRules().length];
+        final String[] results = new String[cmd.getRules().length];
         int i = 0;
 
         boolean endResult = true;
-        for (PortForwardingRuleTO rule : cmd.getRules()) {
+        for (final PortForwardingRuleTO rule : cmd.getRules()) {
             args += rule.revoked() ? " -D " : " -A ";
             args += " -P " + rule.getProtocol().toLowerCase();
             args += " -l " + rule.getSrcIp();
@@ -1123,10 +1122,11 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             args += " -d " + rule.getStringDstPortRange();
 
             try {
-                Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/firewall.sh " + args);
+                final Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/firewall.sh " + args);
 
-                if (s_logger.isDebugEnabled())
+                if (s_logger.isDebugEnabled()) {
                     s_logger.debug("Executing script on domain router " + controlIp + ": /root/firewall.sh " + args);
+                }
 
                 if (!result.first()) {
                     s_logger.error("SetPortForwardingRulesCommand failure on setting one rule. args: " + args);
@@ -1135,7 +1135,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                 } else {
                     results[i++] = null;
                 }
-            } catch (Throwable e) {
+            } catch (final Throwable e) {
                 s_logger.error("SetPortForwardingRulesCommand(args: " + args + ") failed on setting one rule due to " + e.getMessage());
                 results[i++] = "Failed";
                 endResult = false;
@@ -1145,7 +1145,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         return new SetPortForwardingRulesAnswer(cmd, results, endResult);
     }
 
-    protected Answer execute(CheckRouterCommand cmd) {
+    protected Answer execute(final CheckRouterCommand cmd) {
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Executing resource CheckRouterCommand: " + s_gson.toJson(cmd));
             s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /opt/cloud/bin/checkrouter.sh ");
@@ -1154,7 +1154,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         Pair<Boolean, String> result;
         try {
 
-            String controlIp = getRouterSshControlIp(cmd);
+            final String controlIp = getRouterSshControlIp(cmd);
             result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/checkrouter.sh ");
 
             if (!result.first()) {
@@ -1166,15 +1166,15 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("check router command on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed");
             }
-        } catch (Throwable e) {
-            String msg = "CheckRouterCommand failed due to " + e.getMessage();
+        } catch (final Throwable e) {
+            final String msg = "CheckRouterCommand failed due to " + e.getMessage();
             s_logger.error(msg, e);
             return new CheckRouterAnswer(cmd, msg);
         }
         return new CheckRouterAnswer(cmd, result.second(), true);
     }
 
-    protected Answer execute(SetStaticNatRulesCommand cmd) {
+    protected Answer execute(final SetStaticNatRulesCommand cmd) {
 
         if (cmd.getVpcId() != null) {
             //return SetVPCStaticNatRules(cmd);
@@ -1185,10 +1185,10 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         }
 
         String args = null;
-        String[] results = new String[cmd.getRules().length];
+        final String[] results = new String[cmd.getRules().length];
         int i = 0;
         boolean endResult = true;
-        for (StaticNatRuleTO rule : cmd.getRules()) {
+        for (final StaticNatRuleTO rule : cmd.getRules()) {
             // 1:1 NAT needs instanceip;publicip;domrip;op
             args = rule.revoked() ? " -D " : " -A ";
 
@@ -1203,11 +1203,12 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             args += " -G ";
 
             try {
-                String controlIp = getRouterSshControlIp(cmd);
-                Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/firewall.sh " + args);
+                final String controlIp = getRouterSshControlIp(cmd);
+                final Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/firewall.sh " + args);
 
-                if (s_logger.isDebugEnabled())
+                if (s_logger.isDebugEnabled()) {
                     s_logger.debug("Executing script on domain router " + controlIp + ": /root/firewall.sh " + args);
+                }
 
                 if (!result.first()) {
                     s_logger.error("SetStaticNatRulesCommand failure on setting one rule. args: " + args);
@@ -1216,7 +1217,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                 } else {
                     results[i++] = null;
                 }
-            } catch (Throwable e) {
+            } catch (final Throwable e) {
                 s_logger.error("SetStaticNatRulesCommand (args: " + args + ") failed on setting one rule due to " + e.getMessage());
                 results[i++] = "Failed";
                 endResult = false;
@@ -1225,17 +1226,18 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         return new SetStaticNatRulesAnswer(cmd, results, endResult);
     }
 
-    protected Answer execute(PingTestCommand cmd) {
+    protected Answer execute(final PingTestCommand cmd) {
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Executing resource PingTestCommand: " + s_gson.toJson(cmd));
         }
-        String controlIp = cmd.getRouterIp();
-        String args = " -c 1 -n -q " + cmd.getPrivateIp();
+        final String controlIp = cmd.getRouterIp();
+        final String args = " -c 1 -n -q " + cmd.getPrivateIp();
         try {
-            Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/bin/ping" + args);
-            if (result.first())
+            final Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/bin/ping" + args);
+            if (result.first()) {
                 return new Answer(cmd);
-        } catch (Exception e) {
+            }
+        } catch (final Exception e) {
             s_logger.error("Unable to execute ping command on DomR (" + controlIp + "), domR may not be ready yet. failure due to " + e.getMessage());
         }
         return new Answer(cmd, false, "PingTestCommand failed");
@@ -1243,13 +1245,13 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
 
     protected Answer execute(final DeleteIpAliasCommand cmd) {
         cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
-        List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos();
-        List<IpAliasTO> activeIpAliasTOs = cmd.getCreateIpAliasTos();
+        final List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos();
+        final List<IpAliasTO> activeIpAliasTOs = cmd.getCreateIpAliasTos();
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Executing deleteIpAlias command: " + s_gson.toJson(cmd));
         }
-        StringBuilder args = new StringBuilder();
-        for (IpAliasTO ipAliasTO : revokedIpAliasTOs) {
+        final StringBuilder args = new StringBuilder();
+        for (final IpAliasTO ipAliasTO : revokedIpAliasTOs) {
             args.append(ipAliasTO.getAlias_count());
             args.append(":");
             args.append(ipAliasTO.getRouterip());
@@ -1258,7 +1260,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             args.append("-");
         }
         args.append("- ");
-        for (IpAliasTO ipAliasTO : activeIpAliasTOs) {
+        for (final IpAliasTO ipAliasTO : activeIpAliasTOs) {
             args.append(ipAliasTO.getAlias_count());
             args.append(":");
             args.append(ipAliasTO.getRouterip());
@@ -1271,8 +1273,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         }
 
         try {
-            String controlIp = getRouterSshControlIp(cmd);
-            Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/deleteIpAlias.sh " + args);
+            final String controlIp = getRouterSshControlIp(cmd);
+            final Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/deleteIpAlias.sh " + args);
 
             if (!result.first()) {
                 s_logger.error("deleteIpAlias command on domr " + controlIp + " failed, message: " + result.second());
@@ -1284,8 +1286,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                 s_logger.info("deleteIpAlias command on domain router " + controlIp + " completed");
             }
 
-        } catch (Throwable e) {
-            String msg = "deleteIpAlias failed due to " + e.getMessage();
+        } catch (final Throwable e) {
+            final String msg = "deleteIpAlias failed due to " + e.getMessage();
             s_logger.error(msg, e);
             return new Answer(cmd, false, msg);
         }
@@ -1299,19 +1301,19 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             //return VPCLoadBalancerConfig(cmd);
         }
 
-        File keyFile = getSystemVMKeyFile();
+        final File keyFile = getSystemVMKeyFile();
 
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
-        String controlIp = getRouterSshControlIp(cmd);
+        final String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        final String controlIp = getRouterSshControlIp(cmd);
 
-        assert (controlIp != null);
+        assert controlIp != null;
 
-        LoadBalancerConfigurator cfgtr = new HAProxyConfigurator();
-        String[] config = cfgtr.generateConfiguration(cmd);
+        final LoadBalancerConfigurator cfgtr = new HAProxyConfigurator();
+        final String[] config = cfgtr.generateConfiguration(cmd);
 
-        String[][] rules = cfgtr.generateFwRules(cmd);
-        String tmpCfgFilePath = "/tmp/" + routerIp.replace('.', '_') + ".cfg";
-        StringBuilder tmpCfgFileContents = new StringBuilder();
+        final String[][] rules = cfgtr.generateFwRules(cmd);
+        final String tmpCfgFilePath = "/tmp/" + routerIp.replace('.', '_') + ".cfg";
+        final StringBuilder tmpCfgFileContents = new StringBuilder();
         for (int i = 0; i < config.length; i++) {
             tmpCfgFileContents.append(config[i]);
             tmpCfgFileContents.append("\n");
@@ -1322,9 +1324,9 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                     ".cfg", null);
 
             try {
-                String[] addRules = rules[LoadBalancerConfigurator.ADD];
-                String[] removeRules = rules[LoadBalancerConfigurator.REMOVE];
-                String[] statRules = rules[LoadBalancerConfigurator.STATS];
+                final String[] addRules = rules[LoadBalancerConfigurator.ADD];
+                final String[] removeRules = rules[LoadBalancerConfigurator.REMOVE];
+                final String[] statRules = rules[LoadBalancerConfigurator.STATS];
 
                 String args = "";
                 args += "-i " + routerIp;
@@ -1372,7 +1374,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                 result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/loadbalancer.sh " + args);
 
                 if (!result.first()) {
-                    String msg = "LoadBalancerConfigCommand on domain router " + routerIp + " failed. message: " + result.second();
+                    final String msg = "LoadBalancerConfigCommand on domain router " + routerIp + " failed. message: " + result.second();
                     s_logger.error(msg);
 
                     return new Answer(cmd, false, msg);
@@ -1386,20 +1388,20 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             }
 
             return new Answer(cmd);
-        } catch (Throwable e) {
+        } catch (final Throwable e) {
             s_logger.error("Unexpected exception: " + e.toString(), e);
             return new Answer(cmd, false, "LoadBalancerConfigCommand failed due to " + e.getMessage());
         }
     }
 
-    protected Answer execute(SavePasswordCommand cmd) {
+    protected Answer execute(final SavePasswordCommand cmd) {
         if (s_logger.isInfoEnabled()) {
 
             s_logger.info("Executing resource SavePasswordCommand. vmName: " + cmd.getVmName() + ", vmIp: " + cmd.getVmIpAddress() + ", password: " +
                     StringUtils.getMaskedPasswordForDisplay(cmd.getPassword()));
         }
 
-        String controlIp = getRouterSshControlIp(cmd);
+        final String controlIp = getRouterSshControlIp(cmd);
         final String password = cmd.getPassword();
         final String vmIpAddress = cmd.getVmIpAddress();
 
@@ -1415,7 +1417,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
 
         try {
 
-            Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/savepassword.sh " +
+            final Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/savepassword.sh " +
                     args);
 
             if (!result.first()) {
@@ -1428,22 +1430,22 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                 s_logger.info("savepassword command on domain router " + controlIp + " completed");
             }
 
-        } catch (Throwable e) {
-            String msg = "SavePasswordCommand failed due to " + e;
+        } catch (final Throwable e) {
+            final String msg = "SavePasswordCommand failed due to " + e;
             s_logger.error(msg, e);
             return new Answer(cmd, false, msg);
         }
         return new Answer(cmd);
     }
 
-    protected SetFirewallRulesAnswer execute(SetFirewallRulesCommand cmd) {
-        String controlIp = getRouterSshControlIp(cmd);
-        String[] results = new String[cmd.getRules().length];
-        FirewallRuleTO[] allrules = cmd.getRules();
-        FirewallRule.TrafficType trafficType = allrules[0].getTrafficType();
-        String egressDefault = cmd.getAccessDetail(NetworkElementCommand.FIREWALL_EGRESS_DEFAULT);
+    protected SetFirewallRulesAnswer execute(final SetFirewallRulesCommand cmd) {
+        final String controlIp = getRouterSshControlIp(cmd);
+        final String[] results = new String[cmd.getRules().length];
+        final FirewallRuleTO[] allrules = cmd.getRules();
+        final FirewallRule.TrafficType trafficType = allrules[0].getTrafficType();
+        final String egressDefault = cmd.getAccessDetail(NetworkElementCommand.FIREWALL_EGRESS_DEFAULT);
 
-        String[][] rules = cmd.generateFwRules();
+        final String[][] rules = cmd.generateFwRules();
         String args = "";
         args += " -F ";
         if (trafficType == FirewallRule.TrafficType.Egress) {
@@ -1457,8 +1459,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             }
         }
 
-        StringBuilder sb = new StringBuilder();
-        String[] fwRules = rules[0];
+        final StringBuilder sb = new StringBuilder();
+        final String[] fwRules = rules[0];
         if (fwRules.length > 0) {
             for (int i = 0; i < fwRules.length; i++) {
                 sb.append(fwRules[i]).append(',');
@@ -1492,7 +1494,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
 
                 return new SetFirewallRulesAnswer(cmd, false, results);
             }
-        } catch (Throwable e) {
+        } catch (final Throwable e) {
             s_logger.error("SetFirewallRulesCommand(args: " + args + ") failed on setting one rule due to ", e);
             //FIXME - in the future we have to process each rule separately; now we temporarily set every rule to be false if single rule fails
             for (int i = 0; i < results.length; i++) {
@@ -1504,12 +1506,12 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         return new SetFirewallRulesAnswer(cmd, true, results);
     }
 
-    protected Answer execute(VmDataCommand cmd) {
+    protected Answer execute(final VmDataCommand cmd) {
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Executing resource VmDataCommand: " + s_gson.toJson(cmd));
         }
-        String controlIp = getRouterSshControlIp(cmd);
-        Map<String, List<String[]>> data = new HashMap<String, List<String[]>>();
+        final String controlIp = getRouterSshControlIp(cmd);
+        final Map<String, List<String[]>> data = new HashMap<String, List<String[]>>();
         data.put(cmd.getVmIpAddress(), cmd.getVmData());
 
         String json = new Gson().toJson(data);
@@ -1517,10 +1519,10 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
 
         json = Base64.encodeBase64String(json.getBytes(Charset.forName("UTF-8")));
 
-        String args = "-d " + json;
+        final String args = "-d " + json;
 
         try {
-            Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vmdata.py " + args);
+            final Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vmdata.py " + args);
             if (!result.first()) {
                 s_logger.error("vm_data command on domain router " + controlIp + " failed. messge: " + result.second());
                 return new Answer(cmd, false, "VmDataCommand failed due to " + result.second());
@@ -1529,15 +1531,15 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             if (s_logger.isInfoEnabled()) {
                 s_logger.info("vm_data command on domain router " + controlIp + " completed");
             }
-        } catch (Throwable e) {
-            String msg = "VmDataCommand failed due to " + e.getMessage();
+        } catch (final Throwable e) {
+            final String msg = "VmDataCommand failed due to " + e.getMessage();
             s_logger.error(msg, e);
             return new Answer(cmd, false, msg);
         }
         return new Answer(cmd);
     }
 
-    protected Answer execute(DhcpEntryCommand cmd) {
+    protected Answer execute(final DhcpEntryCommand cmd) {
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Executing resource DhcpEntryCommand: " + s_gson.toJson(cmd));
         }
@@ -1576,8 +1578,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         }
 
         try {
-            String controlIp = getRouterSshControlIp(cmd);
-            Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/edithosts.sh " + args);
+            final String controlIp = getRouterSshControlIp(cmd);
+            final Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/edithosts.sh " + args);
 
             if (!result.first()) {
                 s_logger.error("dhcp_entry command on domR " + controlIp + " failed, message: " + result.second());
@@ -1589,8 +1591,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                 s_logger.info("dhcp_entry command on domain router " + controlIp + " completed");
             }
 
-        } catch (Throwable e) {
-            String msg = "DhcpEntryCommand failed due to " + e;
+        } catch (final Throwable e) {
+            final String msg = "DhcpEntryCommand failed due to " + e;
             s_logger.error(msg, e);
             return new Answer(cmd, false, msg);
         }
@@ -1603,9 +1605,9 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             s_logger.info("Executing createIpAlias command: " + s_gson.toJson(cmd));
         }
         cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
-        List<IpAliasTO> ipAliasTOs = cmd.getIpAliasList();
-        StringBuilder args = new StringBuilder();
-        for (IpAliasTO ipaliasto : ipAliasTOs) {
+        final List<IpAliasTO> ipAliasTOs = cmd.getIpAliasList();
+        final StringBuilder args = new StringBuilder();
+        for (final IpAliasTO ipaliasto : ipAliasTOs) {
             args.append(ipaliasto.getAlias_count());
             args.append(":");
             args.append(ipaliasto.getRouterip());
@@ -1618,8 +1620,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         }
 
         try {
-            String controlIp = getRouterSshControlIp(cmd);
-            Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/createIpAlias.sh " + args);
+            final String controlIp = getRouterSshControlIp(cmd);
+            final Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/createIpAlias.sh " + args);
 
             if (!result.first()) {
                 s_logger.error("CreateIpAlias command on domr " + controlIp + " failed, message: " + result.second());
@@ -1631,8 +1633,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
                 s_logger.info("createIpAlias command on domain router " + controlIp + " completed");
             }
 
-        } catch (Throwable e) {
-            String msg = "createIpAlias failed due to " + e;
+        } catch (final Throwable e) {
+            final String msg = "createIpAlias failed due to " + e;
             s_logger.error(msg, e);
             return new Answer(cmd, false, msg);
         }
@@ -1644,14 +1646,14 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Executing dnsmasqConfig command: " + s_gson.toJson(cmd));
         }
-        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
-        String controlIp = getRouterSshControlIp(cmd);
+        final String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
+        final String controlIp = getRouterSshControlIp(cmd);
 
-        assert (controlIp != null);
+        assert controlIp != null;
 
-        List<DhcpTO> dhcpTos = cmd.getIps();
-        StringBuilder args = new StringBuilder();
-        for (DhcpTO dhcpTo : dhcpTos) {
+        final List<DhcpTO> dhcpTos = cmd.getIps();
+        final StringBuilder args = new StringBuilder();
+        for (final DhcpTO dhcpTo : dhcpTos) {
             args.append(dhcpTo.getRouterIp());
             args.append(":");
             args.append(dhcpTo.getGateway());
@@ -1663,7 +1665,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         }
 
         try {
-            Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/dnsmasq.sh " + args);
+            final Pair<Boolean, String> result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/dnsmasq.sh " + args);
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Run command on domain router " + routerIp + ",  /root/dnsmasq.sh");
             }
@@ -1676,8 +1678,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("dnsmasq config command on domain router " + routerIp + " completed");
             }
-        } catch (Throwable e) {
-            String msg = "Dnsmasqconfig command failed due to " + e.getMessage();
+        } catch (final Throwable e) {
+            final String msg = "Dnsmasqconfig command failed due to " + e.getMessage();
             s_logger.error(msg, e);
             return new Answer(cmd, false, msg);
         }
@@ -1701,34 +1703,37 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
     //
     //
 
-    private int findRouterEthDeviceIndex(String domrName, String routerIp, String mac) throws Exception {
+    private int findRouterEthDeviceIndex(final String domrName, final String routerIp, final String mac) throws Exception {
 
         s_logger.info("findRouterEthDeviceIndex. mac: " + mac);
 
         // TODO : this is a temporary very inefficient solution, will refactor it later
-        Pair<Boolean, String> result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null,
+        final Pair<Boolean, String> result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null,
                 "ls /proc/sys/net/ipv4/conf");
 
         // when we dynamically plug in a new NIC into virtual router, it may take time to show up in guest OS
         // we use a waiting loop here as a workaround to synchronize activities in systems
-        long startTick = System.currentTimeMillis();
+        final long startTick = System.currentTimeMillis();
         while (System.currentTimeMillis() - startTick < 15000) {
             if (result.first()) {
-                String[] tokens = result.second().split("\\s+");
-                for (String token : tokens) {
+                final String[] tokens = result.second().split("\\s+");
+                for (final String token : tokens) {
                     if (!("all".equalsIgnoreCase(token) || "default".equalsIgnoreCase(token) || "lo".equalsIgnoreCase(token))) {
-                        String cmd = String.format("ip address show %s | grep link/ether | sed -e 's/^[ \t]*//' | cut -d' ' -f2", token);
+                        final String cmd = String.format("ip address show %s | grep link/ether | sed -e 's/^[ \t]*//' | cut -d' ' -f2", token);
 
-                        if (s_logger.isDebugEnabled())
+                        if (s_logger.isDebugEnabled()) {
                             s_logger.debug("Run domr script " + cmd);
-                        Pair<Boolean, String> result2 = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null,
+                        }
+                        final Pair<Boolean, String> result2 = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null,
                                 // TODO need to find the dev index inside router based on IP address
                                 cmd);
-                        if (s_logger.isDebugEnabled())
+                        if (s_logger.isDebugEnabled()) {
                             s_logger.debug("result: " + result2.first() + ", output: " + result2.second());
+                        }
 
-                        if (result2.first() && result2.second().trim().equalsIgnoreCase(mac.trim()))
+                        if (result2.first() && result2.second().trim().equalsIgnoreCase(mac.trim())) {
                             return Integer.parseInt(token.substring(3));
+                        }
                     }
                 }
             }
@@ -1740,36 +1745,39 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         return -1;
     }
 
-    private Pair<Integer, String> findRouterFreeEthDeviceIndex(String routerIp) throws Exception {
+    private Pair<Integer, String> findRouterFreeEthDeviceIndex(final String routerIp) throws Exception {
 
         s_logger.info("findRouterFreeEthDeviceIndex. mac: ");
 
         // TODO : this is a temporary very inefficient solution, will refactor it later
-        Pair<Boolean, String> result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null,
+        final Pair<Boolean, String> result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null,
                 "ip address | grep DOWN| cut -f2 -d :");
 
         // when we dynamically plug in a new NIC into virtual router, it may take time to show up in guest OS
         // we use a waiting loop here as a workaround to synchronize activities in systems
-        long startTick = System.currentTimeMillis();
+        final long startTick = System.currentTimeMillis();
         while (System.currentTimeMillis() - startTick < 15000) {
             if (result.first() && !result.second().isEmpty()) {
-                String[] tokens = result.second().split("\\n");
-                for (String token : tokens) {
+                final String[] tokens = result.second().split("\\n");
+                for (final String token : tokens) {
                     if (!("all".equalsIgnoreCase(token) || "default".equalsIgnoreCase(token) || "lo".equalsIgnoreCase(token))) {
                         //String cmd = String.format("ip address show %s | grep link/ether | sed -e 's/^[ \t]*//' | cut -d' ' -f2", token);
                         //TODO: don't check for eth0,1,2, as they will be empty by default.
                         //String cmd = String.format("ip address show %s ", token);
-                        String cmd = String.format("ip address show %s | grep link/ether | sed -e 's/^[ \t]*//' | cut -d' ' -f2", token);
-                        if (s_logger.isDebugEnabled())
+                        final String cmd = String.format("ip address show %s | grep link/ether | sed -e 's/^[ \t]*//' | cut -d' ' -f2", token);
+                        if (s_logger.isDebugEnabled()) {
                             s_logger.debug("Run domr script " + cmd);
-                        Pair<Boolean, String> result2 = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null,
+                        }
+                        final Pair<Boolean, String> result2 = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null,
                                 // TODO need to find the dev index inside router based on IP address
                                 cmd);
-                        if (s_logger.isDebugEnabled())
+                        if (s_logger.isDebugEnabled()) {
                             s_logger.debug("result: " + result2.first() + ", output: " + result2.second());
+                        }
 
-                        if (result2.first() && result2.second().trim().length() > 0)
+                        if (result2.first() && result2.second().trim().length() > 0) {
                             return new Pair<Integer, String>(Integer.parseInt(token.trim().substring(3)), result2.second().trim()) ;
+                        }
                     }
                 }
             }
@@ -1781,20 +1789,20 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         return new Pair<Integer, String>(-1, "");
     }
 
-    protected Answer execute(IpAssocCommand cmd) {
+    protected Answer execute(final IpAssocCommand cmd) {
         if (s_logger.isInfoEnabled()) {
             s_logger.info("Executing resource IPAssocCommand: " + s_gson.toJson(cmd));
         }
 
         int i = 0;
-        String[] results = new String[cmd.getIpAddresses().length];
+        final String[] results = new String[cmd.getIpAddresses().length];
 
         try {
 
-            IpAddressTO[] ips = cmd.getIpAddresses();
-            String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
-            String controlIp = getRouterSshControlIp(cmd);
-            for (IpAddressTO ip : ips) {
+            final IpAddressTO[] ips = cmd.getIpAddresses();
+            final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
+            final String controlIp = getRouterSshControlIp(cmd);
+            for (final IpAddressTO ip : ips) {
                 assignPublicIpAddress(routerName, controlIp, ip.getPublicIp(), ip.isAdd(), ip.isFirstIP(), ip.isSourceNat(), ip.getBroadcastUri(), ip.getVlanGateway(),
                         ip.getVlanNetmask(), ip.getVifMacAddress());
                 results[i++] = ip.getPublicIp() + " - success";
@@ -1803,7 +1811,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
             for (; i < cmd.getIpAddresses().length; i++) {
                 results[i++] = IpAssocAnswer.errorResult;
             }
-        } catch (Throwable e) {
+        } catch (final Throwable e) {
             s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e);
 
             for (; i < cmd.getIpAddresses().length; i++) {
@@ -1815,27 +1823,27 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
     }
 
 
-    protected int getVmFreeNicIndex(String vmName) {
-        GetVmConfigCommand vmConfig = new GetVmConfigCommand(vmName);
+    protected int getVmFreeNicIndex(final String vmName) {
+        final GetVmConfigCommand vmConfig = new GetVmConfigCommand(vmName);
         URI agentUri = null;
         int nicposition = -1;
         try {
-            String cmdName = GetVmConfigCommand.class.getName();
+            final String cmdName = GetVmConfigCommand.class.getName();
             agentUri =
                     new URI("https", null, _agentIp, _port,
                             "/api/HypervResource/" + cmdName, null, null);
-        } catch (URISyntaxException e) {
-            String errMsg = "Could not generate URI for Hyper-V agent";
+        } catch (final URISyntaxException e) {
+            final String errMsg = "Could not generate URI for Hyper-V agent";
             s_logger.error(errMsg, e);
         }
-        String ansStr = postHttpRequest(s_gson.toJson(vmConfig), agentUri);
-        Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
+        final String ansStr = postHttpRequest(s_gson.toJson(vmConfig), agentUri);
+        final Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
         s_logger.debug("GetVmConfigCommand response received "
                 + s_gson.toJson(result));
         if (result.length > 0) {
-            GetVmConfigAnswer ans = ((GetVmConfigAnswer)result[0]);
-            List<NicDetails> nics = ans.getNics();
-            for (NicDetails nic : nics) {
+            final GetVmConfigAnswer ans = (GetVmConfigAnswer)result[0];
+            final List<NicDetails> nics = ans.getNics();
+            for (final NicDetails nic : nics) {
                 if (nic.getState() == false) {
                     nicposition = nics.indexOf(nic);
                     break;
@@ -1845,30 +1853,30 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         return nicposition;
     }
 
-    protected int getVmNics(String vmName, String vlanid) {
-        GetVmConfigCommand vmConfig = new GetVmConfigCommand(vmName);
+    protected int getVmNics(final String vmName, String vlanid) {
+        final GetVmConfigCommand vmConfig = new GetVmConfigCommand(vmName);
         URI agentUri = null;
         int nicposition = -1;
         if(vlanid.equalsIgnoreCase("untagged")) {
             vlanid = "-1";
         }
         try {
-            String cmdName = GetVmConfigCommand.class.getName();
+            final String cmdName = GetVmConfigCommand.class.getName();
             agentUri =
                     new URI("https", null, _agentIp, _port,
                             "/api/HypervResource/" + cmdName, null, null);
-        } catch (URISyntaxException e) {
-            String errMsg = "Could not generate URI for Hyper-V agent";
+        } catch (final URISyntaxException e) {
+            final String errMsg = "Could not generate URI for Hyper-V agent";
             s_logger.error(errMsg, e);
         }
-        String ansStr = postHttpRequest(s_gson.toJson(vmConfig), agentUri);
-        Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
+        final String ansStr = postHttpRequest(s_gson.toJson(vmConfig), agentUri);
+        final Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
         s_logger.debug("executeRequest received response "
                 + s_gson.toJson(result));
         if (result.length > 0) {
-            GetVmConfigAnswer ans = ((GetVmConfigAnswer)result[0]);
-            List<NicDetails> nics = ans.getNics();
-            for (NicDetails nic : nics) {
+            final GetVmConfigAnswer ans = (GetVmConfigAnswer)result[0];
+            final List<NicDetails> nics = ans.getNics();
+            for (final NicDetails nic : nics) {
                 nicposition++;
                 if (nicposition > 1 && nic.getVlanid().equals(vlanid)) {
                     break;
@@ -1878,41 +1886,41 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         return nicposition;
     }
 
-    protected void modifyNicVlan(String vmName, String vlanId, String macAddress) {
-        ModifyVmNicConfigCommand modifynic = new ModifyVmNicConfigCommand(vmName, vlanId, macAddress);
+    protected void modifyNicVlan(final String vmName, final String vlanId, final String macAddress) {
+        final ModifyVmNicConfigCommand modifynic = new ModifyVmNicConfigCommand(vmName, vlanId, macAddress);
         URI agentUri = null;
         try {
-            String cmdName = ModifyVmNicConfigCommand.class.getName();
+            final String cmdName = ModifyVmNicConfigCommand.class.getName();
             agentUri =
                     new URI("https", null, _agentIp, _port,
                             "/api/HypervResource/" + cmdName, null, null);
-        } catch (URISyntaxException e) {
-            String errMsg = "Could not generate URI for Hyper-V agent";
+        } catch (final URISyntaxException e) {
+            final String errMsg = "Could not generate URI for Hyper-V agent";
             s_logger.error(errMsg, e);
         }
-        String ansStr = postHttpRequest(s_gson.toJson(modifynic), agentUri);
-        Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
+        final String ansStr = postHttpRequest(s_gson.toJson(modifynic), agentUri);
+        final Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
         s_logger.debug("executeRequest received response "
                 + s_gson.toJson(result));
         if (result.length > 0) {
         }
     }
 
-    protected void modifyNicVlan(String vmName, String vlanId, int pos, boolean enable, String switchLabelName) {
-        ModifyVmNicConfigCommand modifyNic = new ModifyVmNicConfigCommand(vmName, vlanId, pos, enable);
+    protected void modifyNicVlan(final String vmName, final String vlanId, final int pos, final boolean enable, final String switchLabelName) {
+        final ModifyVmNicConfigCommand modifyNic = new ModifyVmNicConfigCommand(vmName, vlanId, pos, enable);
         modifyNic.setSwitchLableName(switchLabelName);
         URI agentUri = null;
         try {
-            String cmdName = ModifyVmNicConfigCommand.class.getName();
+            final String cmdName = ModifyVmNicConfigCommand.class.getName();
             agentUri =
                     new URI("https", null, _agentIp, _port,
                             "/api/HypervResource/" + cmdName, null, null);
-        } catch (URISyntaxException e) {
-            String errMsg = "Could not generate URI for Hyper-V agent";
+        } catch (final URISyntaxException e) {
+            final String errMsg = "Could not generate URI for Hyper-V agent";
             s_logger.error(errMsg, e);
         }
-        String ansStr = postHttpRequest(s_gson.toJson(modifyNic), agentUri);
-        Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
+        final String ansStr = postHttpRequest(s_gson.toJson(modifyNic), agentUri);
+        final Answer[] result = s_gson.fromJson(ansStr, Answer[].class);
         s_logger.debug("executeRequest received response "
                 + s_gson.toJson(result));
         if (result.length > 0) {
@@ -1922,11 +1930,11 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
     protected void assignPublicIpAddress(final String vmName, final String privateIpAddress, final String publicIpAddress, final boolean add, final boolean firstIP,
             final boolean sourceNat, final String broadcastId, final String vlanGateway, final String vlanNetmask, final String vifMacAddress) throws Exception {
 
-        URI broadcastUri = BroadcastDomainType.fromString(broadcastId);
+        final URI broadcastUri = BroadcastDomainType.fromString(broadcastId);
         if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
             throw new InternalErrorException("Unable to assign a public IP to a VIF on network " + broadcastId);
         }
-        String vlanId = BroadcastDomainType.getValue(broadcastUri);
+        final String vlanId = BroadcastDomainType.getValue(broadcastUri);
 
         int publicNicInfo = -1;
         publicNicInfo = getVmNics(vmName, vlanId);
@@ -1944,7 +1952,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
         }
 
         if (addVif) {
-            Pair<Integer, String> nicdevice = findRouterFreeEthDeviceIndex(privateIpAddress);
+            final Pair<Integer, String> nicdevice = findRouterFreeEthDeviceIndex(privateIpAddress);
             publicNicInfo = nicdevice.first();
             if (publicNicInfo > 0) {
                 modifyNicVlan(vmName, vlanId, nicdevice.second());
@@ -1955,7 +1963,7 @@ public class HypervDirectConnectResource extends ServerResourceBase impleme

<TRUNCATED>

Mime
View raw message