aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-04-08 08:47:38 -0400
committerPamela Dragosh <pdragosh@research.att.com>2019-04-10 08:39:41 -0400
commite034d785a227815f66138d1f83f49624c402aa97 (patch)
tree38feabe112c00b97bc3deab32c4fb845f63a7b04
parent5dd6d165a0b3ee88563e5bcabd4c2a7fc42a676b (diff)
Test decision from main entry
Tests a decision upon startup. This also updates the use of ToscaPolicyTypeIdentifier for all the applications. Very basic packaging for applications and their properties. Added cleaning of unused imports to remove sonar issues. Added production persistence.xml file to guard application. Not sure if we need a copy in the application/common resource directory. Issue-ID: POLICY-1440 Change-Id: If96eef5a9e0a7c6cc5461c0bdb6f0cd708cc41bb Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationException.java49
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationServiceProvider.java12
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java6
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java30
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationExceptionTest.java36
-rw-r--r--applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplication.java36
-rw-r--r--applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/LegacyGuardPolicyRequest.java9
-rw-r--r--applications/guard/src/main/resources/META-INF/persistence.xml9
-rw-r--r--applications/guard/src/main/resources/unused/RootGuardPolicy.xml (renamed from applications/guard/src/main/resources/RootGuardPolicy.xml)0
-rw-r--r--applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplicationTest.java25
-rw-r--r--applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java20
-rw-r--r--applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java17
-rw-r--r--applications/monitoring/src/test/resources/xacml.properties2
-rw-r--r--applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java55
-rw-r--r--applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java14
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/comm/XacmlPdpMessage.java2
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/comm/listeners/XacmlPdpStateChangeListener.java1
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManager.java82
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/startstop/Main.java4
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java2
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java59
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java3
-rw-r--r--packages/policy-xacmlpdp-docker/src/main/docker/Dockerfile17
-rw-r--r--packages/policy-xacmlpdp-tarball/src/main/resources/apps/guard/xacml.properties46
-rw-r--r--packages/policy-xacmlpdp-tarball/src/main/resources/apps/monitoring/RootMonitoringPolicy.xml (renamed from applications/monitoring/src/main/resources/RootMonitoringPolicy.xml)0
-rw-r--r--packages/policy-xacmlpdp-tarball/src/main/resources/apps/monitoring/xacml.properties26
-rw-r--r--packages/policy-xacmlpdp-tarball/src/main/resources/apps/optimization/xacml.properties31
-rw-r--r--packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json3
28 files changed, 451 insertions, 145 deletions
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationException.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationException.java
new file mode 100644
index 00000000..e87da762
--- /dev/null
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationException.java
@@ -0,0 +1,49 @@
+/*-
+ * ============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);
+ }
+
+}
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 2ddcd027..cf9b15cc 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
@@ -27,6 +27,7 @@ import java.util.Map;
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
@@ -59,31 +60,30 @@ public interface XacmlApplicationServiceProvider {
*
* @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.
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java
index 30363b43..364b6519 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlPolicyUtils.java
@@ -329,10 +329,6 @@ public class XacmlPolicyUtils {
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());
}
@@ -349,7 +345,6 @@ public class XacmlPolicyUtils {
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 = "#";
@@ -367,6 +362,7 @@ public class XacmlPolicyUtils {
return Paths.get(rootPath.toAbsolutePath().toString(), "xacml.properties");
}
+ @FunctionalInterface
public interface FileCreator {
public File createAFile(String filename) throws IOException;
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 826acbc3..19d8d829 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
@@ -42,6 +42,8 @@ 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.XacmlApplicationException;
import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
import org.onap.policy.pdp.xacml.application.common.XacmlPolicyUtils;
import org.slf4j.Logger;
@@ -69,12 +71,28 @@ public class StdXacmlApplicationServiceProvider implements XacmlApplicationServi
}
@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
//
@@ -82,7 +100,7 @@ public class StdXacmlApplicationServiceProvider implements XacmlApplicationServi
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
@@ -91,17 +109,17 @@ public class StdXacmlApplicationServiceProvider implements XacmlApplicationServi
}
@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");
}
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationExceptionTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationExceptionTest.java
new file mode 100644
index 00000000..be27b313
--- /dev/null
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationExceptionTest.java
@@ -0,0 +1,36 @@
+/*-
+ * ============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));
+ }
+}
diff --git a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplication.java b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplication.java
index 1b12fca8..41773ab7 100644
--- a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplication.java
+++ b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplication.java
@@ -25,12 +25,11 @@ package org.onap.policy.xacml.pdp.application.guard;
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;
@@ -39,7 +38,9 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
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;
@@ -55,20 +56,22 @@ public class GuardPdpApplication extends StdXacmlApplicationServiceProvider {
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
@@ -77,34 +80,33 @@ public class GuardPdpApplication extends StdXacmlApplicationServiceProvider {
}
@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
diff --git a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/LegacyGuardPolicyRequest.java b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/LegacyGuardPolicyRequest.java
index 7346dded..fa04e6bd 100644
--- a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/LegacyGuardPolicyRequest.java
+++ b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/LegacyGuardPolicyRequest.java
@@ -79,9 +79,6 @@ public class LegacyGuardPolicyRequest {
@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();
}
@@ -150,12 +147,6 @@ public class LegacyGuardPolicyRequest {
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;
}
diff --git a/applications/guard/src/main/resources/META-INF/persistence.xml b/applications/guard/src/main/resources/META-INF/persistence.xml
index 8d481a59..e01447e6 100644
--- a/applications/guard/src/main/resources/META-INF/persistence.xml
+++ b/applications/guard/src/main/resources/META-INF/persistence.xml
@@ -23,8 +23,15 @@
<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>
diff --git a/applications/guard/src/main/resources/RootGuardPolicy.xml b/applications/guard/src/main/resources/unused/RootGuardPolicy.xml
index cc63792f..cc63792f 100644
--- a/applications/guard/src/main/resources/RootGuardPolicy.xml
+++ b/applications/guard/src/main/resources/unused/RootGuardPolicy.xml
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 0e5d8593..be0ee2db 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
@@ -54,7 +54,9 @@ import org.onap.policy.common.utils.coder.StandardCoder;
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;
@@ -214,13 +216,15 @@ public class GuardPdpApplicationTest {
//
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
@@ -230,7 +234,8 @@ public class GuardPdpApplicationTest {
}
@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
@@ -271,7 +276,7 @@ public class GuardPdpApplicationTest {
}
@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
@@ -317,7 +322,7 @@ public class GuardPdpApplicationTest {
}
@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
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 d4ffb487..0c928b8c 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
@@ -27,7 +27,6 @@ import com.att.research.xacml.api.Response;
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;
@@ -35,8 +34,8 @@ import java.io.IOException;
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;
@@ -47,6 +46,7 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
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;
@@ -70,7 +70,7 @@ public class MonitoringPdpApplication extends StdXacmlApplicationServiceProvider
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.
@@ -79,12 +79,12 @@ public class MonitoringPdpApplication extends StdXacmlApplicationServiceProvider
//
// 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
@@ -93,19 +93,19 @@ public class MonitoringPdpApplication extends StdXacmlApplicationServiceProvider
}
@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
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 4af4bac4..8099ffdd 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
@@ -46,6 +46,8 @@ import org.onap.policy.common.utils.coder.StandardCoder;
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;
@@ -131,11 +133,11 @@ public class MonitoringPdpApplicationTest {
// 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
//
@@ -156,7 +158,7 @@ public class MonitoringPdpApplicationTest {
@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
@@ -185,8 +187,9 @@ public class MonitoringPdpApplicationTest {
//
assertThat(policyDefinition.containsKey("type")).isTrue();
assertThat(service.canSupportPolicyType(
+ new ToscaPolicyTypeIdentifier(
policyDefinition.get("type").toString(),
- policyDefinition.get("version").toString()))
+ policyDefinition.get("version").toString())))
.isTrue();
}
}
diff --git a/applications/monitoring/src/test/resources/xacml.properties b/applications/monitoring/src/test/resources/xacml.properties
index 56a92d69..36eac3cd 100644
--- a/applications/monitoring/src/test/resources/xacml.properties
+++ b/applications/monitoring/src/test/resources/xacml.properties
@@ -22,5 +22,5 @@ xacml.att.policyFinderFactory=org.onap.policy.pdp.xacml.application.common.OnapP
# 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
diff --git a/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java b/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java
index 4a4a6046..accf7a0c 100644
--- a/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java
+++ b/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java
@@ -25,12 +25,12 @@ package org.onap.policy.xacml.pdp.application.optimization;
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;
@@ -39,6 +39,7 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
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;
@@ -52,26 +53,35 @@ public class OptimizationPdpApplication extends StdXacmlApplicationServiceProvid
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
@@ -80,23 +90,26 @@ public class OptimizationPdpApplication extends StdXacmlApplicationServiceProvid
}
@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
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 efbf730c..e593d5fe 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
@@ -47,6 +47,8 @@ import org.onap.policy.common.utils.coder.StandardCoder;
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;
@@ -139,8 +141,10 @@ public class OptimizationPdpApplicationTest {
// 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
@@ -157,7 +161,8 @@ public class OptimizationPdpApplicationTest {
@SuppressWarnings("unchecked")
@Test
- public void test3AddOptimizationPolicies() throws CoderException, FileNotFoundException, IOException {
+ public void test3AddOptimizationPolicies() throws CoderException, FileNotFoundException, IOException,
+ XacmlApplicationException {
//
// Now load the optimization policies
//
@@ -184,8 +189,9 @@ public class OptimizationPdpApplicationTest {
//
assertThat(policyDefinition.containsKey("type")).isTrue();
assertThat(service.canSupportPolicyType(
+ new ToscaPolicyTypeIdentifier(
policyDefinition.get("type").toString(),
- policyDefinition.get("version").toString()))
+ policyDefinition.get("version").toString())))
.isTrue();
}
}
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/comm/XacmlPdpMessage.java b/main/src/main/java/org/onap/policy/pdpx/main/comm/XacmlPdpMessage.java
index e05120d7..233bd7f7 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/comm/XacmlPdpMessage.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/comm/XacmlPdpMessage.java
@@ -58,6 +58,8 @@ public class XacmlPdpMessage {
status.setState(state);
status.setSupportedPolicyTypes(XacmlPdpApplicationManager.getToscaPolicyTypeIdents());
+ LOGGER.debug("formatStatusMessage state {} status{}", state, status);
+
return status;
}
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/comm/listeners/XacmlPdpStateChangeListener.java b/main/src/main/java/org/onap/policy/pdpx/main/comm/listeners/XacmlPdpStateChangeListener.java
index 68bf06dd..f5b2fbfa 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/comm/listeners/XacmlPdpStateChangeListener.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/comm/listeners/XacmlPdpStateChangeListener.java
@@ -30,7 +30,6 @@ import org.onap.policy.models.pdp.concepts.PdpStatus;
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;
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManager.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManager.java
index 7d3292a6..a5e1d030 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManager.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManager.java
@@ -20,6 +20,8 @@
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;
@@ -29,6 +31,7 @@ import java.util.Map;
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;
@@ -60,44 +63,43 @@ public class XacmlPdpApplicationManager {
// 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());
}
}
//
@@ -129,4 +131,34 @@ public class XacmlPdpApplicationManager {
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);
+ }
+
}
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/startstop/Main.java b/main/src/main/java/org/onap/policy/pdpx/main/startstop/Main.java
index b5915e11..62cdc34a 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/startstop/Main.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/startstop/Main.java
@@ -21,12 +21,10 @@
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;
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java b/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java
index 5beeed38..9695c7b9 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java
@@ -22,6 +22,7 @@ package org.onap.policy.pdpx.main.startstop;
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;
@@ -33,7 +34,6 @@ import org.onap.policy.models.pdp.concepts.PdpStatus;
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;
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
index c93ba6f7..b81336a5 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestDecision.java
@@ -23,12 +23,21 @@ package org.onap.policy.pdpx.main.rest;
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;
@@ -37,11 +46,14 @@ import javax.ws.rs.client.WebTarget;
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;
@@ -50,6 +62,9 @@ import org.onap.policy.models.decisions.concepts.DecisionRequest;
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;
@@ -60,14 +75,40 @@ public class TestDecision {
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
@@ -113,11 +154,11 @@ public class TestDecision {
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);
}
@@ -167,5 +208,13 @@ public class TestDecision {
.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
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java
index 51f737a0..5930dd5e 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestXacmlPdpActivator.java
@@ -26,12 +26,11 @@ import static org.junit.Assert.assertSame;
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;
diff --git a/packages/policy-xacmlpdp-docker/src/main/docker/Dockerfile b/packages/policy-xacmlpdp-docker/src/main/docker/Dockerfile
index e6b37463..3732e589 100644
--- a/packages/policy-xacmlpdp-docker/src/main/docker/Dockerfile
+++ b/packages/policy-xacmlpdp-docker/src/main/docker/Dockerfile
@@ -10,30 +10,27 @@ ENV https_proxy $HTTPS_PROXY
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" ]
diff --git a/packages/policy-xacmlpdp-tarball/src/main/resources/apps/guard/xacml.properties b/packages/policy-xacmlpdp-tarball/src/main/resources/apps/guard/xacml.properties
new file mode 100644
index 00000000..e3ef3ebc
--- /dev/null
+++ b/packages/policy-xacmlpdp-tarball/src/main/resources/apps/guard/xacml.properties
@@ -0,0 +1,46 @@
+#
+# 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
+
diff --git a/applications/monitoring/src/main/resources/RootMonitoringPolicy.xml b/packages/policy-xacmlpdp-tarball/src/main/resources/apps/monitoring/RootMonitoringPolicy.xml
index 5578fda9..5578fda9 100644
--- a/applications/monitoring/src/main/resources/RootMonitoringPolicy.xml
+++ b/packages/policy-xacmlpdp-tarball/src/main/resources/apps/monitoring/RootMonitoringPolicy.xml
diff --git a/packages/policy-xacmlpdp-tarball/src/main/resources/apps/monitoring/xacml.properties b/packages/policy-xacmlpdp-tarball/src/main/resources/apps/monitoring/xacml.properties
new file mode 100644
index 00000000..8ad5152d
--- /dev/null
+++ b/packages/policy-xacmlpdp-tarball/src/main/resources/apps/monitoring/xacml.properties
@@ -0,0 +1,26 @@
+#
+# 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
+
diff --git a/packages/policy-xacmlpdp-tarball/src/main/resources/apps/optimization/xacml.properties b/packages/policy-xacmlpdp-tarball/src/main/resources/apps/optimization/xacml.properties
new file mode 100644
index 00000000..5ea247cf
--- /dev/null
+++ b/packages/policy-xacmlpdp-tarball/src/main/resources/apps/optimization/xacml.properties
@@ -0,0 +1,31 @@
+#
+# 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
diff --git a/packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json b/packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json
index 561574a2..cc13e5b3 100644
--- a/packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json
+++ b/packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json
@@ -7,5 +7,6 @@
"password": "zb!XztG34",
"https": true,
"aaf": false
- }
+ },
+ "applicationPath": "/opt/app/policy/pdpx/apps"
}