summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java15
-rw-r--r--src/main/resources/clds/camel/rest/clamp-api-v2.xml2
-rw-r--r--src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java2
-rw-r--r--src/test/resources/example/policy/policy-merger.json392
-rw-r--r--src/test/resources/http-cache/example/policy/pap/v1/pdps/.file13
5 files changed, 213 insertions, 211 deletions
diff --git a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java
index 4b94355ee..0bd45cd33 100644
--- a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java
+++ b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java
@@ -42,19 +42,22 @@ public class PoliciesPdpMerger {
* This method extract the content of a policy without knowing the key (policy Id).
* This JsonElement normally contains only the policy ID then the content,
* there is only one member in the Json element.
+ * As this is not really practical to use this method remove that
+ * nested Json.
*
* @param policyJsonElement The policy as JsonElement
* @return It return the content as JsonObject
*/
public static JsonObject getPolicyContentOutOfJsonElement(JsonElement policyJsonElement) {
- return policyJsonElement.getAsJsonObject()
- .get(((String) policyJsonElement.getAsJsonObject().keySet().toArray()[0])).getAsJsonObject();
+ mergeJsonElement(policyJsonElement.getAsJsonObject(), policyJsonElement.getAsJsonObject()
+ .remove(((String) policyJsonElement.getAsJsonObject().keySet().toArray()[0])).getAsJsonObject());
+ return policyJsonElement.getAsJsonObject();
}
/**
* This method merges 2 JsonElement together. If the jsonToMerge is null nothign is changed.
*
- * @param json The initial json that will received the data
+ * @param json The initial json that will received the data
* @param jsonToMerge The json that will be added to the first json object
*/
public static void mergeJsonElement(JsonObject json, JsonObject jsonToMerge) {
@@ -69,16 +72,16 @@ public class PoliciesPdpMerger {
*
* @param jsonPoliciesList The Json containing the policies from the PEF
* @param pdpGroupsJson The json containing the PDP groups info from the PEF
- * @return It returns a String containing the policies list enriched with PdpGroup info
+ * @return It returns a JsonObject containing the policies list enriched with PdpGroup info
*/
- public static String mergePoliciesAndPdpGroupStates(String jsonPoliciesList, String pdpGroupsJson) {
+ public static JsonObject mergePoliciesAndPdpGroupStates(String jsonPoliciesList, String pdpGroupsJson) {
PdpGroups pdpGroups = JsonUtils.GSON.fromJson(pdpGroupsJson, PdpGroups.class);
JsonObject policiesListJson =
JsonUtils.GSON.fromJson(jsonPoliciesList, JsonObject.class).get("topology_template")
.getAsJsonObject();
StreamSupport.stream(policiesListJson.get("policies").getAsJsonArray().spliterator(), true)
.forEach(policyJson -> enrichOnePolicy(pdpGroups, getPolicyContentOutOfJsonElement(policyJson)));
- return policiesListJson.toString();
+ return policiesListJson;
}
/**
diff --git a/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
index 011c24a9d..e1f138b1d 100644
--- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -1317,7 +1317,7 @@
</doTry>
</route>
</get>
- <get uri="/v2/policies/list" outType="java.lang.String" produces="application/json">
+ <get uri="/v2/policies/list" outType="com.google.gson.JsonObject" produces="application/json">
<route>
<removeHeaders pattern="*"/>
<doTry>
diff --git a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java
index 5da68f47f..21157eb71 100644
--- a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java
+++ b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java
@@ -97,6 +97,6 @@ public class PoliciesPdpMergerTest {
JSONAssert.assertEquals(ResourceFileUtils.getResourceAsString("example/policy/policy-merger.json"),
PoliciesPdpMerger.mergePoliciesAndPdpGroupStates(
ResourceFileUtils.getResourceAsString("http-cache/example/policy/api/v1/policies/.file"),
- pdpGroupsJson), true);
+ pdpGroupsJson).toString(), true);
}
}
diff --git a/src/test/resources/example/policy/policy-merger.json b/src/test/resources/example/policy/policy-merger.json
index 5c6bd5b6b..e1424fffb 100644
--- a/src/test/resources/example/policy/policy-merger.json
+++ b/src/test/resources/example/policy/policy-merger.json
@@ -1,214 +1,208 @@
{
"policies": [
{
- "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0": {
- "type": "onap.policies.monitoring.tcagen2",
- "type_version": "1.0.0",
- "properties": {
- "tca.policy": {
- "domain": "measurementsForVfScaling",
- "metricsPerEventName": [
- {
- "policyScope": "DCAE",
- "thresholds": [
- {
- "version": "1.0.2",
- "severity": "MAJOR",
- "thresholdValue": 200,
- "closedLoopEventStatus": "ONSET",
- "closedLoopControlName": "LOOP_test",
- "direction": "LESS_OR_EQUAL",
- "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta"
- }
- ],
- "eventName": "vLoadBalancer",
- "policyVersion": "v0.0.1",
- "controlLoopSchemaType": "VM",
- "policyName": "DCAE.Config_tca-hi-lo"
- }
- ]
- }
- },
- "name": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0",
- "version": "1.0.0",
- "metadata": {
- "policy-id": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0",
- "policy-version": "1.0.0"
- },
- "pdpGroupInfo": {
- "pdpGroup": "pdpGroup2",
- "pdpSubGroup": "subGroup2"
- },
- "supportedPdpGroups": [
- {
- "pdpGroup2": [
- "subGroup2",
- "subGroup3"
- ]
- }
- ]
- }
+ "type": "onap.policies.monitoring.tcagen2",
+ "type_version": "1.0.0",
+ "properties": {
+ "tca.policy": {
+ "domain": "measurementsForVfScaling",
+ "metricsPerEventName": [
+ {
+ "policyScope": "DCAE",
+ "thresholds": [
+ {
+ "version": "1.0.2",
+ "severity": "MAJOR",
+ "thresholdValue": 200,
+ "closedLoopEventStatus": "ONSET",
+ "closedLoopControlName": "LOOP_test",
+ "direction": "LESS_OR_EQUAL",
+ "fieldPath": "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta"
+ }
+ ],
+ "eventName": "vLoadBalancer",
+ "policyVersion": "v0.0.1",
+ "controlLoopSchemaType": "VM",
+ "policyName": "DCAE.Config_tca-hi-lo"
+ }
+ ]
+ }
+ },
+ "name": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0",
+ "version": "1.0.0",
+ "metadata": {
+ "policy-id": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0",
+ "policy-version": "1.0.0"
+ },
+ "pdpGroupInfo": {
+ "pdpGroup": "pdpGroup2",
+ "pdpSubGroup": "subGroup2"
+ },
+ "supportedPdpGroups": [
+ {
+ "pdpGroup2": [
+ "subGroup2",
+ "subGroup3"
+ ]
+ }
+ ]
},
{
- "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd": {
- "type": "onap.policies.controlloop.operational.common.Drools",
- "type_version": "1.0.0",
- "properties": {
- "abatement": false,
- "operations": [
- {
- "failure_retries": "final_failure_retries",
- "id": "test1",
- "failure_timeout": "final_failure_timeout",
- "failure": "final_failure",
- "operation": {
- "payload": {
- "artifact_name": "baseconfiguration",
- "artifact_version": "1.0.0",
- "mode": "async",
- "data": "{\"resource-assignment-properties\":{\"request-id\":\"\",\"service-instance-id\":\"\",\"hostname\":\"\",\"request-info\":{\"prop1\":\"\",\"prop2\":\"\"}}}"
- },
- "target": {
- "entityIds": {
- "resourceID": "Vloadbalancerms..vdns..module-3",
- "modelInvariantId": "4c10ba9b-f88f-415e-9de3-5d33336047fa",
- "modelVersionId": "4fa73b49-8a6c-493e-816b-eb401567b720",
- "modelName": "Vloadbalancerms..vdns..module-3",
- "modelVersion": "1",
- "modelCustomizationId": "bafcdab0-801d-4d81-9ead-f464640a38b1"
- },
- "targetType": "VNF"
+ "type": "onap.policies.controlloop.operational.common.Drools",
+ "type_version": "1.0.0",
+ "properties": {
+ "abatement": false,
+ "operations": [
+ {
+ "failure_retries": "final_failure_retries",
+ "id": "test1",
+ "failure_timeout": "final_failure_timeout",
+ "failure": "final_failure",
+ "operation": {
+ "payload": {
+ "artifact_name": "baseconfiguration",
+ "artifact_version": "1.0.0",
+ "mode": "async",
+ "data": "{\"resource-assignment-properties\":{\"request-id\":\"\",\"service-instance-id\":\"\",\"hostname\":\"\",\"request-info\":{\"prop1\":\"\",\"prop2\":\"\"}}}"
+ },
+ "target": {
+ "entityIds": {
+ "resourceID": "Vloadbalancerms..vdns..module-3",
+ "modelInvariantId": "4c10ba9b-f88f-415e-9de3-5d33336047fa",
+ "modelVersionId": "4fa73b49-8a6c-493e-816b-eb401567b720",
+ "modelName": "Vloadbalancerms..vdns..module-3",
+ "modelVersion": "1",
+ "modelCustomizationId": "bafcdab0-801d-4d81-9ead-f464640a38b1"
},
- "actor": "SDNR",
- "operation": "BandwidthOnDemand"
+ "targetType": "VNF"
},
- "failure_guard": "final_failure_guard",
- "retries": 0,
- "timeout": 0,
- "failure_exception": "final_failure_exception",
- "description": "test",
- "success": "final_success"
- }
- ],
- "trigger": "test1",
- "timeout": 0,
- "id": "LOOP_test"
- },
- "name": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd",
- "version": "1.0.0",
- "metadata": {
- "policy-id": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd",
- "policy-version": "1.0.0"
- },
- "pdpGroupInfo": {
- "pdpGroup": "pdpGroup2",
- "pdpSubGroup": "subGroup3"
- },
- "supportedPdpGroups": [
- {
- "pdpGroup2": [
- "subGroup2",
- "subGroup3"
- ]
+ "actor": "SDNR",
+ "operation": "BandwidthOnDemand"
+ },
+ "failure_guard": "final_failure_guard",
+ "retries": 0,
+ "timeout": 0,
+ "failure_exception": "final_failure_exception",
+ "description": "test",
+ "success": "final_success"
}
- ]
- }
+ ],
+ "trigger": "test1",
+ "timeout": 0,
+ "id": "LOOP_test"
+ },
+ "name": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd",
+ "version": "1.0.0",
+ "metadata": {
+ "policy-id": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd",
+ "policy-version": "1.0.0"
+ },
+ "pdpGroupInfo": {
+ "pdpGroup": "pdpGroup2",
+ "pdpSubGroup": "subGroup3"
+ },
+ "supportedPdpGroups": [
+ {
+ "pdpGroup2": [
+ "subGroup2",
+ "subGroup3"
+ ]
+ }
+ ]
},
{
- "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP": {
- "type": "onap.policies.Naming",
- "type_version": "1.0.0",
- "properties": {
- "naming-models": [
- {
- "naming-type": "VNF",
- "naming-recipe": "AIC_CLOUD_REGION|DELIMITER|CONSTANT|DELIMITER|TIMESTAMP",
- "name-operation": "to_lower_case()",
- "naming-properties": [
- {
- "property-name": "AIC_CLOUD_REGION"
- },
- {
- "property-name": "CONSTANT",
- "property-value": "onap-nf"
- },
- {
- "property-name": "TIMESTAMP"
- },
- {
- "property-value": "-",
- "property-name": "DELIMITER"
- }
- ]
- },
- {
- "naming-type": "VNFC",
- "naming-recipe": "VNF_NAME|DELIMITER|NFC_NAMING_CODE|DELIMITER|SEQUENCE",
- "name-operation": "to_lower_case()",
- "naming-properties": [
- {
- "property-name": "VNF_NAME"
- },
- {
- "property-name": "SEQUENCE",
- "increment-sequence": {
- "max": "zzz",
- "scope": "ENTIRETY",
- "start-value": "1",
- "length": "3",
- "increment": "1",
- "sequence-type": "alpha-numeric"
- }
- },
- {
- "property-name": "NFC_NAMING_CODE"
- },
- {
- "property-value": "-",
- "property-name": "DELIMITER"
+ "type": "onap.policies.Naming",
+ "type_version": "1.0.0",
+ "properties": {
+ "naming-models": [
+ {
+ "naming-type": "VNF",
+ "naming-recipe": "AIC_CLOUD_REGION|DELIMITER|CONSTANT|DELIMITER|TIMESTAMP",
+ "name-operation": "to_lower_case()",
+ "naming-properties": [
+ {
+ "property-name": "AIC_CLOUD_REGION"
+ },
+ {
+ "property-name": "CONSTANT",
+ "property-value": "onap-nf"
+ },
+ {
+ "property-name": "TIMESTAMP"
+ },
+ {
+ "property-value": "-",
+ "property-name": "DELIMITER"
+ }
+ ]
+ },
+ {
+ "naming-type": "VNFC",
+ "naming-recipe": "VNF_NAME|DELIMITER|NFC_NAMING_CODE|DELIMITER|SEQUENCE",
+ "name-operation": "to_lower_case()",
+ "naming-properties": [
+ {
+ "property-name": "VNF_NAME"
+ },
+ {
+ "property-name": "SEQUENCE",
+ "increment-sequence": {
+ "max": "zzz",
+ "scope": "ENTIRETY",
+ "start-value": "1",
+ "length": "3",
+ "increment": "1",
+ "sequence-type": "alpha-numeric"
}
- ]
- },
- {
- "naming-type": "VF-MODULE",
- "naming-recipe": "VNF_NAME|DELIMITER|VF_MODULE_LABEL|DELIMITER|VF_MODULE_TYPE|DELIMITER|SEQUENCE",
- "name-operation": "to_lower_case()",
- "naming-properties": [
- {
- "property-name": "VNF_NAME"
- },
- {
- "property-value": "-",
- "property-name": "DELIMITER"
- },
- {
- "property-name": "VF_MODULE_LABEL"
- },
- {
- "property-name": "VF_MODULE_TYPE"
- },
- {
- "property-name": "SEQUENCE",
- "increment-sequence": {
- "max": "zzz",
- "scope": "PRECEEDING",
- "start-value": "1",
- "length": "3",
- "increment": "1",
- "sequence-type": "alpha-numeric"
- }
+ },
+ {
+ "property-name": "NFC_NAMING_CODE"
+ },
+ {
+ "property-value": "-",
+ "property-name": "DELIMITER"
+ }
+ ]
+ },
+ {
+ "naming-type": "VF-MODULE",
+ "naming-recipe": "VNF_NAME|DELIMITER|VF_MODULE_LABEL|DELIMITER|VF_MODULE_TYPE|DELIMITER|SEQUENCE",
+ "name-operation": "to_lower_case()",
+ "naming-properties": [
+ {
+ "property-name": "VNF_NAME"
+ },
+ {
+ "property-value": "-",
+ "property-name": "DELIMITER"
+ },
+ {
+ "property-name": "VF_MODULE_LABEL"
+ },
+ {
+ "property-name": "VF_MODULE_TYPE"
+ },
+ {
+ "property-name": "SEQUENCE",
+ "increment-sequence": {
+ "max": "zzz",
+ "scope": "PRECEEDING",
+ "start-value": "1",
+ "length": "3",
+ "increment": "1",
+ "sequence-type": "alpha-numeric"
}
- ]
- }
- ],
- "policy-instance-name": "ONAP_NF_NAMING_TIMESTAMP"
- },
- "name": "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP",
- "version": "1.0.0",
- "metadata": {
- "policy-id": "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP",
- "policy-version": "1.0.0"
- }
+ }
+ ]
+ }
+ ],
+ "policy-instance-name": "ONAP_NF_NAMING_TIMESTAMP"
+ },
+ "name": "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP",
+ "version": "1.0.0",
+ "metadata": {
+ "policy-id": "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP",
+ "policy-version": "1.0.0"
}
}
]
diff --git a/src/test/resources/http-cache/example/policy/pap/v1/pdps/.file b/src/test/resources/http-cache/example/policy/pap/v1/pdps/.file
index af1944c59..b0d6819af 100644
--- a/src/test/resources/http-cache/example/policy/pap/v1/pdps/.file
+++ b/src/test/resources/http-cache/example/policy/pap/v1/pdps/.file
@@ -16,6 +16,10 @@
{
"name": "onap.policies.controlloop.Operational",
"version": "1.0.0"
+ },
+ {
+ "name": "onap.policies.controlloop.operational.common.*",
+ "version": "1.0.0"
}
]
},
@@ -71,10 +75,6 @@
"pdpType": "xacml",
"policies": [
{
- "name": "SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP",
- "version": "1.0.0"
- },
- {
"name": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0",
"version": "1.0.0"
}
@@ -84,7 +84,12 @@
{
"name": "onap.policies.monitoring.*",
"version": "1.0.0"
+ },
+ {
+ "name": "onap.policies.Naming",
+ "version": "1.0.0"
}
+
]
}
],