Skip to content

Commit 154618b

Browse files
author
Kishan Kavala
committed
CLOUDSTACK-3198: HashSet used for storing ACL rules doesn't maintain the order. Added rules directly to result string array after sorting.
1 parent a52bf1b commit 154618b

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

‎core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ public NetworkACLTO[] getRules() {
4343
return rules;
4444
}
4545
public String[][] generateFwRules() {
46-
String [][] result = new String [2][];
47-
Set<String> toAdd = new HashSet<String>();
4846
List<NetworkACLTO> aclList = Arrays.asList(rules);
4947
Collections.sort(aclList, new Comparator<NetworkACLTO>() {
5048
@Override
5149
public int compare(NetworkACLTO acl1, NetworkACLTO acl2) {
52-
return acl1.getNumber() > acl2.getNumber() ? 1 : -1;
50+
return acl1.getNumber() < acl2.getNumber() ? 1 : -1;
5351
}
5452
});
5553

54+
String [][] result = new String [2][aclList.size()];
55+
int i = 0;
5656
for (NetworkACLTO aclTO: aclList) {
5757
/* example : Ingress:tcp:80:80:0.0.0.0/0:ACCEPT:,Egress:tcp:220:220:0.0.0.0/0:DROP:,
5858
* each entry format Ingress/Egress:protocol:start port: end port:scidrs:action:
@@ -64,7 +64,7 @@ public int compare(NetworkACLTO acl1, NetworkACLTO acl2) {
6464
/* This entry is added just to make sure atleast there will one entry in the list to get the ipaddress */
6565
sb.append(aclTO.getTrafficType().toString()).append(":reverted:0:0:0:");
6666
String aclRuleEntry = sb.toString();
67-
toAdd.add(aclRuleEntry);
67+
result[0][i++] = aclRuleEntry;
6868
continue;
6969
}
7070

@@ -91,11 +91,8 @@ public int compare(NetworkACLTO acl1, NetworkACLTO acl2) {
9191
}
9292
sb.append(":").append(aclTO.getAction()).append(":");
9393
String aclRuleEntry = sb.toString();
94-
95-
toAdd.add(aclRuleEntry);
96-
94+
result[0][i++] = aclRuleEntry;
9795
}
98-
result[0] = toAdd.toArray(new String[toAdd.size()]);
9996

10097
return result;
10198
}

0 commit comments

Comments
 (0)