Skip to content

Commit d90be0d

Browse files
author
Sheng Yang
committed
S2S VPN: CS-15748: Deleting customer vpn gateway when delete account
Conflicts: server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
1 parent 5f2bbf0 commit d90be0d

5 files changed

Lines changed: 46 additions & 7 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.cloud.network.dao;
22

3+
import java.util.List;
4+
35
import com.cloud.network.Site2SiteCustomerGatewayVO;
46
import com.cloud.utils.db.GenericDao;
57

68
public interface Site2SiteCustomerGatewayDao extends GenericDao<Site2SiteCustomerGatewayVO, Long> {
79
Site2SiteCustomerGatewayVO findByGatewayIp(String ip);
810
Site2SiteCustomerGatewayVO findByName(String name);
11+
List<Site2SiteCustomerGatewayVO> listByAccountId(long accountId);
912
}

‎server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.cloud.network.dao;
22

3+
import java.util.List;
4+
35
import javax.ejb.Local;
46

57
import org.apache.log4j.Logger;
@@ -19,6 +21,7 @@ protected Site2SiteCustomerGatewayDaoImpl() {
1921
AllFieldsSearch = createSearchBuilder();
2022
AllFieldsSearch.and("gatewayIp", AllFieldsSearch.entity().getGatewayIp(), SearchCriteria.Op.EQ);
2123
AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), SearchCriteria.Op.EQ);
24+
AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
2225
AllFieldsSearch.done();
2326
}
2427

@@ -36,4 +39,10 @@ public Site2SiteCustomerGatewayVO findByName(String name) {
3639
return findOneBy(sc);
3740
}
3841

42+
@Override
43+
public List<Site2SiteCustomerGatewayVO> listByAccountId(long accountId) {
44+
SearchCriteria<Site2SiteCustomerGatewayVO> sc = AllFieldsSearch.create();
45+
sc.setParameters("accountId", accountId);
46+
return listBy(sc, null);
47+
}
3948
}

‎server/src/com/cloud/network/vpn/Site2SiteVpnManager.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ public interface Site2SiteVpnManager extends Site2SiteVpnService {
1010
boolean cleanupVpnGatewayByVpc(long vpcId);
1111
void markDisconnectVpnConnByVpc(long vpcId);
1212
List<Site2SiteVpnConnectionVO> getConnectionsForRouter(DomainRouterVO router);
13+
boolean deleteCustomerGatewayByAccount(long accountId);
1314
}

‎server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import com.cloud.user.AccountManager;
5151
import com.cloud.user.UserContext;
5252
import com.cloud.user.dao.AccountDao;
53-
import com.cloud.utils.IdentityProxy;
5453
import com.cloud.utils.Ternary;
5554
import com.cloud.utils.component.Inject;
5655
import com.cloud.utils.component.Manager;
@@ -207,10 +206,8 @@ public Site2SiteVpnConnection createVpnConnection(CreateVpnConnectionCmd cmd) th
207206
+ vpnGatewayId + " already existed!");
208207
}
209208
if (_vpnConnectionDao.findByCustomerGatewayId(customerGatewayId) != null) {
210-
List<IdentityProxy> idList = new ArrayList<IdentityProxy>();
211-
// idList.add(new IdentityProxy(customerGateway, customerGatewayId, "customerGatewayId"));
212-
// throw new InvalidParameterValueException("The vpn connection with specified customer gateway id " +
213-
// " already exists!", idList);
209+
throw new InvalidParameterValueException("The vpn connection with specified customer gateway id " + customerGatewayId +
210+
" already exists!");
214211
}
215212
Site2SiteVpnConnectionVO conn = new Site2SiteVpnConnectionVO(owner.getAccountId(), owner.getDomainId(), vpnGatewayId, customerGatewayId);
216213
conn.setState(State.Pending);
@@ -263,9 +260,14 @@ public boolean deleteCustomerGateway(DeleteVpnCustomerGatewayCmd cmd) {
263260
}
264261
_accountMgr.checkAccess(caller, null, false, customerGateway);
265262

