cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yas...@apache.org
Subject git commit: S2S VPN: CS-15748: Deleting customer vpn gateway when delete account
Date Mon, 30 Jul 2012 22:34:47 GMT
Updated Branches:
  refs/heads/vpc 5f2bbf0e2 -> d90be0d9b


S2S VPN: CS-15748: Deleting customer vpn gateway when delete account

Conflicts:

	server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.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/d90be0d9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/d90be0d9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/d90be0d9

Branch: refs/heads/vpc
Commit: d90be0d9bc04eb34f9fe9c9766dede62ddda7934
Parents: 5f2bbf0
Author: Sheng Yang <sheng.yang@citrix.com>
Authored: Mon Jul 30 11:48:30 2012 -0700
Committer: Sheng Yang <sheng.yang@citrix.com>
Committed: Mon Jul 30 15:34:41 2012 -0700

----------------------------------------------------------------------
 .../network/dao/Site2SiteCustomerGatewayDao.java   |    3 ++
 .../dao/Site2SiteCustomerGatewayDaoImpl.java       |    9 +++++
 .../com/cloud/network/vpn/Site2SiteVpnManager.java |    1 +
 .../cloud/network/vpn/Site2SiteVpnManagerImpl.java |   24 +++++++++++----
 server/src/com/cloud/user/AccountManagerImpl.java  |   16 +++++++++-
 5 files changed, 46 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d90be0d9/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDao.java b/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDao.java
index 5b39dbd..7854689 100644
--- a/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDao.java
+++ b/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDao.java
@@ -1,9 +1,12 @@
 package com.cloud.network.dao;
 
+import java.util.List;
+
 import com.cloud.network.Site2SiteCustomerGatewayVO;
 import com.cloud.utils.db.GenericDao;
 
 public interface Site2SiteCustomerGatewayDao extends GenericDao<Site2SiteCustomerGatewayVO,
Long> {
     Site2SiteCustomerGatewayVO findByGatewayIp(String ip);
     Site2SiteCustomerGatewayVO findByName(String name);
+    List<Site2SiteCustomerGatewayVO> listByAccountId(long accountId);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d90be0d9/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java b/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java
index 80b5c02..c3a4d94 100644
--- a/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java
+++ b/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java
@@ -1,5 +1,7 @@
 package com.cloud.network.dao;
 
+import java.util.List;
+
 import javax.ejb.Local;
 
 import org.apache.log4j.Logger;
@@ -19,6 +21,7 @@ public class Site2SiteCustomerGatewayDaoImpl extends GenericDaoBase<Site2SiteCus
         AllFieldsSearch = createSearchBuilder();
         AllFieldsSearch.and("gatewayIp", AllFieldsSearch.entity().getGatewayIp(), SearchCriteria.Op.EQ);
         AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
         AllFieldsSearch.done();
     }
     
@@ -36,4 +39,10 @@ public class Site2SiteCustomerGatewayDaoImpl extends GenericDaoBase<Site2SiteCus
         return findOneBy(sc);
     }
 
