diff options
Diffstat (limited to 'participant/participant-impl/participant-impl-policy/src/main')
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 { |