aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-policy/src/main
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2021-10-27 08:52:32 +0100
committerWayne Dunican <wayne.dunican@est.tech>2021-10-27 09:18:01 +0100
commite7edc5816cd8a25854302c5546e19f5e064c9a7f (patch)
tree7c25cda9a56a82cc4aac4cb733ed725152291562 /participant/participant-impl/participant-impl-policy/src/main
parentd33f694fc4e595054fb11812b2f8010cf94b637f (diff)
Refactor policy-participant policy deployment and undeployment
Change the policy-participant to use DeploymentGroups to generate JSON body rather than manual generation Issue-ID: POLICY-3793 Change-Id: I3a049e2be8a677f5a5aeff7ed14e44d7252a2fb7 Signed-off-by: Wayne Dunican <wayne.dunican@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-policy/src/main')
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/client/PolicyPapHttpClient.java50
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java7
2 files changed, 29 insertions, 28 deletions
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/client/PolicyPapHttpClient.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/client/PolicyPapHttpClient.java
index 3cce3bd8a..f835c6e04 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/client/PolicyPapHttpClient.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/client/PolicyPapHttpClient.java
@@ -20,12 +20,16 @@
package org.onap.policy.clamp.controlloop.participant.policy.client;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
+import java.util.LinkedList;
+import java.util.List;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.onap.policy.clamp.controlloop.participant.policy.main.parameters.ParticipantPolicyParameters;
+import org.onap.policy.models.pdp.concepts.DeploymentGroup;
+import org.onap.policy.models.pdp.concepts.DeploymentGroups;
+import org.onap.policy.models.pdp.concepts.DeploymentSubGroup;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.springframework.stereotype.Component;
@Component
@@ -55,33 +59,27 @@ public class PolicyPapHttpClient extends AbstractHttpClient {
* @return Response
*/
public Response handlePolicyDeployOrUndeploy(final String policyName, final String policyVersion,
- final String action) {
- // policies
- JsonObject policyArrayBody = new JsonObject();
- policyArrayBody.addProperty("name", policyName);
- policyArrayBody.addProperty("version", policyVersion);
- JsonArray policyArr = new JsonArray();
- policyArr.add(policyArrayBody);
+ final DeploymentSubGroup.Action action) {
- // deploymentSubgroups
- JsonObject deploymentSubGrpBody = new JsonObject();
- deploymentSubGrpBody.addProperty("pdpType", pdpType);
- deploymentSubGrpBody.addProperty("action", action);
- deploymentSubGrpBody.add("policies", policyArr);
- JsonArray deployArr = new JsonArray();
- deployArr.add(deploymentSubGrpBody);
+ List<ToscaConceptIdentifier> policies = new LinkedList<ToscaConceptIdentifier>();
+ policies.add(new ToscaConceptIdentifier(policyName, policyVersion));
- // groups
- JsonObject groupArrayBody = new JsonObject();
- groupArrayBody.addProperty("name", pdpGroup);
- groupArrayBody.add("deploymentSubgroups", deployArr);
- JsonArray groupArr = new JsonArray();
- groupArr.add(groupArrayBody);
+ DeploymentSubGroup subGroup = new DeploymentSubGroup();
+ subGroup.setPolicies(policies);
+ subGroup.setPdpType(pdpType);
+ subGroup.setAction(action);
- // main json
- JsonObject mainJson = new JsonObject();
- mainJson.add("groups", groupArr);
+ DeploymentGroup group = new DeploymentGroup();
+ List<DeploymentSubGroup> subGroups = new LinkedList<DeploymentSubGroup>();
+ subGroups.add(subGroup);
+ group.setDeploymentSubgroups(subGroups);
+ group.setName(pdpGroup);
- return executePost(PAP_URI + "pdps/deployments/batch", Entity.entity(mainJson, MediaType.APPLICATION_JSON));
+ DeploymentGroups groups = new DeploymentGroups();
+ List<DeploymentGroup> groupsArr = new LinkedList<DeploymentGroup>();
+ groupsArr.add(group);
+ groups.setGroups(groupsArr);
+
+ return executePost(PAP_URI + "pdps/deployments/batch", Entity.entity(groups, MediaType.APPLICATION_JSON));
}
}
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java
index 29a7852f1..f6d616dac 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/handler/ControlLoopElementHandler.java
@@ -39,6 +39,7 @@ import org.onap.policy.clamp.controlloop.participant.policy.client.PolicyApiHttp
import org.onap.policy.clamp.controlloop.participant.policy.client.PolicyPapHttpClient;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.pdp.concepts.DeploymentSubGroup;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -144,7 +145,8 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
// Deploy all policies of this controlLoop from Policy Framework
if (policyMap.entrySet() != null) {
for (Entry<String, String> policy : policyMap.entrySet()) {
- papHttpClient.handlePolicyDeployOrUndeploy(policy.getKey(), policy.getValue(), "POST");
+ papHttpClient.handlePolicyDeployOrUndeploy(policy.getKey(), policy.getValue(),
+ DeploymentSubGroup.Action.POST);
}
LOGGER.debug("Policies deployed to {} successfully", controlLoopElementId);
} else {
@@ -159,7 +161,8 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
// Undeploy all policies of this controlloop from Policy Framework
if (policyMap.entrySet() != null) {
for (Entry<String, String> policy : policyMap.entrySet()) {
- papHttpClient.handlePolicyDeployOrUndeploy(policy.getKey(), policy.getValue(), "DELETE");
+ papHttpClient.handlePolicyDeployOrUndeploy(policy.getKey(), policy.getValue(),
+ DeploymentSubGroup.Action.DELETE);
}
LOGGER.debug("Undeployed policies from {} successfully", controlLoopElementId);
} else {