summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupsAnalyzer.java9
-rw-r--r--src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java12
-rw-r--r--src/main/resources/clds/camel/rest/clamp-api-v2.xml54
-rw-r--r--src/main/resources/clds/camel/routes/policy-flows.xml296
-rw-r--r--src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java12
-rw-r--r--src/test/resources/example/policy/single-policy-enriched.json47
-rw-r--r--ui-react/src/api/PolicyService.js2
-rw-r--r--ui-react/src/components/dialogs/Policy/ViewAllPolicies.js26
8 files changed, 317 insertions, 141 deletions
diff --git a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupsAnalyzer.java b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupsAnalyzer.java
index 83ece5795..1d6d21977 100644
--- a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupsAnalyzer.java
+++ b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupsAnalyzer.java
@@ -36,10 +36,13 @@ import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
/**
- * This is an utility class to do searching in pdp groups.
+ * This is an utility class to do searching in pdp groups and create json object describing the result.
*/
public class PdpGroupsAnalyzer {
+ public static final String ASSIGNED_PDP_GROUPS_INFO = "pdpGroupInfo";
+ public static final String SUPPORTED_PDP_GROUPS_INFO = "supportedPdpGroups";
+
/**
* Get supported subGroups based on the defined policy type and version for s specific PDPgroup.
* It returns null if the Group is not ACTIVE or if the policytype/version has not been found in the PDPSubgroups.
@@ -80,7 +83,7 @@ public class PdpGroupsAnalyzer {
public static JsonObject getSupportedPdpGroupsForModelType(PdpGroups pdpGroups, String policyType, String version) {
JsonObject supportedPdpGroups = new JsonObject();
JsonArray pdpGroupsArray = new JsonArray();
- supportedPdpGroups.add("supportedPdpGroups", pdpGroupsArray);
+ supportedPdpGroups.add(SUPPORTED_PDP_GROUPS_INFO, pdpGroupsArray);
pdpGroups.getGroups().stream().map(pdpGroup -> PdpGroupsAnalyzer.getSupportedPdpSubgroupsForModelType(pdpGroup,
policyType, version)).filter(Objects::nonNull)
@@ -113,7 +116,7 @@ public class PdpGroupsAnalyzer {
public static JsonObject getPdpGroupDeploymentOfOnePolicy(PdpGroups pdpGroups, String policyName, String version) {
JsonObject pdpGroupInfo = new JsonObject();
JsonObject assignedPdpGroups = new JsonObject();
- pdpGroupInfo.add("pdpGroupInfo", assignedPdpGroups);
+ pdpGroupInfo.add(ASSIGNED_PDP_GROUPS_INFO, assignedPdpGroups);
ToscaPolicyIdentifier toscaPolicyIdentifier = new ToscaPolicyIdentifier(policyName, version);
pdpGroups.getGroups().stream().anyMatch(pdpGroup ->
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 7e3fe8cf4..cf3c1656c 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
@@ -101,4 +101,16 @@ public class PoliciesPdpMerger {
policyJsonNode.get("type_version").getAsString());
mergeJsonElement(policyJsonNode, supportedPdpGroupsJson);
}
+
+ /**
+ * This method removes the pdp States added for one policy.
+ *
+ * @param policyJsonNode The policy node in Json
+ */
+ public static JsonObject removePdpStatesOnePolicy(JsonObject policyJsonNode) {
+ // Simply remove the nodes we have added.
+ policyJsonNode.remove(PdpGroupsAnalyzer.ASSIGNED_PDP_GROUPS_INFO);
+ policyJsonNode.remove(PdpGroupsAnalyzer.SUPPORTED_PDP_GROUPS_INFO);
+ return policyJsonNode;
+ }
} \ No newline at end of file
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 7ca4f081e..bcad3ea33 100644
--- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -1316,7 +1316,9 @@
</doTry>
</route>
</get>
- <get uri="/v2/policies/list" outType="com.google.gson.JsonObject" produces="application/json">
+
+ <!-- Policy Related endpoints, not related to LOOP -->
+ <get uri="/v2/policies" outType="com.google.gson.JsonObject" produces="application/json">
<route>
<removeHeaders pattern="*"/>
<doTry>
@@ -1347,17 +1349,63 @@
<to
uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=errorLog()"/>
<log loggingLevel="ERROR"
- message="GET Policy Model YAML request failed for type: ${header.policyModelType}, ${exception.stacktrace}"/>
+ message="GET Policies list JSON request failed: ${exception.stacktrace}"/>
<setHeader headerName="CamelHttpResponseCode">
<constant>500</constant>
</setHeader>
<setBody>
- <simple>GET Policy model YAML FAILED</simple>
+ <simple>GET Policies list JSON FAILED</simple>
</setBody>
</doCatch>
</doTry>
</route>
</get>
+ <!-- Update an existing policy, therefore it removes it from pdp first, delete it and then recreate it -->
+ <!-- TO BE DONE -->
+
+ <!-- Create a new policy -->
+ <post uri="/v2/policies/{policyModelName}/{policyModelVersion}" outType="com.google.gson.JsonObject" produces="application/json">
+ <route>
+ <removeHeaders pattern="*"
+ excludePattern="policyModelName|policyModelVersion"/>
+ <doTry>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=startLog(*, 'CREATE a new Policy ')"/>
+ <to
+ uri="bean:org.onap.policy.clamp.authorization.AuthorizationController?method=authorize(*,'policies','','update')"/>
+ <setProperty propertyName="policyModelName">
+ <simple>${header.policyModelName}</simple>
+ </setProperty>
+ <setProperty propertyName="policyModelVersion">
+ <simple>${header.policyModelVersion}</simple>
+ </setProperty>
+ <setBody>
+ <method ref="org.onap.policy.clamp.policy.pdpgroup.PoliciesPdpMerger"
+ method="removePdpStatesOnePolicy(${body})"/>
+ </setBody>
+ <to uri="direct:create-policy"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=endLog()"/>
+ <doCatch>
+ <exception>java.lang.Exception</exception>
+ <handled>
+ <constant>true</constant>
+ </handled>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=errorLog()"/>
+ <log loggingLevel="ERROR"
+ message="CREATE Policy request failed for type: ${header.policyModelType}/${header.policyModelVersion}, ${exception.stacktrace}"/>
+ <setHeader headerName="CamelHttpResponseCode">
+ <constant>500</constant>
+ </setHeader>
+ <setBody>
+ <simple>CREATE Policy FAILED</simple>
+ </setBody>
+ </doCatch>
+ </doTry>
+ </route>
+ </post>
+
<get uri="/v2/clampInformation" outType="org.onap.policy.clamp.clds.model.ClampInformation"
produces="application/json">
<to
diff --git a/src/main/resources/clds/camel/routes/policy-flows.xml b/src/main/resources/clds/camel/routes/policy-flows.xml
index 7048a5e03..dda5f2cf2 100644
--- a/src/main/resources/clds/camel/routes/policy-flows.xml
+++ b/src/main/resources/clds/camel/routes/policy-flows.xml
@@ -63,9 +63,9 @@
</handled>
<log loggingLevel="ERROR"
- message="GET policy request FAILED for loop: ${header.loopName}, ${exception.stacktrace}" />
+ message="GET policy request FAILED for loop: ${header.loopName}, ${exception.stacktrace}"/>
<to
- uri="bean:org.onap.policy.clamp.loop.log.LoopLogService?method=addLog('GET policy request failed, Error reported: ${exception.message}','ERROR',${exchangeProperty[loopObject]})" />
+ uri="bean:org.onap.policy.clamp.loop.log.LoopLogService?method=addLog('GET policy request failed, Error reported: ${exception.message}','ERROR',${exchangeProperty[loopObject]})"/>
</doCatch>
<doFinally>
<to uri="direct:reset-raise-http-exception-flag"/>
@@ -117,9 +117,9 @@
</handled>
<log loggingLevel="ERROR"
- message="GET policy request FAILED for loop: ${header.loopName}, ${exception.stacktrace}" />
+ message="GET policy request FAILED for loop: ${header.loopName}, ${exception.stacktrace}"/>
<to
- uri="bean:org.onap.policy.clamp.loop.log.LoopLogService?method=addLog('GET policy request failed, Error reported: ${exception.message}','ERROR',${exchangeProperty[loopObject]})" />
+ uri="bean:org.onap.policy.clamp.loop.log.LoopLogService?method=addLog('GET policy request failed, Error reported: ${exception.message}','ERROR',${exchangeProperty[loopObject]})"/>
</doCatch>
<doFinally>
<to uri="direct:reset-raise-http-exception-flag"/>
@@ -137,108 +137,26 @@
</doFinally>
</doTry>
</route>
- <route id="get-all-policy-models">
- <from uri="direct:get-all-policy-models"/>
- <doTry>
- <log loggingLevel="INFO" message="Getting all the policy models"/>
- <to
- uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Getting all the policy models')"/>
- <setHeader headerName="CamelHttpMethod">
- <constant>GET</constant>
- </setHeader>
- <setHeader headerName="X-ONAP-RequestID">
- <simple>${exchangeProperty[X-ONAP-RequestID]}
- </simple>
- </setHeader>
- <setHeader headerName="X-ONAP-InvocationID">
- <simple>${exchangeProperty[X-ONAP-InvocationID]}
- </simple>
- </setHeader>
- <setHeader headerName="X-ONAP-PartnerName">
- <simple>${exchangeProperty[X-ONAP-PartnerName]}
- </simple>
- </setHeader>
- <log loggingLevel="INFO"
- message="Endpoint to get all policy models: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes"></log>
- <toD
- uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes?bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
- <convertBodyTo type="java.lang.String"/>
- <doFinally>
- <to uri="direct:reset-raise-http-exception-flag"/>
- <to
- uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
- </doFinally>
- </doTry>
- </route>
- <route id="get-policy-tosca-model">
- <from uri="direct:get-policy-tosca-model"/>
- <doTry>
- <log loggingLevel="INFO"
- message="Getting the policy tosca model: ${exchangeProperty[policyModelName]}/${exchangeProperty[policyModelVersion]}"/>
- <to
- uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Getting the policy model')"/>
- <setHeader headerName="CamelHttpMethod">
- <constant>GET</constant>
- </setHeader>
- <setHeader headerName="X-ONAP-RequestID">
- <simple>${exchangeProperty[X-ONAP-RequestID]}
- </simple>
- </setHeader>
- <setHeader headerName="X-ONAP-InvocationID">
- <simple>${exchangeProperty[X-ONAP-InvocationID]}
- </simple>
- </setHeader>
- <setHeader headerName="X-ONAP-PartnerName">
- <simple>${exchangeProperty[X-ONAP-PartnerName]}
- </simple>
- </setHeader>
- <log loggingLevel="INFO"
- message="Endpoint to get policy model: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policyModelName]}/versions/${exchangeProperty[policyModelVersion]}"></log>
- <toD
- uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policyModelName]}/versions/${exchangeProperty[policyModelVersion]}?bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
- <convertBodyTo type="java.lang.String"/>
- <doFinally>
- <to uri="direct:reset-raise-http-exception-flag"/>
- <to
- uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
- </doFinally>
- </doTry>
- </route>
- <route id="create-policy">
- <from uri="direct:create-policy"/>
+
+ <route id="create-policy-from-loop-object">
+ <from uri="direct:create-policy-from-loop-object"/>
<doTry>
<log loggingLevel="INFO"
- message="Creating Policy: ${exchangeProperty[policy].getName()}"/>
+ message="Creating Policy from loop object: ${exchangeProperty[policy].getName()}"/>
<to
- uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Create Policy')"/>
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Creating Policy from loop object')"/>
<setBody>
<simple>${exchangeProperty[policy].createPolicyPayload()}
</simple>
</setBody>
- <setHeader headerName="CamelHttpMethod">
- <constant>POST</constant>
- </setHeader>
- <setHeader headerName="Content-Type">
- <constant>application/json</constant>
- </setHeader>
- <setHeader headerName="X-ONAP-RequestID">
- <simple>${exchangeProperty[X-ONAP-RequestID]}
- </simple>
- </setHeader>
- <setHeader headerName="X-ONAP-InvocationID">
- <simple>${exchangeProperty[X-ONAP-InvocationID]}
- </simple>
- </setHeader>
- <setHeader headerName="X-ONAP-PartnerName">
- <simple>${exchangeProperty[X-ONAP-PartnerName]}
- </simple>
- </setHeader>
- <log loggingLevel="INFO"
- message="Endpoint to create policy: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policy].getPolicyModel().getPolicyModelType()}/versions/${exchangeProperty[policy].getPolicyModel().getVersion()}/policies"></log>
- <toD
- uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policy].getPolicyModel().getPolicyModelType()}/versions/${exchangeProperty[policy].getPolicyModel().getVersion()}/policies?bridgeEndpoint=true&amp;useSystemProperties=true&amp;mapHttpMessageHeaders=false&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+ <setProperty propertyName="policyModelType">
+ <simple>${exchangeProperty[policy].getPolicyModel().getPolicyModelType()}</simple>
+ </setProperty>
+ <setProperty propertyName="policyModelVersion">
+ <simple>${exchangeProperty[policy].getPolicyModel().getVersion()}</simple>
+ </setProperty>
+ <to uri="direct:create-policy"/>
<doFinally>
- <to uri="direct:reset-raise-http-exception-flag"/>
<to
uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
<setProperty propertyName="logMessage">
@@ -303,6 +221,7 @@
</doFinally>
</doTry>
</route>
+
<route id="add-all-to-active-pdp-group">
<from uri="direct:add-all-to-active-pdp-group"/>
<doTry>
@@ -402,6 +321,116 @@
</doFinally>
</doTry>
</route>
+
+ <route id="remove-one-policy-from-active-pdp-group">
+ <from uri="direct:remove-one-policy-from-active-pdp-group"/>
+ <doTry>
+ <log loggingLevel="INFO"
+ message="Removing policy from active PDP group for loop: ${exchangeProperty[loopObject].getName()}"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Removing one policy PDP group')"/>
+ <setProperty propertyName="policyVersion">
+ <simple>1.0.0</simple>
+ </setProperty>
+ <to uri="direct:undeploy-one-policy-from-pap"/>
+ <setProperty propertyName="logMessage">
+ <simple>${exchangeProperty[policyName]} PDP Group removal status
+ </simple>
+ </setProperty>
+ <setProperty propertyName="logComponent">
+ <simple>POLICY</simple>
+ </setProperty>
+ <to uri="direct:dump-loop-log-http-response"/>
+ <doCatch>
+ <exception>java.lang.Exception</exception>
+ <handled>
+ <constant>false</constant>
+ </handled>
+ <setProperty propertyName="logMessage">
+ <simple>PDP Group removal, Error reported: ${exception}</simple>
+ </setProperty>
+ <setProperty propertyName="logComponent">
+ <simple>POLICY</simple>
+ </setProperty>
+ <to uri="direct:dump-loop-log-http-response"/>
+ </doCatch>
+ <doFinally>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
+ </doFinally>
+ </doTry>
+ </route>
+
+ <!-- Camel routes not related to Loop context -->
+ <route id="get-all-policy-models">
+ <from uri="direct:get-all-policy-models"/>
+ <doTry>
+ <log loggingLevel="INFO" message="Getting all the policy models"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Getting all the policy models')"/>
+ <setHeader headerName="CamelHttpMethod">
+ <constant>GET</constant>
+ </setHeader>
+ <setHeader headerName="X-ONAP-RequestID">
+ <simple>${exchangeProperty[X-ONAP-RequestID]}
+ </simple>
+ </setHeader>
+ <setHeader headerName="X-ONAP-InvocationID">
+ <simple>${exchangeProperty[X-ONAP-InvocationID]}
+ </simple>
+ </setHeader>
+ <setHeader headerName="X-ONAP-PartnerName">
+ <simple>${exchangeProperty[X-ONAP-PartnerName]}
+ </simple>
+ </setHeader>
+ <log loggingLevel="INFO"
+ message="Endpoint to get all policy models: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes"></log>
+ <toD
+ uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes?bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+ <convertBodyTo type="java.lang.String"/>
+ <doFinally>
+ <to uri="direct:reset-raise-http-exception-flag"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
+ </doFinally>
+ </doTry>
+ </route>
+
+ <route id="get-policy-tosca-model">
+ <from uri="direct:get-policy-tosca-model"/>
+ <doTry>
+ <log loggingLevel="INFO"
+ message="Getting the policy tosca model: ${exchangeProperty[policyModelName]}/${exchangeProperty[policyModelVersion]}"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Getting the policy model')"/>
+ <setHeader headerName="CamelHttpMethod">
+ <constant>GET</constant>
+ </setHeader>
+ <setHeader headerName="X-ONAP-RequestID">
+ <simple>${exchangeProperty[X-ONAP-RequestID]}
+ </simple>
+ </setHeader>
+ <setHeader headerName="X-ONAP-InvocationID">
+ <simple>${exchangeProperty[X-ONAP-InvocationID]}
+ </simple>
+ </setHeader>
+ <setHeader headerName="X-ONAP-PartnerName">
+ <simple>${exchangeProperty[X-ONAP-PartnerName]}
+ </simple>
+ </setHeader>
+ <log loggingLevel="INFO"
+ message="Endpoint to get policy model: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policyModelName]}/versions/${exchangeProperty[policyModelVersion]}"></log>
+ <toD
+ uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policyModelName]}/versions/${exchangeProperty[policyModelVersion]}?bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+ <convertBodyTo type="java.lang.String"/>
+ <doFinally>
+ <to uri="direct:reset-raise-http-exception-flag"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
+ </doFinally>
+ </doTry>
+ </route>
+
<route id="get-all-pdp-groups">
<from uri="direct:get-all-pdp-groups"/>
<doTry>
@@ -436,6 +465,7 @@
</doFinally>
</doTry>
</route>
+
<route id="get-all-policies">
<from uri="direct:get-all-policies"/>
<doTry>
@@ -470,13 +500,14 @@
</doFinally>
</doTry>
</route>
- <route id="remove-one-policy-from-active-pdp-group">
- <from uri="direct:remove-one-policy-from-active-pdp-group"/>
+
+ <route id="undeploy-one-policy-from-pap">
+ <from uri="direct:undeploy-one-policy-from-pap"/>
<doTry>
<log loggingLevel="INFO"
- message="Removing policy from active PDP group for loop: ${exchangeProperty[loopObject].getName()}"/>
+ message="Undeploy POLICY from PAP: ${exchangeProperty[policyName]}/${exchangeProperty[policyVersion]}"/>
<to
- uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Removing one policy PDP group')"/>
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Undeploy POLICY from PAP')"/>
<setBody>
<constant>null</constant>
</setBody>
@@ -496,30 +527,47 @@
</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/policies/${exchangeProperty[policyName]}/versions/${exchangeProperty[policyVersion]}"></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;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
- <setProperty propertyName="logMessage">
- <simple>${exchangeProperty[policyName]} PDP Group removal status
+ uri="{{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/policies/${exchangeProperty[policyName]}/versions/${exchangeProperty[policyVersion]}?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;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+ <doFinally>
+ <to uri="direct:reset-raise-http-exception-flag"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
+ </doFinally>
+ </doTry>
+ </route>
+
+ <route id="create-policy">
+ <!-- Body should come from outside, expect a json describing the policy -->
+ <from uri="direct:create-policy"/>
+ <doTry>
+ <log loggingLevel="INFO"
+ message="Create Policy from model ${exchangeProperty[policyModelType]}/${exchangeProperty[policyModelVersion]}"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Create Policy')"/>
+ <setHeader headerName="CamelHttpMethod">
+ <constant>POST</constant>
+ </setHeader>
+ <setHeader headerName="Content-Type">
+ <constant>application/json</constant>
+ </setHeader>
+ <setHeader headerName="X-ONAP-RequestID">
+ <simple>${exchangeProperty[X-ONAP-RequestID]}
</simple>
- </setProperty>
- <setProperty propertyName="logComponent">
- <simple>POLICY</simple>
- </setProperty>
- <to uri="direct:dump-loop-log-http-response"/>
- <doCatch>
- <exception>java.lang.Exception</exception>
- <handled>
- <constant>false</constant>
- </handled>
- <setProperty propertyName="logMessage">
- <simple>PDP Group removal, Error reported: ${exception}</simple>
- </setProperty>
- <setProperty propertyName="logComponent">
- <simple>POLICY</simple>
- </setProperty>
- <to uri="direct:dump-loop-log-http-response"/>
- </doCatch>
+ </setHeader>
+ <setHeader headerName="X-ONAP-InvocationID">
+ <simple>${exchangeProperty[X-ONAP-InvocationID]}
+ </simple>
+ </setHeader>
+ <setHeader headerName="X-ONAP-PartnerName">
+ <simple>${exchangeProperty[X-ONAP-PartnerName]}
+ </simple>
+ </setHeader>
+ <log loggingLevel="INFO"
+ message="Endpoint to create policy: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policyModelType]}/versions/${exchangeProperty[policyModelVersion]}/policies"></log>
+ <toD
+ uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policyModelType]}/versions/${exchangeProperty[policyModelVersion]}/policies?bridgeEndpoint=true&amp;useSystemProperties=true&amp;mapHttpMessageHeaders=false&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
<doFinally>
<to uri="direct:reset-raise-http-exception-flag"/>
<to
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 21157eb71..adb797897 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
@@ -25,6 +25,7 @@ package org.onap.policy.clamp.policy.pdpgroup;
import static org.assertj.core.api.Assertions.assertThat;
+import com.google.gson.JsonObject;
import java.io.IOException;
import java.util.Arrays;
import org.junit.BeforeClass;
@@ -99,4 +100,15 @@ public class PoliciesPdpMergerTest {
ResourceFileUtils.getResourceAsString("http-cache/example/policy/api/v1/policies/.file"),
pdpGroupsJson).toString(), true);
}
+
+ @Test
+ public void testRemovePdpStatesOnePolicy() throws IOException {
+ JsonObject policiesList = PoliciesPdpMerger.removePdpStatesOnePolicy(JsonUtils.GSON
+ .fromJson(ResourceFileUtils.getResourceAsString("example/policy/single-policy-enriched.json"),
+ JsonObject.class));
+
+ assertThat(policiesList.get(PdpGroupsAnalyzer.ASSIGNED_PDP_GROUPS_INFO)).isNull();
+ assertThat(policiesList.get(PdpGroupsAnalyzer.SUPPORTED_PDP_GROUPS_INFO)).isNull();
+ assertThat(policiesList.size()).isEqualTo(6);
+ }
}
diff --git a/src/test/resources/example/policy/single-policy-enriched.json b/src/test/resources/example/policy/single-policy-enriched.json
new file mode 100644
index 000000000..66355e589
--- /dev/null
+++ b/src/test/resources/example/policy/single-policy-enriched.json
@@ -0,0 +1,47 @@
+{
+ "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"
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/ui-react/src/api/PolicyService.js b/ui-react/src/api/PolicyService.js
index d591b093d..fdbb5d5ea 100644
--- a/ui-react/src/api/PolicyService.js
+++ b/ui-react/src/api/PolicyService.js
@@ -22,7 +22,7 @@
export default class PolicyService {
static getPoliciesList() {
- return fetch(window.location.pathname + 'restservices/clds/v2/policies/list', {
+ return fetch(window.location.pathname + 'restservices/clds/v2/policies', {
method: 'GET',
credentials: 'same-origin'
})
diff --git a/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js b/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js
index 625aeb341..a1cf9d5c1 100644
--- a/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js
+++ b/ui-react/src/components/dialogs/Policy/ViewAllPolicies.js
@@ -146,8 +146,9 @@ export default class ViewAllPolicies extends React.Component {
this.handlePdpGroupChange = this.handlePdpGroupChange.bind(this);
this.createJsonEditor = this.createJsonEditor.bind(this);
this.handlePrefixGrouping = this.handlePrefixGrouping.bind(this);
- this.deletePolicy = this.deletePolicy.bind(this);
+ this.handleDeletePolicy = this.handleDeletePolicy.bind(this);
this.handleUpdatePolicy = this.handleUpdatePolicy.bind(this);
+ this.handleCreateNewVersion = this.handleCreateNewVersion(this);
this.getAllPolicies();
}
@@ -233,11 +234,6 @@ export default class ViewAllPolicies extends React.Component {
this.props.history.push('/')
}
- handleUpdatePolicy() {
- this.setState({ show: false });
- this.props.history.push('/')
- }
-
handleOnRowClick(rowData) {
PolicyToscaService.getToscaPolicyModel(rowData["type"], rowData["type_version"]).then(respJsonPolicyTosca => {
this.setState({
@@ -251,12 +247,21 @@ export default class ViewAllPolicies extends React.Component {
handlePrefixGrouping(event) {
this.setState({prefixGrouping: event.target.checked});
- };
+ }
- deletePolicy(event, rowData) {
+ handleDeletePolicy(event, rowData) {
return null;
}
+ handleCreateNewVersion(event,rowData) {
+ return null;
+ }
+
+ handleUpdatePolicy() {
+ this.setState({ show: false });
+ this.props.history.push('/')
+ }
+
render() {
return (
<ModalStyled size="xl" show={this.state.show} onHide={this.handleClose} backdrop="static" keyboard={false}>
@@ -285,7 +290,7 @@ export default class ViewAllPolicies extends React.Component {
{
icon: forwardRef((props, ref) => <DeleteOutline {...props} ref={ref} />),
tooltip: 'Delete Policy',
- onClick: (event, rowData) => this.deletePolicy(event, rowData)
+ onClick: (event, rowData) => this.handleDeletePolicy(event, rowData)
}
]}
@@ -293,7 +298,8 @@ export default class ViewAllPolicies extends React.Component {
<JsonEditorDiv>
<h5>Policy Properties Editor</h5>
<div id="policy-editor" title="Policy Properties"/>
- <Button variant="secondary" onClick={this.handleUpdatePolicy}>Update</Button>
+ <Button variant="secondary" title="Create a new policy version from the defined parameters" onClick={this.handleCreateNewVersion}>Create New Version</Button>
+ <Button variant="secondary" title="Update the current policy version, BE CAREFUL this will undeploy the policy from PDP, delete it and then recreate the policy" onClick={this.handleUpdatePolicy}>Update Current Version</Button>
</JsonEditorDiv>
</Modal.Body>
<Modal.Footer>