cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [02/50] [abbrv] git commit: updated refs/heads/feature/systemvm-persistent-config to 8620642
Date Mon, 16 Feb 2015 16:47:43 GMT
Fixing CsDhcp.py
Fixing assign IPv4 on GuestNetworkGuru.java
Fixing getRouters() on VpcVirtualRouterElement.java
Fixing Fixing paths on keepalived.conf.templ

Refactor on the other files


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

Branch: refs/heads/feature/systemvm-persistent-config
Commit: e7e1f47eee70fae35fa039cd2819276c1b9cfc92
Parents: 1e838e9
Author: wilderrodrigues <wrodrigues@schubergphilis.com>
Authored: Mon Jan 12 16:04:04 2015 +0100
Committer: wilderrodrigues <wrodrigues@schubergphilis.com>
Committed: Mon Feb 16 16:08:34 2015 +0100

----------------------------------------------------------------------
 .../schema/src/com/cloud/vm/dao/NicDaoImpl.java |   6 +-
 .../network/element/VirtualRouterElement.java   | 280 +++++++++----------
 .../element/VpcVirtualRouterElement.java        | 116 ++++++--
 .../cloud/network/guru/GuestNetworkGuru.java    |  89 +++---
 .../com/cloud/network/router/NetworkHelper.java |  10 +-
 .../cloud/network/router/NetworkHelperImpl.java | 131 +++++----
 .../VirtualNetworkApplianceManagerImpl.java     |   7 +-
 .../network/router/VpcNetworkHelperImpl.java    |  40 +--
 .../RouterDeploymentDefinitionBuilder.java      |   2 +-
 .../VpcRouterDeploymentDefinition.java          |   7 +-
 .../debian/config/opt/cloud/bin/cs/CsDhcp.py    |   2 +-
 .../opt/cloud/templates/keepalived.conf.templ   |   6 +-
 12 files changed, 395 insertions(+), 301 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e7e1f47e/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
