summaryrefslogtreecommitdiffstats
path: root/applications
diff options
context:
space:
mode:
Diffstat (limited to 'applications')
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java6
-rw-r--r--applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java40
-rw-r--r--applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java95
3 files changed, 108 insertions, 33 deletions
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java
index 93124552..6ff7a7f1 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslatorTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -123,6 +123,10 @@ public class StdCombinedPolicyResultsTranslatorTest {
public void testConvert() throws ToscaPolicyConversionException, CoderException {
StdCombinedPolicyResultsTranslator translator = new StdCombinedPolicyResultsTranslator();
+ assertThatThrownBy(() -> translator.convertPolicy(null)).isInstanceOf(ToscaPolicyConversionException.class)
+ .hasMessageContaining("Cannot convert a NULL policy");
+
+
assertThatThrownBy(() -> translator.convertPolicy(
new ToscaPolicy())).isInstanceOf(ToscaPolicyConversionException.class)
.hasMessageContaining("missing metadata");
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 27bb24e5..436028fd 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,17 +51,14 @@ import org.slf4j.LoggerFactory;
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";
- private static final String ONAP_MONITORING_APPSERVER =
+ public static final String ONAP_MONITORING_BASE_POLICY_TYPE = "onap.Monitoring";
+ public static final String ONAP_MONITORING_CDAP = "onap.policies.monitoring.cdap.tca.hi.lo.app";
+ public static final String ONAP_MONITORING_APPSERVER =
"onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server";
- private static final String ONAP_MONITORING_SONHANDLER = "onap.policies.monitoring.docker.sonhandler.app";
- private static final String ONAP_MONITORING_DERIVED_POLICY_TYPE = "onap.policies.monitoring.";
- // Note: this requirement is temporary; it will no longer be necessary once the PDPs and PAP
- // are updated to use the PDP Group name instead of the supported types.
- private static final String ONAP_MONITORING_ALL_DERIVED_POLICY_TYPE = ONAP_MONITORING_DERIVED_POLICY_TYPE + "*";
+ public static final String ONAP_MONITORING_SONHANDLER = "onap.policies.monitoring.docker.sonhandler.app";
+ public static final String ONAP_MONITORING_DERIVED_POLICY_TYPE = "onap.policies.monitoring.";
- private static final String VERSION_100 = "1.0.0";
+ public static final String VERSION_100 = "1.0.0";
private StdCombinedPolicyResultsTranslator translator = new StdCombinedPolicyResultsTranslator();
private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes = new ArrayList<>();
@@ -77,9 +74,6 @@ public class MonitoringPdpApplication extends StdXacmlApplicationServiceProvider
supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(ONAP_MONITORING_CDAP, VERSION_100));
supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(ONAP_MONITORING_APPSERVER, VERSION_100));
supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(ONAP_MONITORING_SONHANDLER, VERSION_100));
-
- // temporary requirement
- supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(ONAP_MONITORING_ALL_DERIVED_POLICY_TYPE, VERSION_100));
}
@Override
@@ -129,18 +123,18 @@ public class MonitoringPdpApplication extends StdXacmlApplicationServiceProvider
//
// Abbreviate results if needed
//
- if (checkAbbreviateResults(requestQueryParams) && decisionResponse.getPolicies() != null
- && !decisionResponse.getPolicies().isEmpty()) {
+ if (checkAbbreviateResults(requestQueryParams) && decisionResponse.getPolicies() != null) {
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("type_version");
- policy.remove("properties");
- policy.remove("name");
- policy.remove("version");
- }
+ //
+ // DecisionResponse policies will always be a map
+ //
+ @SuppressWarnings("unchecked")
+ Map<String, Object> policy = (Map<String, Object>) entry.getValue();
+ policy.remove("type_version");
+ policy.remove("properties");
+ policy.remove("name");
+ policy.remove("version");
}
}
return Pair.of(decisionResponse, xacmlResponse);
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 fcb99f30..bdb8a343 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,8 +27,10 @@ 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.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.ServiceLoader;
import org.apache.commons.lang3.tuple.Pair;
@@ -140,11 +142,21 @@ public class MonitoringPdpApplicationTest {
// Ensure it has the supported policy types and
// can support the correct policy types.
//
- assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier("onap.Monitoring", "1.0.0"))).isTrue();
- assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier("onap.Monitoring", "1.5.0"))).isTrue();
- assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier(
+ assertThat(service.canSupportPolicyType(
+ new ToscaPolicyTypeIdentifier(MonitoringPdpApplication.ONAP_MONITORING_CDAP, "1.0.0"))).isTrue();
+ assertThat(service.canSupportPolicyType(
+ new ToscaPolicyTypeIdentifier(MonitoringPdpApplication.ONAP_MONITORING_APPSERVER, "1.0.0"))).isTrue();
+ assertThat(service.canSupportPolicyType(
+ new ToscaPolicyTypeIdentifier(MonitoringPdpApplication.ONAP_MONITORING_SONHANDLER, "1.0.0"))).isTrue();
+ assertThat(service.canSupportPolicyType(
+ new ToscaPolicyTypeIdentifier("onap.Monitoring", "1.0.0"))).isTrue();
+ assertThat(service.canSupportPolicyType(
+ new ToscaPolicyTypeIdentifier("onap.Monitoring", "1.5.0"))).isTrue();
+ assertThat(service.canSupportPolicyType(
+ new ToscaPolicyTypeIdentifier(
"onap.policies.monitoring.foobar", "1.0.1"))).isTrue();
- assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier("onap.foobar", "1.0.0"))).isFalse();
+ assertThat(service.canSupportPolicyType(
+ new ToscaPolicyTypeIdentifier("onap.foobar", "1.0.0"))).isFalse();
//
// Ensure it supports decisions
//
@@ -160,9 +172,28 @@ public class MonitoringPdpApplicationTest {
LOGGER.info("Decision {}", decision);
assertThat(decision.getKey()).isNotNull();
- assertThat(decision.getKey().getPolicies().size()).isEqualTo(0);
+ assertThat(decision.getKey().getPolicies()).hasSize(0);
+ //
+ // Test the branch for query params, and we have no policy anyway
+ //
+ Map<String, String[]> requestQueryParams = new HashMap<>();
+ decision = service.makeDecision(requestSinglePolicy, requestQueryParams);
+ LOGGER.info("Decision {}", decision);
+
+ assertThat(decision.getKey()).isNotNull();
+ assertThat(decision.getKey().getPolicies()).hasSize(0);
+ //
+ // Test the branch for query params, and we have no policy anyway
+ //
+ requestQueryParams.put("abbrev", new String[] {"false"});
+ decision = service.makeDecision(requestSinglePolicy, requestQueryParams);
+ LOGGER.info("Decision {}", decision);
+
+ assertThat(decision.getKey()).isNotNull();
+ assertThat(decision.getKey().getPolicies()).hasSize(0);
}
+ @SuppressWarnings("unchecked")
@Test
public void test3AddvDnsPolicy() throws IOException, CoderException, XacmlApplicationException {
//
@@ -182,7 +213,7 @@ public class MonitoringPdpApplicationTest {
LOGGER.info("Decision {}", decision);
assertThat(decision.getKey()).isNotNull();
- assertThat(decision.getKey().getPolicies().size()).isEqualTo(1);
+ assertThat(decision.getKey().getPolicies()).hasSize(1);
//
// Dump it out as Json
//
@@ -194,7 +225,53 @@ public class MonitoringPdpApplicationTest {
LOGGER.info("Decision {}", decision);
assertThat(decision.getKey()).isNotNull();
- assertThat(decision.getKey().getPolicies().size()).isEqualTo(1);
+ assertThat(decision.getKey().getPolicies()).hasSize(1);
+ Map<String, Object> jsonPolicy = (Map<String, Object>) decision.getKey().getPolicies().get("onap.scaleout.tca");
+ assertThat(jsonPolicy).isNotNull();
+ assertThat(jsonPolicy.get("properties")).isNotNull();
+ //
+ // Dump it out as Json
+ //
+ LOGGER.info(gson.encode(decision.getKey()));
+ //
+ // Ask for abbreviated results
+ //
+ Map<String, String[]> requestQueryParams = new HashMap<>();
+ requestQueryParams.put("abbrev", new String[] {"true"});
+ decision = service.makeDecision(requestPolicyType, requestQueryParams);
+ LOGGER.info("Decision {}", decision);
+
+ assertThat(decision.getKey()).isNotNull();
+ assertThat(decision.getKey().getPolicies()).hasSize(1);
+ jsonPolicy = (Map<String, Object>) decision.getKey().getPolicies().get("onap.scaleout.tca");
+ assertThat(jsonPolicy).isNotNull();
+ assertThat(jsonPolicy).doesNotContainKey("properties");
+ //
+ // Don't Ask for abbreviated results
+ //
+ requestQueryParams = new HashMap<>();
+ requestQueryParams.put("abbrev", new String[] {"false"});
+ decision = service.makeDecision(requestPolicyType, requestQueryParams);
+ LOGGER.info("Decision {}", decision);
+
+ assertThat(decision.getKey()).isNotNull();
+ assertThat(decision.getKey().getPolicies()).hasSize(1);
+ jsonPolicy = (Map<String, Object>) decision.getKey().getPolicies().get("onap.scaleout.tca");
+ assertThat(jsonPolicy).isNotNull();
+ assertThat(jsonPolicy.get("properties")).isNotNull();
+ //
+ // Throw an unknown exception
+ //
+ requestQueryParams = new HashMap<>();
+ requestQueryParams.put("unknown", new String[] {"true"});
+ decision = service.makeDecision(requestPolicyType, requestQueryParams);
+ LOGGER.info("Decision {}", decision);
+
+ assertThat(decision.getKey()).isNotNull();
+ assertThat(decision.getKey().getPolicies()).hasSize(1);
+ jsonPolicy = (Map<String, Object>) decision.getKey().getPolicies().get("onap.scaleout.tca");
+ assertThat(jsonPolicy).isNotNull();
+ assertThat(jsonPolicy.get("properties")).isNotNull();
//
// Dump it out as Json
//
@@ -213,7 +290,7 @@ public class MonitoringPdpApplicationTest {
LOGGER.info("Decision {}", decision.getKey());
assertThat(decision.getKey()).isNotNull();
- assertThat(decision.getKey().getPolicies().size()).isEqualTo(0);
+ assertThat(decision.getKey().getPolicies()).hasSize(0);
}
}