summaryrefslogtreecommitdiffstats
path: root/applications/monitoring/src/main
diff options
context:
space:
mode:
authorHOCKLA <ah999m@att.com>2019-10-14 14:25:29 -0500
committerAli Hockla <ah999m@att.com>2019-10-18 07:57:48 -0500
commit9ff68b1ed845e94944f99c32eef209eb63c6469d (patch)
tree7dfc63117d3a2f94e84e011368ace480563c14fc /applications/monitoring/src/main
parentc19f81387f4efc666cfa45b000275f3ee7c1d9d1 (diff)
Modified Decision API to accept query parameters and abbreviate Monitor decision results
Issue-ID: POLICY-2126 Change-Id: I18d50a8746ede792ec9507ab98125383c5914ba1 Signed-off-by: HOCKLA <ah999m@att.com>
Diffstat (limited to 'applications/monitoring/src/main')
-rw-r--r--applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java63
1 files changed, 62 insertions, 1 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;
+ }
}