From 7b106db4b20c457c367a0ab31ca0f984b2d9f752 Mon Sep 17 00:00:00 2001 From: Wilder Rodrigues Date: Thu, 21 Jan 2016 15:51:30 +0100 Subject: [PATCH] CLOUDSTACK-9245 - Formatting NetworkACLManagerImpl class --- .../network/vpc/NetworkACLManagerImpl.java | 127 +++++++++--------- 1 file changed, 61 insertions(+), 66 deletions(-) diff --git a/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java b/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java index fe0d7773dff..24193a4754e 100644 --- a/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java +++ b/server/src/com/cloud/network/vpc/NetworkACLManagerImpl.java @@ -86,8 +86,8 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana MessageBus _messageBus; @Override - public NetworkACL createNetworkACL(String name, String description, long vpcId, Boolean forDisplay) { - NetworkACLVO acl = new NetworkACLVO(name, description, vpcId); + public NetworkACL createNetworkACL(final String name, final String description, final long vpcId, final Boolean forDisplay) { + final NetworkACLVO acl = new NetworkACLVO(name, description, vpcId); if (forDisplay != null) { acl.setDisplay(forDisplay); } @@ -95,23 +95,23 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } @Override - public boolean applyNetworkACL(long aclId) throws ResourceUnavailableException { + public boolean applyNetworkACL(final long aclId) throws ResourceUnavailableException { boolean handled = true; boolean aclApplyStatus = true; - List rules = _networkACLItemDao.listByACL(aclId); + final List rules = _networkACLItemDao.listByACL(aclId); //Find all networks using this ACL and apply the ACL - List networks = _networkDao.listByAclId(aclId); - for (NetworkVO network : networks) { + final List networks = _networkDao.listByAclId(aclId); + for (final NetworkVO network : networks) { if (!applyACLItemsToNetwork(network.getId(), rules)) { handled = false; break; } } - List vpcGateways = _vpcGatewayDao.listByAclIdAndType(aclId, VpcGateway.Type.Private); - for (VpcGatewayVO vpcGateway : vpcGateways) { - PrivateGateway privateGateway = _vpcSvc.getVpcPrivateGateway(vpcGateway.getId()); + final List vpcGateways = _vpcGatewayDao.listByAclIdAndType(aclId, VpcGateway.Type.Private); + for (final VpcGatewayVO vpcGateway : vpcGateways) { + final PrivateGateway privateGateway = _vpcSvc.getVpcPrivateGateway(vpcGateway.getId()); if (!applyACLToPrivateGw(privateGateway)) { aclApplyStatus = false; @@ -121,11 +121,11 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } if (handled && aclApplyStatus) { - for (NetworkACLItem rule : rules) { + for (final NetworkACLItem rule : rules) { if (rule.getState() == NetworkACLItem.State.Revoke) { removeRule(rule); } else if (rule.getState() == NetworkACLItem.State.Add) { - NetworkACLItemVO ruleVO = _networkACLItemDao.findById(rule.getId()); + final NetworkACLItemVO ruleVO = _networkACLItemDao.findById(rule.getId()); ruleVO.setState(NetworkACLItem.State.Active); _networkACLItemDao.update(ruleVO.getId(), ruleVO); } @@ -135,23 +135,18 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } @Override - public NetworkACL getNetworkACL(long id) { + public NetworkACL getNetworkACL(final long id) { return _networkACLDao.findById(id); } @Override - public boolean deleteNetworkACL(NetworkACL acl) { - List aclItems = _networkACLItemDao.listByACL(acl.getId()); - if (aclItems.size() > 0) { - throw new CloudRuntimeException("ACL is not empty. Cannot delete network ACL: " + acl.getUuid()); - } - - List networks = _networkDao.listByAclId(acl.getId()); + public boolean deleteNetworkACL(final NetworkACL acl) { + final List 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 pvtGateways = _vpcGatewayDao.listByAclIdAndType(acl.getId(), VpcGateway.Type.Private); + final List 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()); @@ -161,9 +156,9 @@ 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()); + public boolean replaceNetworkACLForPrivateGw(final NetworkACL acl, final PrivateGateway gateway) throws ResourceUnavailableException { + final VpcGatewayVO vpcGatewayVo = _vpcGatewayDao.findById(gateway.getId()); + final 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 @@ -182,9 +177,9 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } @Override - public boolean replaceNetworkACL(NetworkACL acl, NetworkVO network) throws ResourceUnavailableException { + public boolean replaceNetworkACL(final NetworkACL acl, final NetworkVO network) throws ResourceUnavailableException { - NetworkOffering guestNtwkOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId()); + final NetworkOffering guestNtwkOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId()); if (guestNtwkOff == null) { throw new InvalidParameterValueException("Can't find network offering associated with network: " + network.getUuid()); @@ -198,7 +193,7 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana if (network.getNetworkACLId() != null) { //Revoke ACL Items of the existing ACL if the new ACL is empty //Existing rules won't be removed otherwise - List aclItems = _networkACLItemDao.listByACL(acl.getId()); + final List aclItems = _networkACLItemDao.listByACL(acl.getId()); if (aclItems == null || aclItems.isEmpty()) { s_logger.debug("New network ACL is empty. Revoke existing rules before applying ACL"); if (!revokeACLItemsForNetwork(network.getId())) { @@ -212,7 +207,7 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana if (_networkDao.update(network.getId(), network)) { s_logger.debug("Updated network: " + network.getId() + " with Network ACL Id: " + acl.getId() + ", Applying ACL items"); //Apply ACL to network - Boolean result = applyACLToNetwork(network.getId()); + final Boolean result = applyACLToNetwork(network.getId()); if (result) { // public message on message bus, so that network elements implementing distributed routing capability // can act on the event @@ -234,16 +229,16 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } final Integer numberFinal = number; - NetworkACLItemVO newRule = Transaction.execute(new TransactionCallback() { + final NetworkACLItemVO newRule = Transaction.execute(new TransactionCallback() { @Override - public NetworkACLItemVO doInTransaction(TransactionStatus status) { + public NetworkACLItemVO doInTransaction(final TransactionStatus status) { NetworkACLItem.Action ruleAction = NetworkACLItem.Action.Allow; if ("deny".equalsIgnoreCase(action)) { ruleAction = NetworkACLItem.Action.Deny; } NetworkACLItemVO newRule = - new NetworkACLItemVO(portStart, portEnd, protocol.toLowerCase(), aclId, sourceCidrList, icmpCode, icmpType, trafficType, ruleAction, numberFinal); + new NetworkACLItemVO(portStart, portEnd, protocol.toLowerCase(), aclId, sourceCidrList, icmpCode, icmpType, trafficType, ruleAction, numberFinal); if (forDisplay != null) { newRule.setDisplay(forDisplay); @@ -264,14 +259,14 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } @Override - public NetworkACLItem getNetworkACLItem(long ruleId) { + public NetworkACLItem getNetworkACLItem(final long ruleId) { return _networkACLItemDao.findById(ruleId); } @Override - public boolean revokeNetworkACLItem(long ruleId) { + public boolean revokeNetworkACLItem(final long ruleId) { - NetworkACLItemVO rule = _networkACLItemDao.findById(ruleId); + final NetworkACLItemVO rule = _networkACLItemDao.findById(ruleId); revokeRule(rule); @@ -280,7 +275,7 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana try { applyNetworkACL(rule.getAclId()); success = true; - } catch (ResourceUnavailableException e) { + } catch (final ResourceUnavailableException e) { return false; } @@ -288,7 +283,7 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } @DB - private void revokeRule(NetworkACLItemVO rule) { + private void revokeRule(final NetworkACLItemVO rule) { if (rule.getState() == State.Staged) { if (s_logger.isDebugEnabled()) { s_logger.debug("Found a rule that is still in stage state so just removing it: " + rule); @@ -301,12 +296,12 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } @Override - public boolean revokeACLItemsForNetwork(long networkId) throws ResourceUnavailableException { - Network network = _networkDao.findById(networkId); + public boolean revokeACLItemsForNetwork(final long networkId) throws ResourceUnavailableException { + final Network network = _networkDao.findById(networkId); if (network.getNetworkACLId() == null) { return true; } - List aclItems = _networkACLItemDao.listByACL(network.getNetworkACLId()); + final List aclItems = _networkACLItemDao.listByACL(network.getNetworkACLId()); if (aclItems.isEmpty()) { s_logger.debug("Found no network ACL Items for network id=" + networkId); return true; @@ -316,14 +311,14 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana s_logger.debug("Releasing " + aclItems.size() + " Network ACL Items for network id=" + networkId); } - for (NetworkACLItemVO aclItem : aclItems) { + for (final NetworkACLItemVO aclItem : aclItems) { // Mark all Network ACLs rules as Revoke, but don't update in DB if (aclItem.getState() == State.Add || aclItem.getState() == State.Active) { aclItem.setState(State.Revoke); } } - boolean success = applyACLItemsToNetwork(network.getId(), aclItems); + final boolean success = applyACLItemsToNetwork(network.getId(), aclItems); if (s_logger.isDebugEnabled() && success) { s_logger.debug("Successfully released Network ACLs for network id=" + networkId + " and # of rules now = " + aclItems.size()); @@ -333,9 +328,9 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } @Override - public boolean revokeACLItemsForPrivateGw(PrivateGateway gateway) throws ResourceUnavailableException { + public boolean revokeACLItemsForPrivateGw(final PrivateGateway gateway) throws ResourceUnavailableException { - List aclItems = _networkACLItemDao.listByACL(gateway.getNetworkACLId()); + final List aclItems = _networkACLItemDao.listByACL(gateway.getNetworkACLId()); if (aclItems.isEmpty()) { s_logger.debug("Found no network ACL Items for private gateway id=" + gateway.getId()); return true; @@ -345,14 +340,14 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana s_logger.debug("Releasing " + aclItems.size() + " Network ACL Items for private gateway id=" + gateway.getId()); } - for (NetworkACLItemVO aclItem : aclItems) { + for (final NetworkACLItemVO aclItem : aclItems) { // Mark all Network ACLs rules as Revoke, but don't update in DB if (aclItem.getState() == State.Add || aclItem.getState() == State.Active) { aclItem.setState(State.Revoke); } } - boolean success = applyACLToPrivateGw(gateway, aclItems); + final 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 = " + aclItems.size()); @@ -362,27 +357,27 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } @Override - public List listNetworkACLItems(long guestNtwkId) { - Network network = _networkMgr.getNetwork(guestNtwkId); + public List listNetworkACLItems(final long guestNtwkId) { + final Network network = _networkMgr.getNetwork(guestNtwkId); if (network.getNetworkACLId() == null) { return null; } return _networkACLItemDao.listByACL(network.getNetworkACLId()); } - private void removeRule(NetworkACLItem rule) { + private void removeRule(final NetworkACLItem rule) { //remove the rule _networkACLItemDao.remove(rule.getId()); } @Override - public boolean applyACLToPrivateGw(PrivateGateway gateway) throws ResourceUnavailableException { - VpcGatewayVO vpcGatewayVO = _vpcGatewayDao.findById(gateway.getId()); - List rules = _networkACLItemDao.listByACL(vpcGatewayVO.getNetworkACLId()); + public boolean applyACLToPrivateGw(final PrivateGateway gateway) throws ResourceUnavailableException { + final VpcGatewayVO vpcGatewayVO = _vpcGatewayDao.findById(gateway.getId()); + final List rules = _networkACLItemDao.listByACL(vpcGatewayVO.getNetworkACLId()); return applyACLToPrivateGw(gateway, rules); } - private boolean applyACLToPrivateGw(PrivateGateway gateway, List rules) throws ResourceUnavailableException { + private boolean applyACLToPrivateGw(final PrivateGateway gateway, final List rules) throws ResourceUnavailableException { List vpcElements = null; vpcElements = new ArrayList(); vpcElements.add((VpcProvider)_ntwkModel.getElementImplementingProvider(Network.Provider.VPCVirtualRouter.getName())); @@ -392,29 +387,29 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } try{ - for (VpcProvider provider : vpcElements) { + for (final VpcProvider provider : vpcElements) { return provider.applyACLItemsToPrivateGw(gateway, rules); } - } catch(Exception ex) { + } catch(final Exception ex) { s_logger.debug("Failed to apply acl to private gateway " + gateway); } return false; } @Override - public boolean applyACLToNetwork(long networkId) throws ResourceUnavailableException { - Network network = _networkDao.findById(networkId); + public boolean applyACLToNetwork(final long networkId) throws ResourceUnavailableException { + final Network network = _networkDao.findById(networkId); if (network.getNetworkACLId() == null) { return true; } - List rules = _networkACLItemDao.listByACL(network.getNetworkACLId()); + final List rules = _networkACLItemDao.listByACL(network.getNetworkACLId()); return applyACLItemsToNetwork(networkId, rules); } @Override - public NetworkACLItem updateNetworkACLItem(Long id, String protocol, List sourceCidrList, NetworkACLItem.TrafficType trafficType, String action, - Integer number, Integer sourcePortStart, Integer sourcePortEnd, Integer icmpCode, Integer icmpType, String customId, Boolean forDisplay) throws ResourceUnavailableException { - NetworkACLItemVO aclItem = _networkACLItemDao.findById(id); + public NetworkACLItem updateNetworkACLItem(final Long id, final String protocol, final List sourceCidrList, final NetworkACLItem.TrafficType trafficType, final String action, + final Integer number, final Integer sourcePortStart, final Integer sourcePortEnd, final Integer icmpCode, final Integer icmpType, final String customId, final Boolean forDisplay) throws ResourceUnavailableException { + final NetworkACLItemVO aclItem = _networkACLItemDao.findById(id); aclItem.setState(State.Add); if (protocol != null) { @@ -475,13 +470,13 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana return null; } - public boolean applyACLItemsToNetwork(long networkId, List rules) throws ResourceUnavailableException { - Network network = _networkDao.findById(networkId); + public boolean applyACLItemsToNetwork(final long networkId, final List rules) throws ResourceUnavailableException { + final Network network = _networkDao.findById(networkId); boolean handled = false; boolean foundProvider = false; - for (NetworkACLServiceProvider element : _networkAclElements) { - Network.Provider provider = element.getProvider(); - boolean isAclProvider = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.NetworkACL, provider); + for (final NetworkACLServiceProvider element : _networkAclElements) { + final Network.Provider provider = element.getProvider(); + final boolean isAclProvider = _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.NetworkACL, provider); if (!isAclProvider) { continue; } @@ -506,8 +501,8 @@ public class NetworkACLManagerImpl extends ManagerBase implements NetworkACLMana } @Inject - public void setNetworkAclElements(List networkAclElements) { - this._networkAclElements = networkAclElements; + public void setNetworkAclElements(final List networkAclElements) { + _networkAclElements = networkAclElements; } }