cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [19/50] [abbrv] git commit: updated refs/heads/master to 771d052
Date Tue, 14 Oct 2014 18:15:37 GMT
adding setupPrivateGateway to new style;
removing methods from Vpc appliance;
changing the way VpcElement calls the command;

there is still work tob e done with the destroyPrivateGateway rule.

Conflicts:
	server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java
	server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java
	server/src/org/apache/cloudstack/network/topology/NetworkTopology.java


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

Branch: refs/heads/master
Commit: 01edc8e394aa8d5ddd1da0898a7daa618409836e
Parents: b9bff84
Author: wrodrigues <wrodrigues@schubergphilis.com>
Authored: Wed Aug 20 18:13:33 2014 +0200
Committer: wilderrodrigues <wrodrigues@schubergphilis.com>
Committed: Tue Oct 14 15:02:13 2014 +0200

----------------------------------------------------------------------
 .../element/VpcVirtualRouterElement.java        |   5 +-
 .../VpcVirtualNetworkApplianceManager.java      |   9 --
 .../VpcVirtualNetworkApplianceManagerImpl.java  |  36 -----
 .../network/rules/PrivateGatewayRules.java      | 156 ++++++++++++++++++-
 .../com/cloud/network/rules/RuleApplier.java    |   9 ++
 .../rules/VirtualNetworkApplianceFactory.java   |  47 +++++-
 .../topology/AdvancedNetworkTopology.java       |  12 ++
 .../topology/AdvancedNetworkVisitor.java        |  47 +++++-
 .../network/topology/BasicNetworkTopology.java  |  15 +-
 .../network/topology/NetworkTopology.java       |  17 +-
 .../MockVpcVirtualNetworkApplianceManager.java  |   9 --
 11 files changed, 286 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/01edc8e3/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 5504df3..0f11c73 100644
--- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
+++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java
@@ -384,8 +384,11 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements
Vpc
         }
 
         VirtualRouter router = routers.get(0);
+        
+        DataCenterVO dcVO = _dcDao.findById(gateway.getZoneId());
+        NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
 