+    @Override
+    public List<Site2SiteCustomerGatewayVO> listByAccountId(long accountId) {
+        SearchCriteria<Site2SiteCustomerGatewayVO> sc = AllFieldsSearch.create();
+        sc.setParameters("accountId", accountId);
+        return listBy(sc, null);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d90be0d9/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
index 567b765..922ac2c 100644
--- a/server/src/com/cloud/network/vpn/Site2SiteVpnManager.java
+++ b/server/src/com/cloud/network/vpn/Site2SiteVpnManager.java
@@ -10,4 +10,5 @@ public interface Site2SiteVpnManager extends Site2SiteVpnService {
     boolean cleanupVpnGatewayByVpc(long vpcId);
     void markDisconnectVpnConnByVpc(long vpcId);
     List<Site2SiteVpnConnectionVO> getConnectionsForRouter(DomainRouterVO router);
+    boolean deleteCustomerGatewayByAccount(long accountId);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d90be0d9/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 b723d16..3b6e533 100644
--- a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
+++ b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
@@ -50,7 +50,6 @@ import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.UserContext;
 import com.cloud.user.dao.AccountDao;
-import com.cloud.utils.IdentityProxy;
 import com.cloud.utils.Ternary;
 import com.cloud.utils.component.Inject;
 import com.cloud.utils.component.Manager;
@@ -207,10 +206,8 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager,
Manager {
                     + vpnGatewayId + " already existed!");
         }
         if (_vpnConnectionDao.findByCustomerGatewayId(customerGatewayId) != null) {
-            List<IdentityProxy> idList = new ArrayList<IdentityProxy>();
-//            idList.add(new IdentityProxy(customerGateway, customerGatewayId, "customerGatewayId"));
-//            throw new InvalidParameterValueException("The vpn connection with specified
customer gateway id " +
-//                    " already exists!", idList);
+            throw new InvalidParameterValueException("The vpn connection with specified customer
gateway id " + customerGatewayId +
+                    " already exists!");
         }
         Site2SiteVpnConnectionVO conn = new Site2SiteVpnConnectionVO(owner.getAccountId(),
owner.getDomainId(), vpnGatewayId, customerGatewayId);
         conn.setState(State.Pending);
@@ -263,9 +260,14 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager,
Manager {
         }
         _accountMgr.checkAccess(caller, null, false, customerGateway);
         
+        return doDeleteCustomerGateway(customerGateway);
+    }
+
+    protected boolean doDeleteCustomerGateway(Site2SiteCustomerGateway gw) {
+        long id = gw.getId();
         List<Site2SiteVpnConnectionVO> vpnConnections = _vpnConnectionDao.listByCustomerGatewayId(id);
         if (vpnConnections != null && vpnConnections.size() != 0) {
-            throw new InvalidParameterValueException("Unable to delete VPN customer gateway
" + id + " because there is still related VPN connections!");
+            throw new InvalidParameterValueException("Unable to delete VPN customer gateway
with id " + id + " because there is still related VPN connections!");
         }
         _customerGatewayDao.remove(id);
         return true;
@@ -596,4 +598,14 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager,
Manager {
         conns.addAll(_vpnConnectionDao.listByVpcId(vpcId));
         return conns;
     }
+
+    @Override
+    public boolean deleteCustomerGatewayByAccount(long accountId) {
+        boolean result = true;;
+        List<Site2SiteCustomerGatewayVO> gws = _customerGatewayDao.listByAccountId(accountId);
+        for (Site2SiteCustomerGatewayVO gw : gws) {
+            result = result & doDeleteCustomerGateway(gw);
+        }
+        return result;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/d90be0d9/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java
index 503c45a..38153f3 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -74,16 +74,22 @@ import com.cloud.network.IpAddress;
 import com.cloud.network.NetworkManager;
 import com.cloud.network.NetworkVO;
 import com.cloud.network.RemoteAccessVpnVO;
+import com.cloud.network.Site2SiteCustomerGatewayVO;
+import com.cloud.network.Site2SiteVpnConnectionVO;
 import com.cloud.network.VpnUserVO;
 import com.cloud.network.dao.IPAddressDao;
 import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.dao.RemoteAccessVpnDao;
+import com.cloud.network.dao.Site2SiteCustomerGatewayDao;
+import com.cloud.network.dao.Site2SiteVpnConnectionDao;
+import com.cloud.network.dao.Site2SiteVpnGatewayDao;
 import com.cloud.network.dao.VpnUserDao;
 import com.cloud.network.security.SecurityGroupManager;
 import com.cloud.network.security.dao.SecurityGroupDao;
 import com.cloud.network.vpc.Vpc;
 import com.cloud.network.vpc.VpcManager;
 import com.cloud.network.vpn.RemoteAccessVpnService;
+import com.cloud.network.vpn.Site2SiteVpnManager;
 import com.cloud.projects.Project;
 import com.cloud.projects.Project.ListProjectResourcesCriteria;
 import com.cloud.projects.ProjectInvitationVO;
@@ -211,6 +217,8 @@ public class AccountManagerImpl implements AccountManager, AccountService,
Manag
     private VpcManager _vpcMgr;
     @Inject
     private DomainRouterDao _routerDao;
+    @Inject
+    Site2SiteVpnManager _vpnMgr;
 
     private Adapters<UserAuthenticator> _userAuthenticators;
 
@@ -562,7 +570,7 @@ public class AccountManagerImpl implements AccountManager, AccountService,
Manag
                 s_logger.warn("Failed to cleanup remote access vpn resources as a part of
account id=" + accountId + " cleanup due to Exception: ", ex);
                 accountCleanupNeeded = true;
             }
-
+            
             // Cleanup security groups
             int numRemoved = _securityGroupDao.removeByAccountId(accountId);
             s_logger.info("deleteAccount: Deleted " + numRemoved + " network groups for account
" + accountId);
@@ -613,6 +621,12 @@ public class AccountManagerImpl implements AccountManager, AccountService,
Manag
                 }
             }
 
+            // Delete Site 2 Site VPN customer gateway
+            s_logger.debug("Deleting site-to-site VPN customer gateways for account " + accountId);
+            if (!_vpnMgr.deleteCustomerGatewayByAccount(accountId)) {
+                s_logger.warn("Fail to delete site-to-site VPN customer gateways for account
" + accountId);
+            }
+
             // delete account specific Virtual vlans (belong to system Public Network) -
only when networks are cleaned
             // up successfully
             if (networksDeleted) {


Mime
View raw message