diff options
author | Xue Gao <xg353y@intl.att.com> | 2020-04-15 08:04:08 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-04-15 08:04:08 +0000 |
commit | db5bbd3947a76eb5ab5a17de263b06100d4ce42b (patch) | |
tree | 8517876ed6a5066218c111b7f04fcd5318a754b5 /src/main/java/org | |
parent | 10266c923850e842e14c602d772ce2ebbc77fe89 (diff) | |
parent | 3854d7c1008aa947e4b532bbef9d9efc738f6928 (diff) |
Merge "Fix legacy policy submit issues"
Diffstat (limited to 'src/main/java/org')
3 files changed, 24 insertions, 29 deletions
diff --git a/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java b/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java index 8270a96e..227f40a7 100644 --- a/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java +++ b/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java @@ -28,7 +28,6 @@ import com.att.eelf.configuration.EELFManager; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -76,25 +75,33 @@ public class PolicyComponent extends ExternalComponent { /** * Generates the Json that must be sent to policy to add all policies to Active * PDP group. - * + * @param loop the loop object + * @param action POST (to add policy to group) or DELETE (to delete policy from group) * @return The json, payload to send */ - public static String createPoliciesPayloadPdpGroup(Loop loop) { + public static String createPoliciesPayloadPdpGroup(Loop loop, String action) { Map<String, Map<String, List<JsonObject>>> pdpGroupMap = new HashMap<>(); for (OperationalPolicy opPolicy : loop.getOperationalPolicies()) { updatePdpGroupMap(opPolicy.getPdpGroup(), opPolicy.getPdpSubgroup(), opPolicy.getName(), - opPolicy.getPolicyModel().getVersion(), pdpGroupMap); + "1.0.0", pdpGroupMap); + if (opPolicy.isLegacy()) { + for (String guardName:opPolicy.createGuardPolicyPayloads().keySet()) { + updatePdpGroupMap(opPolicy.getPdpGroup(), opPolicy.getPdpSubgroup(), + guardName, + "1.0.0", pdpGroupMap); + } + } } for (MicroServicePolicy msPolicy : loop.getMicroServicePolicies()) { updatePdpGroupMap(msPolicy.getPdpGroup(), msPolicy.getPdpSubgroup(), msPolicy.getName(), - msPolicy.getPolicyModel().getVersion(), pdpGroupMap); + "1.0.0", pdpGroupMap); } String payload = new GsonBuilder().setPrettyPrinting().create() - .toJson(generateActivatePdpGroupPayload(pdpGroupMap)); + .toJson(generateActivatePdpGroupPayload(pdpGroupMap, action)); logger.info("PdpGroup policy payload: " + payload); return payload; } @@ -102,12 +109,12 @@ public class PolicyComponent extends ExternalComponent { private static void updatePdpGroupMap(String pdpGroup, String pdpSubGroup, String policyName, - String policyModelVersion, + String policyVersion, Map<String, Map<String, List<JsonObject>>> pdpGroupMap) { JsonObject policyJson = new JsonObject(); policyJson.addProperty("name", policyName); - policyJson.addProperty("version", policyModelVersion); + policyJson.addProperty("version", policyVersion); Map<String, List<JsonObject>> pdpSubGroupMap; List<JsonObject> policyList; if (pdpGroupMap.get(pdpGroup) == null) { @@ -129,7 +136,7 @@ public class PolicyComponent extends ExternalComponent { } private static JsonObject generateActivatePdpGroupPayload( - Map<String, Map<String, List<JsonObject>>> pdpGroupMap) { + Map<String, Map<String, List<JsonObject>>> pdpGroupMap, String action) { JsonArray payloadArray = new JsonArray(); for (Entry<String, Map<String, List<JsonObject>>> pdpGroupInfo : pdpGroupMap.entrySet()) { JsonObject pdpGroupNode = new JsonObject(); @@ -141,7 +148,7 @@ public class PolicyComponent extends ExternalComponent { JsonObject pdpSubGroupNode = new JsonObject(); subPdpArray.add(pdpSubGroupNode); pdpSubGroupNode.addProperty("pdpType", pdpSubGroupInfo.getKey()); - pdpSubGroupNode.addProperty("action", "POST"); + pdpSubGroupNode.addProperty("action", action); JsonArray policyArray = new JsonArray(); pdpSubGroupNode.add("policies", policyArray); @@ -157,25 +164,6 @@ public class PolicyComponent extends ExternalComponent { return jsonObject; } - /** - * Generates the list of policy names that must be send/remove to/from active - * PDP group. - * - * @return A list of policy names - */ - public static List<String> listPolicyNamesPdpGroup(Loop loop) { - List<String> policyNamesList = new ArrayList<>(); - for (OperationalPolicy opPolicy : loop.getOperationalPolicies()) { - policyNamesList.add(opPolicy.getName()); - policyNamesList.addAll(opPolicy.createGuardPolicyPayloads().keySet()); - } - for (MicroServicePolicy microServicePolicy : loop.getMicroServicePolicies()) { - policyNamesList.add(microServicePolicy.getName()); - } - logger.info("Policies that will be removed from PDP: " + policyNamesList); - return policyNamesList; - } - private static ExternalComponentState findNewState(boolean found, boolean deployed) { ExternalComponentState newState = NOT_SENT; diff --git a/src/main/java/org/onap/clamp/policy/Policy.java b/src/main/java/org/onap/clamp/policy/Policy.java index d84f2c8a..65e88d18 100644 --- a/src/main/java/org/onap/clamp/policy/Policy.java +++ b/src/main/java/org/onap/clamp/policy/Policy.java @@ -284,4 +284,6 @@ public abstract class Policy extends AuditEntity { .append(blueprintFilename.replaceAll(".yaml", "")); return buffer.toString().replace('.', '_').replaceAll(" ", ""); } + + public abstract Boolean isLegacy(); } diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java index 77627a31..127f495c 100644 --- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java +++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java @@ -157,6 +157,11 @@ public class MicroServicePolicy extends Policy implements Serializable { this.getPolicyModel().getPolicyModelType(), serviceModel)); } + @Override + public Boolean isLegacy() { + return false; + } + public Boolean getShared() { return shared; } |