cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [21/50] [abbrv] git commit: updated refs/heads/vpc-refactor to a8cb7c1
Date Fri, 03 Oct 2014 11:11:59 GMT
adding applyStaticRoutes to the new visitor pattern.


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

Branch: refs/heads/vpc-refactor
Commit: 0de16e0398725a659e02c1145820f979a24c4601
Parents: 51df3aa
Author: wrodrigues <wrodrigues@schubergphilis.com>
Authored: Tue Aug 19 18:04:24 2014 +0200
Committer: Wilder Rodrigues <wrodrigues@schubergphilis.com>
Committed: Fri Oct 3 06:21:27 2014 +0200

----------------------------------------------------------------------
 .../element/VpcVirtualRouterElement.java        |  5 +++-
 .../VpcVirtualNetworkApplianceManager.java      |  8 ------
 .../VpcVirtualNetworkApplianceManagerImpl.java  | 29 -------------------
 .../cloud/network/rules/StaticRoutesRules.java  |  3 +-
 .../rules/VirtualNetworkApplianceFactory.java   |  9 ++++++
 .../topology/AdvancedNetworkTopology.java       | 30 +++++++++++++++++---
 .../topology/AdvancedNetworkVisitor.java        | 10 +++++--
 .../MockVpcVirtualNetworkApplianceManager.java  |  9 ------
 8 files changed, 48 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0de16e03/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 5bc62c0..5504df3 100644
--- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
@@ -493,7 +493,10 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements
Vpc
             return true;
         }
 
