diff options
author | xuegao <xg353y@intl.att.com> | 2020-02-21 15:28:30 +0100 |
---|---|---|
committer | sebdet <sebastien.determe@intl.att.com> | 2020-03-03 01:43:10 -0800 |
commit | 492a5ddfdd09ce0a046a61abd6e76a69d9cf477a (patch) | |
tree | 8ddda219ddf698166109b10fc3d60fa7ce044f3a /src/main | |
parent | d2a4df0b62b6a32c42bac45b4bee344016faa8fb (diff) |
Rework the activate pdp group payload
Rework the payload which triggers the activate pdp group policy API
based on the new requirement.
Issue-ID: CLAMP-646
Change-Id: I9bd7e3f2d1907c7e22c5435c792910b8245780b2
Signed-off-by: xuegao <xg353y@intl.att.com>
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 44ee52262..d47bc9644 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. |