index 2a9a602..1e78262 100644
--- a/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
+++ b/engine/schema/src/com/cloud/vm/dao/NicDaoImpl.java
@@ -214,7 +214,11 @@ public class NicDaoImpl extends GenericDaoBase<NicVO, Long> implements NicDao {
         SearchCriteria<NicVO> sc = AllFieldsSearch.create();
         sc.setParameters("network", networkId);
         sc.setParameters("instance", instanceId);
-        return findOneBy(sc).getIp4Address();
+        NicVO nicVo = findOneBy(sc);
+        if (nicVo != null) {
+            return nicVo.getIp4Address();
+        }
+        return null;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e7e1f47e/server/src/com/cloud/network/element/VirtualRouterElement.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java
index 2c28f87..1a340fa 100644
--- a/server/src/com/cloud/network/element/VirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VirtualRouterElement.java
@@ -112,8 +112,8 @@ import com.google.gson.Gson;
 @Local(value = { NetworkElement.class, FirewallServiceProvider.class, DhcpServiceProvider.class, UserDataServiceProvider.class, StaticNatServiceProvider.class,
         LoadBalancingServiceProvider.class, PortForwardingServiceProvider.class, IpDeployer.class, RemoteAccessVPNServiceProvider.class, NetworkMigrationResponder.class })
 public class VirtualRouterElement extends AdapterBase implements VirtualRouterElementService, DhcpServiceProvider, UserDataServiceProvider, SourceNatServiceProvider,
-        StaticNatServiceProvider, FirewallServiceProvider, LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer,
-        NetworkMigrationResponder, AggregatedCommandExecutor {
+StaticNatServiceProvider, FirewallServiceProvider, LoadBalancingServiceProvider, PortForwardingServiceProvider, RemoteAccessVPNServiceProvider, IpDeployer,
+NetworkMigrationResponder, AggregatedCommandExecutor {
     private static final Logger s_logger = Logger.getLogger(VirtualRouterElement.class);
     public static final AutoScaleCounterType AutoScaleCounterCpu = new AutoScaleCounterType("cpu");
     public static final AutoScaleCounterType AutoScaleCounterMemory = new AutoScaleCounterType("memory");
@@ -165,7 +165,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
     protected RouterDeploymentDefinitionBuilder routerDeploymentDefinitionBuilder;
 
     protected boolean canHandle(final Network network, final Service service) {
-        Long physicalNetworkId = _networkMdl.getPhysicalNetworkId(network);
+        final Long physicalNetworkId = _networkMdl.getPhysicalNetworkId(network);
         if (physicalNetworkId == null) {
             return false;
         }
@@ -201,10 +201,10 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
             return false;
         }
 
-        Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
+        final Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
         params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
 
-        RouterDeploymentDefinition routerDeploymentDefinition =
+        final RouterDeploymentDefinition routerDeploymentDefinition =
                 routerDeploymentDefinitionBuilder.create()
                 .setGuestNetwork(network)
                 .setDeployDestination(dest)
@@ -212,7 +212,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
                 .setParams(params)
                 .build();
 
-        List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
+        final List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
 
         int routerCounts = 1;
         if (offering.getRedundantRouter()) {
@@ -236,7 +236,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
             return false;
         }
 
-        NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
+        final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
         if (offering.isSystemOnly()) {
             return false;
         }
@@ -244,7 +244,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
             return false;
         }
 
-        RouterDeploymentDefinition routerDeploymentDefinition =
+        final RouterDeploymentDefinition routerDeploymentDefinition =
                 routerDeploymentDefinitionBuilder.create()
                 .setGuestNetwork(network)
                 .setDeployDestination(dest)
@@ -252,7 +252,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
                 .setParams(vm.getParameters())
                 .build();
 
-        List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
+        final List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
 
         if (routers == null || routers.size() == 0) {
             throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
@@ -263,7 +263,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
     @Override
     public boolean applyFWRules(final Network network, final List<? extends FirewallRule> rules) throws ResourceUnavailableException {
         if (canHandle(network, Service.Firewall)) {
-            List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+            final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
             if (routers == null || routers.isEmpty()) {
                 s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + "router doesn't exist in the network " + network.getId());
                 return true;
@@ -278,8 +278,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
                 }
             }
 
-            DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-            NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+            final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
             if (!networkTopology.applyFirewallRules(network, rules, routers)) {
                 throw new CloudRuntimeException("Failed to apply firewall rules in network " + network.getId());
@@ -308,8 +308,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
                 return false; // at least one numeric and one char. example:
             }
             // 3h
-            char strEnd = str.toCharArray()[str.length() - 1];
-            for (char c : endChar.toCharArray()) {
+            final char strEnd = str.toCharArray()[str.length() - 1];
+            for (final char c : endChar.toCharArray()) {
                 if (strEnd == c) {
                     number = str.substring(0, str.length() - 1);
                     matchedEndChar = true;
@@ -322,22 +322,22 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
         }
         try {
             Integer.parseInt(number);
-        } catch (NumberFormatException e) {
+        } catch (final NumberFormatException e) {
             return false;
         }
         return true;
     }
 
     public static boolean validateHAProxyLBRule(final LoadBalancingRule rule) {
-        String timeEndChar = "dhms";
+        final String timeEndChar = "dhms";
 
         if (rule.getSourcePortStart() == NetUtils.HAPROXY_STATS_PORT) {
             s_logger.debug("Can't create LB on port 8081, haproxy is listening for  LB stats on this port");
             return false;
         }
 
-        for (LbStickinessPolicy stickinessPolicy : rule.getStickinessPolicies()) {
-            List<Pair<String, String>> paramsList = stickinessPolicy.getParams();
+        for (final LbStickinessPolicy stickinessPolicy : rule.getStickinessPolicies()) {
+            final List<Pair<String, String>> paramsList = stickinessPolicy.getParams();
 
             if (StickinessMethodType.LBCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
 
@@ -346,9 +346,9 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
                 String expire = "30m"; // optional
 
                 /* overwrite default values with the stick parameters */
-                for (Pair<String, String> paramKV : paramsList) {
-                    String key = paramKV.first();
-                    String value = paramKV.second();
+                for (final Pair<String, String> paramKV : paramsList) {
+                    final String key = paramKV.first();
+                    final String value = paramKV.second();
                     if ("tablesize".equalsIgnoreCase(key)) {
                         tablesize = value;
                     }
@@ -367,9 +367,9 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
                 String length = null; // optional
                 String holdTime = null; // optional
 
-                for (Pair<String, String> paramKV : paramsList) {
-                    String key = paramKV.first();
-                    String value = paramKV.second();
+                for (final Pair<String, String> paramKV : paramsList) {
+                    final String key = paramKV.first();
+                    final String value = paramKV.second();
                     if ("length".equalsIgnoreCase(key)) {
                         length = value;
                     }
@@ -391,10 +391,10 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
 
     @Override
     public boolean validateLBRule(final Network network, final LoadBalancingRule rule) {
-        List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
+        final List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
         rules.add(rule);
         if (canHandle(network, Service.Lb) && canHandleLbRules(rules)) {
-            List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+            final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
             if (routers == null || routers.isEmpty()) {
                 return true;
             }
@@ -410,14 +410,14 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
                 return false;
             }
 
-            List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+            final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
             if (routers == null || routers.isEmpty()) {
                 s_logger.debug("Virtual router elemnt doesn't need to apply lb rules on the backend; virtual " + "router doesn't exist in the network " + network.getId());
                 return true;
             }
 
-            DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-            NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+            final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
             if (!networkTopology.applyLoadBalancingRules(network, rules, routers)) {
                 throw new CloudRuntimeException("Failed to apply load balancing rules in network " + network.getId());
@@ -435,16 +435,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
             return null;
         }
 
-        Network network = _networksDao.findById(vpn.getNetworkId());
+        final Network network = _networksDao.findById(vpn.getNetworkId());
         if (canHandle(network, Service.Vpn)) {
-            List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+            final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
             if (routers == null || routers.isEmpty()) {
                 s_logger.debug("Virtual router elemnt doesn't need to apply vpn users on the backend; virtual router" + " doesn't exist in the network " + network.getId());
                 return null;
             }
 
-            DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-            NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+            final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
             return networkTopology.applyVpnUsers(network, users, routers);
         } else {
@@ -459,9 +459,9 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
             return false;
         }
 
-        Network network = _networksDao.findById(vpn.getNetworkId());
+        final Network network = _networksDao.findById(vpn.getNetworkId());
         if (canHandle(network, Service.Vpn)) {
-            List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+            final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
             if (routers == null || routers.isEmpty()) {
                 s_logger.debug("Virtual router elemnt doesn't need stop vpn on the backend; virtual router doesn't" + " exist in the network " + network.getId());
                 return true;
@@ -479,9 +479,9 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
             return false;
         }
 
-        Network network = _networksDao.findById(vpn.getNetworkId());
+        final Network network = _networksDao.findById(vpn.getNetworkId());
         if (canHandle(network, Service.Vpn)) {
-            List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+            final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
             if (routers == null || routers.isEmpty()) {
                 s_logger.debug("Virtual router elemnt doesn't need stop vpn on the backend; virtual router doesn't " + "exist in the network " + network.getId());
                 return true;
@@ -496,21 +496,21 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
     @Override
     public boolean applyIps(final Network network, final List<? extends PublicIpAddress> ipAddress, final Set<Service> services) throws ResourceUnavailableException {
         boolean canHandle = true;
-        for (Service service : services) {
+        for (final Service service : services) {
             if (!canHandle(network, service)) {
                 canHandle = false;
                 break;
             }
         }
         if (canHandle) {
-            List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+            final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
             if (routers == null || routers.isEmpty()) {
                 s_logger.debug("Virtual router elemnt doesn't need to associate ip addresses on the backend; virtual " + "router doesn't exist in the network " + network.getId());
                 return true;
             }
 
-            DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-            NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+            final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
             return networkTopology.associatePublicIP(network, ipAddress, routers);
         } else {
@@ -530,7 +530,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
 
     public static String getHAProxyStickinessCapability() {
         LbStickinessMethod method;
-        List<LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>(1);
+        final List<LbStickinessMethod> methodList = new ArrayList<LbStickinessMethod>(1);
 
         method = new LbStickinessMethod(StickinessMethodType.LBCookieBased, "This is loadbalancer cookie based stickiness method.");
         method.addParam("cookie-name", false, "Cookie name passed in http header by the LB to the client.", false);
@@ -577,7 +577,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
                 false,
                 "When this option is specified, haproxy will match on the cookie prefix (or URL parameter prefix). "
                         + "The appsession value is the data following this prefix. Example : appsession ASPSESSIONID len 64 timeout 3h prefix  This will match the cookie ASPSESSIONIDXXXX=XXXXX, the appsession value will be XXXX=XXXXX.",
-                true);
+                        true);
         method.addParam("mode", false, "This option allows to change the URL parser mode. 2 modes are currently supported : - path-parameters "
                 + ": The parser looks for the appsession in the path parameters part (each parameter is separated by a semi-colon), "
                 + "which is convenient for JSESSIONID for example.This is the default mode if the option is not set. - query-string :"
@@ -590,16 +590,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
                 + " example: expire=30m 20s 50h 4d. Default value:3h", false);
         methodList.add(method);
 
-        Gson gson = new Gson();
-        String capability = gson.toJson(methodList);
+        final Gson gson = new Gson();
+        final String capability = gson.toJson(methodList);
         return capability;
     }
 
     private static Map<Service, Map<Capability, String>> setCapabilities() {
-        Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
+        final Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
 
         // Set capabilities for LB service
-        Map<Capability, String> lbCapabilities = new HashMap<Capability, String>();
+        final Map<Capability, String> lbCapabilities = new HashMap<Capability, String>();
         lbCapabilities.put(Capability.SupportedLBAlgorithms, "roundrobin,leastconn,source");
         lbCapabilities.put(Capability.SupportedLBIsolation, "dedicated");
         lbCapabilities.put(Capability.SupportedProtocols, "tcp, udp");
@@ -609,18 +609,18 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
         // specifies that LB rules can support autoscaling and the list of
         // counters it supports
         AutoScaleCounter counter;
-        List<AutoScaleCounter> counterList = new ArrayList<AutoScaleCounter>();
+        final List<AutoScaleCounter> counterList = new ArrayList<AutoScaleCounter>();
         counter = new AutoScaleCounter(AutoScaleCounterCpu);
         counterList.add(counter);
         counter = new AutoScaleCounter(AutoScaleCounterMemory);
         counterList.add(counter);
-        Gson gson = new Gson();
-        String autoScaleCounterList = gson.toJson(counterList);
+        final Gson gson = new Gson();
+        final String autoScaleCounterList = gson.toJson(counterList);
         lbCapabilities.put(Capability.AutoScaleCounters, autoScaleCounterList);
         capabilities.put(Service.Lb, lbCapabilities);
 
         // Set capabilities for Firewall service
-        Map<Capability, String> firewallCapabilities = new HashMap<Capability, String>();
+        final Map<Capability, String> firewallCapabilities = new HashMap<Capability, String>();
         firewallCapabilities.put(Capability.TrafficStatistics, "per public ip");
         firewallCapabilities.put(Capability.SupportedProtocols, "tcp,udp,icmp");
         firewallCapabilities.put(Capability.SupportedEgressProtocols, "tcp,udp,icmp, all");
@@ -629,24 +629,24 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
         capabilities.put(Service.Firewall, firewallCapabilities);
 
         // Set capabilities for vpn
-        Map<Capability, String> vpnCapabilities = new HashMap<Capability, String>();
+        final Map<Capability, String> vpnCapabilities = new HashMap<Capability, String>();
         vpnCapabilities.put(Capability.SupportedVpnProtocols, "pptp,l2tp,ipsec");
         vpnCapabilities.put(Capability.VpnTypes, "removeaccessvpn");
         capabilities.put(Service.Vpn, vpnCapabilities);
 
-        Map<Capability, String> dnsCapabilities = new HashMap<Capability, String>();
+        final Map<Capability, String> dnsCapabilities = new HashMap<Capability, String>();
         dnsCapabilities.put(Capability.AllowDnsSuffixModification, "true");
         capabilities.put(Service.Dns, dnsCapabilities);
 
         capabilities.put(Service.UserData, null);
 
-        Map<Capability, String> dhcpCapabilities = new HashMap<Capability, String>();
+        final Map<Capability, String> dhcpCapabilities = new HashMap<Capability, String>();
         dhcpCapabilities.put(Capability.DhcpAccrossMultipleSubnets, "true");
         capabilities.put(Service.Dhcp, dhcpCapabilities);
 
         capabilities.put(Service.Gateway, null);
 
-        Map<Capability, String> sourceNatCapabilities = new HashMap<Capability, String>();
+        final Map<Capability, String> sourceNatCapabilities = new HashMap<Capability, String>();
         sourceNatCapabilities.put(Capability.SupportedSourceNatTypes, "peraccount");
         sourceNatCapabilities.put(Capability.RedundantRouter, "true");
         capabilities.put(Service.SourceNat, sourceNatCapabilities);
@@ -660,14 +660,14 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
     @Override
     public boolean applyStaticNats(final Network network, final List<? extends StaticNat> rules) throws ResourceUnavailableException {
         if (canHandle(network, Service.StaticNat)) {
-            List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+            final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
             if (routers == null || routers.isEmpty()) {
                 s_logger.debug("Virtual router elemnt doesn't need to apply static nat on the backend; virtual " + "router doesn't exist in the network " + network.getId());
                 return true;
             }
 
-            DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-            NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+            final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
             return networkTopology.applyStaticNats(network, rules, routers);
         } else {
@@ -677,12 +677,12 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
 
     @Override
     public boolean shutdown(final Network network, final ReservationContext context, final boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
-        List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+        final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
         if (routers == null || routers.isEmpty()) {
             return true;
         }
         boolean result = true;
-        for (DomainRouterVO router : routers) {
+        for (final DomainRouterVO router : routers) {
             result = result && _routerMgr.stop(router, false, context.getCaller(), context.getAccount()) != null;
             if (cleanup) {
                 if (!result) {
@@ -699,7 +699,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
 
     @Override
     public boolean destroy(final Network config, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
-        List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(config.getId(), Role.VIRTUAL_ROUTER);
+        final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(config.getId(), Role.VIRTUAL_ROUTER);
         if (routers == null || routers.isEmpty()) {
             return true;
         }
@@ -708,8 +708,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
         // it will fail permission check there. Context passed in from
         // deleteNetwork is the network account,
         // not caller account
-        Account callerAccount = _accountMgr.getAccount(context.getCaller().getAccountId());
-        for (DomainRouterVO router : routers) {
+        final Account callerAccount = _accountMgr.getAccount(context.getCaller().getAccountId());
+        for (final DomainRouterVO router : routers) {
             result = result && _routerMgr.destroyRouter(router.getId(), callerAccount, context.getCaller().getId()) != null;
         }
         return result;
@@ -720,27 +720,27 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
         if (!canHandle(network, null)) {
             return false;
         }
-        List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+        final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
         if (routers == null || routers.isEmpty()) {
             s_logger.debug("Can't find virtual router element in network " + network.getId());
             return true;
         }
 
-        VirtualMachineProfile uservm = vm;
+        final VirtualMachineProfile uservm = vm;
 
-        DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-        NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+        final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
         // If any router is running then send save password command otherwise
         // save the password in DB
-        for (VirtualRouter router : routers) {
+        for (final VirtualRouter router : routers) {
             if (router.getState() == State.Running) {
                 return networkTopology.savePasswordToRouter(network, nic, uservm, routers);
             }
         }
-        String password = (String) uservm.getParameter(VirtualMachineProfile.Param.VmPassword);
-        String password_encrypted = DBEncryptionUtil.encrypt(password);
-        UserVmVO userVmVO = _userVmDao.findById(vm.getId());
+        final String password = (String) uservm.getParameter(VirtualMachineProfile.Param.VmPassword);
+        final String password_encrypted = DBEncryptionUtil.encrypt(password);
+        final UserVmVO userVmVO = _userVmDao.findById(vm.getId());
 
         _userVmDao.loadDetails(userVmVO);
         userVmVO.setDetail("password", password_encrypted);
@@ -757,16 +757,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
         if (!canHandle(network, null)) {
             return false;
         }
-        List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+        final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
         if (routers == null || routers.isEmpty()) {
             s_logger.debug("Can't find virtual router element in network " + network.getId());
             return true;
         }
 
-        VirtualMachineProfile uservm = vm;
+        final VirtualMachineProfile uservm = vm;
 
-        DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-        NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+        final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
         return networkTopology.saveSSHPublicKeyToRouter(network, nic, uservm, routers, sshPublicKey);
     }
@@ -776,23 +776,23 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
         if (!canHandle(network, null)) {
             return false;
         }
-        List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+        final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
         if (routers == null || routers.isEmpty()) {
             s_logger.debug("Can't find virtual router element in network " + network.getId());
             return true;
         }
 
-        VirtualMachineProfile uservm = vm;
+        final VirtualMachineProfile uservm = vm;
 
-        DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-        NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+        final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
         return networkTopology.saveUserDataToRouter(network, nic, uservm, routers);
     }
 
     @Override
     public List<Class<?>> getCommands() {
-        List<Class<?>> cmdList = new ArrayList<Class<?>>();
+        final List<Class<?>> cmdList = new ArrayList<Class<?>>();
         cmdList.add(CreateVirtualRouterElementCmd.class);
         cmdList.add(ConfigureVirtualRouterElementCmd.class);
         cmdList.add(ListVirtualRouterElementsCmd.class);
@@ -801,7 +801,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
 
     @Override
     public VirtualRouterProvider configure(final ConfigureVirtualRouterElementCmd cmd) {
-        VirtualRouterProviderVO element = _vrProviderDao.findById(cmd.getId());
+        final VirtualRouterProviderVO element = _vrProviderDao.findById(cmd.getId());
         if (element == null || !(element.getType() == Type.VirtualRouter || element.getType() == Type.VPCVirtualRouter)) {
             s_logger.debug("Can't find Virtual Router element with network service provider id " + cmd.getId());
             return null;
@@ -815,7 +815,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
 
     @Override
     public OvsProvider configure(final ConfigureOvsElementCmd cmd) {
-        OvsProviderVO element = _ovsProviderDao.findById(cmd.getId());
+        final OvsProviderVO element = _ovsProviderDao.findById(cmd.getId());
         if (element == null) {
             s_logger.debug("Can't find Ovs element with network service provider id " + cmd.getId());
             return null;
@@ -845,14 +845,14 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
     @Override
     public boolean applyPFRules(final Network network, final List<PortForwardingRule> rules) throws ResourceUnavailableException {
         if (canHandle(network, Service.PortForwarding)) {
-            List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+            final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
             if (routers == null || routers.isEmpty()) {
                 s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + "router doesn't exist in the network " + network.getId());
                 return true;
             }
 
-            DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-            NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+            final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
             if (!networkTopology.applyFirewallRules(network, rules, routers)) {
                 throw new CloudRuntimeException("Failed to apply firewall rules in network " + network.getId());
@@ -866,7 +866,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
 
     @Override
     public boolean isReady(final PhysicalNetworkServiceProvider provider) {
-        VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), getVirtualRouterProvider());
+        final VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), getVirtualRouterProvider());
         if (element == null) {
             return false;
         }
@@ -875,16 +875,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
 
     @Override
     public boolean shutdownProviderInstances(final PhysicalNetworkServiceProvider provider, final ReservationContext context) throws ConcurrentOperationException,
-            ResourceUnavailableException {
-        VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), getVirtualRouterProvider());
+    ResourceUnavailableException {
+        final VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), getVirtualRouterProvider());
         if (element == null) {
             return true;
         }
         // Find domain routers
-        long elementId = element.getId();
-        List<DomainRouterVO> routers = _routerDao.listByElementId(elementId);
+        final long elementId = element.getId();
+        final List<DomainRouterVO> routers = _routerDao.listByElementId(elementId);
         boolean result = true;
-        for (DomainRouterVO router : routers) {
+        for (final DomainRouterVO router : routers) {
             result = result && _routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()) != null;
         }
         _vrProviderDao.remove(elementId);
@@ -898,13 +898,13 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
     }
 
     public Long getIdByNspId(final Long nspId) {
-        VirtualRouterProviderVO vr = _vrProviderDao.findByNspIdAndType(nspId, Type.VirtualRouter);
+        final VirtualRouterProviderVO vr = _vrProviderDao.findByNspIdAndType(nspId, Type.VirtualRouter);
         return vr.getId();
     }
 
     @Override
     public VirtualRouterProvider getCreatedElement(final long id) {
-        VirtualRouterProvider provider = _vrProviderDao.findById(id);
+        final VirtualRouterProvider provider = _vrProviderDao.findById(id);
         if (!(provider.getType() == Type.VirtualRouter || provider.getType() == Type.VPCVirtualRouter)) {
             throw new InvalidParameterValueException("Unable to find provider by id");
         }
@@ -913,7 +913,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
 
     @Override
     public boolean release(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final ReservationContext context) throws ConcurrentOperationException,
-            ResourceUnavailableException {
+    ResourceUnavailableException {
         return true;
     }
 
@@ -925,16 +925,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
                 return false;
             }
 
-            VirtualMachineProfile uservm = vm;
+            final VirtualMachineProfile uservm = vm;
 
-            List<DomainRouterVO> routers = getRouters(network, dest);
+            final List<DomainRouterVO> routers = getRouters(network, dest);
 
             if (routers == null || routers.size() == 0) {
                 throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
             }
 
-            DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-            NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+            final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
             return networkTopology.configDhcpForSubnet(network, nic, uservm, dest, routers);
         }
@@ -944,13 +944,13 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
     @Override
     public boolean removeDhcpSupportForSubnet(final Network network) throws ResourceUnavailableException {
         if (canHandle(network, Service.Dhcp)) {
-            List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
+            final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
             if (routers == null || routers.size() == 0) {
                 throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
             }
             try {
                 return _routerMgr.removeDhcpSupportForSubnet(network, routers);
-            } catch (ResourceUnavailableException e) {
+            } catch (final ResourceUnavailableException e) {
                 s_logger.debug("Router resource unavailable ");
             }
         }
@@ -965,16 +965,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
                 return false;
             }
 
-            VirtualMachineProfile uservm = vm;
+            final VirtualMachineProfile uservm = vm;
 
-            List<DomainRouterVO> routers = getRouters(network, dest);
+            final List<DomainRouterVO> routers = getRouters(network, dest);
 
             if (routers == null || routers.size() == 0) {
                 throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
             }
 
-            DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-            NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+            final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
             return networkTopology.applyDhcpEntry(network, nic, uservm, dest, routers);
         }
@@ -994,16 +994,16 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
                 return true;
             }
 
-            VirtualMachineProfile uservm = vm;
+            final VirtualMachineProfile uservm = vm;
 
-            List<DomainRouterVO> routers = getRouters(network, dest);
+            final List<DomainRouterVO> routers = getRouters(network, dest);
 
             if (routers == null || routers.size() == 0) {
                 throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
             }
 
-            DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-            NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+            final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
             return networkTopology.applyUserData(network, nic, uservm, dest, routers);
         }
@@ -1015,7 +1015,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
         if (_networkMdl.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, getProvider())) {
             publicNetwork = true;
         }
-        boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic || _networkMdl.isSecurityGroupSupportedInNetwork(network))
+        final boolean isPodBased = (dest.getDataCenter().getNetworkType() == NetworkType.Basic || _networkMdl.isSecurityGroupSupportedInNetwork(network))
                 && network.getTrafficType() == TrafficType.Guest;
 
         List<DomainRouterVO> routers;
@@ -1024,7 +1024,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
             routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
         } else {
             if (isPodBased && dest.getPod() != null) {
-                Long podId = dest.getPod().getId();
+                final Long podId = dest.getPod().getId();
                 routers = _routerDao.listByNetworkAndPodAndRole(network.getId(), podId, Role.VIRTUAL_ROUTER);
             } else {
                 // With pod == null, it's network restart case, we would add all
@@ -1040,8 +1040,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
         // With pod == null, it's network restart case, we already add all
         // routers to it
         if (isPodBased && dest.getPod() != null && _routerMgr.getDnsBasicZoneUpdate().equalsIgnoreCase("all")) {
-            Long podId = dest.getPod().getId();
-            List<DomainRouterVO> allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), podId, State.Running, Role.VIRTUAL_ROUTER);
+            final Long podId = dest.getPod().getId();
+            final List<DomainRouterVO> allRunningRoutersOutsideThePod = _routerDao.findByNetworkOutsideThePod(network.getId(), podId, State.Running, Role.VIRTUAL_ROUTER);
             routers.addAll(allRunningRoutersOutsideThePod);
         }
         return routers;
@@ -1049,11 +1049,11 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
 
     @Override
     public List<? extends VirtualRouterProvider> searchForVirtualRouterElement(final ListVirtualRouterElementsCmd cmd) {
-        Long id = cmd.getId();
-        Long nspId = cmd.getNspId();
-        Boolean enabled = cmd.getEnabled();
+        final Long id = cmd.getId();
+        final Long nspId = cmd.getNspId();
+        final Boolean enabled = cmd.getEnabled();
 
-        QueryBuilder<VirtualRouterProviderVO> sc = QueryBuilder.create(VirtualRouterProviderVO.class);
+        final QueryBuilder<VirtualRouterProviderVO> sc = QueryBuilder.create(VirtualRouterProviderVO.class);
         if (id != null) {
             sc.and(sc.entity().getId(), Op.EQ, id);
         }
@@ -1072,10 +1072,10 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
 
     @Override
     public List<? extends OvsProvider> searchForOvsElement(final ListOvsElementsCmd cmd) {
-        Long id = cmd.getId();
-        Long nspId = cmd.getNspId();
-        Boolean enabled = cmd.getEnabled();
-        QueryBuilder<OvsProviderVO> sc = QueryBuilder.create(OvsProviderVO.class);
+        final Long id = cmd.getId();
+        final Long nspId = cmd.getNspId();
+        final Boolean enabled = cmd.getEnabled();
+        final QueryBuilder<OvsProviderVO> sc = QueryBuilder.create(OvsProviderVO.class);
 
         if (id != null) {
             sc.and(sc.entity().getId(), Op.EQ, id);
@@ -1111,11 +1111,11 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
     }
 
     private boolean canHandleLbRules(final List<LoadBalancingRule> rules) {
-        Map<Capability, String> lbCaps = getCapabilities().get(Service.Lb);
+        final Map<Capability, String> lbCaps = getCapabilities().get(Service.Lb);
         if (!lbCaps.isEmpty()) {
-            String schemeCaps = lbCaps.get(Capability.LbSchemes);
+            final String schemeCaps = lbCaps.get(Capability.LbSchemes);
             if (schemeCaps != null) {
-                for (LoadBalancingRule rule : rules) {
+                for (final LoadBalancingRule rule : rules) {
                     if (!schemeCaps.contains(rule.getScheme().toString())) {
                         s_logger.debug("Scheme " + rules.get(0).getScheme() + " is not supported by the provider " + getName());
                         return false;
@@ -1133,19 +1133,19 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
         }
         if (vm.getType() == VirtualMachine.Type.DomainRouter) {
             assert vm instanceof DomainRouterVO;
-            DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine();
+            final DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine();
 
-            DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-            NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+            final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
             try {
                 networkTopology.setupDhcpForPvlan(false, router, router.getHostId(), nic);
-            } catch (ResourceUnavailableException e) {
+            } catch (final ResourceUnavailableException e) {
                 s_logger.warn("Timed Out", e);
             }
         } else if (vm.getType() == VirtualMachine.Type.User) {
             assert vm instanceof UserVmVO;
-            UserVmVO userVm = (UserVmVO) vm.getVirtualMachine();
+            final UserVmVO userVm = (UserVmVO) vm.getVirtualMachine();
             _userVmMgr.setupVmForPvlan(false, userVm.getHostId(), nic);
         }
         return true;
@@ -1158,19 +1158,19 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
         }
         if (vm.getType() == VirtualMachine.Type.DomainRouter) {
             assert vm instanceof DomainRouterVO;
-            DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine();
+            final DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine();
 
-            DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-            NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+            final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
             try {
                 networkTopology.setupDhcpForPvlan(true, router, router.getHostId(), nic);
-            } catch (ResourceUnavailableException e) {
+            } catch (final ResourceUnavailableException e) {
                 s_logger.warn("Timed Out", e);
             }
         } else if (vm.getType() == VirtualMachine.Type.User) {
             assert vm instanceof UserVmVO;
-            UserVmVO userVm = (UserVmVO) vm.getVirtualMachine();
+            final UserVmVO userVm = (UserVmVO) vm.getVirtualMachine();
             _userVmMgr.setupVmForPvlan(true, userVm.getHostId(), nic);
         }
     }
@@ -1182,26 +1182,26 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
         }
         if (vm.getType() == VirtualMachine.Type.DomainRouter) {
             assert vm instanceof DomainRouterVO;
-            DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine();
+            final DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine();
 
-            DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
-            NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
+            final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
             try {
                 networkTopology.setupDhcpForPvlan(true, router, router.getHostId(), nic);
-            } catch (ResourceUnavailableException e) {
+            } catch (final ResourceUnavailableException e) {
                 s_logger.warn("Timed Out", e);
             }
         } else if (vm.getType() == VirtualMachine.Type.User) {
             assert vm instanceof UserVmVO;
-            UserVmVO userVm = (UserVmVO) vm.getVirtualMachine();
+            final UserVmVO userVm = (UserVmVO) vm.getVirtualMachine();
             _userVmMgr.setupVmForPvlan(true, userVm.getHostId(), nic);
         }
     }
 
     @Override
     public boolean prepareAggregatedExecution(final Network network, final DeployDestination dest) throws ResourceUnavailableException {
-        List<DomainRouterVO> routers = getRouters(network, dest);
+        final List<DomainRouterVO> routers = getRouters(network, dest);
 
         if (routers == null || routers.size() == 0) {
             throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
@@ -1212,7 +1212,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
 
     @Override
     public boolean completeAggregatedExecution(final Network network, final DeployDestination dest) throws ResourceUnavailableException {
-        List<DomainRouterVO> routers = getRouters(network, dest);
+        final List<DomainRouterVO> routers = getRouters(network, dest);
 
         if (routers == null || routers.size() == 0) {
             throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e7e1f47e/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
index f44d7aa..f0c0fba 100644
--- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
@@ -16,6 +16,7 @@
 // under the License.
 package com.cloud.network.element;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -28,6 +29,8 @@ import org.apache.cloudstack.network.topology.NetworkTopology;
 import org.apache.log4j.Logger;
 import org.cloud.network.router.deployment.RouterDeploymentDefinition;
 import org.cloud.network.router.deployment.RouterDeploymentDefinitionBuilder;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 
 import com.cloud.dc.DataCenter;
 import com.cloud.dc.DataCenterVO;
@@ -36,6 +39,7 @@ import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.IpAddress;
+import com.cloud.network.IpAddressManager;
 import com.cloud.network.Network;
 import com.cloud.network.Network.Capability;
 import com.cloud.network.Network.Provider;
@@ -53,6 +57,7 @@ import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.dao.Site2SiteVpnGatewayDao;
 import com.cloud.network.router.VirtualRouter;
 import com.cloud.network.router.VirtualRouter.Role;
+import com.cloud.network.router.VpcNetworkHelperImpl;
 import com.cloud.network.router.VpcVirtualNetworkApplianceManager;
 import com.cloud.network.vpc.NetworkACLItem;
 import com.cloud.network.vpc.NetworkACLItemDao;
@@ -62,6 +67,7 @@ import com.cloud.network.vpc.StaticRouteProfile;
 import com.cloud.network.vpc.Vpc;
 import com.cloud.network.vpc.VpcGateway;
 import com.cloud.network.vpc.VpcManager;
+import com.cloud.network.vpc.dao.VpcDao;
 import com.cloud.network.vpc.dao.VpcGatewayDao;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.utils.db.EntityManager;
@@ -70,13 +76,18 @@ import com.cloud.vm.DomainRouterVO;
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.ReservationContext;
 import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineManager;
 import com.cloud.vm.VirtualMachineProfile;
 
 @Local(value = { NetworkElement.class, FirewallServiceProvider.class, DhcpServiceProvider.class, UserDataServiceProvider.class, StaticNatServiceProvider.class,
         LoadBalancingServiceProvider.class, PortForwardingServiceProvider.class, IpDeployer.class, VpcProvider.class, Site2SiteVpnServiceProvider.class,
         NetworkACLServiceProvider.class })
 public class VpcVirtualRouterElement extends VirtualRouterElement implements VpcProvider, Site2SiteVpnServiceProvider, NetworkACLServiceProvider {
+
     private static final Logger s_logger = Logger.getLogger(VpcVirtualRouterElement.class);
+
+    private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
+
     @Inject
     VpcManager _vpcMgr;
     @Inject
@@ -95,12 +106,20 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
     NetworkACLItemDao _networkACLItemDao;
     @Inject
     EntityManager _entityMgr;
+    @Inject
+    VirtualMachineManager _itMgr;
+    @Inject
+    IpAddressManager _ipAddrMgr;
+    @Inject
+    VpcDao _vpcDao;
+
+    @Autowired
+    @Qualifier("vpcNetworkHelper")
+    private VpcNetworkHelperImpl _vpcNetWprkHelper;
 
     @Inject
     private RouterDeploymentDefinitionBuilder routerDeploymentDefinitionBuilder;
 
-    private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
-
     @Override
     protected boolean canHandle(final Network network, final Service service) {
         final Long physicalNetworkId = _networkMdl.getPhysicalNetworkId(network);
@@ -179,8 +198,13 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
         final Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
         params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
 
-        final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setVpc(vpc).setDeployDestination(dest)
-                .setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).setParams(params).build();
+        final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create()
+                .setGuestNetwork(network)
+                .setVpc(vpc)
+                .setDeployDestination(dest)
+                .setAccountOwner(_accountMgr.getAccount(vpc.getAccountId()))
+                .setParams(params)
+                .build();
 
         final List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
 
@@ -188,23 +212,29 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
             throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
         }
 
+        configureGuestNetwork(network, routers);
+
+        return true;
+    }
+
+    protected void configureGuestNetwork(final Network network, final List<DomainRouterVO> routers )
+            throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
+
         s_logger.info("Adding VPC routers to Guest Network: " + routers.size() + " to be added!");
 
-        for (final DomainRouterVO domainRouterVO : routers) {
-            if (!_networkMdl.isVmPartOfNetwork(domainRouterVO.getId(), network.getId())) {
+        for (final DomainRouterVO router : routers) {
+            if (!_networkMdl.isVmPartOfNetwork(router.getId(), network.getId())) {
                 final Map<VirtualMachineProfile.Param, Object> paramsForRouter = new HashMap<VirtualMachineProfile.Param, Object>(1);
                 if (network.getState() == State.Setup) {
                     paramsForRouter.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
                 }
-                if (!_vpcRouterMgr.addVpcRouterToGuestNetwork(domainRouterVO, network, paramsForRouter)) {
-                    s_logger.error("Failed to add VPC router " + domainRouterVO + " to guest network " + network);
+                if (!_vpcRouterMgr.addVpcRouterToGuestNetwork(router, network, paramsForRouter)) {
+                    s_logger.error("Failed to add VPC router " + router + " to guest network " + network);
                 } else {
-                    s_logger.debug("Successfully added VPC router " + domainRouterVO + " to guest network " + network);
+                    s_logger.debug("Successfully added VPC router " + router + " to guest network " + network);
                 }
             }
         }
-
-        return true;
     }
 
     @Override
@@ -227,31 +257,21 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
             final Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
             params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
 
-            final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setVpc(vpc).setDeployDestination(dest)
-                    .setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).setParams(params).build();
+            final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create()
+                    .setGuestNetwork(network)
+                    .setVpc(vpc)
+                    .setDeployDestination(dest)
+                    .setAccountOwner(_accountMgr.getAccount(vpc.getAccountId()))
+                    .setParams(params)
+                    .build();
+
             final List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
 
             if (routers == null || routers.size() == 0) {
                 throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
             }
 
-            s_logger.info("Adding VPC routers to Guest Network: " + routers.size() + " to be added!");
-
-            for (final DomainRouterVO domainRouterVO : routers) {
-                // Add router to guest network if needed
-                if (!_networkMdl.isVmPartOfNetwork(domainRouterVO.getId(), network.getId())) {
-                    final Map<VirtualMachineProfile.Param, Object> paramsForRouter = new HashMap<VirtualMachineProfile.Param, Object>(1);
-                    // need to reprogram guest network if it comes in a setup state
-                    if (network.getState() == State.Setup) {
-                        paramsForRouter.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
-                    }
-                    if (!_vpcRouterMgr.addVpcRouterToGuestNetwork(domainRouterVO, network, paramsForRouter)) {
-                        s_logger.error("Failed to add VPC router " + domainRouterVO + " to guest network " + network);
-                    } else {
-                        s_logger.debug("Successfully added VPC router " + domainRouterVO + " to guest network " + network);
-                    }
-                }
-            }
+            configureGuestNetwork(network, routers);
         }
 
         return true;
@@ -318,6 +338,42 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
         return Provider.VPCVirtualRouter;
     }
 
+    @Override
+    protected List<DomainRouterVO> getRouters(final Network network, final DeployDestination dest) {
+        List<DomainRouterVO> routers = new ArrayList<DomainRouterVO>();
+
+        final Long vpcId = network.getVpcId();
+        if (vpcId == null) {
+            s_logger.error("Network " + network + " is not associated with any VPC");
+            return routers;
+        }
+
+        final Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
+        if (vpc == null) {
+            s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
+            return routers;
+        }
+
+        final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create()
+                .setGuestNetwork(network)
+                .setVpc(vpc)
+                .setDeployDestination(dest)
+                .setAccountOwner(_accountMgr.getAccount(vpc.getAccountId()))
+                .build();
+
+        try {
+            routers = routerDeploymentDefinition.deployVirtualRouter();
+        } catch (final ConcurrentOperationException e) {
+            s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
+        } catch (final InsufficientCapacityException e) {
+            s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
+        } catch (final ResourceUnavailableException e) {
+            s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
+        }
+
+        return routers;
+    }
+
     private static Map<Service, Map<Capability, String>> setCapabilities() {
         final Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
         capabilities.putAll(VirtualRouterElement.capabilities);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e7e1f47e/server/src/com/cloud/network/guru/GuestNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java
index 17b313c..25b1f54 100644
--- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java
@@ -62,6 +62,8 @@ import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.dao.NetworkVO;
 import com.cloud.network.dao.PhysicalNetworkDao;
 import com.cloud.network.dao.PhysicalNetworkVO;
+import com.cloud.network.vpc.Vpc;
+import com.cloud.network.vpc.dao.VpcDao;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.server.ConfigurationServer;
 import com.cloud.user.Account;
@@ -83,6 +85,9 @@ import com.cloud.vm.dao.NicDao;
 @Local(value = NetworkGuru.class)
 public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGuru, Configurable {
     private static final Logger s_logger = Logger.getLogger(GuestNetworkGuru.class);
+
+    @Inject
+    protected VpcDao _vpcDao;
     @Inject
     protected NetworkOrchestrationService _networkMgr;
     @Inject
@@ -130,8 +135,8 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
     }
 
     @Override
-    public boolean isMyTrafficType(TrafficType type) {
-        for (TrafficType t : TrafficTypes) {
+    public boolean isMyTrafficType(final TrafficType type) {
+        for (final TrafficType t : TrafficTypes) {
             if (t == type) {
                 return true;
             }
@@ -144,14 +149,14 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
         return TrafficTypes;
     }
 
-    public boolean isMyIsolationMethod(PhysicalNetwork physicalNetwork) {
+    public boolean isMyIsolationMethod(final PhysicalNetwork physicalNetwork) {
         if (physicalNetwork == null) {
             // Can't tell if there is no physical network
             return false;
         }
 
         List<String> methods = new ArrayList<String>();
-        for (String method : physicalNetwork.getIsolationMethods()) {
+        for (final String method : physicalNetwork.getIsolationMethods()) {
             methods.add(method.toLowerCase());
         }
         if (methods.isEmpty()) {
@@ -161,7 +166,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
             methods.add("VLAN".toLowerCase());
         }
 
-        for (IsolationMethod m : _isolationMethods) {
+        for (final IsolationMethod m : _isolationMethods) {
             if (methods.contains(m.toString().toLowerCase())) {
                 return true;
             }
@@ -177,19 +182,19 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
     protected abstract boolean canHandle(NetworkOffering offering, final NetworkType networkType, PhysicalNetwork physicalNetwork);
 
     @Override
-    public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
-        DataCenter dc = _dcDao.findById(plan.getDataCenterId());
-        PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
+    public Network design(final NetworkOffering offering, final DeploymentPlan plan, final Network userSpecified, final Account owner) {
+        final DataCenter dc = _dcDao.findById(plan.getDataCenterId());
+        final PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
 
         if (!canHandle(offering, dc.getNetworkType(), physnet)) {
             return null;
         }
 
-        NetworkVO network =
+        final NetworkVO network =
                 new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), State.Allocated, plan.getDataCenterId(),
                         plan.getPhysicalNetworkId(), offering.getRedundantRouter());
         if (userSpecified != null) {
-            if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || (userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
+            if (userSpecified.getCidr() == null && userSpecified.getGateway() != null || userSpecified.getCidr() != null && userSpecified.getGateway() == null) {
                 throw new InvalidParameterValueException("cidr and gateway must be specified together.");
             }
 
@@ -197,9 +202,9 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
                 network.setCidr(userSpecified.getCidr());
                 network.setGateway(userSpecified.getGateway());
             } else {
-                String guestNetworkCidr = dc.getGuestNetworkCidr();
+                final String guestNetworkCidr = dc.getGuestNetworkCidr();
                 if (guestNetworkCidr != null) {
-                    String[] cidrTuple = guestNetworkCidr.split("\\/");
+                    final String[] cidrTuple = guestNetworkCidr.split("\\/");
                     network.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])));
                     network.setCidr(guestNetworkCidr);
                 } else if (dc.getNetworkType() == NetworkType.Advanced) {
@@ -212,11 +217,11 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
                 network.setState(State.Setup);
             }
         } else {
-            String guestNetworkCidr = dc.getGuestNetworkCidr();
+            final String guestNetworkCidr = dc.getGuestNetworkCidr();
             if (guestNetworkCidr == null && dc.getNetworkType() == NetworkType.Advanced) {
                 throw new CloudRuntimeException("Can't design network " + network + "; guest CIDR is not configured per zone " + dc);
             }
-            String[] cidrTuple = guestNetworkCidr.split("\\/");
+            final String[] cidrTuple = guestNetworkCidr.split("\\/");
             network.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])));
             network.setCidr(guestNetworkCidr);
         }
@@ -226,7 +231,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
 
     @Override
     @DB
-    public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) {
+    public void deallocate(final Network network, final NicProfile nic, final VirtualMachineProfile vm) {
         if (network.getSpecifyIpRanges()) {
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Deallocate network: networkId: " + nic.getNetworkId() + ", ip: " + nic.getIp4Address());
@@ -236,7 +241,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
             if (ip != null) {
                 Transaction.execute(new TransactionCallbackNoReturn() {
                     @Override
-                    public void doInTransactionWithoutResult(TransactionStatus status) {
+                    public void doInTransactionWithoutResult(final TransactionStatus status) {
                         _ipAddrMgr.markIpAsUnavailable(ip.getId());
                         _ipAddressDao.unassignIpAddress(ip.getId());
                     }
@@ -246,8 +251,8 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
         }
     }
 
-    public int getVlanOffset(long physicalNetworkId, int vlanTag) {
-        PhysicalNetworkVO pNetwork = _physicalNetworkDao.findById(physicalNetworkId);
+    public int getVlanOffset(final long physicalNetworkId, final int vlanTag) {
+        final PhysicalNetworkVO pNetwork = _physicalNetworkDao.findById(physicalNetworkId);
         if (pNetwork == null) {
             throw new CloudRuntimeException("Could not find the physical Network " + physicalNetworkId + ".");
         }
@@ -256,9 +261,9 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
             throw new CloudRuntimeException("Could not find vlan range for physical Network " + physicalNetworkId + ".");
         }
         Integer lowestVlanTag = null;
-        List<Pair<Integer, Integer>> vnetList = pNetwork.getVnet();
+        final List<Pair<Integer, Integer>> vnetList = pNetwork.getVnet();
         //finding the vlanrange in which the vlanTag lies.
-        for (Pair<Integer, Integer> vnet : vnetList) {
+        for (final Pair<Integer, Integer> vnet : vnetList) {
             if (vlanTag >= vnet.first() && vlanTag <= vnet.second()) {
                 lowestVlanTag = vnet.first();
             }
@@ -271,17 +276,17 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
 
     public int getGloballyConfiguredCidrSize() {
         try {
-            String globalVlanBits = _configDao.getValue(Config.GuestVlanBits.key());
+            final String globalVlanBits = _configDao.getValue(Config.GuestVlanBits.key());
             return 8 + Integer.parseInt(globalVlanBits);
-        } catch (Exception e) {
+        } catch (final Exception e) {
             throw new CloudRuntimeException("Failed to read the globally configured VLAN bits size.");
         }
     }
 
-    protected void allocateVnet(Network network, NetworkVO implemented, long dcId, long physicalNetworkId, String reservationId)
+    protected void allocateVnet(final Network network, final NetworkVO implemented, final long dcId, final long physicalNetworkId, final String reservationId)
             throws InsufficientVirtualNetworkCapacityException {
         if (network.getBroadcastUri() == null) {
-            String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId, UseSystemGuestVlans.valueIn(network.getAccountId()));
+            final String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId, UseSystemGuestVlans.valueIn(network.getAccountId()));
             if (vnet == null) {
                 throw new InsufficientVirtualNetworkCapacityException("Unable to allocate vnet as a " + "part of network " + network + " implement ", DataCenter.class,
                         dcId);
@@ -295,11 +300,11 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
     }
 
     @Override
-    public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context)
+    public Network implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context)
             throws InsufficientVirtualNetworkCapacityException {
-        assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
+        assert network.getState() == State.Implementing : "Why are we implementing " + network;
 
-        long dcId = dest.getDataCenter().getId();
+        final long dcId = dest.getDataCenter().getId();
 
         //get physical network id
         Long physicalNetworkId = network.getPhysicalNetworkId();
@@ -309,7 +314,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
             physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
         }
 
-        NetworkVO implemented =
+        final NetworkVO implemented =
                 new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
                         network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
 
@@ -326,16 +331,16 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
     }
 
     @Override
-    public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException,
+    public NicProfile allocate(final Network network, NicProfile nic, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException,
     InsufficientAddressCapacityException {
 
-        assert (network.getTrafficType() == TrafficType.Guest) : "Look at my name!  Why are you calling" + " me when the traffic type is : " + network.getTrafficType();
+        assert network.getTrafficType() == TrafficType.Guest : "Look at my name!  Why are you calling" + " me when the traffic type is : " + network.getTrafficType();
 
         if (nic == null) {
             nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
         }
 
-        DataCenter dc = _dcDao.findById(network.getDataCenterId());
+        final DataCenter dc = _dcDao.findById(network.getDataCenterId());
 
         if (nic.getIp4Address() == null) {
             nic.setBroadcastUri(network.getBroadcastUri());
@@ -350,7 +355,9 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
                 boolean isGateway = false;
                 if (vm.getVirtualMachine().getType() == VirtualMachine.Type.DomainRouter) {
                     if (network.getVpcId() != null) {
-                        if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.VPCVirtualRouter)) {
+                        final Vpc vpc = _vpcDao.findById(network.getVpcId());
+                        // Redundant Networks need a guest IP that is not the same as the gateway IP.
+                        if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.VPCVirtualRouter) && !vpc.isRedundant()) {
                             isGateway = true;
                         }
                     } else {
@@ -392,8 +399,8 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
     }
 
     @Override
-    public void updateNicProfile(NicProfile profile, Network network) {
-        DataCenter dc = _dcDao.findById(network.getDataCenterId());
+    public void updateNicProfile(final NicProfile profile, final Network network) {
+        final DataCenter dc = _dcDao.findById(network.getDataCenterId());
         if (profile != null) {
             profile.setDns1(dc.getDns1());
             profile.setDns2(dc.getDns2());
@@ -401,23 +408,23 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
     }
 
     @Override
-    public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
+    public void reserve(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context)
             throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
-        assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? ";
+        assert nic.getReservationStrategy() == ReservationStrategy.Start : "What can I do for nics that are not allocated at start? ";
 
         nic.setBroadcastUri(network.getBroadcastUri());
         nic.setIsolationUri(network.getBroadcastUri());
     }
 
     @Override
-    public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
+    public boolean release(final NicProfile nic, final VirtualMachineProfile vm, final String reservationId) {
         nic.setBroadcastUri(null);
         nic.setIsolationUri(null);
         return true;
     }
 
     @Override
-    public void shutdown(NetworkProfile profile, NetworkOffering offering) {
+    public void shutdown(final NetworkProfile profile, final NetworkOffering offering) {
         if (profile.getBroadcastUri() == null) {
             return; // Nothing to do here if the uri is null already
         }
@@ -434,13 +441,13 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
     }
 
     @Override
-    public boolean trash(Network network, NetworkOffering offering) {
+    public boolean trash(final Network network, final NetworkOffering offering) {
         return true;
     }
 
     @Override
-    public void updateNetworkProfile(NetworkProfile networkProfile) {
-        DataCenter dc = _dcDao.findById(networkProfile.getDataCenterId());
+    public void updateNetworkProfile(final NetworkProfile networkProfile) {
+        final DataCenter dc = _dcDao.findById(networkProfile.getDataCenterId());
         networkProfile.setDns1(dc.getDns1());
         networkProfile.setDns2(dc.getDns2());
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e7e1f47e/server/src/com/cloud/network/router/NetworkHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/NetworkHelper.java b/server/src/com/cloud/network/router/NetworkHelper.java
index 4ee5b85..073f32f 100644
--- a/server/src/com/cloud/network/router/NetworkHelper.java
+++ b/server/src/com/cloud/network/router/NetworkHelper.java
@@ -31,7 +31,9 @@ import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.InsufficientServerCapacityException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.exception.StorageUnavailableException;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.network.Network;
+import com.cloud.storage.VMTemplateVO;
 import com.cloud.user.Account;
 import com.cloud.user.User;
 import com.cloud.vm.DomainRouterVO;
@@ -81,6 +83,12 @@ public interface NetworkHelper {
                     InsufficientServerCapacityException, InsufficientCapacityException,
                     StorageUnavailableException, ResourceUnavailableException;
 
-    public abstract LinkedHashMap<Network, List<? extends NicProfile>> createRouterNetworks(RouterDeploymentDefinition routerDeploymentDefinition)
+    public abstract void reallocateRouterNetworks(RouterDeploymentDefinition routerDeploymentDefinition, VirtualRouter router, VMTemplateVO template, HypervisorType hType)
+            throws ConcurrentOperationException, InsufficientAddressCapacityException, InsufficientCapacityException;
+
+    public abstract LinkedHashMap<Network, List<? extends NicProfile>> configureDefaultNics(RouterDeploymentDefinition routerDeploymentDefinition)
+            throws ConcurrentOperationException, InsufficientAddressCapacityException;
+
+    public abstract LinkedHashMap<Network, List<? extends NicProfile>> configureGuestNic(RouterDeploymentDefinition routerDeploymentDefinition)
             throws ConcurrentOperationException, InsufficientAddressCapacityException;
 }
\ No newline at end of file


Mime
View raw message