* ============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.
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<>();
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
//
// 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);
* ============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.
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;
// 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
//
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 {
//
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
//
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
//
LOGGER.info("Decision {}", decision.getKey());
assertThat(decision.getKey()).isNotNull();
- assertThat(decision.getKey().getPolicies().size()).isEqualTo(0);
+ assertThat(decision.getKey().getPolicies()).hasSize(0);
}
}