aboutsummaryrefslogtreecommitdiffstats
path: root/applications
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-10-21 12:56:25 +0000
committerGerrit Code Review <gerrit@onap.org>2019-10-21 12:56:25 +0000
commit3107498c86304ef114e6799ee430013fc26e1750 (patch)
tree62ecf0aeed2947f559c89d51ba9dc12c4abb4a2f /applications
parent8f6a9a6df2ab7255bddbbdfb9ee03aa5713674d0 (diff)
parent9ff68b1ed845e94944f99c32eef209eb63c6469d (diff)
Merge "Modified Decision API to accept query parameters and abbreviate Monitor decision results"
Diffstat (limited to 'applications')
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationServiceProvider.java7
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java3
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java2
-rw-r--r--applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java5
-rw-r--r--applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplicationTest.java9
-rw-r--r--applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java63
-rw-r--r--applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java8
-rw-r--r--applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java4
8 files changed, 79 insertions, 22 deletions
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationServiceProvider.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationServiceProvider.java
index c3d66255..0b9975f7 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationServiceProvider.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationServiceProvider.java
@@ -22,10 +22,9 @@
package org.onap.policy.pdp.xacml.application.common;
import com.att.research.xacml.api.Response;
-
import java.nio.file.Path;
import java.util.List;
-
+import java.util.Map;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
@@ -103,8 +102,10 @@ public interface XacmlApplicationServiceProvider {
* Makes a decision given the incoming request and returns a response.
*
* @param request Incoming DecisionRequest object
+ * @param requestQueryParameters Http request query parameters
* @return response Responding DecisionResponse object
*/
- Pair<DecisionResponse, Response> makeDecision(DecisionRequest request);
+ Pair<DecisionResponse, Response> makeDecision(DecisionRequest request,
+ Map<String, String[]> requestQueryParameters);
}
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java
index 17119858..5f639c5c 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java
@@ -228,7 +228,8 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica
}
@Override
- public Pair<DecisionResponse, Response> makeDecision(DecisionRequest request) {
+ public Pair<DecisionResponse, Response> makeDecision(DecisionRequest request,
+ Map<String, String[]> requestQueryParams) {
//
// Convert to a XacmlRequest
//
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java
index 30419daf..6139a528 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProviderTest.java
@@ -263,7 +263,7 @@ public class StdXacmlApplicationServiceProviderTest {
DecisionResponse decresp = mock(DecisionResponse.class);
when(trans.convertResponse(resp)).thenReturn(decresp);
- Pair<DecisionResponse, Response> result = prov.makeDecision(decreq);
+ Pair<DecisionResponse, Response> result = prov.makeDecision(decreq, any());
assertSame(decresp, result.getKey());
assertSame(resp, result.getValue());
diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java
index ecd0fb76..efa0bdc9 100644
--- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java
+++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java
@@ -25,7 +25,6 @@ package org.onap.policy.xacml.pdp.application.guard;
import static org.assertj.core.api.Assertions.assertThat;
import com.att.research.xacml.api.Response;
-
import java.io.File;
import java.io.IOException;
import java.sql.Date;
@@ -35,10 +34,8 @@ import java.util.Map;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.UUID;
-
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
-
import org.apache.commons.lang3.tuple.Pair;
import org.junit.AfterClass;
import org.junit.Before;
@@ -202,7 +199,7 @@ public class CoordinationTest {
//
// Ask for a decision
//
- Pair<DecisionResponse, Response> decision = service.makeDecision(request);
+ Pair<DecisionResponse, Response> decision = service.makeDecision(request, null);
//
// Check decision
//
diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplicationTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplicationTest.java
index 4b9db0a3..7435fb96 100644
--- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplicationTest.java
+++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplicationTest.java
@@ -25,7 +25,6 @@ package org.onap.policy.xacml.pdp.application.guard;
import static org.assertj.core.api.Assertions.assertThat;
import com.att.research.xacml.api.Response;
-
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -37,10 +36,8 @@ import java.util.Map;
import java.util.Properties;
import java.util.ServiceLoader;
import java.util.UUID;
-
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
-
import org.apache.commons.lang3.tuple.Pair;
import org.junit.AfterClass;
import org.junit.Before;
@@ -196,7 +193,7 @@ public class GuardPdpApplicationTest {
//
// Ask for a decision
//
- Pair<DecisionResponse, Response> decision = service.makeDecision(request);
+ Pair<DecisionResponse, Response> decision = service.makeDecision(request, null);
//
// Check decision
//
@@ -344,7 +341,7 @@ public class GuardPdpApplicationTest {
//
// Ask for a decision - should get permit
//
- Pair<DecisionResponse, Response> decision = service.makeDecision(request);
+ Pair<DecisionResponse, Response> decision = service.makeDecision(request, null);
LOGGER.info("Looking for Permit Decision {}", decision.getKey());
assertThat(decision.getKey()).isNotNull();
assertThat(decision.getKey().getStatus()).isNotNull();
@@ -355,7 +352,7 @@ public class GuardPdpApplicationTest {
guard.put("vfCount", "10");
resource.put("guard", guard);
request.setResource(resource);
- decision = service.makeDecision(request);
+ decision = service.makeDecision(request, null);
LOGGER.info("Looking for Deny Decision {}", decision.getKey());
assertThat(decision.getKey()).isNotNull();
assertThat(decision.getKey().getStatus()).isNotNull();
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();
diff --git a/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java b/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java
index 01fd3268..b39f5c7f 100644
--- a/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java
+++ b/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java
@@ -168,7 +168,7 @@ public class OptimizationPdpApplicationTest {
//
// Ask for a decision
//
- Pair<DecisionResponse, Response> decision = service.makeDecision(requestAffinity);
+ Pair<DecisionResponse, Response> decision = service.makeDecision(requestAffinity, null);
LOGGER.info("Decision {}", decision.getKey());
assertThat(decision.getKey()).isNotNull();
@@ -185,7 +185,7 @@ public class OptimizationPdpApplicationTest {
//
// Ask for a decision
//
- Pair<DecisionResponse, Response> decision = service.makeDecision(requestAffinity);
+ Pair<DecisionResponse, Response> decision = service.makeDecision(requestAffinity, null);
LOGGER.info("Decision {}", decision.getKey());
assertThat(decision.getKey()).isNotNull();