CLOUDSTACK-3124: Deletion of ACL associated with a tier/ pvt gateway should not be allowed. Check for associated tiers/gateways before deletion

This commit is contained in:
Kishan Kavala 2013-06-24 17:53:15 +05:30
parent e9df9c29bd
commit da0006618f
3 changed files with 22 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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());
}