diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2019-10-21 12:56:25 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-10-21 12:56:25 +0000 |
commit | 3107498c86304ef114e6799ee430013fc26e1750 (patch) | |
tree | 62ecf0aeed2947f559c89d51ba9dc12c4abb4a2f /applications/monitoring | |
parent | 8f6a9a6df2ab7255bddbbdfb9ee03aa5713674d0 (diff) | |
parent | 9ff68b1ed845e94944f99c32eef209eb63c6469d (diff) |
Merge "Modified Decision API to accept query parameters and abbreviate Monitor decision results"
Diffstat (limited to 'applications/monitoring')
2 files changed, 66 insertions, 5 deletions
diff --git a/applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java b/applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java index 1591b919..3c9a4fba 100644 --- a/applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java +++ b/applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java @@ -22,14 +22,22 @@ package org.onap.policy.xacml.pdp.application.monitoring; +import com.att.research.xacml.api.Request; +import com.att.research.xacml.api.Response; import java.util.ArrayList; import java.util.Arrays; import java.util.List; - +import java.util.Map; +import java.util.Map.Entry; +import org.apache.commons.lang3.tuple.Pair; +import org.onap.policy.models.decisions.concepts.DecisionRequest; +import org.onap.policy.models.decisions.concepts.DecisionResponse; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator; import org.onap.policy.pdp.xacml.application.common.std.StdCombinedPolicyResultsTranslator; import org.onap.policy.pdp.xacml.application.common.std.StdXacmlApplicationServiceProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This is the engine class that manages the instance of the XACML PDP engine. @@ -41,6 +49,7 @@ import org.onap.policy.pdp.xacml.application.common.std.StdXacmlApplicationServi * */ public class MonitoringPdpApplication extends StdXacmlApplicationServiceProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPdpApplication.class); private static final String ONAP_MONITORING_BASE_POLICY_TYPE = "onap.Monitoring"; private static final String ONAP_MONITORING_CDAP = "onap.policies.monitoring.cdap.tca.hi.lo.app"; @@ -96,8 +105,60 @@ public class MonitoringPdpApplication extends StdXacmlApplicationServiceProvider } @Override + public Pair<DecisionResponse, Response> makeDecision(DecisionRequest request, + Map<String, String[]> requestQueryParams) { + // + // Convert to a XacmlRequest + // + Request xacmlRequest = this.getTranslator().convertRequest(request); + // + // Now get a decision + // + Response xacmlResponse = this.xacmlDecision(xacmlRequest); + // + // Convert to a DecisionResponse + // + DecisionResponse decisionResponse = this.getTranslator().convertResponse(xacmlResponse); + // + // Abbreviate results if needed + // + if (checkAbbreviateResults(requestQueryParams) && decisionResponse.getPolicies() != null + && !decisionResponse.getPolicies().isEmpty()) { + LOGGER.info("Abbreviating decision results {}", decisionResponse); + for (Entry<String, Object> entry : decisionResponse.getPolicies().entrySet()) { + if (entry.getValue() instanceof Map) { + @SuppressWarnings("unchecked") + Map<String, Object> policy = (Map<String, Object>) entry.getValue(); + policy.remove("properties"); + policy.remove("name"); + policy.remove("version"); + } + } + } + return Pair.of(decisionResponse, xacmlResponse); + } + + @Override protected ToscaPolicyTranslator getTranslator(String type) { return translator; } + /** + * Checks the query parameters to determine whether the decision results should be abbreviated. + * + * @param queryParams - http request query parameters + */ + private boolean checkAbbreviateResults(Map<String, String[]> queryParams) { + if (queryParams != null && !queryParams.isEmpty()) { + // Check if query params contains "abbrev" flag + if (queryParams.containsKey("abbrev")) { + return Arrays.asList(queryParams.get("abbrev")).contains("true"); + } else { + LOGGER.info("Unsupported query param for Monitoring application: {}", queryParams); + return false; + } + } + LOGGER.info("Query parameters empty"); + return false; + } } diff --git a/applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java b/applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java index a92ba6f8..1cba4967 100644 --- a/applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java +++ b/applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java @@ -156,7 +156,7 @@ public class MonitoringPdpApplicationTest { // // Ask for a decision // - Pair<DecisionResponse, Response> decision = service.makeDecision(requestSinglePolicy); + Pair<DecisionResponse, Response> decision = service.makeDecision(requestSinglePolicy, null); LOGGER.info("Decision {}", decision); assertThat(decision.getKey()).isNotNull(); @@ -178,7 +178,7 @@ public class MonitoringPdpApplicationTest { // // Ask for a decision // - Pair<DecisionResponse, Response> decision = service.makeDecision(requestSinglePolicy); + Pair<DecisionResponse, Response> decision = service.makeDecision(requestSinglePolicy, null); LOGGER.info("Decision {}", decision); assertThat(decision.getKey()).isNotNull(); @@ -190,7 +190,7 @@ public class MonitoringPdpApplicationTest { // // Ask for a decision based on policy-type // - decision = service.makeDecision(requestPolicyType); + decision = service.makeDecision(requestPolicyType, null); LOGGER.info("Decision {}", decision); assertThat(decision.getKey()).isNotNull(); @@ -209,7 +209,7 @@ public class MonitoringPdpApplicationTest { // // Ask for a decision // - decision = service.makeDecision(requestSinglePolicy); + decision = service.makeDecision(requestSinglePolicy, null); LOGGER.info("Decision {}", decision.getKey()); assertThat(decision.getKey()).isNotNull(); |