263+
return doDeleteCustomerGateway(customerGateway);
264+
}
265+
266+
protected boolean doDeleteCustomerGateway(Site2SiteCustomerGateway gw) {
267+
long id = gw.getId();
266268
List<Site2SiteVpnConnectionVO> vpnConnections = _vpnConnectionDao.listByCustomerGatewayId(id);
267269
if (vpnConnections != null && vpnConnections.size() != 0) {
268-
throw new InvalidParameterValueException("Unable to delete VPN customer gateway " + id + " because there is still related VPN connections!");
270+
throw new InvalidParameterValueException("Unable to delete VPN customer gateway with id " + id + " because there is still related VPN connections!");
269271
}
270272
_customerGatewayDao.remove(id);
271273
return true;
@@ -596,4 +598,14 @@ public List<Site2SiteVpnConnectionVO> getConnectionsForRouter(DomainRouterVO rou
596598
conns.addAll(_vpnConnectionDao.listByVpcId(vpcId));
597599
return conns;
598600
}
601+
602+
@Override
603+
public boolean deleteCustomerGatewayByAccount(long accountId) {
604+
boolean result = true;;
605+
List<Site2SiteCustomerGatewayVO> gws = _customerGatewayDao.listByAccountId(accountId);
606+
for (Site2SiteCustomerGatewayVO gw : gws) {
607+
result = result & doDeleteCustomerGateway(gw);
608+
}
609+
return result;
610+
}
599611
}

‎server/src/com/cloud/user/AccountManagerImpl.java‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,22 @@
7474
import com.cloud.network.NetworkManager;
7575
import com.cloud.network.NetworkVO;
7676
import com.cloud.network.RemoteAccessVpnVO;
77+
import com.cloud.network.Site2SiteCustomerGatewayVO;
78+
import com.cloud.network.Site2SiteVpnConnectionVO;
7779
import com.cloud.network.VpnUserVO;
7880
import com.cloud.network.dao.IPAddressDao;
7981
import com.cloud.network.dao.NetworkDao;
8082
import com.cloud.network.dao.RemoteAccessVpnDao;
83+
import com.cloud.network.dao.Site2SiteCustomerGatewayDao;
84+
import com.cloud.network.dao.Site2SiteVpnConnectionDao;
85+
import com.cloud.network.dao.Site2SiteVpnGatewayDao;
8186
import com.cloud.network.dao.VpnUserDao;
8287
import com.cloud.network.security.SecurityGroupManager;
8388
import com.cloud.network.security.dao.SecurityGroupDao;
8489
import com.cloud.network.vpc.Vpc;
8590
import com.cloud.network.vpc.VpcManager;
8691
import com.cloud.network.vpn.RemoteAccessVpnService;
92+
import com.cloud.network.vpn.Site2SiteVpnManager;
8793
import com.cloud.projects.Project;
8894
import com.cloud.projects.Project.ListProjectResourcesCriteria;
8995
import com.cloud.projects.ProjectInvitationVO;
@@ -211,6 +217,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
211217
private VpcManager _vpcMgr;
212218
@Inject
213219
private DomainRouterDao _routerDao;
220+
@Inject
221+
Site2SiteVpnManager _vpnMgr;
214222

215223
private Adapters<UserAuthenticator> _userAuthenticators;
216224

@@ -562,7 +570,7 @@ public boolean cleanupAccount(AccountVO account, long callerUserId, Account call
562570
s_logger.warn("Failed to cleanup remote access vpn resources as a part of account id=" + accountId + " cleanup due to Exception: ", ex);
563571
accountCleanupNeeded = true;
564572
}
565-
573+
566574
// Cleanup security groups
567575
int numRemoved = _securityGroupDao.removeByAccountId(accountId);
568576
s_logger.info("deleteAccount: Deleted " + numRemoved + " network groups for account " + accountId);
@@ -613,6 +621,12 @@ public boolean cleanupAccount(AccountVO account, long callerUserId, Account call
613621
}
614622
}
615623

624+
// Delete Site 2 Site VPN customer gateway
625+
s_logger.debug("Deleting site-to-site VPN customer gateways for account " + accountId);
626+
if (!_vpnMgr.deleteCustomerGatewayByAccount(accountId)) {
627+
s_logger.warn("Fail to delete site-to-site VPN customer gateways for account " + accountId);
628+
}
629+
616630
// delete account specific Virtual vlans (belong to system Public Network) - only when networks are cleaned
617631
// up successfully
618632
if (networksDeleted) {

0 commit comments

Comments
 (0)