-        if (!_vpcRouterMgr.applyStaticRoutes(routes, routers)) {
+        DataCenterVO dcVO = _dcDao.findById(vpc.getZoneId());
+        NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
+
+        if (!networkTopology.applyStaticRoutes(routes, routers)) {
             throw new CloudRuntimeException("Failed to apply static routes in vpc " + vpc);
         } else {
             s_logger.debug("Applied static routes on vpc " + vpc);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0de16e03/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java
index db8a1dc..7aecba5 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java
@@ -49,14 +49,6 @@ public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplian
     boolean destroyPrivateGateway(PrivateGateway gateway, VirtualRouter router) throws ConcurrentOperationException,
ResourceUnavailableException;
 
     /**
-     * @param routes
-     * @param routers
-     * @return
-     * @throws ResourceUnavailableException
-     */
-    boolean applyStaticRoutes(List<StaticRouteProfile> routes, List<DomainRouterVO>
routers) throws ResourceUnavailableException;
-
-    /**
      * @param conn
      * @param routers
      * @return

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0de16e03/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
index 9af35d6..b3993d9 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -774,35 +774,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
         }
     }
 
-    @Override
-    public boolean applyStaticRoutes(final List<StaticRouteProfile> staticRoutes, final
List<DomainRouterVO> routers) throws ResourceUnavailableException {
-        if (staticRoutes == null || staticRoutes.isEmpty()) {
-            s_logger.debug("No static routes to apply");
-            return true;
-        }
-
-        boolean result = true;
-        for (VirtualRouter router : routers) {
-            if (router.getState() == State.Running) {
-                result = result && sendStaticRoutes(staticRoutes, routers.get(0));
-            } else if (router.getState() == State.Stopped || router.getState() == State.Stopping)
{
-                s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState()
+ ", so not sending StaticRoute command to the backend");
-            } else {
-                s_logger.warn("Unable to apply StaticRoute, virtual router is not in the
right state " + router.getState());
-
-                throw new ResourceUnavailableException("Unable to apply StaticRoute on the
backend," + " virtual router is not in the right state", DataCenter.class,
-                        router.getDataCenterId());
-            }
-        }
-        return result;
-    }
-
-    protected boolean sendStaticRoutes(final List<StaticRouteProfile> staticRoutes,
final DomainRouterVO router) throws ResourceUnavailableException {
-        Commands cmds = new Commands(Command.OnError.Continue);
-        createStaticRouteCommands(staticRoutes, router, cmds);
-        return _nwHelper.sendCommandsToRouter(router, cmds);
-    }
-
     /**
      * @param staticRoutes
      * @param router

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0de16e03/server/src/com/cloud/network/rules/StaticRoutesRules.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/rules/StaticRoutesRules.java b/server/src/com/cloud/network/rules/StaticRoutesRules.java
index f7c4de9..b94cea2 100644
--- a/server/src/com/cloud/network/rules/StaticRoutesRules.java
+++ b/server/src/com/cloud/network/rules/StaticRoutesRules.java
@@ -28,7 +28,6 @@ import com.cloud.dc.DataCenterVO;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.router.VirtualRouter;
 import com.cloud.network.vpc.StaticRouteProfile;
-import com.cloud.vm.DomainRouterVO;
 
 public class StaticRoutesRules extends RuleApplier {
 
@@ -50,7 +49,7 @@ public class StaticRoutesRules extends RuleApplier {
         return visitor.visit(this);
     }
 
-    public void createStaticRouteCommands(final List<StaticRouteProfile> staticRoutes,
final DomainRouterVO router, final Commands cmds) {
+    public void createStaticRouteCommands(final List<StaticRouteProfile> staticRoutes,
final VirtualRouter router, final Commands cmds) {
         SetStaticRouteCommand cmd = new SetStaticRouteCommand(staticRoutes);
         cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _networkHelper.getRouterControlIp(router.getId()));
         cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0de16e03/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java b/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java
index 4815cbf..2ea092d 100644
--- a/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java
+++ b/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java
@@ -41,6 +41,7 @@ import com.cloud.network.router.NetworkHelper;
 import com.cloud.network.router.RouterControlHelper;
 import com.cloud.network.router.VirtualNetworkApplianceManager;
 import com.cloud.network.vpc.NetworkACLItem;
+import com.cloud.network.vpc.StaticRouteProfile;
 import com.cloud.network.vpc.VpcManager;
 import com.cloud.network.vpc.dao.VpcDao;
 import com.cloud.offerings.dao.NetworkOfferingDao;
@@ -303,4 +304,12 @@ public class VirtualNetworkApplianceFactory {
 
         return pvlanRules;
     }
+
+	public StaticRoutesRules createStaticRoutesRules(List<StaticRouteProfile> staticRoutes)
{
+		StaticRoutesRules routesRules = new StaticRoutesRules(staticRoutes);
+		
+		initBeans(routesRules);
+		
+		return routesRules;
+	}
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0de16e03/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
b/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
index bea28cf..8cc47d2 100644
--- a/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
+++ b/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
@@ -41,6 +41,7 @@ import com.cloud.network.rules.NetworkAclsRules;
 import com.cloud.network.rules.NicPlugInOutRules;
 import com.cloud.network.rules.RuleApplier;
 import com.cloud.network.rules.RuleApplierWrapper;
+import com.cloud.network.rules.StaticRoutesRules;
 import com.cloud.network.rules.UserdataPwdRules;
 import com.cloud.network.rules.VpcIpAssociationRules;
 import com.cloud.network.vpc.NetworkACLItem;
@@ -60,10 +61,31 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
     protected AdvancedNetworkVisitor _advancedVisitor;
 
     @Override
-    public boolean applyStaticRoutes(final List<StaticRouteProfile> staticRoutes,
-            final List<DomainRouterVO> routers) throws ResourceUnavailableException
{
-        // TODO Auto-generated method stub
-        return super.applyStaticRoutes(staticRoutes, routers);
+    public boolean applyStaticRoutes(final List<StaticRouteProfile> staticRoutes, final
List<DomainRouterVO> routers) throws ResourceUnavailableException {
+        
+    	if (staticRoutes == null || staticRoutes.isEmpty()) {
+            s_logger.debug("No static routes to apply");
+            return true;
+        }
+
+    	StaticRoutesRules routesRules = _virtualNetworkApplianceFactory.createStaticRoutesRules(staticRoutes);
+        
+        boolean result = true;
+        for (VirtualRouter router : routers) {
+            if (router.getState() == State.Running) {
+            	
+                result = result && routesRules.accept(_advancedVisitor, router);
+                
+            } else if (router.getState() == State.Stopped || router.getState() == State.Stopping)
{
+                s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState()
+ ", so not sending StaticRoute command to the backend");
+            } else {
+                s_logger.warn("Unable to apply StaticRoute, virtual router is not in the
right state " + router.getState());
+
+                throw new ResourceUnavailableException("Unable to apply StaticRoute on the
backend," + " virtual router is not in the right state", DataCenter.class,
+                        router.getDataCenterId());
+            }
+        }
+        return result;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0de16e03/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkVisitor.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkVisitor.java
b/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkVisitor.java
index d1e5175..464dd1f 100644
--- a/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkVisitor.java
+++ b/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkVisitor.java
@@ -41,6 +41,7 @@ import com.cloud.network.rules.StaticRoutesRules;
 import com.cloud.network.rules.UserdataPwdRules;
 import com.cloud.network.rules.VpcIpAssociationRules;
 import com.cloud.network.vpc.NetworkACLItem;
+import com.cloud.network.vpc.StaticRouteProfile;
 import com.cloud.vm.NicVO;
 import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VirtualMachineProfile;
@@ -164,7 +165,12 @@ public class AdvancedNetworkVisitor extends BasicNetworkVisitor {
 
     @Override
     public boolean visit(final StaticRoutesRules staticRoutesRules) throws ResourceUnavailableException
{
-
-        return false;
+    	final VirtualRouter router = staticRoutesRules.getRouter();
+    	List<StaticRouteProfile> staticRoutes = staticRoutesRules.getStaticRoutes();
+    	
+    	Commands cmds = new Commands(Command.OnError.Continue);
+    	staticRoutesRules.createStaticRouteCommands(staticRoutes, router, cmds);
+    	
+    	return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0de16e03/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java b/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
index 8802f9b..7153ed7 100644
--- a/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
+++ b/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
@@ -227,15 +227,6 @@ public class MockVpcVirtualNetworkApplianceManager extends ManagerBase
implement
     }
 
     /* (non-Javadoc)
-     * @see com.cloud.network.router.VpcVirtualNetworkApplianceManager#applyStaticRoutes(java.util.List,
java.util.List)
-     */
-    @Override
-    public boolean applyStaticRoutes(final List<StaticRouteProfile> routes, final List<DomainRouterVO>
routers) throws ResourceUnavailableException {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-    /* (non-Javadoc)
      * @see com.cloud.network.router.VpcVirtualNetworkApplianceManager#startSite2SiteVpn(com.cloud.network.Site2SiteVpnConnection,
com.cloud.network.router.VirtualRouter)
      */
     @Override


Mime
View raw message