Skip to content

Commit f7b3159

Browse files
committed
<fix>[securityGroup]: remove strict consecutive priority validation for security group rules
Resolves: ZSTAC-79067 Change-Id: I76c6d17b02f87f5836506e2c79be5538b3b0d89f
1 parent 709d8bc commit f7b3159

1 file changed

Lines changed: 11 additions & 23 deletions

File tree

plugin/securityGroup/src/main/java/org/zstack/network/securitygroup/SecurityGroupApiInterceptor.java

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,8 @@ private void validate(APISetVmNicSecurityGroupMsg msg) {
343343
if (!aoMap.isEmpty()) {
344344
Integer[] priorities = aoMap.keySet().toArray(new Integer[aoMap.size()]);
345345
Arrays.sort(priorities);
346-
if (priorities[0] != 1) {
347-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10022, "could no set vm nic security group, because invalid priority, priority expects to start at 1, but [%d]", priorities[0]));
348-
}
349-
for (int i = 0; i < priorities.length - 1; i++) {
350-
if (priorities[i] + 1 != priorities[i + 1]) {
351-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10023, "could no set vm nic security group, because invalid priority, priority[%d] and priority[%d] expected to be consecutive", priorities[i], priorities[i + 1]));
352-
}
346+
if (priorities[0] < 1) {
347+
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10022, "could no set vm nic security group, because invalid priority, priority expects to be positive, but [%d]", priorities[0]));
353348
}
354349
}
355350

@@ -390,13 +385,8 @@ private void validate(APISetVmNicSecurityGroupMsg msg) {
390385
if (!adminIntegers.isEmpty()) {
391386
Integer[] priorities = adminIntegers.toArray(new Integer[adminIntegers.size()]);
392387
Arrays.sort(priorities);
393-
if (priorities[0] != 1) {
394-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10024, "could no set vm nic security group, because admin security group priority[%d] must be higher than users", priorities[0]));
395-
}
396-
for (int i = 0; i < priorities.length - 1; i++) {
397-
if (priorities[i] + 1 != priorities[i + 1]) {
398-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10025, "could no set vm nic security group, because admin security group priority[%d] must be higher than users", priorities[i + 1]));
399-
}
388+
if (priorities[0] < 1) {
389+
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10024, "could no set vm nic security group, because admin security group priority[%d] must be positive", priorities[0]));
400390
}
401391
}
402392
}
@@ -498,8 +488,9 @@ private void validate(APIUpdateSecurityGroupRulePriorityMsg msg) {
498488
rvos.stream().filter(rvo -> rvo.getUuid().equals(ao.getRuleUuid())).findFirst().orElseThrow(() ->
499489
new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10041, "could not update security group rule priority, because rule[uuid:%s] not in security group[uuid:%s]", ao.getRuleUuid(), msg.getSecurityGroupUuid())));
500490

501-
rvos.stream().filter(rvo -> rvo.getPriority() == ao.getPriority()).findFirst().orElseThrow(() ->
502-
new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10042, "could not update security group rule priority, because priority[%d] not in security group[uuid:%s]", ao.getPriority(), msg.getSecurityGroupUuid())));
491+
if (ao.getPriority() < 1) {
492+
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10042, "could not update security group rule priority, because priority[%d] must be positive", ao.getPriority()));
493+
}
503494
}
504495

505496
List<String> uuidList = new ArrayList<>(priorityMap.values());
@@ -534,8 +525,8 @@ private void validate(APIChangeSecurityGroupRuleMsg msg) {
534525
if (count.intValue() > SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)) {
535526
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10047, "could not change security group rule, because security group %s rules number[%d] is out of max limit[%d]", vo.getType(), count.intValue(), SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)));
536527
}
537-
if (msg.getPriority() > count.intValue()) {
538-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10048, "could not change security group rule, because the maximum priority of %s rule is [%d]", vo.getType().toString(), count.intValue()));
528+
if (msg.getPriority() > SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)) {
529+
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10048, "could not change security group rule, because priority[%d] exceeds the maximum limit[%d]", msg.getPriority(), SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)));
539530
}
540531
if (msg.getPriority() < 0) {
541532
msg.setPriority(SecurityGroupConstant.LOWEST_RULE_PRIORITY);
@@ -1198,11 +1189,8 @@ private void validate(APIAddSecurityGroupRuleMsg msg) {
11981189
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10119, "could not add security group rule, because security group %s rules number[%d] is out of max limit[%d]",
11991190
SecurityGroupRuleType.Egress, (egressRuleCount + toCreateEgressRuleCount), SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)));
12001191
}
1201-
if (msg.getPriority() > (ingressRuleCount + 1) && toCreateIngressRuleCount > 0) {
1202-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10120, "could not add security group rule, because priority[%d] must be consecutive, the ingress rule maximum priority is [%d]", msg.getPriority(), ingressRuleCount));
1203-
}
1204-
if (msg.getPriority() > (egressRuleCount + 1) && toCreateEgressRuleCount > 0) {
1205-
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10121, "could not add security group rule, because priority[%d] must be consecutive, the egress rule maximum priority is [%d]", msg.getPriority(), egressRuleCount));
1192+
if (msg.getPriority() > SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)) {
1193+
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_SECURITYGROUP_10120, "could not add security group rule, because priority[%d] exceeds the maximum limit[%d]", msg.getPriority(), SecurityGroupGlobalConfig.SECURITY_GROUP_RULES_NUM_LIMIT.value(Integer.class)));
12061194
}
12071195
}
12081196

0 commit comments

Comments
 (0)