--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pdp.xacml.application.common;
+
+public class XacmlApplicationException extends Exception {
+ private static final long serialVersionUID = 7588170228926173716L;
+
+ public XacmlApplicationException() {
+ super();
+ }
+
+ public XacmlApplicationException(String message) {
+ super(message);
+ }
+
+ public XacmlApplicationException(Throwable cause) {
+ super(cause);
+ }
+
+ public XacmlApplicationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public XacmlApplicationException(String message, Throwable cause, boolean enableSuppression,
+ boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+
+}
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;
/**
* This interface is how the XACML REST controller can communicate
*
* @param pathForData Local Path
*/
- void initialize(Path pathForData);
+ void initialize(Path pathForData) throws XacmlApplicationException;
/**
* Returns a list of supported Tosca Policy Types.
*
* @return List of Strings (eg. "onap.policy.foo.bar")
*/
- List<String> supportedPolicyTypes();
+ List<ToscaPolicyTypeIdentifier> supportedPolicyTypes();
/**
* Asks whether the application can support the incoming
* Tosca Policy Type and version.
*
- * @param policyType String Tosca Policy Type
- * @param policyTypeVersion String of the Tosca Policy Type version
+ * @param toscaPolicyId Identifier for policy type
* @return true if supported
*/
- boolean canSupportPolicyType(String policyType, String policyTypeVersion);
+ boolean canSupportPolicyType(ToscaPolicyTypeIdentifier toscaPolicyId);
/**
* Load a Map representation of a Tosca Policy.
*
* @param toscaPolicies Map of Tosca Policy Objects
*/
- void loadPolicies(Map<String, Object> toscaPolicies);
+ void loadPolicies(Map<String, Object> toscaPolicies) throws XacmlApplicationException;
/**
* Makes a decision given the incoming request and returns a response.
properties.load(is);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Loaded xacml properties {} {}", System.lineSeparator(), properties);
- //
- // It would be nice to sort this first
- //
- properties.list(System.out);
for (Entry<Object, Object> entrySet : properties.entrySet()) {
LOGGER.debug("{} -> {}", entrySet.getKey(), entrySet.getValue());
}
public static void storeXacmlProperties(Properties properties, Path propertyPath) throws IOException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Storing xacml properties {} {} {}", properties, System.lineSeparator(), propertyPath);
- properties.list(System.out);
}
try (OutputStream os = Files.newOutputStream(propertyPath)) {
String strComments = "#";
return Paths.get(rootPath.toAbsolutePath().toString(), "xacml.properties");
}
+ @FunctionalInterface
public interface FileCreator {
public File createAFile(String filename) throws IOException;
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.XacmlApplicationException;
import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
import org.slf4j.Logger;
}
@Override
- public void initialize(Path pathForData) {
+ public void initialize(Path pathForData) throws XacmlApplicationException {
//
// Save our path
//
this.pathForData = pathForData;
- LOGGER.debug("New Path is {}", this.pathForData.toAbsolutePath());
+ LOGGER.info("New Path is {}", this.pathForData.toAbsolutePath());
+ //
+ // Ensure properties exist
+ //
+ Path propertiesPath = XacmlPolicyUtils.getPropertiesPath(pathForData);
+ if (! propertiesPath.toFile().exists()) {
+ LOGGER.info("Copying src/main/resources/xacml.properties to path");
+ //
+ // Properties do not exist, by default we will copy ours over
+ // from src/main/resources
+ //
+ try {
+ Files.copy(Paths.get("src/main/resources/xacml.properties"), propertiesPath);
+ } catch (IOException e) {
+ throw new XacmlApplicationException("Failed to copy xacml.propertis", e);
+ }
+ }
//
// Look for and load the properties object
//
pdpProperties = XacmlPolicyUtils.loadXacmlProperties(XacmlPolicyUtils.getPropertiesPath(pathForData));
LOGGER.debug("{}", pdpProperties);
} catch (IOException e) {
- LOGGER.error("{}", e);
+ throw new XacmlApplicationException("Failed to load xacml.propertis", e);
}
//
// Create an engine
}
@Override
- public List<String> supportedPolicyTypes() {
+ public List<ToscaPolicyTypeIdentifier> supportedPolicyTypes() {
return Collections.emptyList();
}
@Override
- public boolean canSupportPolicyType(String policyType, String policyTypeVersion) {
+ public boolean canSupportPolicyType(ToscaPolicyTypeIdentifier policyTypeId) {
return false;
}
@Override
- public void loadPolicies(Map<String, Object> toscaPolicies) {
+ public void loadPolicies(Map<String, Object> toscaPolicies) throws XacmlApplicationException {
throw new UnsupportedOperationException("Please override and implement loadPolicies");
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2019 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pdp.xacml.application.common;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.policy.common.utils.test.ExceptionsTester;
+
+public class XacmlApplicationExceptionTest {
+
+ @Test
+ public void test() {
+ assertEquals(5, new ExceptionsTester().test(XacmlApplicationException.class));
+ }
+}
import com.att.research.xacml.api.Request;
import com.att.research.xacml.api.Response;
import com.att.research.xacml.util.XACMLPolicyWriter;
-import com.google.common.collect.Lists;
import java.io.IOException;
import java.nio.file.Path;
+import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
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.ToscaPolicyConversionException;
+import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException;
import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
import org.onap.policy.pdp.xacml.application.common.std.StdXacmlApplicationServiceProvider;
import org.slf4j.Logger;
private static final Logger LOGGER = LoggerFactory.getLogger(GuardPdpApplication.class);
private static final String STRING_VERSION100 = "1.0.0";
- private Map<String, String> supportedPolicyTypes = new HashMap<>();
+ private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes = new ArrayList<>();
private LegacyGuardTranslator translator = new LegacyGuardTranslator();
/** Constructor.
*
*/
public GuardPdpApplication() {
- this.supportedPolicyTypes.put("onap.policies.controlloop.guard.FrequencyLimiter", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.controlloop.guard.MinMax", STRING_VERSION100);
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier("onap.policies.controlloop.guard.FrequencyLimiter",
+ STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier("onap.policies.controlloop.guard.MinMax",
+ STRING_VERSION100));
}
@Override
public String applicationName() {
- return "Guard Application";
+ return "guard";
}
@Override
}
@Override
- public List<String> supportedPolicyTypes() {
- return Lists.newArrayList(supportedPolicyTypes.keySet());
+ public List<ToscaPolicyTypeIdentifier> supportedPolicyTypes() {
+ return supportedPolicyTypes;
}
@Override
- public boolean canSupportPolicyType(String policyType, String policyTypeVersion) {
+ public boolean canSupportPolicyType(ToscaPolicyTypeIdentifier policyTypeId) {
//
// For the time being, restrict this if the version isn't known.
// Could be too difficult to support changing of versions dynamically.
//
- if (! this.supportedPolicyTypes.containsKey(policyType)) {
- return false;
+ for (ToscaPolicyTypeIdentifier supported : this.supportedPolicyTypes) {
+ if (policyTypeId.equals(supported)) {
+ return true;
+ }
}
- //
- // Must match version exactly
- //
- return this.supportedPolicyTypes.get(policyType).equals(policyTypeVersion);
+ return false;
}
@Override
- public void loadPolicies(Map<String, Object> toscaPolicies) {
+ public void loadPolicies(Map<String, Object> toscaPolicies) throws XacmlApplicationException {
try {
//
// Convert the policies first
//
List<PolicyType> listPolicies = translator.scanAndConvertPolicies(toscaPolicies);
if (listPolicies.isEmpty()) {
- throw new ToscaPolicyConversionException("Converted 0 policies");
+ throw new XacmlApplicationException("Converted 0 policies");
}
//
// Create a copy of the properties object
@XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:max")
private Integer max;
- @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:operation:operation-count")
- private Integer operationCount;
-
public LegacyGuardPolicyRequest() {
super();
}
if (guard.containsKey("max")) {
request.max = Integer.decode(guard.get("max").toString());
}
- //
- // TODO - remove this when the PIP is hooked up
- //
- if (guard.containsKey("operationCount")) {
- request.operationCount = Integer.decode(guard.get("operationCount").toString());
- }
return request;
}
<persistence-unit name="OperationsHistoryPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ <class>org.onap.policy.pdp.xacml.application.common.OnapOperationsHistoryDbao</class>
<properties>
- <property name="eclipselink.ddl-generation" value="create-tables" />
+ <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
+ <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://policydb:3306/policy" />
+ <property name="javax.persistence.jdbc.user" value="policy_user" />
+ <property name="javax.persistence.jdbc.password" value="policy_user" />
+ <property name="javax.persistence.schema-generation.database.action" value="create" />
+ <property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
+ <property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.logging.level" value="INFO" />
</properties>
</persistence-unit>
import org.onap.policy.common.utils.resources.TextFileUtils;
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.OnapOperationsHistoryDbao;
+import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException;
import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
import org.slf4j.Logger;
//
assertThat(service.supportedPolicyTypes()).isNotEmpty();
assertThat(service.supportedPolicyTypes().size()).isEqualTo(2);
- assertThat(service.canSupportPolicyType("onap.policies.controlloop.guard.FrequencyLimiter", "1.0.0"))
- .isTrue();
- assertThat(service.canSupportPolicyType("onap.policies.controlloop.guard.FrequencyLimiter", "1.0.1"))
- .isFalse();
- assertThat(service.canSupportPolicyType("onap.policies.controlloop.guard.MinMax", "1.0.0")).isTrue();
- assertThat(service.canSupportPolicyType("onap.policies.controlloop.guard.MinMax", "1.0.1")).isFalse();
- assertThat(service.canSupportPolicyType("onap.foo", "1.0.1")).isFalse();
+ assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier(
+ "onap.policies.controlloop.guard.FrequencyLimiter", "1.0.0"))).isTrue();
+ assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier(
+ "onap.policies.controlloop.guard.FrequencyLimiter", "1.0.1"))).isFalse();
+ assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier(
+ "onap.policies.controlloop.guard.MinMax", "1.0.0"))).isTrue();
+ assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier(
+ "onap.policies.controlloop.guard.MinMax", "1.0.1"))).isFalse();
+ assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier("onap.foo", "1.0.1"))).isFalse();
}
@Test
}
@Test
- public void test3FrequencyLimiter() throws CoderException, FileNotFoundException, IOException {
+ public void test3FrequencyLimiter() throws CoderException, FileNotFoundException, IOException,
+ XacmlApplicationException {
LOGGER.info("**************** Running test3 ****************");
//
// Now load the vDNS frequency limiter Policy - make sure
}
@Test
- public void test4MinMax() throws CoderException, FileNotFoundException, IOException {
+ public void test4MinMax() throws CoderException, FileNotFoundException, IOException, XacmlApplicationException {
LOGGER.info("**************** Running test4 ****************");
//
// Now load the vDNS min max Policy - make sure
}
@Test
- public void test5MissingFields() throws FileNotFoundException, IOException {
+ public void test5MissingFields() throws FileNotFoundException, IOException, XacmlApplicationException {
LOGGER.info("**************** Running test5 ****************");
//
// Most likely we would not get a policy with missing fields passed to
import com.att.research.xacml.util.XACMLPolicyScanner;
import com.att.research.xacml.util.XACMLPolicyWriter;
import com.att.research.xacml.util.XACMLProperties;
-import com.google.common.collect.Lists;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
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.ToscaPolicyConversionException;
import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
import org.onap.policy.pdp.xacml.application.common.std.StdCombinedPolicyResultsTranslator;
private static final String ONAP_MONITORING_DERIVED_POLICY_TYPE = "onap.policies.monitoring";
private StdCombinedPolicyResultsTranslator translator = new StdCombinedPolicyResultsTranslator();
- private Map<String, String> supportedPolicyTypes = new HashMap<>();
+ private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes = new ArrayList<>();
/**
* Constructor.
//
// By default this supports just Monitoring policy types
//
- supportedPolicyTypes.put(ONAP_MONITORING_BASE_POLICY_TYPE, "1.0.0");
+ supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(ONAP_MONITORING_BASE_POLICY_TYPE, "1.0.0"));
}
@Override
public String applicationName() {
- return "Monitoring Application";
+ return "monitoring";
}
@Override
}
@Override
- public synchronized List<String> supportedPolicyTypes() {
- return Lists.newArrayList(supportedPolicyTypes.keySet());
+ public synchronized List<ToscaPolicyTypeIdentifier> supportedPolicyTypes() {
+ return supportedPolicyTypes;
}
@Override
- public boolean canSupportPolicyType(String policyType, String policyTypeVersion) {
+ public boolean canSupportPolicyType(ToscaPolicyTypeIdentifier policyTypeId) {
//
// For Monitoring, we will attempt to support all versions
// of the policy type. Since we are only packaging a decision
// back with a JSON payload of the property contents.
//
- return (policyType.equals(ONAP_MONITORING_BASE_POLICY_TYPE)
- || policyType.startsWith(ONAP_MONITORING_DERIVED_POLICY_TYPE));
+ return (policyTypeId.getName().equals(ONAP_MONITORING_BASE_POLICY_TYPE)
+ || policyTypeId.getName().startsWith(ONAP_MONITORING_DERIVED_POLICY_TYPE));
}
@Override
import org.onap.policy.common.utils.resources.TextFileUtils;
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.XacmlApplicationException;
import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
import org.slf4j.Logger;
// Ensure it has the supported policy types and
// can support the correct policy types.
//
- assertThat(service.canSupportPolicyType("onap.Monitoring", "1.0.0")).isTrue();
- assertThat(service.canSupportPolicyType("onap.Monitoring", "1.5.0")).isTrue();
- assertThat(service.canSupportPolicyType("onap.policies.monitoring.foobar", "1.0.1")).isTrue();
- assertThat(service.canSupportPolicyType("onap.foobar", "1.0.0")).isFalse();
- assertThat(service.supportedPolicyTypes()).contains("onap.Monitoring");
+ 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();
//
// Ensure it supports decisions
//
@SuppressWarnings("unchecked")
@Test
- public void test3AddvDnsPolicy() throws IOException, CoderException {
+ public void test3AddvDnsPolicy() throws IOException, CoderException, XacmlApplicationException {
//
// Now load the vDNS Policy - make sure
// the pdp can support it and have it load
//
assertThat(policyDefinition.containsKey("type")).isTrue();
assertThat(service.canSupportPolicyType(
+ new ToscaPolicyTypeIdentifier(
policyDefinition.get("type").toString(),
- policyDefinition.get("version").toString()))
+ policyDefinition.get("version").toString())))
.isTrue();
}
}
# Policies to load
#
xacml.rootPolicies=monitoring
-monitoring.file=src/main/resources/RootMonitoringPolicy.xml
+monitoring.file=../../packages/policy-xacmlpdp-tarball/src/main/resources/apps/monitoring/RootMonitoringPolicy.xml
import com.att.research.xacml.api.Request;
import com.att.research.xacml.api.Response;
import com.att.research.xacml.util.XACMLPolicyWriter;
-import com.google.common.collect.Lists;
import java.io.IOException;
import java.nio.file.Path;
+import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
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.ToscaPolicyConversionException;
import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
import org.onap.policy.pdp.xacml.application.common.std.StdMatchableTranslator;
private static final String STRING_VERSION100 = "1.0.0";
private StdMatchableTranslator translator = new StdMatchableTranslator();
- private Map<String, String> supportedPolicyTypes = new HashMap<>();
+ private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes = new ArrayList<>();
/**
* Constructor.
*/
public OptimizationPdpApplication() {
- this.supportedPolicyTypes.put("onap.policies.optimization.AffinityPolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.DistancePolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.HpaPolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.OptimizationPolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.PciPolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.QueryPolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.SubscriberPolicy", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.Vim_fit", STRING_VERSION100);
- this.supportedPolicyTypes.put("onap.policies.optimization.VnfPolicy", STRING_VERSION100);
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.AffinityPolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.DistancePolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.HpaPolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.OptimizationPolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.PciPolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.QueryPolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.SubscriberPolicy", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.Vim_fit", STRING_VERSION100));
+ this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.VnfPolicy", STRING_VERSION100));
}
@Override
public String applicationName() {
- return "Optimization Application";
+ return "optimization";
}
@Override
}
@Override
- public synchronized List<String> supportedPolicyTypes() {
- return Lists.newArrayList(supportedPolicyTypes.keySet());
+ public synchronized List<ToscaPolicyTypeIdentifier> supportedPolicyTypes() {
+ return Collections.unmodifiableList(supportedPolicyTypes);
}
@Override
- public boolean canSupportPolicyType(String policyType, String policyTypeVersion) {
+ public boolean canSupportPolicyType(ToscaPolicyTypeIdentifier policyTypeId) {
//
// For the time being, restrict this if the version isn't known.
// Could be too difficult to support changing of versions dynamically.
//
- if (! this.supportedPolicyTypes.containsKey(policyType)) {
- return false;
- }
//
- // Must match version exactly
+ // For the time being, restrict this if the version isn't known.
+ // Could be too difficult to support changing of versions dynamically.
//
- return this.supportedPolicyTypes.get(policyType).equals(policyTypeVersion);
+ for (ToscaPolicyTypeIdentifier supported : this.supportedPolicyTypes) {
+ if (policyTypeId.equals(supported)) {
+ return true;
+ }
+ }
+ return false;
}
@Override
import org.onap.policy.common.utils.resources.TextFileUtils;
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.XacmlApplicationException;
import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
import org.slf4j.Logger;
// Ensure it has the supported policy types and
// can support the correct policy types.
//
- assertThat(service.canSupportPolicyType("onap.policies.optimization.AffinityPolicy", "1.0.0")).isTrue();
- assertThat(service.canSupportPolicyType("onap.foobar", "1.0.0")).isFalse();
+ assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier(
+ "onap.policies.optimization.AffinityPolicy", "1.0.0"))).isTrue();
+ assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier(
+ "onap.foobar", "1.0.0"))).isFalse();
}
@Test
@SuppressWarnings("unchecked")
@Test
- public void test3AddOptimizationPolicies() throws CoderException, FileNotFoundException, IOException {
+ public void test3AddOptimizationPolicies() throws CoderException, FileNotFoundException, IOException,
+ XacmlApplicationException {
//
// Now load the optimization policies
//
//
assertThat(policyDefinition.containsKey("type")).isTrue();
assertThat(service.canSupportPolicyType(
+ new ToscaPolicyTypeIdentifier(
policyDefinition.get("type").toString(),
- policyDefinition.get("version").toString()))
+ policyDefinition.get("version").toString())))
.isTrue();
}
}
status.setState(state);
status.setSupportedPolicyTypes(XacmlPdpApplicationManager.getToscaPolicyTypeIdents());
+ LOGGER.debug("formatStatusMessage state {} status{}", state, status);
+
return status;
}
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.pdpx.main.comm.XacmlPdpHeartbeatPublisher;
import org.onap.policy.pdpx.main.comm.XacmlPdpMessage;
-import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.onap.policy.pdpx.main.rest;
+import java.io.IOException;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.ServiceLoader;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException;
import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// Load service
//
applicationLoader = ServiceLoader.load(XacmlApplicationServiceProvider.class);
-
//
- // Iterate through them the applications for actions and supported policy types
+ // Iterate through the applications for actions and supported policy types
//
for (XacmlApplicationServiceProvider application : applicationLoader) {
-
LOGGER.info("Application {} supports {}", application.applicationName(),
application.supportedPolicyTypes());
-
//
- // Iterate through the actions and save in the providerActionMap
+ // We are not going to make this available unless the application can
+ // install correctly.
//
- int pathCount = 1;
- for (String action : application.actionDecisionsSupported()) {
+ boolean applicationInitialized = false;
+ //
+ // Have it initialize at a path
+ //
+ try {
+ initializeApplicationPath(applicationPath, application);
//
- // Save the actions that it supports
+ // We are initialized
//
- providerActionMap.put(action, application);
+ applicationInitialized = true;
+ } catch (XacmlApplicationException e) {
+ LOGGER.error("Failed to initialize path for {}", application.applicationName(), e);
+ }
+ if (applicationInitialized) {
//
- // Create a unique path for the application to store its data
- // May need to scan this name to remove unsafe characters etc.
- // But for debugging purposes, its good to use the application name
+ // Iterate through the actions and save in the providerActionMap
//
- Path path = Paths.get(applicationPath.toAbsolutePath().toString(),
- application.applicationName(), Integer.toString(pathCount++));
+ for (String action : application.actionDecisionsSupported()) {
+ //
+ // Save the actions that it supports
+ //
+ providerActionMap.put(action, application);
+ }
//
- // Have the application initialize
+ // Add all the supported policy types
//
- application.initialize(path);
- }
-
- // Get string list of supportedPolicyTypes
- List<String> supportedPolicyTypes = application.supportedPolicyTypes();
-
- // Iterate through the supportedPolicyTypes to set the toscaPolicyTypeIdents
- for (String name : supportedPolicyTypes) {
- ToscaPolicyTypeIdentifier ident = new ToscaPolicyTypeIdentifier(name, "1.0.0");
- toscaPolicyTypeIdents.add(ident);
+ toscaPolicyTypeIdents.addAll(application.supportedPolicyTypes());
}
}
//
return types;
}
+ private static void initializeApplicationPath(Path basePath, XacmlApplicationServiceProvider application)
+ throws XacmlApplicationException {
+ //
+ // Making an assumption that all application names are unique, and
+ // they can result in a valid directory being created.
+ //
+ Path path = Paths.get(basePath.toAbsolutePath().toString(), application.applicationName());
+ LOGGER.info("initializeApplicationPath {} at this path {}", application.applicationName(), path);
+ //
+ // Create that the directory if it does not exist. Ideally
+ // this is only for testing, but could be used for production
+ // Probably better to have the docker container and/or helm
+ // scripts setup the local directory.
+ //
+ if (! path.toFile().exists()) {
+ try {
+ //
+ // Try to create the directory
+ //
+ Files.createDirectory(path);
+ } catch (IOException e) {
+ LOGGER.error("Failed to create application directory", e);
+ }
+ }
+ //
+ // Have the application initialize
+ //
+ application.initialize(path);
+ }
+
}
package org.onap.policy.pdpx.main.startstop;
import java.io.FileInputStream;
-import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Properties;
-import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClientException;
+
import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
-import org.onap.policy.pdpx.main.comm.XacmlPdpPapRegistration;
import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterHandler;
import org.slf4j.Logger;
import java.util.Arrays;
import java.util.Properties;
+
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.pdp.enums.PdpMessageType;
import org.onap.policy.models.pdp.enums.PdpState;
-import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
import org.onap.policy.pdpx.main.PolicyXacmlPdpRuntimeException;
import org.onap.policy.pdpx.main.comm.XacmlPdpMessage;
import org.onap.policy.pdpx.main.comm.XacmlPdpPapRegistration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.ClassRule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.models.decisions.concepts.DecisionResponse;
import org.onap.policy.models.errors.concepts.ErrorResponse;
import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
+import org.onap.policy.pdpx.main.parameters.RestServerBuilder;
+import org.onap.policy.pdpx.main.parameters.RestServerParameters;
+import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
import org.onap.policy.pdpx.main.startstop.Main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static Main main;
+ @ClassRule
+ public static final TemporaryFolder appsFolder = new TemporaryFolder();
+
/**
* BeforeClass setup environment.
+ * @throws IOException Cannot create temp apps folder
*/
@BeforeClass
- public static void beforeClass() {
+ public static void beforeClass() throws IOException {
System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StdErrLog");
System.setProperty("org.eclipse.jetty.LEVEL", "OFF");
- main = startXacmlPdpService();
+ //
+ // Copy test directory over of the application directories
+ //
+ Path src = Paths.get("../packages/policy-xacmlpdp-tarball/src/main/resources/apps");
+ File apps = appsFolder.newFolder("apps");
+ Files.walk(src).forEach(source -> {
+ copy(source, apps.toPath().resolve(src.relativize(source)));
+ });
+ //
+ // Get the parameters file correct.
+ //
+ RestServerParameters rest = new RestServerParameters(new RestServerBuilder()
+ .setHost("0.0.0.0").setPort(6969).setUserName("healthcheck").setPassword("zb!XztG34"));
+ XacmlPdpParameterGroup params = new XacmlPdpParameterGroup("XacmlPdpGroup", rest, apps.getAbsolutePath());
+ final Gson gson = new GsonBuilder().create();
+ File fileParams = appsFolder.newFile("params.json");
+ String jsonParams = gson.toJson(params);
+ LOGGER.info("Creating new params: {}", jsonParams);
+ Files.write(fileParams.toPath(), jsonParams.getBytes());
+ //
+ // Start the service
+ //
+ main = startXacmlPdpService(fileParams);
}
@AfterClass
DecisionResponse response = getDecision(request);
LOGGER.info("Response {}", response);
- //assertThat(response.getErrorMessage()).isEqualToIgnoringCase("No application for action foo");
+ assertThat(response.getStatus()).isEqualTo("Permit");
}
- private static Main startXacmlPdpService() {
- final String[] XacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters.json", "-p",
+ private static Main startXacmlPdpService(File params) {
+ final String[] XacmlPdpConfigParameters = {"-c", params.getAbsolutePath(), "-p",
"parameters/topic.properties"};
return new Main(XacmlPdpConfigParameters);
}
.userName("healthcheck").password("zb!XztG34").managed(true).build());
}
+ private static void copy(Path source, Path dest) {
+ try {
+ LOGGER.info("Copying {} to {}", source, dest);
+ Files.copy(source, dest, StandardCopyOption.REPLACE_EXISTING);
+ } catch (IOException e) {
+ LOGGER.error("Failed to copy {} to {}", source, dest);
+ }
+ }
}
\ No newline at end of file
import static org.junit.Assert.assertTrue;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.net.UnknownHostException;
import java.util.Properties;
+
import org.junit.After;
import org.junit.BeforeClass;
-
import org.junit.Test;
import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClientException;
import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
ENV BUILD_VERSION ${BUILD_VERSION}
ENV POLICY_LOGS ${POLICY_LOGS}
-ENV POLICY_HOME=/opt/app/policy
-ENV POLICY_PDPX_HOME=${POLICY_HOME}/pdpx
+ENV POLICY_HOME=/opt/app/policy/pdpx
RUN \
apk add --no-cache --update busybox-extras bash nss procps coreutils findutils grep \
zip unzip curl wget openssh maven openjdk8 jq httpie py-pip
-
RUN addgroup policy && \
adduser -S --shell /bin/bash -G policy policy
-RUN mkdir -p ${POLICY_PDPX_HOME} ${POLICY_LOGS} ${POLICY_HOME}/etc/ssl ${POLICY_PDPX_HOME}/bin && \
- chown -R policy:policy ${POLICY_HOME} ${POLICY_PDPX_HOME} ${POLICY_LOGS}
+RUN mkdir -p ${POLICY_HOME} ${POLICY_LOGS} ${POLICY_HOME}/etc/ssl ${POLICY_HOME}/bin ${POLICY_HOME}/apps && \
+ chown -R policy:policy ${POLICY_HOME} ${POLICY_LOGS}
RUN mkdir /packages
COPY /maven/* /packages
-RUN tar xvfz /packages/policy-xacmlpdp.tar.gz --directory ${POLICY_PDPX_HOME} && \
+RUN tar xvfz /packages/policy-xacmlpdp.tar.gz --directory ${POLICY_HOME} && \
rm /packages/policy-xacmlpdp.tar.gz
-WORKDIR ${POLICY_PDPX_HOME}
+WORKDIR ${POLICY_HOME}
COPY policy-pdpx.sh bin/.
-RUN chown -R policy:policy * && chmod +x bin/*.sh && \
- cp ${POLICY_PDPX_HOME}/etc/ssl/* ${POLICY_HOME}/etc/ssl && chown policy:policy ${POLICY_HOME}/etc/ssl/*
+RUN chown -R policy:policy * && chmod +x bin/*.sh
USER policy
-WORKDIR ${POLICY_PDPX_HOME}/bin
+WORKDIR ${POLICY_HOME}/bin
ENTRYPOINT [ "bash", "./policy-pdpx.sh" ]
--- /dev/null
+#
+# Properties that the embedded PDP engine uses to configure and load
+#
+# Standard API Factories
+#
+xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory
+xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory
+xacml.pepEngineFactory=com.att.research.xacml.std.pep.StdEngineFactory
+xacml.pipFinderFactory=com.att.research.xacml.std.pip.StdPIPFinderFactory
+xacml.traceEngineFactory=com.att.research.xacml.std.trace.LoggingTraceEngineFactory
+#
+# AT&T PDP Implementation Factories
+#
+xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory
+xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory
+xacml.att.functionDefinitionFactory=com.att.research.xacmlatt.pdp.std.StdFunctionDefinitionFactory
+#
+# ONAP PDP Implementation Factories
+#
+xacml.att.policyFinderFactory=org.onap.policy.pdp.xacml.application.common.OnapPolicyFinderFactory
+
+#
+# Use a root combining algorithm
+#
+xacml.att.policyFinderFactory.combineRootPolicies=urn:oasis:names:tc:xacml:3.0:policy-combining-algorithm:permit-unless-deny
+
+xacml.pip.engines=historydb
+
+#
+# PIP Engine Definition
+#
+historydb.classname=org.onap.policy.pdp.xacml.application.common.OnapOperationsHistoryPipEngine
+historydb.issuer=urn:org:onap:xacml:guard:historydb
+historydb.name=operationHistoryDB
+historydb.description=Returns operation counts based on time window
+
+#
+# Database persistence for PIP
+#
+historydb.persistenceunit=OperationsHistoryPU
+
+# Policies to load
+#
+#xacml.rootPolicies=guard
+#guard.file=src/main/resources/RootGuardPolicy.xml
+
--- /dev/null
+#
+# Properties that the embedded PDP engine uses to configure and load
+#
+# Standard API Factories
+#
+xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory
+xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory
+xacml.pepEngineFactory=com.att.research.xacml.std.pep.StdEngineFactory
+xacml.pipFinderFactory=com.att.research.xacml.std.pip.StdPIPFinderFactory
+xacml.traceEngineFactory=com.att.research.xacml.std.trace.LoggingTraceEngineFactory
+#
+# AT&T PDP Implementation Factories
+#
+xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory
+xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory
+xacml.att.functionDefinitionFactory=com.att.research.xacmlatt.pdp.std.StdFunctionDefinitionFactory
+#
+# ONAP PDP Implementation Factories
+#
+xacml.att.policyFinderFactory=org.onap.policy.pdp.xacml.application.common.OnapPolicyFinderFactory
+
+# Policies to load
+#
+xacml.rootPolicies=monitoring
+monitoring.file=/opt/app/policy/pdpx/apps/monitoring/RootMonitoringPolicy.xml
+
--- /dev/null
+#
+# Properties that the embedded PDP engine uses to configure and load
+#
+# Standard API Factories
+#
+xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory
+xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory
+xacml.pepEngineFactory=com.att.research.xacml.std.pep.StdEngineFactory
+xacml.pipFinderFactory=com.att.research.xacml.std.pip.StdPIPFinderFactory
+xacml.traceEngineFactory=com.att.research.xacml.std.trace.LoggingTraceEngineFactory
+#
+# AT&T PDP Implementation Factories
+#
+xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory
+xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory
+xacml.att.functionDefinitionFactory=com.att.research.xacmlatt.pdp.std.StdFunctionDefinitionFactory
+#
+# ONAP PDP Implementation Factories
+#
+xacml.att.policyFinderFactory=org.onap.policy.pdp.xacml.application.common.OnapPolicyFinderFactory
+
+#
+# Use a root combining algorithm
+#
+xacml.att.policyFinderFactory.combineRootPolicies=urn:com:att:xacml:3.0:policy-combining-algorithm:combined-permit-overrides
+
+#
+# Policies to load
+#
+xacml.rootPolicies=
+xacml.referencedPolicies=
\ No newline at end of file
"password": "zb!XztG34",
"https": true,
"aaf": false
- }
+ },
+ "applicationPath": "/opt/app/policy/pdpx/apps"
}