CLOUDSTACK-3124: Deletion of ACL associated with a tier/ pvt gateway should not be allowed. Check for associated tiers/gateways before deletion
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/da000661 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/da000661 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/da000661 Branch: refs/heads/vmsync Commit: da0006618f5bd33cea1e51e65208ade2ebcfaf7b Parents: e9df9c2 Author: Kishan Kavala <kis...@cloud.com> Authored: Mon Jun 24 17:53:15 2013 +0530 Committer: Kishan Kavala <kis...@cloud.com> Committed: Mon Jun 24 17:58:29 2013 +0530 ---------------------------------------------------------------------- .../src/com/cloud/network/vpc/dao/VpcGatewayDao.java | 2 ++ .../com/cloud/network/vpc/dao/VpcGatewayDaoImpl.java | 8 ++++++++ .../com/cloud/network/vpc/NetworkACLManagerImpl.java | 12 ++++++++++++ 3 files changed, 22 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/da000661/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDao.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDao.java index 24d9deb..42144b6 100644 --- a/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDao.java +++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDao.java @@ -30,4 +30,6 @@ public interface VpcGatewayDao extends GenericDao<VpcGatewayVO, Long>{ Long getNetworkAclIdForPrivateIp(long vpcId, long networkId, String ipaddr); List<VpcGatewayVO> listByVpcIdAndType(long vpcId, VpcGateway.Type type); + + List<VpcGatewayVO> listByAclIdAndType(long aclId, VpcGateway.Type type); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/da000661/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDaoImpl.java b/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDaoImpl.java index 6a2f8bd..a8cb2b3 100644 --- a/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDaoImpl.java +++ b/engine/schema/src/com/cloud/network/vpc/dao/VpcGatewayDaoImpl.java @@ -41,6 +41,7 @@ public class VpcGatewayDaoImpl extends GenericDaoBase<VpcGatewayVO, Long> implem AllFieldsSearch.and("type", AllFieldsSearch.entity().getType(), SearchCriteria.Op.EQ); AllFieldsSearch.and("networkid", AllFieldsSearch.entity().getNetworkId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("ipaddress", AllFieldsSearch.entity().getIp4Address(), SearchCriteria.Op.EQ); + AllFieldsSearch.and("aclId", AllFieldsSearch.entity().getNetworkACLId(), SearchCriteria.Op.EQ); AllFieldsSearch.done(); } @@ -86,4 +87,11 @@ public class VpcGatewayDaoImpl extends GenericDaoBase<VpcGatewayVO, Long> implem return listBy(sc); } + @Override + public List<VpcGatewayVO> listByAclIdAndType(long aclId, VpcGateway.Type type) { + SearchCriteria<VpcGatewayVO> sc = AllFieldsSearch.create(); + sc.setParameters("aclId", aclId); + sc.setParameters("type", type); + return listBy(sc); + } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/da000661/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java b/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java index c2d092a..4881b73 100644 --- a/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java +++ b/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java @@ -122,6 +122,18 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana if(aclItems.size() > 0){ throw new CloudRuntimeException("ACL is not empty. Cannot delete network ACL: "+acl.getUuid()); } + + List<NetworkVO> networks = _networkDao.listByAclId(acl.getId()); + if(networks != null && networks.size() > 0){ + throw new CloudRuntimeException("ACL is still associated with "+networks.size()+" tier(s). Cannot delete network ACL: "+acl.getUuid()); + } + + List<VpcGatewayVO> pvtGateways = _vpcGatewayDao.listByAclIdAndType(acl.getId(), VpcGateway.Type.Private); + + if(pvtGateways != null && pvtGateways.size() > 0){ + throw new CloudRuntimeException("ACL is still associated with "+pvtGateways.size()+" private gateway(s). Cannot delete network ACL: "+acl.getUuid()); + } + return _networkACLDao.remove(acl.getId()); }