diff options
author | Sébastien Determe <sebastien.determe@intl.att.com> | 2020-03-03 09:57:30 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-03-03 09:57:30 +0000 |
commit | ae6a9829f0c572cb4789812ea65871132ec861fd (patch) | |
tree | 08b2a46011795685b1a165684f95d5a59867bc9e /src/main | |
parent | 47caef3827de362e7b6204b01d73238fb6faa714 (diff) | |
parent | 492a5ddfdd09ce0a046a61abd6e76a69d9cf477a (diff) |
Merge "Rework the activate pdp group payload"
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java | 37 |
1 files changed, 32 insertions, 5 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 44ee5226..d47bc964 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 @@ -35,6 +35,7 @@ import java.util.List; import javax.persistence.Transient; import org.apache.camel.Exchange; +import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.loop.Loop; import org.onap.clamp.policy.microservice.MicroServicePolicy; import org.onap.clamp.policy.operational.OperationalPolicy; @@ -81,18 +82,44 @@ public class PolicyComponent extends ExternalComponent { public static String createPoliciesPayloadPdpGroup(Loop loop) { JsonObject jsonObject = new JsonObject(); JsonArray jsonArray = new JsonArray(); - jsonObject.add("policies", jsonArray); + jsonObject.add("groups", jsonArray); - for (String policyName : PolicyComponent.listPolicyNamesPdpGroup(loop)) { - JsonObject policyNode = new JsonObject(); - jsonArray.add(policyNode); - policyNode.addProperty("policy-id", policyName); + for (OperationalPolicy opPolicy : loop.getOperationalPolicies()) { + jsonArray.add(createPdpDeploymentPayload(opPolicy.getPdpGroup(), opPolicy.getPdpSubGroup(), + opPolicy.getPolicyModel().getPolicyModelType(), opPolicy.getPolicyModel().getVersion())); + } + + for (MicroServicePolicy msPolicy : loop.getMicroServicePolicies()) { + jsonArray.add(createPdpDeploymentPayload(msPolicy.getPdpGroup(), msPolicy.getPdpSubGroup(), + msPolicy.getPolicyModel().getPolicyModelType(), msPolicy.getPolicyModel().getVersion())); } + String payload = new GsonBuilder().setPrettyPrinting().create().toJson(jsonObject); logger.info("PdpGroup policy payload: " + payload); return new GsonBuilder().setPrettyPrinting().create().toJson(jsonObject); } + private static JsonObject createPdpDeploymentPayload(String pdpGroup, String pdpSubGroup, + String policyType, String version) { + JsonObject pdpGroupNode = new JsonObject(); + JsonArray subPdpArray = new JsonArray(); + pdpGroupNode.addProperty("name", pdpGroup); + pdpGroupNode.add("deploymentSubgroups", subPdpArray); + + JsonObject pdpSubGroupNode = new JsonObject(); + subPdpArray.add(pdpSubGroupNode); + pdpSubGroupNode.addProperty("pdpType", pdpSubGroup); + pdpSubGroupNode.addProperty("action", "POST"); + + JsonArray policyArray = new JsonArray(); + pdpSubGroupNode.add("policies", policyArray); + JsonObject policyNode = new JsonObject(); + policyNode.addProperty("name", policyType); + policyNode.addProperty("version", version); + policyArray.add(policyNode); + return pdpGroupNode; + } + /** * Generates the list of policy names that must be send/remove to/from active * PDP group. |