From 61f3706255b5a658e77014fe7f20acab2707219a Mon Sep 17 00:00:00 2001 From: Wilder Rodrigues Date: Wed, 6 Jan 2016 09:08:21 +0100 Subject: [PATCH 1/2] CLOUDSTACK-9213 - Formatting the code --- .../api/routing/SetNetworkACLCommand.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java b/core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java index 0cb1c3ec1acd..395ab5f0fb17 100644 --- a/core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java +++ b/core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java @@ -19,14 +19,14 @@ package com.cloud.agent.api.routing; -import com.cloud.agent.api.to.NetworkACLTO; -import com.cloud.agent.api.to.NicTO; - import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; +import com.cloud.agent.api.to.NetworkACLTO; +import com.cloud.agent.api.to.NicTO; + public class SetNetworkACLCommand extends NetworkElementCommand { NetworkACLTO[] rules; NicTO nic; @@ -34,7 +34,7 @@ public class SetNetworkACLCommand extends NetworkElementCommand { protected SetNetworkACLCommand() { } - public SetNetworkACLCommand(List rules, NicTO nic) { + public SetNetworkACLCommand(final List rules, final NicTO nic) { this.rules = rules.toArray(new NetworkACLTO[rules.size()]); this.nic = nic; } @@ -44,32 +44,32 @@ public NetworkACLTO[] getRules() { } public String[][] generateFwRules() { - List aclList = Arrays.asList(rules); + final List aclList = Arrays.asList(rules); Collections.sort(aclList, new Comparator() { @Override - public int compare(NetworkACLTO acl1, NetworkACLTO acl2) { + public int compare(final NetworkACLTO acl1, final NetworkACLTO acl2) { return acl1.getNumber() < acl2.getNumber() ? 1 : -1; } }); - String[][] result = new String[2][aclList.size()]; + final String[][] result = new String[2][aclList.size()]; int i = 0; - for (NetworkACLTO aclTO : aclList) { + for (final NetworkACLTO aclTO : aclList) { /* example : Ingress:tcp:80:80:0.0.0.0/0:ACCEPT:,Egress:tcp:220:220:0.0.0.0/0:DROP:, * each entry format Ingress/Egress:protocol:start port: end port:scidrs:action: * reverted entry format Ingress/Egress:reverted:0:0:0: */ if (aclTO.revoked() == true) { - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); /* This entry is added just to make sure atleast there will one entry in the list to get the ipaddress */ sb.append(aclTO.getTrafficType().toString()).append(":reverted:0:0:0:"); - String aclRuleEntry = sb.toString(); + final String aclRuleEntry = sb.toString(); result[0][i++] = aclRuleEntry; continue; } List cidr; - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); sb.append(aclTO.getTrafficType().toString()).append(":").append(aclTO.getProtocol()).append(":"); if ("icmp".compareTo(aclTO.getProtocol()) == 0) { sb.append(aclTO.getIcmpType()).append(":").append(aclTO.getIcmpCode()).append(":"); @@ -81,15 +81,16 @@ public int compare(NetworkACLTO acl1, NetworkACLTO acl2) { sb.append("0.0.0.0/0"); } else { Boolean firstEntry = true; - for (String tag : cidr) { - if (!firstEntry) + for (final String tag : cidr) { + if (!firstEntry) { sb.append("-"); + } sb.append(tag); firstEntry = false; } } sb.append(":").append(aclTO.getAction()).append(":"); - String aclRuleEntry = sb.toString(); + final String aclRuleEntry = sb.toString(); result[0][i++] = aclRuleEntry; } From 94c0dc5dfec1d8b20afcbc1e652eb7c9350b4946 Mon Sep 17 00:00:00 2001 From: Wilder Rodrigues Date: Wed, 6 Jan 2016 09:08:56 +0100 Subject: [PATCH 2/2] CLOUDSTACK-9213 - Split the ACL rules using comma instead of dash. - The router code no longer deals with parsing the ALC list again. It's not necessary if it's sent in the proper way. --- core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java b/core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java index 395ab5f0fb17..59ef6686ef08 100644 --- a/core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java +++ b/core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java @@ -83,7 +83,7 @@ public int compare(final NetworkACLTO acl1, final NetworkACLTO acl2) { Boolean firstEntry = true; for (final String tag : cidr) { if (!firstEntry) { - sb.append("-"); + sb.append(","); } sb.append(tag); firstEntry = false;