diff --git a/api/src/com/cloud/network/element/VpcProvider.java b/api/src/com/cloud/network/element/VpcProvider.java index acdd05d063c..dc7b3bb3094 100644 --- a/api/src/com/cloud/network/element/VpcProvider.java +++ b/api/src/com/cloud/network/element/VpcProvider.java @@ -24,6 +24,7 @@ import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientNetworkCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.vpc.NetworkACLItem; import com.cloud.network.vpc.PrivateGateway; import com.cloud.network.vpc.StaticRouteProfile; import com.cloud.network.vpc.Vpc; @@ -53,5 +54,5 @@ public interface VpcProvider extends NetworkElement{ boolean applyStaticRoutes(Vpc vpc, List routes) throws ResourceUnavailableException; - boolean applyACLItemsToPrivateGw(PrivateGateway gateway) throws ResourceUnavailableException; + boolean applyACLItemsToPrivateGw(PrivateGateway gateway, List rules) throws ResourceUnavailableException; } diff --git a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java index 51c527c9152..966710c36c9 100644 --- a/server/src/com/cloud/network/element/VpcVirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VpcVirtualRouterElement.java @@ -343,7 +343,8 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc if ( _vpcRouterMgr.setupPrivateGateway(gateway, router) ) { try { - if (!applyACLItemsToPrivateGw(gateway)) { + List rules = _networkACLItemDao.listByACL(gateway.getNetworkACLId()); + if (!applyACLItemsToPrivateGw(gateway, rules)) { s_logger.debug ("Failed to apply network acl id "+ gateway.getNetworkACLId() + " on gateway "); return false; } @@ -446,9 +447,8 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc } @Override - public boolean applyACLItemsToPrivateGw(PrivateGateway gateway) throws ResourceUnavailableException { + public boolean applyACLItemsToPrivateGw(PrivateGateway gateway,List rules) throws ResourceUnavailableException { VpcGatewayVO vpcGatewayVo = _vpcGatewayDao.findById(gateway.getId()); - List rules = _networkACLItemDao.listByACL(vpcGatewayVo.getNetworkACLId()); Network config = _networkDao.findById(gateway.getNetworkId()); boolean isPrivateGateway = true; diff --git a/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java b/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java index eb18eb7f515..5c45a86c6d6 100644 --- a/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java +++ b/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java @@ -153,6 +153,17 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana @Override public boolean replaceNetworkACLForPrivateGw(NetworkACL acl, PrivateGateway gateway) throws ResourceUnavailableException { VpcGatewayVO vpcGatewayVo = _vpcGatewayDao.findById(gateway.getId()); + List aclItems = _networkACLItemDao.listByACL(acl.getId()); + if (aclItems == null || aclItems.isEmpty()) { + //Revoke ACL Items of the existing ACL if the new network acl is empty + //Other wise existing rules will not be removed on the router elelment + s_logger.debug("New network ACL is empty. Revoke existing rules before applying ACL"); + if(!revokeACLItemsForPrivateGw (gateway)){ + throw new CloudRuntimeException("Failed to replace network ACL. Error while removing existing ACL " + + "items for privatewa gateway: "+ gateway.getId()); + } + } + vpcGatewayVo.setNetworkACLId(acl.getId()); if (_vpcGatewayDao.update(vpcGatewayVo.getId(),vpcGatewayVo)) { return applyACLToPrivateGw(gateway); @@ -318,7 +329,7 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } } - boolean success = applyACLItemsToPrivateGw(gateway, aclItems); + boolean success = applyACLToPrivateGw(gateway, aclItems); if (s_logger.isDebugEnabled() && success) { s_logger.debug("Successfully released Network ACLs for private gateway id=" + gateway.getId() + " and # of rules now = " @@ -345,11 +356,11 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana @Override public boolean applyACLToPrivateGw(PrivateGateway gateway) throws ResourceUnavailableException { VpcGatewayVO vpcGatewayVO = _vpcGatewayDao.findById(gateway.getId()); - List rules = _networkACLItemDao.listByACL(vpcGatewayVO.getNetworkACLId()); - return applyACLItemsToPrivateGw(gateway, rules); + List rules = _networkACLItemDao.listByACL(vpcGatewayVO.getNetworkACLId()); + return applyACLToPrivateGw(gateway, rules); } - private boolean applyACLItemsToPrivateGw(PrivateGateway gateway, List rules) throws ResourceUnavailableException { + private boolean applyACLToPrivateGw(PrivateGateway gateway, List rules) throws ResourceUnavailableException { List vpcElements = null; vpcElements = new ArrayList(); vpcElements.add((VpcProvider)_ntwkModel.getElementImplementingProvider(Network.Provider.VPCVirtualRouter.getName())); @@ -359,7 +370,7 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } for (VpcProvider provider: vpcElements){ - return provider.applyACLItemsToPrivateGw(gateway); + return provider.applyACLItemsToPrivateGw(gateway, rules); } return false; }