summaryrefslogtreecommitdiffstats
path: root/participant
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2021-10-29 10:52:29 +0000
committerGerrit Code Review <gerrit@onap.org>2021-10-29 10:52:29 +0000
commit9a49920ac001f76d796cbffce823abd7c0c7d9e2 (patch)
treed669313ef39f547d1cfaf4ea5d4e82559f187b51 /participant
parent31d34fd6f8aca8a2d7136176c84cf855eaac6f3e (diff)
parente7edc5816cd8a25854302c5546e19f5e064c9a7f (diff)
Merge "Refactor policy-participant policy deployment and undeployment"
Diffstat (limited to 'participant')
-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 {