aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl/participant-impl-policy
diff options
context:
space:
mode:
Diffstat (limited to 'participant/participant-impl/participant-impl-policy')
-rw-r--r--participant/participant-impl/participant-impl-policy/pom.xml2
-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.java11
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java105
4 files changed, 39 insertions, 129 deletions
diff --git a/participant/participant-impl/participant-impl-policy/pom.xml b/participant/participant-impl/participant-impl-policy/pom.xml
index bed42b081..ed0667ffd 100644
--- a/participant/participant-impl/participant-impl-policy/pom.xml
+++ b/participant/participant-impl/participant-impl-policy/pom.xml
@@ -25,7 +25,7 @@
<parent>
<groupId>org.onap.policy.clamp.participant</groupId>
<artifactId>policy-clamp-participant-impl</artifactId>
- <version>6.1.3-SNAPSHOT</version>
+ <version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>policy-clamp-participant-impl-policy</artifactId>
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..901fb682b 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;
@@ -101,7 +102,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
break;
case PASSIVE:
try {
- undeployPolicies(controlLoopElementId, orderedState);
+ undeployPolicies(controlLoopElementId);
} catch (PfModelRuntimeException e) {
LOGGER.debug("Undeploying policies failed - no policies to undeploy {}", controlLoopElementId);
}
@@ -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 {
@@ -155,11 +157,12 @@ public class ControlLoopElementHandler implements ControlLoopElementListener {
ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
}
- private void undeployPolicies(UUID controlLoopElementId, ControlLoopOrderedState newState) {
+ private void undeployPolicies(UUID controlLoopElementId) {
// 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 {
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java
index 25da5a3e9..d517ef61e 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/main/utils/TestListenerUtils.java
@@ -33,9 +33,9 @@ import java.util.Set;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.onap.policy.clamp.controlloop.common.utils.CommonUtils;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
@@ -53,7 +53,6 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
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.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -64,8 +63,6 @@ public final class TestListenerUtils {
private static final Coder CODER = new StandardCoder();
static CommonTestData commonTestData = new CommonTestData();
private static final Logger LOGGER = LoggerFactory.getLogger(TestListenerUtils.class);
- private static final String POLICY_TYPE_ID = "policy_type_id";
- private static final String POLICY_ID = "policy_id";
/**
* Method to create a controlLoop from a yaml file.
@@ -174,65 +171,13 @@ public final class TestListenerUtils {
List<ParticipantUpdates> participantUpdates = new ArrayList<>();
for (ControlLoopElement element : elements.values()) {
- populateToscaNodeTemplateFragment(element, toscaServiceTemplate);
- prepareParticipantUpdateForControlLoop(element, participantUpdates);
+ CommonUtils.setServiceTemplatePolicyInfo(element, toscaServiceTemplate);
+ CommonUtils.prepareParticipantUpdate(element, participantUpdates);
}
clUpdateMsg.setParticipantUpdatesList(participantUpdates);
return clUpdateMsg;
}
- private static void populateToscaNodeTemplateFragment(ControlLoopElement clElement,
- ToscaServiceTemplate toscaServiceTemplate) {
- ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
- .get(clElement.getDefinition().getName());
- // If the ControlLoopElement has policy_type_id or policy_id, identify it as a PolicyControlLoopElement
- // and pass respective PolicyTypes or Policies as part of toscaServiceTemplateFragment
- if ((toscaNodeTemplate.getProperties().get(POLICY_TYPE_ID) != null)
- || (toscaNodeTemplate.getProperties().get(POLICY_ID) != null)) {
- // ControlLoopElement for policy framework, send policies and policyTypes to participants
- if ((toscaServiceTemplate.getPolicyTypes() != null)
- || (toscaServiceTemplate.getToscaTopologyTemplate().getPolicies() != null)) {
- ToscaServiceTemplate toscaServiceTemplateFragment = new ToscaServiceTemplate();
- toscaServiceTemplateFragment.setPolicyTypes(toscaServiceTemplate.getPolicyTypes());
-
- ToscaTopologyTemplate toscaTopologyTemplate = new ToscaTopologyTemplate();
- toscaTopologyTemplate.setPolicies(toscaServiceTemplate.getToscaTopologyTemplate().getPolicies());
- toscaServiceTemplateFragment.setToscaTopologyTemplate(toscaTopologyTemplate);
-
- toscaServiceTemplateFragment.setDataTypes(toscaServiceTemplate.getDataTypes());
-
- clElement.setToscaServiceTemplateFragment(toscaServiceTemplateFragment);
- }
- }
- }
-
- private static void prepareParticipantUpdateForControlLoop(ControlLoopElement clElement,
- List<ParticipantUpdates> participantUpdates) {
- if (participantUpdates.isEmpty()) {
- participantUpdates.add(getControlLoopElementList(clElement));
- } else {
- boolean participantExists = false;
- for (ParticipantUpdates participantUpdate : participantUpdates) {
- if (participantUpdate.getParticipantId().equals(clElement.getParticipantId())) {
- participantUpdate.getControlLoopElementList().add(clElement);
- participantExists = true;
- }
- }
- if (!participantExists) {
- participantUpdates.add(getControlLoopElementList(clElement));
- }
- }
- }
-
- private static ParticipantUpdates getControlLoopElementList(ControlLoopElement clElement) {
- ParticipantUpdates participantUpdate = new ParticipantUpdates();
- List<ControlLoopElement> controlLoopElementList = new ArrayList<>();
- participantUpdate.setParticipantId(clElement.getParticipantId());
- controlLoopElementList.add(clElement);
- participantUpdate.setControlLoopElementList(controlLoopElementList);
- return participantUpdate;
- }
-
/**
* Method to create participantUpdateMsg.
*
@@ -259,10 +204,10 @@ public final class TestListenerUtils {
.getNodeTemplates().entrySet()) {
if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(),
toscaServiceTemplate)) {
- var clParticipantType =
- ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties());
- prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(),
- toscaInputEntry.getValue(), participantDefinitionUpdates);
+ CommonUtils.prepareParticipantDefinitionUpdate(
+ ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()),
+ toscaInputEntry.getKey(), toscaInputEntry.getValue(),
+ participantDefinitionUpdates, null);
}
}
@@ -270,42 +215,6 @@ public final class TestListenerUtils {
return participantUpdateMsg;
}
- private static void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey,
- ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
-
- var clDefinition = new ControlLoopElementDefinition();
- clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion()));
- clDefinition.setControlLoopElementToscaNodeTemplate(entryValue);
- List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>();
-
- if (participantDefinitionUpdates.isEmpty()) {
- participantDefinitionUpdates
- .add(getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
- } else {
- boolean participantExists = false;
- for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) {
- if (participantDefinitionUpdate.getParticipantType().equals(clParticipantType)) {
- participantDefinitionUpdate.getControlLoopElementDefinitionList().add(clDefinition);
- participantExists = true;
- }
- }
- if (!participantExists) {
- participantDefinitionUpdates.add(
- getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList));
- }
- }
- }
-
- private static ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition,
- ToscaConceptIdentifier clParticipantType,
- List<ControlLoopElementDefinition> controlLoopElementDefinitionList) {
- ParticipantDefinition participantDefinition = new ParticipantDefinition();
- participantDefinition.setParticipantType(clParticipantType);
- controlLoopElementDefinitionList.add(clDefinition);
- participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList);
- return participantDefinition;
- }
-
/**
* Method to create ControlLoopUpdate using the arguments passed.
*