aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java93
-rw-r--r--src/main/java/org/onap/clamp/policy/Policy.java15
-rw-r--r--src/main/resources/clds/camel/routes/policy-flows.xml8
-rw-r--r--src/test/resources/tosca/micro-service-policy-payload.json1
-rw-r--r--src/test/resources/tosca/micro-service-policy-properties.json44
-rw-r--r--src/test/resources/tosca/pdp-group-policy-payload.json12
6 files changed, 102 insertions, 71 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 4cabe7f1f..99b021947 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
@@ -30,7 +30,10 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map.Entry;
import javax.persistence.Transient;
@@ -79,44 +82,78 @@ public class PolicyComponent extends ExternalComponent {
* @return The json, payload to send
*/
public static String createPoliciesPayloadPdpGroup(Loop loop) {
- JsonObject jsonObject = new JsonObject();
- JsonArray jsonArray = new JsonArray();
- jsonObject.add("groups", jsonArray);
-
+ HashMap<String,HashMap<String, List<JsonObject>>> pdpGroupMap = new HashMap <String,HashMap<String, List<JsonObject>>>();
for (OperationalPolicy opPolicy : loop.getOperationalPolicies()) {
- jsonArray.add(createPdpDeploymentPayload(opPolicy.getPdpGroup(), opPolicy.getPdpSubgroup(),
- opPolicy.getPolicyModel().getPolicyModelType(), opPolicy.getPolicyModel().getVersion()));
+ pdpGroupMap = updatePdpGroupMap(opPolicy.getPdpGroup(), opPolicy.getPdpSubgroup(),
+ opPolicy.getName(),
+ opPolicy.getPolicyModel().getVersion(), pdpGroupMap);
}
for (MicroServicePolicy msPolicy : loop.getMicroServicePolicies()) {
- jsonArray.add(createPdpDeploymentPayload(msPolicy.getPdpGroup(), msPolicy.getPdpSubgroup(),
- msPolicy.getPolicyModel().getPolicyModelType(), msPolicy.getPolicyModel().getVersion()));
+ pdpGroupMap = updatePdpGroupMap(msPolicy.getPdpGroup(), msPolicy.getPdpSubgroup(),
+ msPolicy.getName(),
+ msPolicy.getPolicyModel().getVersion(), pdpGroupMap);
}
- String payload = new GsonBuilder().setPrettyPrinting().create().toJson(jsonObject);
+ String payload = new GsonBuilder().setPrettyPrinting().create()
+ .toJson(generateActivatePdpGroupPayload(pdpGroupMap));
logger.info("PdpGroup policy payload: " + payload);
return payload;
}
- 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;
+ private static HashMap<String,HashMap<String, List<JsonObject>>> updatePdpGroupMap (String pdpGroup, String pdpSubGroup, String policyName,
+ String policyModelVersion, HashMap<String,HashMap<String, List<JsonObject>>> pdpGroupMap){
+
+ JsonObject policyJson = new JsonObject();
+ policyJson.addProperty("name", policyName);
+ policyJson.addProperty("version", policyModelVersion);
+ HashMap<String, List<JsonObject>> pdpSubGroupMap;
+ List<JsonObject> policyList;
+ if (pdpGroupMap.get(pdpGroup) == null) {
+ pdpSubGroupMap = new HashMap <String, List<JsonObject>>();
+ policyList = new LinkedList<JsonObject>();
+ } else {
+ pdpSubGroupMap = pdpGroupMap.get(pdpGroup);
+ if (pdpSubGroupMap.get(pdpSubGroup) == null) {
+ policyList = new LinkedList<JsonObject>();
+ } else {
+ policyList = (List<JsonObject>)pdpSubGroupMap.get(pdpSubGroup);
+ }
+ }
+ policyList.add(policyJson);
+ pdpSubGroupMap.put(pdpSubGroup, policyList);
+ pdpGroupMap.put(pdpGroup, pdpSubGroupMap);
+
+ return pdpGroupMap;
+ }
+
+ private static JsonObject generateActivatePdpGroupPayload(HashMap<String,HashMap<String, List<JsonObject>>> pdpGroupMap) {
+ JsonArray payloadArray = new JsonArray();
+ for (Entry<String, HashMap<String, List<JsonObject>>> pdpGroupInfo : pdpGroupMap.entrySet()) {
+ JsonObject pdpGroupNode = new JsonObject();
+ JsonArray subPdpArray = new JsonArray();
+ pdpGroupNode.addProperty("name", pdpGroupInfo.getKey());
+ pdpGroupNode.add("deploymentSubgroups", subPdpArray);
+
+ JsonObject pdpSubGroupNode = new JsonObject();
+ subPdpArray.add(pdpSubGroupNode);
+
+ for (Entry<String, List<JsonObject>> pdpSubGroupInfo : pdpGroupInfo.getValue().entrySet()) {
+ pdpSubGroupNode.addProperty("pdpType", pdpSubGroupInfo.getKey());
+ pdpSubGroupNode.addProperty("action", "POST");
+
+ JsonArray policyArray = new JsonArray();
+ pdpSubGroupNode.add("policies", policyArray);
+
+ for (JsonObject policy : pdpSubGroupInfo.getValue()) {
+ policyArray.add(policy);
+ }
+ }
+ payloadArray.add(pdpGroupNode);
+ }
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.add("groups", payloadArray);
+ return jsonObject;
}
/**
diff --git a/src/main/java/org/onap/clamp/policy/Policy.java b/src/main/java/org/onap/clamp/policy/Policy.java
index 87d36f3d2..abb16d73f 100644
--- a/src/main/java/org/onap/clamp/policy/Policy.java
+++ b/src/main/java/org/onap/clamp/policy/Policy.java
@@ -97,13 +97,6 @@ public abstract class Policy extends AuditEntity {
return new Gson().fromJson(jsonObject.toString(), JsonObject.class);
}
- private String getModelPropertyNameFromTosca(JsonObject object, String policyModelType) {
- return object.getAsJsonObject("policy_types").getAsJsonObject(policyModelType)
- .getAsJsonObject(
- "properties")
- .keySet().toArray(new String[1])[0];
- }
-
/**
* This method create the policy payload that must be sent to PEF.
*
@@ -129,17 +122,15 @@ public abstract class Policy extends AuditEntity {
JsonObject policyDetails = new JsonObject();
thisPolicy.add(this.getName(), policyDetails);
policyDetails.addProperty("type", this.getPolicyModel().getPolicyModelType());
+ policyDetails.addProperty("type_version", this.getPolicyModel().getVersion());
policyDetails.addProperty("version", this.getPolicyModel().getVersion());
JsonObject policyMetadata = new JsonObject();
policyDetails.add("metadata", policyMetadata);
policyMetadata.addProperty("policy-id", this.getName());
- JsonObject policyProperties = new JsonObject();
- policyDetails.add("properties", policyProperties);
- policyProperties
- .add(this.getModelPropertyNameFromTosca(toscaJson, this.getPolicyModel().getPolicyModelType()),
- this.getConfigurationsJson());
+ policyDetails.add("properties", this.getConfigurationsJson());
+
String policyPayload = new GsonBuilder().setPrettyPrinting().create().toJson(policyPayloadResult);
logger.info("Policy payload: " + policyPayload);
return policyPayload;
diff --git a/src/main/resources/clds/camel/routes/policy-flows.xml b/src/main/resources/clds/camel/routes/policy-flows.xml
index 2b704acea..a2c7a4ca3 100644
--- a/src/main/resources/clds/camel/routes/policy-flows.xml
+++ b/src/main/resources/clds/camel/routes/policy-flows.xml
@@ -597,9 +597,9 @@
</simple>
</setHeader>
<log loggingLevel="INFO"
- message="Endpoint to add policies to PDP Group: {{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/policies"></log>
+ message="Endpoint to add policies to PDP Group: {{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/deployments/batch"></log>
<toD
- uri="{{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/policies?bridgeEndpoint=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;useSystemProperties=true&amp;authUsername={{clamp.config.policy.pap.userName}}&amp;authPassword={{clamp.config.policy.pap.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+ uri="{{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/deployments/batch?bridgeEndpoint=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;useSystemProperties=true&amp;authUsername={{clamp.config.policy.pap.userName}}&amp;authPassword={{clamp.config.policy.pap.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
<doFinally>
<to uri="direct:reset-raise-http-exception-flag"/>
@@ -648,9 +648,9 @@
</simple>
</setHeader>
<log loggingLevel="INFO"
- message="Endpoint to delete policy from PDP Group: {{clamp.config.policy.pap.url}}/pdps/policies/${exchangeProperty[policyName]}/versions/1.0.0"></log>
+ message="Endpoint to delete policy from PDP Group: {{clamp.config.policy.pap.url}}/pdps/deployments/batch/${exchangeProperty[policyName]}/versions/1.0.0"></log>
<toD
- uri="{{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/policies/${exchangeProperty[policyName]}/versions/1.0.0?bridgeEndpoint=true&amp;useSystemProperties=true&amp;mapHttpMessageHeaders=false&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authUsername={{clamp.config.policy.pap.userName}}&amp;authPassword={{clamp.config.policy.pap.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+ uri="{{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/deployments/batch/${exchangeProperty[policyName]}/versions/1.0.0?bridgeEndpoint=true&amp;useSystemProperties=true&amp;mapHttpMessageHeaders=false&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authUsername={{clamp.config.policy.pap.userName}}&amp;authPassword={{clamp.config.policy.pap.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
<setProperty propertyName="logMessage">
<simple>${exchangeProperty[policyName]} PDP Group removal status
</simple>
diff --git a/src/test/resources/tosca/micro-service-policy-payload.json b/src/test/resources/tosca/micro-service-policy-payload.json
index 2de06b083..2533a5410 100644
--- a/src/test/resources/tosca/micro-service-policy-payload.json
+++ b/src/test/resources/tosca/micro-service-policy-payload.json
@@ -5,6 +5,7 @@
{
"testPolicy": {
"type": "onap.policies.monitoring.cdap.tca.hi.lo.app",
+ "type_version": "1.0.0",
"version": "1.0.0",
"metadata": {
"policy-id": "testPolicy"
diff --git a/src/test/resources/tosca/micro-service-policy-properties.json b/src/test/resources/tosca/micro-service-policy-properties.json
index 6baa32942..04fe0cc7f 100644
--- a/src/test/resources/tosca/micro-service-policy-properties.json
+++ b/src/test/resources/tosca/micro-service-policy-properties.json
@@ -1,23 +1,25 @@
{
- "domain": "measurementsForVfScaling",
- "metricsPerEventName": [
- {
- "policyVersion": "1.0.0",
- "thresholds": [
- {
- "severity": "CRITICAL",
- "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta",
- "thresholdValue": 1,
- "closedLoopEventStatus": "ONSET",
- "closedLoopControlName": "test",
- "version": "1.0.0",
- "direction": "LESS"
- }
- ],
- "policyName": "test",
- "controlLoopSchemaType": "VM",
- "policyScope": "test",
- "eventName": "test"
- }
- ]
+ "tca_policy": {
+ "domain": "measurementsForVfScaling",
+ "metricsPerEventName": [
+ {
+ "policyVersion": "1.0.0",
+ "thresholds": [
+ {
+ "severity": "CRITICAL",
+ "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta",
+ "thresholdValue": 1,
+ "closedLoopEventStatus": "ONSET",
+ "closedLoopControlName": "test",
+ "version": "1.0.0",
+ "direction": "LESS"
+ }
+ ],
+ "policyName": "test",
+ "controlLoopSchemaType": "VM",
+ "policyScope": "test",
+ "eventName": "test"
+ }
+ ]
+ }
}
diff --git a/src/test/resources/tosca/pdp-group-policy-payload.json b/src/test/resources/tosca/pdp-group-policy-payload.json
index 93a85457a..4ea746dea 100644
--- a/src/test/resources/tosca/pdp-group-policy-payload.json
+++ b/src/test/resources/tosca/pdp-group-policy-payload.json
@@ -1,14 +1,14 @@
{
"groups": [
{
- "name": "pdpGroup2",
+ "name": "pdpGroup1",
"deploymentSubgroups": [
{
- "pdpType": "pdpSubgroup2",
+ "pdpType": "pdpSubgroup1",
"action": "POST",
"policies": [
{
- "name": "onap.policies.controlloop.Operational",
+ "name": "configPolicyTest",
"version": "1.0.0"
}
]
@@ -16,14 +16,14 @@
]
},
{
- "name": "pdpGroup1",
+ "name": "pdpGroup2",
"deploymentSubgroups": [
{
- "pdpType": "pdpSubgroup1",
+ "pdpType": "pdpSubgroup2",
"action": "POST",
"policies": [
{
- "name": "onap.policies.monitoring.test",
+ "name": "opPolicy",
"version": "1.0.0"
}
]