-        if (_vpcRouterMgr.setupPrivateGateway(gateway, router)) {
+        if (networkTopology.setupPrivateGateway(gateway, router)) {
             try {
                 List<NetworkACLItemVO> rules = _networkACLItemDao.listByACL(gateway.getNetworkACLId());
                 if (!applyACLItemsToPrivateGw(gateway, rules)) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/01edc8e3/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 7aecba5..5785263 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManager.java
@@ -32,15 +32,6 @@ public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplian
 
     /**
      * @param gateway
-     * @param router TODO
-     * @return
-     * @throws ResourceUnavailableException
-     * @throws ConcurrentOperationException
-     */
-    boolean setupPrivateGateway(PrivateGateway gateway, VirtualRouter router) throws ConcurrentOperationException,
ResourceUnavailableException;
-
-    /**
-     * @param gateway
      * @param router
      * @return
      * @throws ResourceUnavailableException

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/01edc8e3/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 dfdb4cc..1761699 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -649,42 +649,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
         return _nwHelper.sendCommandsToRouter(router, cmds);
     }
 
-    @Override
-    public boolean setupPrivateGateway(final PrivateGateway gateway, final VirtualRouter
router) throws ConcurrentOperationException, ResourceUnavailableException {
-        boolean result = true;
-        try {
-            Network network = _networkModel.getNetwork(gateway.getNetworkId());
-            NicProfile requested = vpcHelper.createPrivateNicProfileForGateway(gateway);
-
-            if (!_nwHelper.checkRouterVersion(router)) {
-                s_logger.warn("Router requires upgrade. Unable to send command to router:
" + router.getId());
-                return false;
-            }
-            NicProfile guestNic = _itMgr.addVmToNetwork(router, network, requested);
-
-            //setup source nat
-            if (guestNic != null) {
-                result = setupVpcPrivateNetwork(router, true, guestNic);
-            } else {
-                s_logger.warn("Failed to setup gateway " + gateway + " on router " + router
+ " with the source nat");
-                result = false;
-            }
-        } catch (Exception ex) {
-            s_logger.warn("Failed to create private gateway " + gateway + " on router " +
router + " due to ", ex);
-            result = false;
-        } finally {
-            if (!result) {
-                s_logger.debug("Removing gateway " + gateway + " from router " + router +
" as a part of cleanup");
-                if (destroyPrivateGateway(gateway, router)) {
-                    s_logger.debug("Removed the gateway " + gateway + " from router " + router
+ " as a part of cleanup");
-                } else {
-                    s_logger.warn("Failed to remove the gateway " + gateway + " from router
" + router + " as a part of cleanup");
-                }
-            }
-        }
-        return result;
-    }
-
     /**
      * @param router
      * @param add

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/01edc8e3/server/src/com/cloud/network/rules/PrivateGatewayRules.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/rules/PrivateGatewayRules.java b/server/src/com/cloud/network/rules/PrivateGatewayRules.java
index 364aded..f7a88ea 100644
--- a/server/src/com/cloud/network/rules/PrivateGatewayRules.java
+++ b/server/src/com/cloud/network/rules/PrivateGatewayRules.java
@@ -17,32 +17,172 @@
 
 package com.cloud.network.rules;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.cloudstack.network.topology.NetworkTopologyVisitor;
+import org.apache.log4j.Logger;
 
+import com.cloud.agent.api.routing.IpAssocVpcCommand;
+import com.cloud.agent.api.routing.NetworkElementCommand;
+import com.cloud.agent.api.to.IpAddressTO;
+import com.cloud.agent.manager.Commands;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.Network;
 import com.cloud.network.router.VirtualRouter;
-import com.cloud.network.vpc.NetworkACLItem;
+import com.cloud.network.vpc.PrivateGateway;
+import com.cloud.network.vpc.PrivateIpAddress;
+import com.cloud.network.vpc.PrivateIpVO;
+import com.cloud.user.Account;
+import com.cloud.vm.NicProfile;
 
 public class PrivateGatewayRules extends RuleApplier {
 
-    private final List<? extends NetworkACLItem> rules;
+	private static final Logger s_logger = Logger.getLogger(PrivateGatewayRules.class);
+	
+	private final PrivateGateway _privateGateway;
+	
+	private boolean _isAddOperation;
+	private NicProfile _nicProfile;
 
-    public PrivateGatewayRules(final Network network, final List<? extends NetworkACLItem>
rules) {
-        super(network);
-        this.rules = rules;
+    public PrivateGatewayRules(final PrivateGateway privateGateway) {
+        super(null);
+        this._privateGateway = privateGateway;
     }
 
     @Override
     public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router)
throws ResourceUnavailableException {
         this._router = router;
 
-        return visitor.visit(this);
+        boolean result = false;
+        try {
+            _network = _networkModel.getNetwork(_privateGateway.getNetworkId());
+            NicProfile requested = _vpcNetworkHelper.createPrivateNicProfileForGateway(_privateGateway);
+
+            if (!_networkHelper.checkRouterVersion(router)) {
+                s_logger.warn("Router requires upgrade. Unable to send command to router:
" + router.getId());
+                return false;
+            }
+            _nicProfile = _itMgr.addVmToNetwork(router, _network, requested);
+
+            //setup source nat
+            if (_nicProfile != null) {
+            	_isAddOperation = true;
+                //result = setupVpcPrivateNetwork(router, true, guestNic);
+                result = visitor.visit(this);
+            }
+        } catch (Exception ex) {
+            s_logger.warn("Failed to create private gateway " + _privateGateway + " on router
" + router + " due to ", ex);
+        } finally {
+            if (!result) {
+            	s_logger.debug("Failed to setup gateway " + _privateGateway + " on router "
+ router + " with the source nat. Will now remove the gateway.");
+            	_isAddOperation = false;
+            	boolean isRemoved = destroyPrivateGateway(visitor);
+            	
+                if (isRemoved) {
+                    s_logger.debug("Removed the gateway " + _privateGateway + " from router
" + router + " as a part of cleanup");
+                } else {
+                    s_logger.warn("Failed to remove the gateway " + _privateGateway + " from
router " + router + " as a part of cleanup");
+                }
+            }
+        }
+        return result;
+    }
+    
+    public boolean isAddOperation() {
+		return _isAddOperation;
+	}
+    
+    public NicProfile getNicProfile() {
+		return _nicProfile;
+	}
+
+    public PrivateIpVO retrivePrivateIP() {
+    	PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(_nicProfile.getNetworkId(),
_nicProfile.getIp4Address());
+    	return ipVO;
+    }
+    
+    public Network retrievePrivateNetwork() {
+    	// This network might be the same we have already as an instance in the RuleApplier
super class.
+    	// Just doing this here, but will double check is remove if it's not needed.
+    	Network network = _networkDao.findById(_nicProfile.getNetworkId());
+    	return network;
     }
 
-    public List<? extends NetworkACLItem> getRules() {
-        return rules;
+    protected boolean destroyPrivateGateway(final NetworkTopologyVisitor visitor) throws
ConcurrentOperationException, ResourceUnavailableException {
+
+        if (!_networkModel.isVmPartOfNetwork(_router.getId(), _privateGateway.getNetworkId()))
{
+            s_logger.debug("Router doesn't have nic for gateway " + _privateGateway + " so
no need to removed it");
+            return true;
+        }
+
+        Network privateNetwork = _networkModel.getNetwork(_privateGateway.getNetworkId());
+
+        s_logger.debug("Releasing private ip for gateway " + _privateGateway + " from " +
_router);
+
+        _nicProfile = _networkModel.getNicProfile(_router, privateNetwork.getId(), null);
+        boolean result = visitor.visit(this);
+        if (!result) {
+            s_logger.warn("Failed to release private ip for gateway " + _privateGateway +
" on router " + _router);
+            return false;
+        }
+
+        //revoke network acl on the private gateway.
+        if (!_networkACLMgr.revokeACLItemsForPrivateGw(_privateGateway)) {
+            s_logger.debug("Failed to delete network acl items on " + _privateGateway + "
from router " + _router);
+            return false;
+        }
+
+        s_logger.debug("Removing router " + _router + " from private network " + privateNetwork
+ " as a part of delete private gateway");
+        result = result && _itMgr.removeVmFromNetwork(_router, privateNetwork, null);
+        s_logger.debug("Private gateawy " + _privateGateway + " is removed from router "
+ _router);
+        return result;
+    }
+
+    public void createVpcAssociatePrivateIPCommands(final VirtualRouter router, final List<PrivateIpAddress>
ips, final Commands cmds, final boolean add) {
+
+        // Ensure that in multiple vlans case we first send all ip addresses of vlan1, then
all ip addresses of vlan2, etc..
+        Map<String, ArrayList<PrivateIpAddress>> vlanIpMap = new HashMap<String,
ArrayList<PrivateIpAddress>>();
+        for (final PrivateIpAddress ipAddress : ips) {
+            String vlanTag = ipAddress.getBroadcastUri();
+            ArrayList<PrivateIpAddress> ipList = vlanIpMap.get(vlanTag);
+            if (ipList == null) {
+                ipList = new ArrayList<PrivateIpAddress>();
+            }
+
+            ipList.add(ipAddress);
+            vlanIpMap.put(vlanTag, ipList);
+        }
+
+        for (Map.Entry<String, ArrayList<PrivateIpAddress>> vlanAndIp : vlanIpMap.entrySet())
{
+            List<PrivateIpAddress> ipAddrList = vlanAndIp.getValue();
+            IpAddressTO[] ipsToSend = new IpAddressTO[ipAddrList.size()];
+            int i = 0;
+
+            for (final PrivateIpAddress ipAddr : ipAddrList) {
+                Network network = _networkModel.getNetwork(ipAddr.getNetworkId());
+                IpAddressTO ip =
+                        new IpAddressTO(Account.ACCOUNT_ID_SYSTEM, ipAddr.getIpAddress(),
add, false, ipAddr.getSourceNat(), ipAddr.getBroadcastUri(), ipAddr.getGateway(),
+                                ipAddr.getNetmask(), ipAddr.getMacAddress(), null, false);
+
+                ip.setTrafficType(network.getTrafficType());
+                ip.setNetworkName(_networkModel.getNetworkTag(router.getHypervisorType(),
network));
+                ipsToSend[i++] = ip;
+
+            }
+
+            IpAssocVpcCommand cmd = new IpAssocVpcCommand(ipsToSend);
+            cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
+            cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(ipAddrList.get(0).getNetworkId(),
router.getId()));
+            cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
+            DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
+            cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
+
+            cmds.addCommand("IPAssocVpcCommand", cmd);
+        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/01edc8e3/server/src/com/cloud/network/rules/RuleApplier.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/rules/RuleApplier.java b/server/src/com/cloud/network/rules/RuleApplier.java
index 84ad5230..6abeb01 100644
--- a/server/src/com/cloud/network/rules/RuleApplier.java
+++ b/server/src/com/cloud/network/rules/RuleApplier.java
@@ -40,7 +40,10 @@ import com.cloud.network.lb.LoadBalancingRulesManager;
 import com.cloud.network.router.NetworkHelper;
 import com.cloud.network.router.RouterControlHelper;
 import com.cloud.network.router.VirtualRouter;
+import com.cloud.network.router.VpcNetworkHelper;
+import com.cloud.network.vpc.NetworkACLManager;
 import com.cloud.network.vpc.VpcManager;
+import com.cloud.network.vpc.dao.PrivateIpDao;
 import com.cloud.network.vpc.dao.VpcDao;
 import com.cloud.offerings.dao.NetworkOfferingDao;
 import com.cloud.service.dao.ServiceOfferingDao;
@@ -95,12 +98,16 @@ public abstract class RuleApplier {
 
     protected IPAddressDao _ipAddressDao;
 
+    protected PrivateIpDao _privateIpDao;
+
     protected VpcManager _vpcMgr;
 
     protected VirtualMachineManager _itMgr;
 
     protected IpAddressManager _ipAddrMgr;
 
+    protected NetworkACLManager _networkACLMgr;
+
     protected Network _network;
 
     protected VirtualRouter _router;
@@ -109,6 +116,8 @@ public abstract class RuleApplier {
 
     protected NetworkHelper _networkHelper;
 
+    protected VpcNetworkHelper _vpcNetworkHelper;
+
     public RuleApplier(final Network network) {
         _network = network;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/01edc8e3/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 2ea092d..207560b 100644
--- a/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java
+++ b/server/src/com/cloud/network/rules/VirtualNetworkApplianceFactory.java
@@ -30,6 +30,7 @@ import com.cloud.network.IpAddressManager;
 import com.cloud.network.Network;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.PublicIpAddress;
+import com.cloud.network.RemoteAccessVpn;
 import com.cloud.network.VpnUser;
 import com.cloud.network.dao.FirewallRulesDao;
 import com.cloud.network.dao.IPAddressDao;
@@ -41,8 +42,11 @@ 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.NetworkACLManager;
+import com.cloud.network.vpc.PrivateGateway;
 import com.cloud.network.vpc.StaticRouteProfile;
 import com.cloud.network.vpc.VpcManager;
+import com.cloud.network.vpc.dao.PrivateIpDao;
 import com.cloud.network.vpc.dao.VpcDao;
 import com.cloud.offerings.dao.NetworkOfferingDao;
 import com.cloud.service.dao.ServiceOfferingDao;
@@ -122,6 +126,9 @@ public class VirtualNetworkApplianceFactory {
     protected IPAddressDao _ipAddressDao;
 
     @Inject
+    protected PrivateIpDao _privateIpDao;
+
+    @Inject
     protected RouterControlHelper _routerControlHelper;
 
     @Inject
@@ -131,8 +138,14 @@ public class VirtualNetworkApplianceFactory {
     protected IpAddressManager _ipAddrMgr;
 
     @Inject
+    protected NetworkACLManager _networkACLMgr;
+
+    @Inject
     protected NetworkHelper _networkHelper;
 
+    @Inject
+    protected VpcNetworkHelper _vpcNetworkHelper;
+
     public LoadBalancingRules createLoadBalancingRules(final Network network, final List<LoadBalancingRule>
rules) {
         LoadBalancingRules lbRules = new LoadBalancingRules(network, rules);
 
@@ -305,11 +318,31 @@ public class VirtualNetworkApplianceFactory {
         return pvlanRules;
     }
 
-	public StaticRoutesRules createStaticRoutesRules(List<StaticRouteProfile> staticRoutes)
{
-		StaticRoutesRules routesRules = new StaticRoutesRules(staticRoutes);
-		
-		initBeans(routesRules);
-		
-		return routesRules;
-	}
+    public StaticRoutesRules createStaticRoutesRules(final List<StaticRouteProfile>
staticRoutes) {
+        StaticRoutesRules routesRules = new StaticRoutesRules(staticRoutes);
+
+        initBeans(routesRules);
+
+        return routesRules;
+    }
+
+    public AdvancedVpnRules createAdvancedVpnRules(final RemoteAccessVpn remoteAccessVpn,
final List<? extends VpnUser> users) {
+        AdvancedVpnRules vpnRules = new AdvancedVpnRules(remoteAccessVpn, users);
+
+        initBeans(vpnRules);
+
+        return vpnRules;
+    }
+
+    public PrivateGatewayRules createPrivateGatewayRules(final PrivateGateway gateway) {
+        PrivateGatewayRules gwRules = new PrivateGatewayRules(gateway);
+
+        initBeans(gwRules);
+
+        gwRules._privateIpDao = _privateIpDao;
+        gwRules._networkACLMgr = _networkACLMgr;
+        gwRules._vpcNetworkHelper = _vpcNetworkHelper;
+
+        return gwRules;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/01edc8e3/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 8cc47d2..13d1cb7 100644
--- a/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
+++ b/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
@@ -30,6 +30,7 @@ import com.cloud.dc.DataCenter.NetworkType;
 import com.cloud.dc.Pod;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.exception.AgentUnavailableException;
+import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.host.Status;
 import com.cloud.network.Network;
@@ -39,12 +40,14 @@ import com.cloud.network.rules.DhcpEntryRules;
 import com.cloud.network.rules.DhcpSubNetRules;
 import com.cloud.network.rules.NetworkAclsRules;
 import com.cloud.network.rules.NicPlugInOutRules;
+import com.cloud.network.rules.PrivateGatewayRules;
 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;
+import com.cloud.network.vpc.PrivateGateway;
 import com.cloud.network.vpc.StaticRouteProfile;
 import com.cloud.vm.DomainRouterVO;
 import com.cloud.vm.NicProfile;
@@ -117,6 +120,15 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
 
         return subNetRules.accept(_advancedVisitor, router);
     }
+    
+    @Override
+    public boolean setupPrivateGateway(PrivateGateway gateway, VirtualRouter router) throws
ConcurrentOperationException, ResourceUnavailableException {
+    	s_logger.debug("SETUP PRIVATE GATEWAY RULES");
+
+    	PrivateGatewayRules routesRules = _virtualNetworkApplianceFactory.createPrivateGatewayRules(gateway);
+
+    	return routesRules.accept(_advancedVisitor, router);
+    }
 
     @Override
     public boolean applyUserData(final Network network, final NicProfile nic, final VirtualMachineProfile
profile, final DeployDestination dest, final List<DomainRouterVO> routers)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/01edc8e3/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 464dd1f..1f94370 100644
--- a/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkVisitor.java
+++ b/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkVisitor.java
@@ -28,6 +28,7 @@ import com.cloud.agent.api.Command;
 import com.cloud.agent.api.PvlanSetupCommand;
 import com.cloud.agent.api.routing.IpAliasTO;
 import com.cloud.agent.manager.Commands;
+import com.cloud.dc.DataCenter;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.Network;
 import com.cloud.network.PublicIpAddress;
@@ -41,9 +42,14 @@ 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.PrivateIpAddress;
+import com.cloud.network.vpc.PrivateIpVO;
 import com.cloud.network.vpc.StaticRouteProfile;
+import com.cloud.utils.net.NetUtils;
+import com.cloud.vm.NicProfile;
 import com.cloud.vm.NicVO;
 import com.cloud.vm.UserVmVO;
+import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.dao.NicIpAliasVO;
 
@@ -123,7 +129,46 @@ public class AdvancedNetworkVisitor extends BasicNetworkVisitor {
 
     @Override
     public boolean visit(final PrivateGatewayRules privateGW) throws ResourceUnavailableException
{
-        return false;
+    	final VirtualRouter router = privateGW.getRouter();
+    	final NicProfile nicProfile = privateGW.getNicProfile();
+
+    	final boolean isAddOperation = privateGW.isAddOperation();
+
+    	if (router.getState() == State.Running) {
+    		
+            PrivateIpVO ipVO = privateGW.retrivePrivateIP();
+            Network network = privateGW.retrievePrivateNetwork();
+            
+            String netmask = NetUtils.getCidrNetmask(network.getCidr());
+            PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(),
network.getGateway(), netmask, nicProfile.getMacAddress());
+
+            List<PrivateIpAddress> privateIps = new ArrayList<PrivateIpAddress>(1);
+            privateIps.add(ip);
+            
+            Commands cmds = new Commands(Command.OnError.Stop);
+            privateGW.createVpcAssociatePrivateIPCommands(router, privateIps, cmds, isAddOperation);
+
+            try{
+                if (_networkGeneralHelper.sendCommandsToRouter(router, cmds)) {
+                    s_logger.debug("Successfully applied ip association for ip " + ip + "
in vpc network " + network);
+                    return true;
+                } else {
+                    s_logger.warn("Failed to associate ip address " + ip + " in vpc network
" + network);
+                    return false;
+                }
+            }catch (Exception ex) {
+                s_logger.warn("Failed to send  " + (isAddOperation ?"add ":"delete ") + "
private network " + network + " commands to rotuer ");
+                return false;
+            }
+        } else if (router.getState() == State.Stopped || router.getState() == State.Stopping)
{
+            s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState()
+ ", so not sending setup private network command to the backend");
+        } else {
+            s_logger.warn("Unable to setup private gateway, virtual router " + router + "
is not in the right state " + router.getState());
+
+            throw new ResourceUnavailableException("Unable to setup Private gateway on the
backend," + " virtual router " + router + " is not in the right state",
+                    DataCenter.class, router.getDataCenterId());
+        }
+        return true;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/01edc8e3/server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java b/server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java
index dd0cd15..6d05b56 100644
--- a/server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java
+++ b/server/src/org/apache/cloudstack/network/topology/BasicNetworkTopology.java
@@ -33,12 +33,14 @@ import com.cloud.dc.Pod;
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.exception.AgentUnavailableException;
+import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.host.Status;
 import com.cloud.host.dao.HostDao;
 import com.cloud.network.Network;
 import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.PublicIpAddress;
+import com.cloud.network.RemoteAccessVpn;
 import com.cloud.network.VpnUser;
 import com.cloud.network.lb.LoadBalancingRule;
 import com.cloud.network.router.NetworkHelper;
@@ -59,6 +61,7 @@ import com.cloud.network.rules.UserdataToRouterRules;
 import com.cloud.network.rules.VirtualNetworkApplianceFactory;
 import com.cloud.network.rules.VpnRules;
 import com.cloud.network.vpc.NetworkACLItem;
+import com.cloud.network.vpc.PrivateGateway;
 import com.cloud.network.vpc.StaticRouteProfile;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.DomainRouterVO;
@@ -104,8 +107,13 @@ public class BasicNetworkTopology implements NetworkTopology {
     }
 
     @Override
-    public NicProfile retrieveControlNic(final VirtualMachineProfile profile) {
-        return null;
+    public boolean setupPrivateGateway(final PrivateGateway gateway, final VirtualRouter
router) throws ConcurrentOperationException, ResourceUnavailableException {
+        throw new CloudRuntimeException("setupPrivateGateway not implemented in Basic Network
Topology.");
+    }
+
+    @Override
+    public String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser>
users, final VirtualRouter router) throws ResourceUnavailableException {
+        throw new CloudRuntimeException("applyVpnUsers not implemented in Basic Network Topology.");
     }
 
     @Override
@@ -410,7 +418,8 @@ public class BasicNetworkTopology implements NetworkTopology {
 
         if (!connectedRouters.isEmpty()) {
             if (!isZoneBasic && !disconnectedRouters.isEmpty() && disconnectedRouters.get(0).getIsRedundantRouter())
{
-                // These disconnected redundant virtual routers are out of sync now, stop
them for synchronization
+                // These disconnected redundant virtual routers are out of sync
+                // now, stop them for synchronization
                 _nwHelper.handleSingleWorkingRedundantRouter(connectedRouters, disconnectedRouters,
msg);
             }
         } else if (!disconnectedRouters.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/01edc8e3/server/src/org/apache/cloudstack/network/topology/NetworkTopology.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/network/topology/NetworkTopology.java b/server/src/org/apache/cloudstack/network/topology/NetworkTopology.java
index 3975878..4e9175e 100644
--- a/server/src/org/apache/cloudstack/network/topology/NetworkTopology.java
+++ b/server/src/org/apache/cloudstack/network/topology/NetworkTopology.java
@@ -21,6 +21,7 @@ import java.util.List;
 
 import com.cloud.dc.DataCenter;
 import com.cloud.deploy.DeployDestination;
+import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.network.Network;
 import com.cloud.network.PublicIpAddress;
@@ -32,6 +33,7 @@ import com.cloud.network.rules.RuleApplier;
 import com.cloud.network.rules.RuleApplierWrapper;
 import com.cloud.network.rules.StaticNat;
 import com.cloud.network.vpc.NetworkACLItem;
+import com.cloud.network.vpc.PrivateGateway;
 import com.cloud.network.vpc.StaticRouteProfile;
 import com.cloud.vm.DomainRouterVO;
 import com.cloud.vm.NicProfile;
@@ -39,6 +41,7 @@ import com.cloud.vm.VirtualMachineProfile;
 
 public interface NetworkTopology {
 
+<<<<<<< HEAD
     StringBuilder createGuestBootLoadArgs(final NicProfile guestNic, final String defaultDns1,
final String defaultDns2, DomainRouterVO router);
 
     String retrieveGuestDhcpRange(final NicProfile guestNic, final Network guestNetwork,
final DataCenter dc);
@@ -47,6 +50,9 @@ public interface NetworkTopology {
 
 
     // ====== USER FOR VPC ONLY ====== //
+=======
+    // ====== USED FOR VPC ONLY ====== //
+>>>>>>> 0b8b22f... adding setupPrivateGateway to new style;
 
     boolean setupDhcpForPvlan(final boolean add, final DomainRouterVO router, final Long
hostId, final NicProfile nic) throws ResourceUnavailableException;
 
@@ -57,8 +63,15 @@ public interface NetworkTopology {
             throws ResourceUnavailableException;
 
     boolean applyStaticRoutes(final List<StaticRouteProfile> staticRoutes, final List<DomainRouterVO>
routers) throws ResourceUnavailableException;
-
-    // ====== USER FOR GUEST NETWORK AND VCP ====== //
+<<<<<<< HEAD
+=======
+    
+    boolean setupPrivateGateway(final PrivateGateway gateway, final VirtualRouter router)
throws ConcurrentOperationException, ResourceUnavailableException;
+    
+    String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser>
users, final VirtualRouter router) throws ResourceUnavailableException;
+>>>>>>> 0b8b22f... adding setupPrivateGateway to new style;
+
+    // ====== USED FOR GUEST NETWORK AND VCP ====== //
 
     boolean applyDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile
profile, final DeployDestination dest, final List<DomainRouterVO> routers)
             throws ResourceUnavailableException;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/01edc8e3/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 7153ed7..fa780c0 100644
--- a/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
+++ b/server/test/com/cloud/vpc/MockVpcVirtualNetworkApplianceManager.java
@@ -209,15 +209,6 @@ public class MockVpcVirtualNetworkApplianceManager extends ManagerBase
implement
     }
 
     /* (non-Javadoc)
-     * @see com.cloud.network.router.VpcVirtualNetworkApplianceManager#setupPrivateGateway(com.cloud.network.vpc.PrivateGateway,
com.cloud.network.router.VirtualRouter)
-     */
-    @Override
-    public boolean setupPrivateGateway(final PrivateGateway gateway, final VirtualRouter
router) throws ConcurrentOperationException, ResourceUnavailableException {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-    /* (non-Javadoc)
      * @see com.cloud.network.router.VpcVirtualNetworkApplianceManager#destroyPrivateGateway(com.cloud.network.vpc.PrivateGateway,
com.cloud.network.router.VirtualRouter)
      */
     @Override


Mime
View raw message