From 44a539f0b8ac56494ce2100aab798f268526a127 Mon Sep 17 00:00:00 2001 From: sebdet Date: Tue, 16 Feb 2021 14:53:43 +0100 Subject: Introduce a new endpoint to create policy One first part of the update is to create a policy version from an existing one (this is similar as the create new policy). The policy-flow.xml has been refactored so that the same policy query is done for policies and loop related flows. A code has been added to remove fields from the UI that could be present (the PDP group info json enrichment) Issue-ID: POLICY-2926 Signed-off-by: sebdet Change-Id: Ia60c656a9b5100296042d3346d5c97c8dad5d041 (cherry picked from commit a0a3a03686a386bf6def6f7da6de4d3f6a11ce61) --- .../clamp/policy/pdpgroup/PdpGroupsAnalyzer.java | 9 +- .../clamp/policy/pdpgroup/PoliciesPdpMerger.java | 12 + .../resources/clds/camel/rest/clamp-api-v2.xml | 54 +++- .../resources/clds/camel/routes/policy-flows.xml | 296 ++++++++++++--------- .../policy/pdpgroup/PoliciesPdpMergerTest.java | 12 + .../example/policy/single-policy-enriched.json | 47 ++++ ui-react/src/api/PolicyService.js | 2 +- .../components/dialogs/Policy/ViewAllPolicies.js | 26 +- 8 files changed, 317 insertions(+), 141 deletions(-) create mode 100644 src/test/resources/example/policy/single-policy-enriched.json 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 @@ - + + + @@ -1347,17 +1349,63 @@ + message="GET Policies list JSON request failed: ${exception.stacktrace}"/> 500 - GET Policy model YAML FAILED + GET Policies list JSON FAILED + + + + + + + + + + + + ${header.policyModelName} + + + ${header.policyModelVersion} + + + + + + + + java.lang.Exception + + true + + + + + 500 + + + CREATE Policy FAILED + + + + + + + message="GET policy request FAILED for loop: ${header.loopName}, ${exception.stacktrace}"/> + uri="bean:org.onap.policy.clamp.loop.log.LoopLogService?method=addLog('GET policy request failed, Error reported: ${exception.message}','ERROR',${exchangeProperty[loopObject]})"/> @@ -117,9 +117,9 @@ + message="GET policy request FAILED for loop: ${header.loopName}, ${exception.stacktrace}"/> + uri="bean:org.onap.policy.clamp.loop.log.LoopLogService?method=addLog('GET policy request failed, Error reported: ${exception.message}','ERROR',${exchangeProperty[loopObject]})"/> @@ -137,108 +137,26 @@ - - - - - - - GET - - - ${exchangeProperty[X-ONAP-RequestID]} - - - - ${exchangeProperty[X-ONAP-InvocationID]} - - - - ${exchangeProperty[X-ONAP-PartnerName]} - - - - - - - - - - - - - - - - - - GET - - - ${exchangeProperty[X-ONAP-RequestID]} - - - - ${exchangeProperty[X-ONAP-InvocationID]} - - - - ${exchangeProperty[X-ONAP-PartnerName]} - - - - - - - - - - - - - + + + + message="Creating Policy from loop object: ${exchangeProperty[policy].getName()}"/> + uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Creating Policy from loop object')"/> ${exchangeProperty[policy].createPolicyPayload()} - - POST - - - application/json - - - ${exchangeProperty[X-ONAP-RequestID]} - - - - ${exchangeProperty[X-ONAP-InvocationID]} - - - - ${exchangeProperty[X-ONAP-PartnerName]} - - - - + + ${exchangeProperty[policy].getPolicyModel().getPolicyModelType()} + + + ${exchangeProperty[policy].getPolicyModel().getVersion()} + + - @@ -303,6 +221,7 @@ + @@ -402,6 +321,116 @@ + + + + + + + + 1.0.0 + + + + ${exchangeProperty[policyName]} PDP Group removal status + + + + POLICY + + + + java.lang.Exception + + false + + + PDP Group removal, Error reported: ${exception} + + + POLICY + + + + + + + + + + + + + + + + + GET + + + ${exchangeProperty[X-ONAP-RequestID]} + + + + ${exchangeProperty[X-ONAP-InvocationID]} + + + + ${exchangeProperty[X-ONAP-PartnerName]} + + + + + + + + + + + + + + + + + + + GET + + + ${exchangeProperty[X-ONAP-RequestID]} + + + + ${exchangeProperty[X-ONAP-InvocationID]} + + + + ${exchangeProperty[X-ONAP-PartnerName]} + + + + + + + + + + + + @@ -436,6 +465,7 @@ + @@ -470,13 +500,14 @@ - - + + + + message="Undeploy POLICY from PAP: ${exchangeProperty[policyName]}/${exchangeProperty[policyVersion]}"/> + uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Undeploy POLICY from PAP')"/> null @@ -496,30 +527,47 @@ + message="Endpoint to delete policy from PDP Group: {{clamp.config.policy.pap.url}}/pdps/policies/${exchangeProperty[policyName]}/versions/${exchangeProperty[policyVersion]}"> - - ${exchangeProperty[policyName]} PDP Group removal status + uri="{{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/policies/${exchangeProperty[policyName]}/versions/${exchangeProperty[policyVersion]}?bridgeEndpoint=true&useSystemProperties=true&mapHttpMessageHeaders=false&throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&authUsername={{clamp.config.policy.pap.userName}}&authPassword={{clamp.config.policy.pap.password}}&httpClient.connectTimeout=10000&httpClient.socketTimeout=20000&authenticationPreemptive=true&connectionClose=true"/> + + + + + + + + + + + + + + + POST + + + application/json + + + ${exchangeProperty[X-ONAP-RequestID]} - - - POLICY - - - - java.lang.Exception - - false - - - PDP Group removal, Error reported: ${exception} - - - POLICY - - - + + + ${exchangeProperty[X-ONAP-InvocationID]} + + + + ${exchangeProperty[X-ONAP-PartnerName]} + + + + { 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 ( @@ -285,7 +290,7 @@ export default class ViewAllPolicies extends React.Component { { icon: forwardRef((props, 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 {
Policy Properties Editor
- + + -- cgit 1.2.3-korg