cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [2/6] CLOUDSTACK-6003 fixing plus refactoring dispatcher
Date Tue, 04 Feb 2014 12:38:33 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/447430c3/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index bf2516a..589b50c 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -105,7 +105,6 @@ import com.cloud.agent.api.to.StaticNatRuleTO;
 import com.cloud.agent.manager.Commands;
 import com.cloud.alert.AlertManager;
 import com.cloud.api.ApiAsyncJobDispatcher;
-import com.cloud.api.ApiDispatcher;
 import com.cloud.api.ApiGsonHelper;
 import com.cloud.cluster.ManagementServerHostVO;
 import com.cloud.cluster.dao.ManagementServerHostDao;
@@ -427,8 +426,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     BlockingQueue<Long> _vrUpdateQueue = null;
 
     @Override
-    public boolean sendSshKeysToHost(Long hostId, String pubKey, String prvKey) {
-        ModifySshKeysCommand cmd = new ModifySshKeysCommand(pubKey, prvKey);
+    public boolean sendSshKeysToHost(final Long hostId, final String pubKey, final String prvKey) {
+        final ModifySshKeysCommand cmd = new ModifySshKeysCommand(pubKey, prvKey);
         final Answer answer = _agentMgr.easySend(hostId, cmd);
 
         if (answer != null) {
@@ -439,13 +438,13 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     @Override
-    public VirtualRouter destroyRouter(final long routerId, Account caller, Long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException {
+    public VirtualRouter destroyRouter(final long routerId, final Account caller, final Long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException {
 
         if (s_logger.isDebugEnabled()) {
             s_logger.debug("Attempting to destroy router " + routerId);
         }
 
-        DomainRouterVO router = _routerDao.findById(routerId);
+        final DomainRouterVO router = _routerDao.findById(routerId);
         if (router == null) {
             return null;
         }
@@ -459,12 +458,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     @DB
-    public VirtualRouter upgradeRouter(UpgradeRouterCmd cmd) {
-        Long routerId = cmd.getId();
-        Long serviceOfferingId = cmd.getServiceOfferingId();
-        Account caller = CallContext.current().getCallingAccount();
+    public VirtualRouter upgradeRouter(final UpgradeRouterCmd cmd) {
+        final Long routerId = cmd.getId();
+        final Long serviceOfferingId = cmd.getServiceOfferingId();
+        final Account caller = CallContext.current().getCallingAccount();
 
-        DomainRouterVO router = _routerDao.findById(routerId);
+        final DomainRouterVO router = _routerDao.findById(routerId);
         if (router == null) {
             throw new InvalidParameterValueException("Unable to find router with id " + routerId);
         }
@@ -476,7 +475,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             return _routerDao.findById(routerId);
         }
 
-        ServiceOffering newServiceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
+        final ServiceOffering newServiceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
         if (newServiceOffering == null) {
             throw new InvalidParameterValueException("Unable to find service offering with id " + serviceOfferingId);
         }
@@ -493,7 +492,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 "; make sure the router is stopped and not in an error state before upgrading.");
         }
 
-        ServiceOfferingVO currentServiceOffering = _serviceOfferingDao.findById(router.getServiceOfferingId());
+        final ServiceOfferingVO currentServiceOffering = _serviceOfferingDao.findById(router.getServiceOfferingId());
 
         // Check that the service offering being upgraded to has the same storage pool preference as the VM's current service
         // offering
@@ -512,7 +511,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     @Override
-    public boolean savePasswordToRouter(Network network, final NicProfile nic, VirtualMachineProfile profile, List<? extends VirtualRouter> routers)
+    public boolean savePasswordToRouter(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final List<? extends VirtualRouter> routers)
         throws ResourceUnavailableException {
         _userVmDao.loadDetails((UserVmVO)profile.getVirtualMachine());
 
@@ -520,10 +519,10 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         return applyRules(network, routers, "save password entry", false, null, false, new RuleApplier() {
             @Override
-            public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException {
+            public boolean execute(final Network network, final VirtualRouter router) throws ResourceUnavailableException {
                 // for basic zone, send vm data/password information only to the router in the same pod
-                Commands cmds = new Commands(Command.OnError.Stop);
-                NicVO nicVo = _nicDao.findById(nic.getId());
+                final Commands cmds = new Commands(Command.OnError.Stop);
+                final NicVO nicVo = _nicDao.findById(nic.getId());
                 createPasswordCommand(router, updatedProfile, nicVo, cmds);
                 return sendCommandsToRouter(router, cmds);
             }
@@ -531,7 +530,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     @Override
-    public boolean saveSSHPublicKeyToRouter(Network network, final NicProfile nic, VirtualMachineProfile profile, List<? extends VirtualRouter> routers,
+    public boolean saveSSHPublicKeyToRouter(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final List<? extends VirtualRouter> routers,
         final String sshPublicKey) throws ResourceUnavailableException {
         final UserVmVO vm = _userVmDao.findById(profile.getVirtualMachine().getId());
         _userVmDao.loadDetails(vm);
@@ -540,11 +539,11 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         return applyRules(network, routers, "save SSHkey entry", false, null, false, new RuleApplier() {
             @Override
-            public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException {
+            public boolean execute(final Network network, final VirtualRouter router) throws ResourceUnavailableException {
                 // for basic zone, send vm data/password information only to the router in the same pod
-                Commands cmds = new Commands(Command.OnError.Stop);
-                NicVO nicVo = _nicDao.findById(nic.getId());
-                VMTemplateVO template = _templateDao.findByIdIncludingRemoved(updatedProfile.getTemplateId());
+                final Commands cmds = new Commands(Command.OnError.Stop);
+                final NicVO nicVo = _nicDao.findById(nic.getId());
+                final VMTemplateVO template = _templateDao.findByIdIncludingRemoved(updatedProfile.getTemplateId());
                 if (template != null && template.getEnablePassword()) {
                     createPasswordCommand(router, updatedProfile, nicVo, cmds);
                 }
@@ -555,17 +554,17 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     @Override
-    public boolean saveUserDataToRouter(Network network, final NicProfile nic, VirtualMachineProfile profile, List<? extends VirtualRouter> routers)
+    public boolean saveUserDataToRouter(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final List<? extends VirtualRouter> routers)
         throws ResourceUnavailableException {
         final UserVmVO vm = _userVmDao.findById(profile.getVirtualMachine().getId());
         _userVmDao.loadDetails(vm);
 
         return applyRules(network, routers, "save userdata entry", false, null, false, new RuleApplier() {
             @Override
-            public boolean execute(Network network, VirtualRouter router) throws ResourceUnavailableException {
+            public boolean execute(final Network network, final VirtualRouter router) throws ResourceUnavailableException {
                 // for basic zone, send vm data/password information only to the router in the same pod
-                Commands cmds = new Commands(Command.OnError.Stop);
-                NicVO nicVo = _nicDao.findById(nic.getId());
+                final Commands cmds = new Commands(Command.OnError.Stop);
+                final NicVO nicVo = _nicDao.findById(nic.getId());
                 createVmDataCommand(router, vm, nicVo, null, cmds);
                 return sendCommandsToRouter(router, cmds);
             }
@@ -574,9 +573,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_ROUTER_STOP, eventDescription = "stopping router Vm", async = true)
-    public VirtualRouter stopRouter(long routerId, boolean forced) throws ResourceUnavailableException, ConcurrentOperationException {
-        CallContext context = CallContext.current();
-        Account account = context.getCallingAccount();
+    public VirtualRouter stopRouter(final long routerId, final boolean forced) throws ResourceUnavailableException, ConcurrentOperationException {
+        final CallContext context = CallContext.current();
+        final Account account = context.getCallingAccount();
 
         // verify parameters
         DomainRouterVO router = _routerDao.findById(routerId);
@@ -586,9 +585,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         _accountMgr.checkAccess(account, null, true, router);
 
-        UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
+        final UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
 
-        VirtualRouter virtualRouter = stop(router, forced, user, account);
+        final VirtualRouter virtualRouter = stop(router, forced, user, account);
         if (virtualRouter == null) {
             throw new CloudRuntimeException("Failed to stop router with id " + routerId);
         }
@@ -604,13 +603,13 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     @DB
-    public void processStopOrRebootAnswer(final DomainRouterVO router, Answer answer) {
+    public void processStopOrRebootAnswer(final DomainRouterVO router, final Answer answer) {
         Transaction.execute(new TransactionCallbackNoReturn() {
             @Override
-            public void doInTransactionWithoutResult(TransactionStatus status) {
+            public void doInTransactionWithoutResult(final TransactionStatus status) {
                 //FIXME!!! - UserStats command should grab bytesSent/Received for all guest interfaces of the VR
-                List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId());
-                for (Long guestNtwkId : routerGuestNtwkIds) {
+                final List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId());
+                for (final Long guestNtwkId : routerGuestNtwkIds) {
                     final UserStatisticsVO userStats =
                         _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), guestNtwkId, null, router.getId(), router.getType().toString());
                     if (userStats != null) {
@@ -633,12 +632,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_ROUTER_REBOOT, eventDescription = "rebooting router Vm", async = true)
-    public VirtualRouter rebootRouter(long routerId, boolean reprogramNetwork) throws ConcurrentOperationException, ResourceUnavailableException,
+    public VirtualRouter rebootRouter(final long routerId, final boolean reprogramNetwork) throws ConcurrentOperationException, ResourceUnavailableException,
         InsufficientCapacityException {
-        Account caller = CallContext.current().getCallingAccount();
+        final Account caller = CallContext.current().getCallingAccount();
 
         // verify parameters
-        DomainRouterVO router = _routerDao.findById(routerId);
+        final DomainRouterVO router = _routerDao.findById(routerId);
         if (router == null) {
             throw new InvalidParameterValueException("Unable to find domain router with id " + routerId + ".");
         }
@@ -651,7 +650,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             throw new ResourceUnavailableException("Unable to reboot domR, it is not in right state " + router.getState(), DataCenter.class, router.getDataCenterId());
         }
 
-        UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
+        final UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
         s_logger.debug("Stopping and starting router " + router + " as a part of router reboot");
 
         if (stop(router, false, user, caller) != null) {
@@ -682,10 +681,10 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         _routerExtraPublicNics = NumbersUtil.parseInt(_configDao.getValue(Config.RouterExtraPublicNics.key()), 2);
 
-        String guestOSString = configs.get("network.dhcp.nondefaultnetwork.setgateway.guestos");
+        final String guestOSString = configs.get("network.dhcp.nondefaultnetwork.setgateway.guestos");
         if (guestOSString != null) {
-            String[] guestOSList = guestOSString.split(",");
-            for (String os : guestOSList) {
+            final String[] guestOSList = guestOSString.split(",");
+            for (final String os : guestOSList) {
                 _guestOSNeedGatewayOnNonDefaultNetwork.add(os);
             }
         }
@@ -715,7 +714,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             _instance = "DEFAULT";
         }
 
-        String rpValue = configs.get("network.disable.rpfilter");
+        final String rpValue = configs.get("network.disable.rpfilter");
         if (rpValue != null && rpValue.equalsIgnoreCase("true")) {
             _disableRpFilter = true;
         }
@@ -726,7 +725,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         _agentMgr.registerForHostEvents(new SshKeysDistriMonitor(_agentMgr, _hostDao, _configDao), true, false, false);
 
-        boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
+        final boolean useLocalStorage = Boolean.parseBoolean(configs.get(Config.SystemVMUseLocalStorage.key()));
         _offering =
             new ServiceOfferingVO("System Offering For Software Router", 1, _routerRamSize, _routerCpuMHz, null, null, true, null, useLocalStorage, true, null, true,
                 VirtualMachine.Type.DomainRouter, true);
@@ -735,14 +734,14 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         // this can sometimes happen, if DB is manually or programmatically manipulated
         if (_offering == null) {
-            String msg = "Data integrity problem : System Offering For Software router VM has been removed?";
+            final String msg = "Data integrity problem : System Offering For Software router VM has been removed?";
             s_logger.error(msg);
             throw new ConfigurationException(msg);
         }
 
         _systemAcct = _accountMgr.getSystemAccount();
 
-        String aggregationRange = configs.get("usage.stats.job.aggregation.range");
+        final String aggregationRange = configs.get("usage.stats.job.aggregation.range");
         _usageAggregationRange = NumbersUtil.parseInt(aggregationRange, 1440);
         _usageTimeZone = configs.get("usage.aggregation.timezone");
         if (_usageTimeZone == null) {
@@ -765,11 +764,11 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         }
 
         //Schedule Network stats update task
-        TimeZone usageTimezone = TimeZone.getTimeZone(_usageTimeZone);
-        Calendar cal = Calendar.getInstance(usageTimezone);
+        final TimeZone usageTimezone = TimeZone.getTimeZone(_usageTimeZone);
+        final Calendar cal = Calendar.getInstance(usageTimezone);
         cal.setTime(new Date());
         long endDate = 0;
-        int HOURLY_TIME = 60;
+        final int HOURLY_TIME = 60;
         final int DAILY_TIME = 60 * 24;
         if (_usageAggregationRange == DAILY_TIME) {
             cal.roll(Calendar.DAY_OF_YEAR, false);
@@ -823,15 +822,15 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     protected VirtualNetworkApplianceManagerImpl() {
     }
 
-    private VmDataCommand generateVmDataCommand(VirtualRouter router, String vmPrivateIpAddress, String userData, String serviceOffering, String zoneName,
-        String guestIpAddress, String vmName, String vmInstanceName, long vmId, String vmUuid, String publicKey, long guestNetworkId) {
-        VmDataCommand cmd = new VmDataCommand(vmPrivateIpAddress, vmName, _networkModel.getExecuteInSeqNtwkElmtCmd());
+    private VmDataCommand generateVmDataCommand(final VirtualRouter router, final String vmPrivateIpAddress, final String userData, final String serviceOffering, final String zoneName,
+        final String guestIpAddress, final String vmName, final String vmInstanceName, final long vmId, final String vmUuid, final String publicKey, final long guestNetworkId) {
+        final VmDataCommand cmd = new VmDataCommand(vmPrivateIpAddress, vmName, _networkModel.getExecuteInSeqNtwkElmtCmd());
 
         cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
         cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, getRouterIpInNetwork(guestNetworkId, router.getId()));
         cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
 
-        DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
+        final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
         cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
 
         cmd.addVmData("userdata", "user-data", userData);
@@ -868,12 +867,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         return cmd;
     }
 
-    private void setVmInstanceId(String vmUuid, VmDataCommand cmd) {
+    private void setVmInstanceId(final String vmUuid, final VmDataCommand cmd) {
         cmd.addVmData("metadata", "instance-id", vmUuid);
         cmd.addVmData("metadata", "vm-id", vmUuid);
     }
 
-    private void setVmInstanceId(String vmInstanceName, long vmId, VmDataCommand cmd) {
+    private void setVmInstanceId(final String vmInstanceName, final long vmId, final VmDataCommand cmd) {
         cmd.addVmData("metadata", "instance-id", vmInstanceName);
         cmd.addVmData("metadata", "vm-id", String.valueOf(vmId));
     }
@@ -890,11 +889,11 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 s_logger.debug("Found " + routers.size() + " running routers. ");
 
                 for (final DomainRouterVO router : routers) {
-                    String privateIP = router.getPrivateIpAddress();
+                    final String privateIP = router.getPrivateIpAddress();
 
                     if (privateIP != null) {
                         final boolean forVpc = router.getVpcId() != null;
-                        List<? extends Nic> routerNics = _nicDao.listByVmId(router.getId());
+                        final List<? extends Nic> routerNics = _nicDao.listByVmId(router.getId());
                         for (final Nic routerNic : routerNics) {
                             final Network network = _networkModel.getNetwork(routerNic.getNetworkId());
                             //Send network usage command for public nic in VPC VR
@@ -909,7 +908,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                                 NetworkUsageAnswer answer = null;
                                 try {
                                     answer = (NetworkUsageAnswer)_agentMgr.easySend(router.getHostId(), usageCmd);
-                                } catch (Exception e) {
+                                } catch (final Exception e) {
                                     s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId(),
                                         e);
                                     continue;
@@ -929,8 +928,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                                         final NetworkUsageAnswer answerFinal = answer;
                                         Transaction.execute(new TransactionCallbackNoReturn() {
                                             @Override
-                                            public void doInTransactionWithoutResult(TransactionStatus status) {
-                                                UserStatisticsVO stats =
+                                            public void doInTransactionWithoutResult(final TransactionStatus status) {
+                                                final UserStatisticsVO stats =
                                                     _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), network.getId(),
                                                         (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
                                                 if (stats == null) {
@@ -973,7 +972,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                                             }
                                         });
 
-                                    } catch (Exception e) {
+                                    } catch (final Exception e) {
                                         s_logger.warn("Unable to update user statistics for account: " + router.getAccountId() + " Rx: " + answer.getBytesReceived() +
                                             "; Tx: " + answer.getBytesSent());
                                     }
@@ -982,7 +981,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                         }
                     }
                 }
-            } catch (Exception e) {
+            } catch (final Exception e) {
                 s_logger.warn("Error while collecting network stats", e);
             }
         }
@@ -995,12 +994,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         @Override
         protected void runInContext() {
-            GlobalLock scanLock = GlobalLock.getInternLock("network.stats");
+            final GlobalLock scanLock = GlobalLock.getInternLock("network.stats");
             try {
                 if (scanLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
                     //Check for ownership
                     //msHost in UP state with min id should run the job
-                    ManagementServerHostVO msHost = _msHostDao.findOneInUpState(new Filter(ManagementServerHostVO.class, "id", true, 0L, 1L));
+                    final ManagementServerHostVO msHost = _msHostDao.findOneInUpState(new Filter(ManagementServerHostVO.class, "id", true, 0L, 1L));
                     if (msHost == null || (msHost.getMsid() != mgmtSrvrId)) {
                         s_logger.debug("Skipping aggregate network stats update");
                         scanLock.unlock();
@@ -1009,17 +1008,17 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                     try {
                         Transaction.execute(new TransactionCallbackNoReturn() {
                             @Override
-                            public void doInTransactionWithoutResult(TransactionStatus status) {
+                            public void doInTransactionWithoutResult(final TransactionStatus status) {
                                 //get all stats with delta > 0
-                                List<UserStatisticsVO> updatedStats = _userStatsDao.listUpdatedStats();
-                                Date updatedTime = new Date();
-                                for (UserStatisticsVO stat : updatedStats) {
+                                final List<UserStatisticsVO> updatedStats = _userStatsDao.listUpdatedStats();
+                                final Date updatedTime = new Date();
+                                for (final UserStatisticsVO stat : updatedStats) {
                                     //update agg bytes
                                     stat.setAggBytesReceived(stat.getCurrentBytesReceived() + stat.getNetBytesReceived());
                                     stat.setAggBytesSent(stat.getCurrentBytesSent() + stat.getNetBytesSent());
                                     _userStatsDao.update(stat.getId(), stat);
                                     //insert into op_user_stats_log
-                                    UserStatsLogVO statsLog =
+                                    final UserStatsLogVO statsLog =
                                         new UserStatsLogVO(stat.getId(), stat.getNetBytesReceived(), stat.getNetBytesSent(), stat.getCurrentBytesReceived(),
                                             stat.getCurrentBytesSent(), stat.getAggBytesReceived(), stat.getAggBytesSent(), updatedTime);
                                     _userStatsLogDao.persist(statsLog);
@@ -1027,13 +1026,13 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                                 s_logger.debug("Successfully updated aggregate network stats");
                             }
                         });
-                    } catch (Exception e) {
+                    } catch (final Exception e) {
                         s_logger.debug("Failed to update aggregate network stats", e);
                     } finally {
                         scanLock.unlock();
                     }
                 }
-            } catch (Exception e) {
+            } catch (final Exception e) {
                 s_logger.debug("Exception while trying to acquire network stats lock", e);
             } finally {
                 scanLock.releaseRef();
@@ -1042,14 +1041,14 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     @DB
-    protected void updateSite2SiteVpnConnectionState(List<DomainRouterVO> routers) {
-        for (DomainRouterVO router : routers) {
-            List<Site2SiteVpnConnectionVO> conns = _s2sVpnMgr.getConnectionsForRouter(router);
+    protected void updateSite2SiteVpnConnectionState(final List<DomainRouterVO> routers) {
+        for (final DomainRouterVO router : routers) {
+            final List<Site2SiteVpnConnectionVO> conns = _s2sVpnMgr.getConnectionsForRouter(router);
             if (conns == null || conns.isEmpty()) {
                 continue;
             }
             if (router.getState() != State.Running) {
-                for (Site2SiteVpnConnectionVO conn : conns) {
+                for (final Site2SiteVpnConnectionVO conn : conns) {
                     if (conn.getState() != Site2SiteVpnConnection.State.Error) {
                         conn.setState(Site2SiteVpnConnection.State.Disconnected);
                         _s2sVpnConnectionDao.persist(conn);
@@ -1057,16 +1056,16 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 }
                 continue;
             }
-            List<String> ipList = new ArrayList<String>();
-            for (Site2SiteVpnConnectionVO conn : conns) {
+            final List<String> ipList = new ArrayList<String>();
+            for (final Site2SiteVpnConnectionVO conn : conns) {
                 if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected) {
                     continue;
                 }
-                Site2SiteCustomerGateway gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
+                final Site2SiteCustomerGateway gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
                 ipList.add(gw.getGatewayIp());
             }
-            String privateIP = router.getPrivateIpAddress();
-            HostVO host = _hostDao.findById(router.getHostId());
+            final String privateIP = router.getPrivateIpAddress();
+            final HostVO host = _hostDao.findById(router.getHostId());
             if (host == null || host.getState() != Status.Up) {
                 continue;
             } else if (host.getManagementServerId() != ManagementServerNode.getManagementServerId()) {
@@ -1089,8 +1088,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                     s_logger.warn("Unable to update router " + router.getHostName() + "'s VPN connection status");
                     continue;
                 }
-                for (Site2SiteVpnConnectionVO conn : conns) {
-                    Site2SiteVpnConnectionVO lock = _s2sVpnConnectionDao.acquireInLockTable(conn.getId());
+                for (final Site2SiteVpnConnectionVO conn : conns) {
+                    final Site2SiteVpnConnectionVO lock = _s2sVpnConnectionDao.acquireInLockTable(conn.getId());
                     if (lock == null) {
                         throw new CloudRuntimeException("Unable to acquire lock on " + lock);
                     }
@@ -1098,8 +1097,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                         if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected) {
                             continue;
                         }
-                        Site2SiteVpnConnection.State oldState = conn.getState();
-                        Site2SiteCustomerGateway gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
+                        final Site2SiteVpnConnection.State oldState = conn.getState();
+                        final Site2SiteCustomerGateway gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
                         if (answer.isConnected(gw.getGatewayIp())) {
                             conn.setState(Site2SiteVpnConnection.State.Connected);
                         } else {
@@ -1107,8 +1106,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                         }
                         _s2sVpnConnectionDao.persist(conn);
                         if (oldState != conn.getState()) {
-                            String title = "Site-to-site Vpn Connection to " + gw.getName() + " just switch from " + oldState + " to " + conn.getState();
-                            String context =
+                            final String title = "Site-to-site Vpn Connection to " + gw.getName() + " just switch from " + oldState + " to " + conn.getState();
+                            final String context =
                                 "Site-to-site Vpn Connection to " + gw.getName() + " on router " + router.getHostName() + "(id: " + router.getId() + ") " +
                                     " just switch from " + oldState + " to " + conn.getState();
                             s_logger.info(context);
@@ -1122,21 +1121,21 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         }
     }
 
-    protected void updateRoutersRedundantState(List<DomainRouterVO> routers) {
+    protected void updateRoutersRedundantState(final List<DomainRouterVO> routers) {
         boolean updated = false;
-        for (DomainRouterVO router : routers) {
+        for (final DomainRouterVO router : routers) {
             updated = false;
             if (!router.getIsRedundantRouter()) {
                 continue;
             }
-            RedundantState prevState = router.getRedundantState();
+            final RedundantState prevState = router.getRedundantState();
             if (router.getState() != State.Running) {
                 router.setRedundantState(RedundantState.UNKNOWN);
                 router.setIsPriorityBumpUp(false);
                 updated = true;
             } else {
-                String privateIP = router.getPrivateIpAddress();
-                HostVO host = _hostDao.findById(router.getHostId());
+                final String privateIP = router.getPrivateIpAddress();
+                final HostVO host = _hostDao.findById(router.getHostId());
                 if (host == null || host.getState() != Status.Up) {
                     router.setRedundantState(RedundantState.UNKNOWN);
                     updated = true;
@@ -1166,10 +1165,10 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             if (updated) {
                 _routerDao.update(router.getId(), router);
             }
-            RedundantState currState = router.getRedundantState();
+            final RedundantState currState = router.getRedundantState();
             if (prevState != currState) {
-                String title = "Redundant virtual router " + router.getInstanceName() + " just switch from " + prevState + " to " + currState;
-                String context =
+                final String title = "Redundant virtual router " + router.getInstanceName() + " just switch from " + prevState + " to " + currState;
+                final String context =
                     "Redundant virtual router (name: " + router.getHostName() + ", id: " + router.getId() + ") " + " just switch from " + prevState + " to " + currState;
                 s_logger.info(context);
                 if (currState == RedundantState.MASTER) {
@@ -1180,30 +1179,30 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     //Ensure router status is update to date before execute this function. The function would try best to recover all routers except MASTER
-    protected void recoverRedundantNetwork(DomainRouterVO masterRouter, DomainRouterVO backupRouter) {
+    protected void recoverRedundantNetwork(final DomainRouterVO masterRouter, final DomainRouterVO backupRouter) {
         if (masterRouter.getState() == State.Running && backupRouter.getState() == State.Running) {
-            HostVO masterHost = _hostDao.findById(masterRouter.getHostId());
-            HostVO backupHost = _hostDao.findById(backupRouter.getHostId());
+            final HostVO masterHost = _hostDao.findById(masterRouter.getHostId());
+            final HostVO backupHost = _hostDao.findById(backupRouter.getHostId());
             if (masterHost.getState() == Status.Up && backupHost.getState() == Status.Up) {
-                String title = "Reboot " + backupRouter.getInstanceName() + " to ensure redundant virtual routers work";
+                final String title = "Reboot " + backupRouter.getInstanceName() + " to ensure redundant virtual routers work";
                 if (s_logger.isDebugEnabled()) {
                     s_logger.debug(title);
                 }
                 _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, backupRouter.getDataCenterId(), backupRouter.getPodIdToDeployIn(), title, title);
                 try {
                     rebootRouter(backupRouter.getId(), true);
-                } catch (ConcurrentOperationException e) {
+                } catch (final ConcurrentOperationException e) {
                     s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
-                } catch (ResourceUnavailableException e) {
+                } catch (final ResourceUnavailableException e) {
                     s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
-                } catch (InsufficientCapacityException e) {
+                } catch (final InsufficientCapacityException e) {
                     s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
                 }
             }
         }
     }
 
-    private int getRealPriority(DomainRouterVO router) {
+    private int getRealPriority(final DomainRouterVO router) {
         int priority = router.getPriority();
         if (router.getIsPriorityBumpUp()) {
             priority += DEFAULT_DELTA;
@@ -1221,27 +1220,27 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
          * 1. Backup router's priority = Master's priority - DELTA + 1
          * 2. Backup router's priority hasn't been bumped up.
          */
-        private void checkSanity(List<DomainRouterVO> routers) {
-            Set<Long> checkedNetwork = new HashSet<Long>();
-            for (DomainRouterVO router : routers) {
+        private void checkSanity(final List<DomainRouterVO> routers) {
+            final Set<Long> checkedNetwork = new HashSet<Long>();
+            for (final DomainRouterVO router : routers) {
                 if (!router.getIsRedundantRouter()) {
                     continue;
                 }
 
-                List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId());
+                final List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId());
 
-                for (Long routerGuestNtwkId : routerGuestNtwkIds) {
+                for (final Long routerGuestNtwkId : routerGuestNtwkIds) {
                     if (checkedNetwork.contains(routerGuestNtwkId)) {
                         continue;
                     }
                     checkedNetwork.add(routerGuestNtwkId);
-                    List<DomainRouterVO> checkingRouters = _routerDao.listByNetworkAndRole(routerGuestNtwkId, Role.VIRTUAL_ROUTER);
+                    final List<DomainRouterVO> checkingRouters = _routerDao.listByNetworkAndRole(routerGuestNtwkId, Role.VIRTUAL_ROUTER);
                     if (checkingRouters.size() != 2) {
                         continue;
                     }
                     DomainRouterVO masterRouter = null;
                     DomainRouterVO backupRouter = null;
-                    for (DomainRouterVO r : checkingRouters) {
+                    for (final DomainRouterVO r : checkingRouters) {
                         if (r.getRedundantState() == RedundantState.MASTER) {
                             if (masterRouter == null) {
                                 masterRouter = r;
@@ -1266,18 +1265,18 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             }
         }
 
-        private void checkDuplicateMaster(List<DomainRouterVO> routers) {
-            Map<Long, DomainRouterVO> networkRouterMaps = new HashMap<Long, DomainRouterVO>();
-            for (DomainRouterVO router : routers) {
-                List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId());
+        private void checkDuplicateMaster(final List<DomainRouterVO> routers) {
+            final Map<Long, DomainRouterVO> networkRouterMaps = new HashMap<Long, DomainRouterVO>();
+            for (final DomainRouterVO router : routers) {
+                final List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId());
 
-                for (Long routerGuestNtwkId : routerGuestNtwkIds) {
+                for (final Long routerGuestNtwkId : routerGuestNtwkIds) {
                     if (router.getRedundantState() == RedundantState.MASTER) {
                         if (networkRouterMaps.containsKey(routerGuestNtwkId)) {
-                            DomainRouterVO dupRouter = networkRouterMaps.get(routerGuestNtwkId);
-                            String title =
+                            final DomainRouterVO dupRouter = networkRouterMaps.get(routerGuestNtwkId);
+                            final String title =
                                 "More than one redundant virtual router is in MASTER state! Router " + router.getHostName() + " and router " + dupRouter.getHostName();
-                            String context =
+                            final String context =
                                 "Virtual router (name: " + router.getHostName() + ", id: " + router.getId() + " and router (name: " + dupRouter.getHostName() + ", id: " +
                                     router.getId() + ") are both in MASTER state! If the problem persist, restart both of routers. ";
                             _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), title, context);
@@ -1296,8 +1295,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         protected void runInContext() {
             while (true) {
                 try {
-                    Long networkId = _vrUpdateQueue.take();  // This is a blocking call so this thread won't run all the time if no work item in queue.
-                    List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(networkId, Role.VIRTUAL_ROUTER);
+                    final Long networkId = _vrUpdateQueue.take();  // This is a blocking call so this thread won't run all the time if no work item in queue.
+                    final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(networkId, Role.VIRTUAL_ROUTER);
 
                     if (routers.size() != 2) {
                         continue;
@@ -1306,8 +1305,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                      * We update the router pair which the lower id router owned by this mgmt server, in order
                      * to prevent duplicate update of router status from cluster mgmt servers
                      */
-                    DomainRouterVO router0 = routers.get(0);
-                    DomainRouterVO router1 = routers.get(1);
+                    final DomainRouterVO router0 = routers.get(0);
+                    final DomainRouterVO router1 = routers.get(1);
                     DomainRouterVO router = router0;
                     if ((router0.getId() < router1.getId()) && router0.getHostId() != null) {
                         router = router0;
@@ -1318,7 +1317,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                         s_logger.debug("Skip router pair (" + router0.getInstanceName() + "," + router1.getInstanceName() + ") due to can't find host");
                         continue;
                     }
-                    HostVO host = _hostDao.findById(router.getHostId());
+                    final HostVO host = _hostDao.findById(router.getHostId());
                     if (host == null || host.getManagementServerId() == null || host.getManagementServerId() != ManagementServerNode.getManagementServerId()) {
                         s_logger.debug("Skip router pair (" + router0.getInstanceName() + "," + router1.getInstanceName() + ") due to not belong to this mgmt server");
                         continue;
@@ -1326,7 +1325,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                     updateRoutersRedundantState(routers);
                     checkDuplicateMaster(routers);
                     checkSanity(routers);
-                } catch (Exception ex) {
+                } catch (final Exception ex) {
                     s_logger.error("Fail to complete the RvRStatusUpdateTask! ", ex);
                 }
             }
@@ -1348,13 +1347,13 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
                 final List<NetworkVO> networks = _networkDao.listRedundantNetworks();
                 s_logger.debug("Found " + networks.size() + " networks to update RvR status. ");
-                for (NetworkVO network : networks) {
+                for (final NetworkVO network : networks) {
                     if (!_vrUpdateQueue.offer(network.getId(), 500, TimeUnit.MILLISECONDS)) {
                         s_logger.warn("Cannot insert into virtual router update queue! Adjustment of router.check.interval and router.check.poolsize maybe needed.");
                         break;
                     }
                 }
-            } catch (Exception ex) {
+            } catch (final Exception ex) {
                 s_logger.error("Fail to complete the CheckRouterTask! ", ex);
             }
         }
@@ -1363,13 +1362,13 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     private final static int DEFAULT_PRIORITY = 100;
     private final static int DEFAULT_DELTA = 2;
 
-    protected int getUpdatedPriority(Network guestNetwork, List<DomainRouterVO> routers, DomainRouterVO exclude) throws InsufficientVirtualNetworkCapcityException {
+    protected int getUpdatedPriority(final Network guestNetwork, final List<DomainRouterVO> routers, final DomainRouterVO exclude) throws InsufficientVirtualNetworkCapcityException {
         int priority;
         if (routers.size() == 0) {
             priority = DEFAULT_PRIORITY;
         } else {
             int maxPriority = 0;
-            for (DomainRouterVO r : routers) {
+            for (final DomainRouterVO r : routers) {
                 if (!r.getIsRedundantRouter()) {
                     throw new CloudRuntimeException("Redundant router is mixed with single router in one network!");
                 }
@@ -1397,19 +1396,19 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     /*
      * Ovm won't support any system. So we have to choose a partner cluster in the same pod to start domain router for us
      */
-    private HypervisorType getClusterToStartDomainRouterForOvm(long podId) {
-        List<ClusterVO> clusters = _clusterDao.listByPodId(podId);
-        for (ClusterVO cv : clusters) {
+    private HypervisorType getClusterToStartDomainRouterForOvm(final long podId) {
+        final List<ClusterVO> clusters = _clusterDao.listByPodId(podId);
+        for (final ClusterVO cv : clusters) {
             if (cv.getHypervisorType() == HypervisorType.Ovm || cv.getHypervisorType() == HypervisorType.BareMetal) {
                 continue;
             }
 
-            List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(cv.getId());
+            final List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(cv.getId());
             if (hosts == null || hosts.isEmpty()) {
                 continue;
             }
 
-            for (HostVO h : hosts) {
+            for (final HostVO h : hosts) {
                 if (h.getState() == Status.Up) {
                     s_logger.debug("Pick up host that has hypervisor type " + h.getHypervisorType() + " in cluster " + cv.getId() + " to start domain router for OVM");
                     return h.getHypervisorType();
@@ -1417,16 +1416,16 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             }
         }
 
-        String errMsg =
+        final String errMsg =
             "Cannot find an available cluster in Pod " + podId + " to start domain router for Ovm. \n Ovm won't support any system vm including domain router, " +
                 "please make sure you have a cluster with hypervisor type of any of xenserver/KVM/Vmware in the same pod" +
                 " with Ovm cluster. And there is at least one host in UP status in that cluster.";
         throw new CloudRuntimeException(errMsg);
     }
 
-    private void checkAndResetPriorityOfRedundantRouter(List<DomainRouterVO> routers) {
+    private void checkAndResetPriorityOfRedundantRouter(final List<DomainRouterVO> routers) {
         boolean allStopped = true;
-        for (DomainRouterVO router : routers) {
+        for (final DomainRouterVO router : routers) {
             if (!router.getIsRedundantRouter() || router.getState() != VirtualMachine.State.Stopped) {
                 allStopped = false;
                 break;
@@ -1436,7 +1435,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             return;
         }
 
-        for (DomainRouterVO router : routers) {
+        for (final DomainRouterVO router : routers) {
             // getUpdatedPriority() would update the value later
             router.setPriority(0);
             router.setIsPriorityBumpUp(false);
@@ -1445,11 +1444,11 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     @DB
-    protected List<DomainRouterVO> findOrDeployVirtualRouterInGuestNetwork(Network guestNetwork, DeployDestination dest, Account owner, boolean isRedundant,
-        Map<Param, Object> params) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
+    protected List<DomainRouterVO> findOrDeployVirtualRouterInGuestNetwork(final Network guestNetwork, final DeployDestination dest, Account owner, final boolean isRedundant,
+        final Map<Param, Object> params) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
 
         List<DomainRouterVO> routers = new ArrayList<DomainRouterVO>();
-        Network lock = _networkDao.acquireInLockTable(guestNetwork.getId(), NetworkOrchestrationService.NetworkLockTimeout.value());
+        final Network lock = _networkDao.acquireInLockTable(guestNetwork.getId(), NetworkOrchestrationService.NetworkLockTimeout.value());
         if (lock == null) {
             throw new ConcurrentOperationException("Unable to lock network " + guestNetwork.getId());
         }
@@ -1465,22 +1464,22 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             assert guestNetwork.getTrafficType() == TrafficType.Guest;
 
             // 1) Get deployment plan and find out the list of routers
-            boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic);
+            final boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic);
 
             // dest has pod=null, for Basic Zone findOrDeployVRs for all Pods
-            List<DeployDestination> destinations = new ArrayList<DeployDestination>();
+            final List<DeployDestination> destinations = new ArrayList<DeployDestination>();
 
             // for basic zone, if 'dest' has pod set to null then this is network restart scenario otherwise it is a vm deployment scenario
             if (dest.getDataCenter().getNetworkType() == NetworkType.Basic && dest.getPod() == null) {
                 // Find all pods in the data center with running or starting user vms
-                long dcId = dest.getDataCenter().getId();
-                List<HostPodVO> pods = listByDataCenterIdVMTypeAndStates(dcId, VirtualMachine.Type.User, VirtualMachine.State.Starting, VirtualMachine.State.Running);
+                final long dcId = dest.getDataCenter().getId();
+                final List<HostPodVO> pods = listByDataCenterIdVMTypeAndStates(dcId, VirtualMachine.Type.User, VirtualMachine.State.Starting, VirtualMachine.State.Running);
 
                 // Loop through all the pods skip those with running or starting VRs
-                for (HostPodVO pod : pods) {
+                for (final HostPodVO pod : pods) {
                     // Get list of VRs in starting or running state
-                    long podId = pod.getId();
-                    List<DomainRouterVO> virtualRouters = _routerDao.listByPodIdAndStates(podId, VirtualMachine.State.Starting, VirtualMachine.State.Running);
+                    final long podId = pod.getId();
+                    final List<DomainRouterVO> virtualRouters = _routerDao.listByPodIdAndStates(podId, VirtualMachine.State.Starting, VirtualMachine.State.Running);
 
                     assert (virtualRouters.size() <= 1) : "Pod can have utmost one VR in Basic Zone, please check!";
 
@@ -1502,8 +1501,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             }
 
             // Except for Basic Zone, the for loop will iterate only once
-            for (DeployDestination destination : destinations) {
-                Pair<DeploymentPlan, List<DomainRouterVO>> planAndRouters = getDeploymentPlanAndRouters(isPodBased, destination, guestNetwork.getId());
+            for (final DeployDestination destination : destinations) {
+                final Pair<DeploymentPlan, List<DomainRouterVO>> planAndRouters = getDeploymentPlanAndRouters(isPodBased, destination, guestNetwork.getId());
                 routers = planAndRouters.second();
 
                 // 2) Figure out required routers count
@@ -1526,13 +1525,13 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 }
 
                 // Check if providers are supported in the physical networks
-                Type type = Type.VirtualRouter;
-                Long physicalNetworkId = _networkModel.getPhysicalNetworkId(guestNetwork);
-                PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, type.toString());
+                final Type type = Type.VirtualRouter;
+                final Long physicalNetworkId = _networkModel.getPhysicalNetworkId(guestNetwork);
+                final PhysicalNetworkServiceProvider provider = _physicalProviderDao.findByServiceProvider(physicalNetworkId, type.toString());
                 if (provider == null) {
                     throw new CloudRuntimeException("Cannot find service provider " + type.toString() + " in physical network " + physicalNetworkId);
                 }
-                VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), type);
+                final VirtualRouterProvider vrProvider = _vrProviderDao.findByNspIdAndType(provider.getId(), type);
                 if (vrProvider == null) {
                     throw new CloudRuntimeException("Cannot find virtual router provider " + type.toString() + " as service provider " + provider.getId());
                 }
@@ -1562,13 +1561,13 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 }
 
                 // 3) deploy virtual router(s)
-                int count = routerCount - routers.size();
-                DeploymentPlan plan = planAndRouters.first();
+                final int count = routerCount - routers.size();
+                final DeploymentPlan plan = planAndRouters.first();
                 for (int i = 0; i < count; i++) {
-                    LinkedHashMap<Network, NicProfile> networks =
+                    final LinkedHashMap<Network, NicProfile> networks =
                         createRouterNetworks(owner, isRedundant, plan, guestNetwork, new Pair<Boolean, PublicIp>(publicNetwork, sourceNatIp));
                     //don't start the router as we are holding the network lock that needs to be released at the end of router allocation
-                    DomainRouterVO router = deployRouter(owner, destination, plan, params, isRedundant, vrProvider, offeringId, null, networks, false, null);
+                    final DomainRouterVO router = deployRouter(owner, destination, plan, params, isRedundant, vrProvider, offeringId, null, networks, false, null);
 
                     if (router != null) {
                         _routerDao.addRouterToGuestNetwork(router, guestNetwork);
@@ -1587,42 +1586,42 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         return routers;
     }
 
-    protected List<HostPodVO> listByDataCenterIdVMTypeAndStates(long id, VirtualMachine.Type type, VirtualMachine.State... states) {
-        SearchBuilder<VMInstanceVO> vmInstanceSearch = _vmDao.createSearchBuilder();
+    protected List<HostPodVO> listByDataCenterIdVMTypeAndStates(final long id, final VirtualMachine.Type type, final VirtualMachine.State... states) {
+        final SearchBuilder<VMInstanceVO> vmInstanceSearch = _vmDao.createSearchBuilder();
         vmInstanceSearch.and("type", vmInstanceSearch.entity().getType(), SearchCriteria.Op.EQ);
         vmInstanceSearch.and("states", vmInstanceSearch.entity().getState(), SearchCriteria.Op.IN);
 
-        SearchBuilder<HostPodVO> podIdSearch = _podDao.createSearchBuilder();
+        final SearchBuilder<HostPodVO> podIdSearch = _podDao.createSearchBuilder();
         podIdSearch.and("dc", podIdSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
         podIdSearch.select(null, SearchCriteria.Func.DISTINCT, podIdSearch.entity().getId());
         podIdSearch.join("vmInstanceSearch", vmInstanceSearch, podIdSearch.entity().getId(), vmInstanceSearch.entity().getPodIdToDeployIn(), JoinBuilder.JoinType.INNER);
         podIdSearch.done();
 
-        SearchCriteria<HostPodVO> sc = podIdSearch.create();
+        final SearchCriteria<HostPodVO> sc = podIdSearch.create();
         sc.setParameters("dc", id);
         sc.setJoinParameters("vmInstanceSearch", "type", type);
         sc.setJoinParameters("vmInstanceSearch", "states", (Object[])states);
         return _podDao.search(sc, null);
     }
 
-    protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map<Param, Object> params, boolean isRedundant,
-        VirtualRouterProvider vrProvider, long svcOffId, Long vpcId, LinkedHashMap<Network, NicProfile> networks, boolean startRouter,
-        List<HypervisorType> supportedHypervisors) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException,
+    protected DomainRouterVO deployRouter(final Account owner, final DeployDestination dest, final DeploymentPlan plan, final Map<Param, Object> params, final boolean isRedundant,
+        final VirtualRouterProvider vrProvider, final long svcOffId, final Long vpcId, final LinkedHashMap<Network, NicProfile> networks, final boolean startRouter,
+        final List<HypervisorType> supportedHypervisors) throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientServerCapacityException,
         InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException {
 
-        ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId);
+        final ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(svcOffId);
 
         // Router is the network element, we don't know the hypervisor type yet.
         // Try to allocate the domR twice using diff hypervisors, and when failed both times, throw the exception up
-        List<HypervisorType> hypervisors = getHypervisors(dest, plan, supportedHypervisors);
+        final List<HypervisorType> hypervisors = getHypervisors(dest, plan, supportedHypervisors);
 
         int allocateRetry = 0;
         int startRetry = 0;
         DomainRouterVO router = null;
-        for (Iterator<HypervisorType> iter = hypervisors.iterator(); iter.hasNext();) {
-            HypervisorType hType = iter.next();
+        for (final Iterator<HypervisorType> iter = hypervisors.iterator(); iter.hasNext();) {
+            final HypervisorType hType = iter.next();
             try {
-                long id = _routerDao.getNextInSequence(Long.class, "id");
+                final long id = _routerDao.getNextInSequence(Long.class, "id");
                 if (s_logger.isDebugEnabled()) {
                     s_logger.debug("Allocating the VR i=" + id + " in datacenter " + dest.getDataCenter() + "with the hypervisor type " + hType);
                 }
@@ -1647,7 +1646,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                     default:
                         break;
                 }
-                VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName);
+                final VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName);
 
                 if (template == null) {
                     s_logger.debug(hType + " won't support system vm, skip it");
@@ -1669,7 +1668,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 router = _routerDao.persist(router);
                 _itMgr.allocate(router.getInstanceName(), template, routerOffering, networks, plan, null);
                 router = _routerDao.findById(router.getId());
-            } catch (InsufficientCapacityException ex) {
+            } catch (final InsufficientCapacityException ex) {
                 if (allocateRetry < 2 && iter.hasNext()) {
                     s_logger.debug("Failed to allocate the VR with hypervisor type " + hType + ", retrying one more time");
                     continue;
@@ -1684,7 +1683,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 try {
                     router = startVirtualRouter(router, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount(), params);
                     break;
-                } catch (InsufficientCapacityException ex) {
+                } catch (final InsufficientCapacityException ex) {
                     if (startRetry < 2 && iter.hasNext()) {
                         s_logger.debug("Failed to start the VR  " + router + " with hypervisor type " + hType + ", " + "destroying it and recreating one more time");
                         // destroy the router
@@ -1705,7 +1704,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         return router;
     }
 
-    protected List<HypervisorType> getHypervisors(DeployDestination dest, DeploymentPlan plan, List<HypervisorType> supportedHypervisors)
+    protected List<HypervisorType> getHypervisors(final DeployDestination dest, final DeploymentPlan plan, final List<HypervisorType> supportedHypervisors)
         throws InsufficientServerCapacityException {
         List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
 
@@ -1716,7 +1715,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 hypervisors.add(dest.getCluster().getHypervisorType());
             }
         } else {
-            HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId());
+            final HypervisorType defaults = _resourceMgr.getDefaultHypervisor(dest.getDataCenter().getId());
             if (defaults != HypervisorType.None) {
                 hypervisors.add(defaults);
             } else {
@@ -1726,16 +1725,16 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         }
 
         //keep only elements defined in supported hypervisors
-        StringBuilder hTypesStr = new StringBuilder();
+        final StringBuilder hTypesStr = new StringBuilder();
         if (supportedHypervisors != null && !supportedHypervisors.isEmpty()) {
             hypervisors.retainAll(supportedHypervisors);
-            for (HypervisorType hType : supportedHypervisors) {
+            for (final HypervisorType hType : supportedHypervisors) {
                 hTypesStr.append(hType).append(" ");
             }
         }
 
         if (hypervisors.isEmpty()) {
-            String errMsg = (hTypesStr.capacity() > 0) ? "supporting hypervisors " + hTypesStr.toString() : "";
+            final String errMsg = (hTypesStr.capacity() > 0) ? "supporting hypervisors " + hTypesStr.toString() : "";
             if (plan.getPodId() != null) {
                 throw new InsufficientServerCapacityException("Unable to create virtual router, " + "there are no clusters in the pod " + errMsg, Pod.class,
                     plan.getPodId());
@@ -1746,8 +1745,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         return hypervisors;
     }
 
-    protected LinkedHashMap<Network, NicProfile> createRouterNetworks(Account owner, boolean isRedundant, DeploymentPlan plan, Network guestNetwork,
-        Pair<Boolean, PublicIp> publicNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException {
+    protected LinkedHashMap<Network, NicProfile> createRouterNetworks(final Account owner, final boolean isRedundant, final DeploymentPlan plan, final Network guestNetwork,
+        final Pair<Boolean, PublicIp> publicNetwork) throws ConcurrentOperationException, InsufficientAddressCapacityException {
 
         boolean setupPublicNetwork = false;
         if (publicNetwork != null) {
@@ -1755,7 +1754,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         }
 
         //Form networks
-        LinkedHashMap<Network, NicProfile> networks = new LinkedHashMap<Network, NicProfile>(3);
+        final LinkedHashMap<Network, NicProfile> networks = new LinkedHashMap<Network, NicProfile>(3);
 
         //1) Guest network
         boolean hasGuestNetwork = false;
@@ -1763,13 +1762,13 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork);
             String defaultNetworkStartIp = null, defaultNetworkStartIpv6 = null;
             if (!setupPublicNetwork) {
-                Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, plan.getPodId());
+                final Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, plan.getPodId());
                 if (guestNetwork.getCidr() != null) {
                     if (placeholder != null && placeholder.getIp4Address() != null) {
                         s_logger.debug("Requesting ipv4 address " + placeholder.getIp4Address() + " stored in placeholder nic for the network " + guestNetwork);
                         defaultNetworkStartIp = placeholder.getIp4Address();
                     } else {
-                        String startIp = _networkModel.getStartIpAddress(guestNetwork.getId());
+                        final String startIp = _networkModel.getStartIpAddress(guestNetwork.getId());
                         if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
                             defaultNetworkStartIp = startIp;
                         } else if (s_logger.isDebugEnabled()) {
@@ -1784,7 +1783,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                         s_logger.debug("Requesting ipv6 address " + placeholder.getIp6Address() + " stored in placeholder nic for the network " + guestNetwork);
                         defaultNetworkStartIpv6 = placeholder.getIp6Address();
                     } else {
-                        String startIpv6 = _networkModel.getStartIpv6Address(guestNetwork.getId());
+                        final String startIpv6 = _networkModel.getStartIpv6Address(guestNetwork.getId());
                         if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(), startIpv6) == null) {
                             defaultNetworkStartIpv6 = startIpv6;
                         } else if (s_logger.isDebugEnabled()) {
@@ -1795,7 +1794,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 }
             }
 
-            NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp, defaultNetworkStartIpv6);
+            final NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp, defaultNetworkStartIpv6);
             if (setupPublicNetwork) {
                 if (isRedundant) {
                     gatewayNic.setIp4Address(_ipAddrMgr.acquireGuestIpAddress(guestNetwork, null));
@@ -1806,7 +1805,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
                 gatewayNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
                 gatewayNic.setIsolationUri(guestNetwork.getBroadcastUri());
                 gatewayNic.setMode(guestNetwork.getMode());
-                String gatewayCidr = guestNetwork.getCidr();
+                final String gatewayCidr = guestNetwork.getCidr();
                 gatewayNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
             } else {
                 gatewayNic.setDefaultNic(true);
@@ -1818,24 +1817,24 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         //2) Control network
         s_logger.debug("Adding nic for Virtual Router in Control network ");
-        List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
-        NetworkOffering controlOffering = offerings.get(0);
-        Network controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0);
+        final List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
+        final NetworkOffering controlOffering = offerings.get(0);
+        final Network controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0);
         networks.put(controlConfig, null);
 
         //3) Public network
         if (setupPublicNetwork) {
-            PublicIp sourceNatIp = publicNetwork.second();
+            final PublicIp sourceNatIp = publicNetwork.second();
             s_logger.debug("Adding nic for Virtual Router in Public network ");
             //if source nat service is supported by the network, get the source nat ip address
-            NicProfile defaultNic = new NicProfile();
+            final NicProfile defaultNic = new NicProfile();
             defaultNic.setDefaultNic(true);
             defaultNic.setIp4Address(sourceNatIp.getAddress().addr());
             defaultNic.setGateway(sourceNatIp.getGateway());
             defaultNic.setNetmask(sourceNatIp.getNetmask());
             defaultNic.setMacAddress(sourceNatIp.getMacAddress());
             // get broadcast from public network
-            Network pubNet = _networkDao.findById(sourceNatIp.getNetworkId());
+            final Network pubNet = _networkDao.findById(sourceNatIp.getNetworkId());
             if (pubNet.getBroadcastDomainType() == BroadcastDomainType.Vxlan) {
                 defaultNic.setBroadcastType(BroadcastDomainType.Vxlan);
                 defaultNic.setBroadcastUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag()));
@@ -1848,11 +1847,11 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             if (hasGuestNetwork) {
                 defaultNic.setDeviceId(2);
             }
-            NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
-            List<? extends Network> publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false);
-            String publicIp = defaultNic.getIp4Address();
+            final NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
+            final List<? extends Network> publicNetworks = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false);
+            final String publicIp = defaultNic.getIp4Address();
             // We want to use the identical MAC address for RvR on public interface if possible
-            NicVO peerNic = _nicDao.findByIp4AddressAndNetworkId(publicIp, publicNetworks.get(0).getId());
+            final NicVO peerNic = _nicDao.findByIp4AddressAndNetworkId(publicIp, publicNetworks.get(0).getId());
             if (peerNic != null) {
                 s_logger.info("Use same MAC as previous RvR, the MAC is " + peerNic.getMacAddress());
                 defaultNic.setMacAddress(peerNic.getMacAddress());
@@ -1863,12 +1862,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         return networks;
     }
 
-    protected Pair<DeploymentPlan, List<DomainRouterVO>> getDeploymentPlanAndRouters(boolean isPodBased, DeployDestination dest, long guestNetworkId) {
-        long dcId = dest.getDataCenter().getId();
+    protected Pair<DeploymentPlan, List<DomainRouterVO>> getDeploymentPlanAndRouters(final boolean isPodBased, final DeployDestination dest, final long guestNetworkId) {
+        final long dcId = dest.getDataCenter().getId();
         List<DomainRouterVO> routers = null;
         DeploymentPlan plan = new DataCenterDeployment(dcId);
         if (isPodBased) {
-            Pod pod = dest.getPod();
+            final Pod pod = dest.getPod();
             Long podId = null;
             if (pod != null) {
                 podId = pod.getId();
@@ -1884,7 +1883,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         return new Pair<DeploymentPlan, List<DomainRouterVO>>(plan, routers);
     }
 
-    private DomainRouterVO startVirtualRouter(DomainRouterVO router, User user, Account caller, Map<Param, Object> params) throws StorageUnavailableException,
+    private DomainRouterVO startVirtualRouter(final DomainRouterVO router, final User user, final Account caller, final Map<Param, Object> params) throws StorageUnavailableException,
         InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
 
         if (router.getRole() != Role.VIRTUAL_ROUTER || !router.getIsRedundantRouter()) {
@@ -1896,18 +1895,18 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             return router;
         }
 
-        DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null);
+        final DataCenterDeployment plan = new DataCenterDeployment(0, null, null, null, null, null);
         DomainRouterVO result = null;
         assert router.getIsRedundantRouter();
-        List<Long> networkIds = _routerDao.getRouterNetworks(router.getId());
+        final List<Long> networkIds = _routerDao.getRouterNetworks(router.getId());
         //Not support VPC now
         if (networkIds.size() > 1) {
             throw new ResourceUnavailableException("Unable to support more than one guest network for redundant router now!", DataCenter.class, router.getDataCenterId());
         }
         DomainRouterVO routerToBeAvoid = null;
         if (networkIds.size() != 0) {
-            List<DomainRouterVO> routerList = _routerDao.findByNetwork(networkIds.get(0));
-            for (DomainRouterVO rrouter : routerList) {
+            final List<DomainRouterVO> routerList = _routerDao.findByNetwork(networkIds.get(0));
+            for (final DomainRouterVO rrouter : routerList) {
                 if (rrouter.getHostId() != null && rrouter.getIsRedundantRouter() && rrouter.getState() == State.Running) {
                     if (routerToBeAvoid != null) {
                         throw new ResourceUnavailableException("Try to start router " + router.getInstanceName() + "(" + router.getId() + ")" +
@@ -1923,14 +1922,14 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             return this.start(router, user, caller, params, null);
         }
         // We would try best to deploy the router to another place
-        int retryIndex = 5;
-        ExcludeList[] avoids = new ExcludeList[5];
+        final int retryIndex = 5;
+        final ExcludeList[] avoids = new ExcludeList[5];
         avoids[0] = new ExcludeList();
         avoids[0].addPod(routerToBeAvoid.getPodIdToDeployIn());
         avoids[1] = new ExcludeList();
         avoids[1].addCluster(_hostDao.findById(routerToBeAvoid.getHostId()).getClusterId());
         avoids[2] = new ExcludeList();
-        List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(routerToBeAvoid.getId(), Volume.Type.ROOT);
+        final List<VolumeVO> volumes = _volumeDao.findByInstanceAndType(routerToBeAvoid.getId(), Volume.Type.ROOT);
         if (volumes != null && volumes.size() != 0) {
             avoids[2].addPool(volumes.get(0).getPoolId());
         }
@@ -1946,7 +1945,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             plan.setAvoids(avoids[i]);
             try {
                 result = this.start(router, user, caller, params, plan);
-            } catch (InsufficientServerCapacityException ex) {
+            } catch (final InsufficientServerCapacityException ex) {
                 result = null;
             }
             if (result != null) {
@@ -1957,15 +1956,15 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     @Override
-    public List<DomainRouterVO> deployVirtualRouterInGuestNetwork(Network guestNetwork, DeployDestination dest, Account owner, Map<Param, Object> params,
-        boolean isRedundant) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
+    public List<DomainRouterVO> deployVirtualRouterInGuestNetwork(final Network guestNetwork, final DeployDestination dest, final Account owner, final Map<Param, Object> params,
+        final boolean isRedundant) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
 
-        List<DomainRouterVO> routers = findOrDeployVirtualRouterInGuestNetwork(guestNetwork, dest, owner, isRedundant, params);
+        final List<DomainRouterVO> routers = findOrDeployVirtualRouterInGuestNetwork(guestNetwork, dest, owner, isRedundant, params);
 
         return startRouters(params, routers);
     }
 
-    protected List<DomainRouterVO> startRouters(Map<Param, Object> params, List<DomainRouterVO> routers) throws StorageUnavailableException,
+    protected List<DomainRouterVO> startRouters(final Map<Param, Object> params, final List<DomainRouterVO> routers) throws StorageUnavailableException,
         InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
         List<DomainRouterVO> runningRouters = null;
 
@@ -1975,9 +1974,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         for (DomainRouterVO router : routers) {
             boolean skip = false;
-            State state = router.getState();
+            final State state = router.getState();
             if (router.getHostId() != null && state != State.Running) {
-                HostVO host = _hostDao.findById(router.getHostId());
+                final HostVO host = _hostDao.findById(router.getHostId());
                 if (host == null || host.getState() != Status.Up) {
                     skip = true;
                 }
@@ -1995,22 +1994,22 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     @Override
-    public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
+    public boolean finalizeVirtualMachineProfile(final VirtualMachineProfile profile, final DeployDestination dest, final ReservationContext context) {
 
         boolean dnsProvided = true;
         boolean dhcpProvided = true;
         boolean publicNetwork = false;
-        DataCenterVO dc = _dcDao.findById(dest.getDataCenter().getId());
+        final DataCenterVO dc = _dcDao.findById(dest.getDataCenter().getId());
         _dcDao.loadDetails(dc);
 
         //1) Set router details
-        DomainRouterVO router = _routerDao.findById(profile.getVirtualMachine().getId());
-        Map<String, String> details = _vmDetailsDao.listDetailsKeyPairs(router.getId());
+        final DomainRouterVO router = _routerDao.findById(profile.getVirtualMachine().getId());
+        final Map<String, String> details = _vmDetailsDao.listDetailsKeyPairs(router.getId());
         router.setDetails(details);
 
         //2) Prepare boot loader elements related with Control network
 
-        StringBuilder buf = profile.getBootArgsBuilder();
+        final StringBuilder buf = profile.getBootArgsBuilder();
         buf.append(" template=domP");
         buf.append(" name=").append(profile.getHostName());
 
@@ -2023,8 +2022,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         String defaultDns2 = null;
         String defaultIp6Dns1 = null;
         String defaultIp6Dns2 = null;
-        for (NicProfile nic : profile.getNics()) {
-            int deviceId = nic.getDeviceId();
+        for (final NicProfile nic : profile.getNics()) {
+            final int deviceId = nic.getDeviceId();
             boolean ipv4 = false, ipv6 = false;
             if (nic.getIp4Address() != null) {
                 ipv4 = true;
@@ -2091,7 +2090,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
             throw new CloudRuntimeException("Didn't start a control port");
         }
 
-        String rpValue = _configDao.getValue(Config.NetworkRouterRpFilter.key());
+        final String rpValue = _configDao.getValue(Config.NetworkRouterRpFilter.key());
         if (rpValue != null && rpValue.equalsIgnoreCase("true")) {
             _disableRpFilter = true;
         } else {
@@ -2120,7 +2119,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
 
         buf.append(" type=" + type + rpFilter);
 
-        String domain_suffix = dc.getDetail(ZoneConfig.DnsSearchOrder.getName());
+        final String domain_suffix = dc.getDetail(ZoneConfig.DnsSearchOrder.getName());
         if (domain_suffix != null) {
             buf.append(" dnssearchorder=").append(domain_suffix);
         }
@@ -2162,36 +2161,36 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         return true;
     }
 
-    protected StringBuilder createGuestBootLoadArgs(NicProfile guestNic, String defaultDns1, String defaultDns2, DomainRouterVO router) {
-        long guestNetworkId = guestNic.getNetworkId();
-        NetworkVO guestNetwork = _networkDao.findById(guestNetworkId);
+    protected StringBuilder createGuestBootLoadArgs(final NicProfile guestNic, final String defaultDns1, final String defaultDns2, DomainRouterVO router) {
+        final long guestNetworkId = guestNic.getNetworkId();
+        final NetworkVO guestNetwork = _networkDao.findById(guestNetworkId);
         String dhcpRange = null;
-        DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId());
+        final DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId());
 
-        StringBuilder buf = new StringBuilder();
+        final StringBuilder buf = new StringBuilder();
 
-        boolean isRedundant = router.getIsRedundantRouter();
+        final boolean isRedundant = router.getIsRedundantRouter();
         if (isRedundant) {
             buf.append(" redundant_router=1");
-            List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER);
+            final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER);
             try {
-                int priority = getUpdatedPriority(guestNetwork, routers, router);
+                final int priority = getUpdatedPriority(guestNetwork, routers, router);
                 router.setPriority(priority);
                 router = _routerDao.persist(router);
-            } catch (InsufficientVirtualNetworkCapcityException e) {
+            } catch (final InsufficientVirtualNetworkCapcityException e) {
                 s_logger.error("Failed to get update priority!", e);
                 throw new CloudRuntimeException("Failed to get update priority!");
             }
-            Network net = _networkModel.getNetwork(guestNic.getNetworkId());
+            final Network net = _networkModel.getNetwork(guestNic.getNetworkId());
             buf.append(" guestgw=").append(net.getGateway());
-            String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask()));
+            final String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask()));
             buf.append(" guestbrd=").append(brd);
             buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(guestNic.getNetmask()));
             buf.append(" router_pr=").append(router.getPriority());
         }
 
         //setup network domain
-        String domain = guestNetwork.getNetworkDomain();
+        final String domain = guestNetwork.getNetworkDomain();
         if (domain != null) {
             buf.append(" domain=" + domain);
         }
@@ -2199,14 +2198,14 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         //setup dhcp range
         if (dc.getNetworkType() == NetworkType.Basic) {
             if (guestNic.isDefaultNic()) {
-                long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask());
-                String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize);
+                final long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask());
+                final String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize);
                 if (cidr != null) {
                     dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize);
                 }
             }
         } else if (dc.getNetworkType() == NetworkType.Advanced) {
-            String cidr = guestNetwork.getCidr();
+            final String cidr = guestNetwork.getCidr();
             if (cidr != null) {
                 dhcpRange = NetUtils.getDhcpRange(cidr);
             }
@@ -2219,17 +2218,17 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         return buf;
     }
 
-    protected String getGuestDhcpRange(NicProfile guestNic, Network guestNetwork, DataCenter dc) {
+    protected String getGuestDhcpRange(final NicProfile guestNic, final Network guestNetwork, final DataCenter dc) {
         String dhcpRange = null;
         //setup dhcp range
         if (dc.getNetworkType() == NetworkType.Basic) {
-            long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask());
-            String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize);
+            final long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask());
+            final String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize);
             if (cidr != null) {
                 dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize);
             }
         } else if (dc.getNetworkType() == NetworkType.Advanced) {
-            String cidr = guestNetwork.getCidr();
+            final String cidr = guestNetwork.getCidr();
             if (cidr != null) {
                 dhcpRange = NetUtils.getDhcpRange(cidr);
             }
@@ -2238,7 +2237,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
     }
 
     @Override
-    public boolean setupDhcpForPvlan(boolean add, DomainRouterVO router, Long hostId, NicProfile nic) {
+    public boolean setupDhcpForPvlan(final boolean add, final DomainRouterVO router, final Long hostId, final NicProfile nic) {
         if (!nic.getBroadCastUri().getScheme().equals("pvlan")) {
             return false;
         }
@@ -2246,18 +2245,18 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
         if (!add) {
             op = "delete";
         }
-        Network network = _networkDao.findById(nic.getNetworkId());
-        String networkTag = _networkModel.getNetworkTag(router.getHypervisorType(), network);
-        PvlanSetupCommand cmd =
+        final Network network = _networkDao.findById(nic.getNetworkId());
+        final String networkTag = _networkModel.getNetworkTag(router.getHypervisorType(), network);
+        final PvlanSetupCommand cmd =
             PvlanSetupCommand.createDhcpSetup(op, nic.getBroadCastUri(), networkTag, router.getInstanceName(), nic.getMacAddress(), nic.getIp4Address());
         // In fact we send command to the host of router, we're not programming router but the host
         Answer answer = null;
         try {
             answer = _agentMgr.se

<TRUNCATED>

Mime
View raw message