fix secg rule deduplicate
@@ -278,6 +278,8 @@ public class SecurityGroupApiInterceptor implements ApiMessageInterceptor {
SimpleQuery<SecurityGroupRuleVO> lsquery = dbf.createQuery(SecurityGroupRuleVO.class);
lsquery.add(SecurityGroupRuleVO_.securityGroupUuid, Op.EQ, msg.getSecurityGroupUuid());
List<SecurityGroupRuleVO> vos = lsquery.list();
+ boolean hasRemoteGroups = msg.getRemoteSecurityGroupUuids() == null || msg.getRemoteSecurityGroupUuids().isEmpty();
+
for (SecurityGroupRuleVO svo : vos) {
SecurityGroupRuleAO ao = new SecurityGroupRuleAO();
ao.setType(svo.getType().toString());
@@ -286,11 +288,10 @@ public class SecurityGroupApiInterceptor implements ApiMessageInterceptor {
ao.setStartPort(svo.getStartPort());
ao.setEndPort(svo.getEndPort());
-
for (SecurityGroupRuleAO sao : msg.getRules()) {
if (checkSecurityGroupRuleEqual(ao, sao) && (
- msg.getRemoteSecurityGroupUuids() == null ||
- msg.getRemoteSecurityGroupUuids().contains(svo.getRemoteSecurityGroupUuid())
+ !hasRemoteGroups && svo.getRemoteSecurityGroupUuid() == null ||
+ hasRemoteGroups && msg.getRemoteSecurityGroupUuids().contains(svo.getRemoteSecurityGroupUuid())
)) {
throw new ApiMessageInterceptionException(argerr("rule exist. rule dump: %s, remoteSecurityGroupUuid:[%s]",
JSONObjectUtil.toJsonString(sao), svo.getRemoteSecurityGroupUuid()));
