incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yas...@apache.org
Subject [3/13] git commit: CS-15574: Delete VPN gateway and connection when deleting VPC
Date Mon, 23 Jul 2012 21:57:40 GMT
CS-15574: Delete VPN gateway and connection when deleting VPC

Conflicts:

	server/src/com/cloud/network/vpc/VpcManagerImpl.java


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

Branch: refs/heads/vpc
Commit: c357134330e3d7f10270678d8c623e9101ffbb6a
Parents: 7d68e33
Author: Sheng Yang <sheng.yang@citrix.com>
Authored: Tue Jul 17 18:05:31 2012 -0700
Committer: Sheng Yang <sheng.yang@citrix.com>
Committed: Mon Jul 23 14:45:42 2012 -0700

----------------------------------------------------------------------
 .../src/com/cloud/network/vpc/VpcManagerImpl.java  |   20 +++++++--
 .../com/cloud/network/vpn/Site2SiteVpnManager.java |    6 +++
 .../cloud/network/vpn/Site2SiteVpnManagerImpl.java |   33 ++++++++++++--
 3 files changed, 49 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c3571343/server/src/com/cloud/network/vpc/VpcManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpc/VpcManagerImpl.java b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
index 9e5cf3f..d6977f2 100644
--- a/server/src/com/cloud/network/vpc/VpcManagerImpl.java
+++ b/server/src/com/cloud/network/vpc/VpcManagerImpl.java
@@ -64,6 +64,7 @@ import com.cloud.network.addr.PublicIp;
 import com.cloud.network.dao.IPAddressDao;
 import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.dao.PhysicalNetworkDao;
+import com.cloud.network.dao.Site2SiteVpnConnectionDao;
 import com.cloud.network.dao.Site2SiteVpnGatewayDao;
 import com.cloud.network.element.VpcProvider;
 import com.cloud.network.vpc.VpcOffering.State;
@@ -73,6 +74,7 @@ import com.cloud.network.vpc.Dao.VpcDao;
 import com.cloud.network.vpc.Dao.VpcGatewayDao;
 import com.cloud.network.vpc.Dao.VpcOfferingDao;
 import com.cloud.network.vpc.Dao.VpcOfferingServiceMapDao;
+import com.cloud.network.vpn.Site2SiteVpnManager;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.offerings.NetworkOfferingServiceMapVO;
 import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
@@ -146,6 +148,8 @@ public class VpcManagerImpl implements VpcManager, Manager{
     FirewallRulesDao _firewallDao;
     @Inject
     Site2SiteVpnGatewayDao _vpnGatewayDao;
+    @Inject
+    Site2SiteVpnManager _s2sVpnMgr;
 
     private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1,
new NamedThreadFactory("VpcChecker"));
     
@@ -1003,8 +1007,14 @@ public class VpcManagerImpl implements VpcManager, Manager{
             throws ResourceUnavailableException, ConcurrentOperationException {
         s_logger.debug("Cleaning up resources for vpc id=" + vpcId);
         boolean success = true;
+
+        //1) Remove VPN connections and VPN gateway
+        s_logger.debug("Cleaning up existed site to site VPN connections");
+        _s2sVpnMgr.cleanupVpnConnectionByVpc(vpcId);
+        s_logger.debug("Cleaning up existed site to site VPN gateways");
+        _s2sVpnMgr.cleanupVpnGatewayByVpc(vpcId);
         
-        //1) release all ip addresses
+        //2) release all ip addresses
         List<IPAddressVO> ipsToRelease = _ipAddressDao.listByAssociatedVpc(vpcId, null);
         s_logger.debug("Releasing ips for vpc id=" + vpcId + " as a part of vpc cleanup");
         for (IPAddressVO ipToRelease : ipsToRelease) {
@@ -1020,14 +1030,14 @@ public class VpcManagerImpl implements VpcManager, Manager{
             s_logger.warn("Failed to release ip addresses for vpc id=" + vpcId + " as a part
of cleanup vpc process");
             //although it failed, proceed to the next cleanup step as it doesn't depend on
the public ip release
         }
-        
-        //2) Delete all static route rules
+
+        //3) Delete all static route rules
         if (!revokeStaticRoutesForVpc(vpcId, caller)) {
             s_logger.warn("Failed to revoke static routes for vpc " + vpcId + " as a part
of cleanup vpc process");
             return false;
         }
-        
-        //3) Delete private gateway
+
+        //4) Delete private gateway
         VpcGateway gateway = getPrivateGatewayForVpc(vpcId);
         if (gateway != null) {
             s_logger.debug("Deleting private gateway " + gateway + " as a part of vpc " +
vpcId + " resources cleanup");

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c3571343/server/src/com/cloud/network/vpn/Site2SiteVpnManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpn/Site2SiteVpnManager.java b/server/src/com/cloud/network/vpn/Site2SiteVpnManager.java
new file mode 100644
index 0000000..92820f1
--- /dev/null
+++ b/server/src/com/cloud/network/vpn/Site2SiteVpnManager.java
@@ -0,0 +1,6 @@
+package com.cloud.network.vpn;
+
+public interface Site2SiteVpnManager extends Site2SiteVpnService {
+    boolean cleanupVpnConnectionByVpc(long vpcId);
+    boolean cleanupVpnGatewayByVpc(long vpcId);
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c3571343/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
index b3de904..b3c3452 100644
--- a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
+++ b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
@@ -48,8 +48,8 @@ import com.cloud.utils.component.Manager;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.NetUtils;
 
-@Local(value = Site2SiteVpnService.class)
-public class Site2SiteVpnManagerImpl implements Site2SiteVpnService, Manager {
+@Local(value = Site2SiteVpnManager.class)
+public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager {
     private static final Logger s_logger = Logger.getLogger(Site2SiteVpnManagerImpl.class);
 
     @Inject Site2SiteCustomerGatewayDao _customerGatewayDao;
@@ -226,9 +226,7 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnService, Manager
{
         return true;
     }
 
-    @Override
-    public boolean deleteVpnGateway(DeleteVpnGatewayCmd cmd) {
-        Long id = cmd.getId();
+    protected void doDeleteVpnGateway(long id) {
         Site2SiteVpnGateway vpnGateway = _vpnGatewayDao.findById(id);
         if (vpnGateway == null) {
             throw new InvalidParameterValueException("Fail to find vpn gateway with " + id
+ " !");
@@ -238,6 +236,12 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnService,
Manager {
             throw new InvalidParameterValueException("Unable to delete VPN gateway " + id
+ " because there is still related VPN connections!");
         }
         _vpnGatewayDao.remove(id);
+    }
+    
+    @Override
+    public boolean deleteVpnGateway(DeleteVpnGatewayCmd cmd) {
+        Long id = cmd.getId();
+        doDeleteVpnGateway(id);
         return true;
     }
 
@@ -386,4 +390,23 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnService,
Manager {
         }
         return results;
     }
+
+    @Override
+    public boolean cleanupVpnConnectionByVpc(long vpcId) {
+        List<Site2SiteVpnConnectionVO> conns = _vpnConnectionDao.listByVpcId(vpcId);
+        for (Site2SiteVpnConnection conn : conns) {
+            _vpnConnectionDao.remove(conn.getId());
+        }
+        return true;
+    }
+
+    @Override
+    public boolean cleanupVpnGatewayByVpc(long vpcId) {
+        Site2SiteVpnGatewayVO gw = _vpnGatewayDao.findByVpcId(vpcId);
+        if (gw == null) {
+            return true;
+        }
+        doDeleteVpnGateway(gw.getId());
+        return true;
+    }
 }


Mime
View raw message