summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplication.java4
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlApplicationParameters.java18
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManager.java13
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java7
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java1
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java15
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/TestGuardOverrideApplication.java70
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java12
-rw-r--r--main/src/test/resources/META-INF/services/org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider1
-rw-r--r--main/src/test/resources/parameters/XacmlPdpConfigParameters_Exclusions.json36
10 files changed, 166 insertions, 11 deletions
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 1832945c..b2c9f125 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory;
*/
public class GuardPdpApplication extends StdXacmlApplicationServiceProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(GuardPdpApplication.class);
- private static final String STRING_VERSION100 = "1.0.0";
+ protected static final String STRING_VERSION100 = "1.0.0";
private GuardTranslator guardTranslator = new GuardTranslator();
private CoordinationGuardTranslator coordinationTranslator = new CoordinationGuardTranslator();
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlApplicationParameters.java b/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlApplicationParameters.java
index f1ec19d3..ad840513 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlApplicationParameters.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/parameters/XacmlApplicationParameters.java
@@ -20,7 +20,9 @@
package org.onap.policy.pdpx.main.parameters;
+import java.util.List;
import lombok.Getter;
+import lombok.NonNull;
import org.onap.policy.common.parameters.ParameterGroupImpl;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
@@ -32,8 +34,24 @@ public class XacmlApplicationParameters extends ParameterGroupImpl {
@NotNull
private String applicationPath;
+ private List<String> exclusions;
+
public XacmlApplicationParameters() {
super(XacmlApplicationParameters.class.getSimpleName());
}
+ /**
+ * Looks for an application class that has been configured
+ * as excluded.
+ *
+ * @param canonicalName The classname
+ * @return true if excluded
+ */
+ public boolean isExcluded(@NonNull String canonicalName) {
+ if (exclusions == null) {
+ return false;
+ }
+ return exclusions.contains(canonicalName);
+ }
+
}
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 5ecf1aa5..6cd46838 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
@@ -77,6 +77,13 @@ public class XacmlPdpApplicationManager {
application.supportedPolicyTypes());
}
//
+ // Check for exclusions
+ //
+ if (applicationParameters.isExcluded(application.getClass().getName())) {
+ LOGGER.info("excluded {}", application.getClass().getName());
+ continue;
+ }
+ //
// We are not going to make this available unless the application can
// install correctly.
//
@@ -218,11 +225,7 @@ public class XacmlPdpApplicationManager {
* @return Total count added from all applications
*/
public long getPolicyTypeCount() {
- long types = 0;
- for (XacmlApplicationServiceProvider application : applicationLoader) {
- types += application.supportedPolicyTypes().size();
- }
- return types;
+ return toscaPolicyTypeIdents.size();
}
/**
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
index 8b79ae9b..21475da8 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
@@ -176,12 +176,17 @@ public class CommonTestData {
*
* @param isEmpty boolean value to represent that object created should be empty or not
* @param tempPath Application Path string
+ * @param exclusions An optional list of application classnames for exclusion
* @return a property map suitable for constructing an object
*/
- public Map<String, Object> getXacmlapplicationParametersMap(boolean isEmpty, String tempPath) {
+ public Map<String, Object> getXacmlapplicationParametersMap(boolean isEmpty, String tempPath,
+ String... exclusions) {
final Map<String, Object> map = new TreeMap<>();
if (!isEmpty) {
map.put("applicationPath", tempPath);
+ if (exclusions != null) {
+ map.put("exclusions", List.of(exclusions));
+ }
}
return map;
}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
index f71c99c2..cb9825cc 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
@@ -81,6 +81,7 @@ public class TestXacmlPdpParameterGroup {
assertEquals("flavor", pdpxParameters.getPdpType());
assertFalse(pdpxParameters.getRestServerParameters().isHttps());
assertFalse(pdpxParameters.getRestServerParameters().isAaf());
+ assertThat(pdpxParameters.getApplicationParameters().getExclusions()).isEmpty();
}
@Test
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java
index 1e86fee7..00e95db7 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java
@@ -21,6 +21,7 @@
package org.onap.policy.pdpx.main.parameters;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -169,6 +170,20 @@ public class TestXacmlPdpParameterHandler {
}
@Test
+ public void testXacmlPdpParameterGroup_Exclusions() throws PolicyXacmlPdpException {
+ final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters_Exclusions.json"};
+
+ final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
+ arguments.parse(xacmlPdpConfigParameters);
+
+ final XacmlPdpParameterGroup parGroup = new XacmlPdpParameterHandler().getParameters(arguments);
+ assertTrue(arguments.checkSetConfigurationFilePath());
+ assertEquals(CommonTestData.PDPX_PARAMETER_GROUP_NAME, parGroup.getName());
+ assertEquals(CommonTestData.PDPX_GROUP, parGroup.getPdpGroup());
+ assertThat(parGroup.getApplicationParameters().getExclusions()).hasSize(2);
+ }
+
+ @Test
public void testXacmlPdpVersion() throws PolicyXacmlPdpException {
final String[] xacmlPdpConfigParameters = {"-v"};
final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestGuardOverrideApplication.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestGuardOverrideApplication.java
new file mode 100644
index 00000000..1b8411e5
--- /dev/null
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestGuardOverrideApplication.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2021 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.pdpx.main.rest;
+
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator;
+import org.onap.policy.xacml.pdp.application.guard.GuardPdpApplication;
+import org.onap.policy.xacml.pdp.application.guard.GuardTranslator;
+
+public class TestGuardOverrideApplication extends GuardPdpApplication {
+ public static final String MY_EXTRAGUARD_POLICY_TYPE = "onap.policies.controlloop.guard.common.myGuard";
+
+ private static class MyTranslator extends GuardTranslator {
+
+ }
+
+ private final GuardTranslator myTranslator = new MyTranslator();
+
+ /**
+ * Constructor calls the super to add all the default policy types,
+ * and then adds the extra supported guard policy type.
+ */
+ public TestGuardOverrideApplication() {
+ super();
+ this.supportedPolicyTypes.add(new ToscaConceptIdentifier(
+ MY_EXTRAGUARD_POLICY_TYPE,
+ STRING_VERSION100));
+
+ }
+
+ @Override
+ protected ToscaPolicyTranslator getTranslator(String type) {
+ if (MY_EXTRAGUARD_POLICY_TYPE.equals(type)) {
+ return myTranslator;
+ }
+ return super.getTranslator(type);
+ }
+
+ @Override
+ public boolean canSupportPolicyType(ToscaConceptIdentifier policyTypeId) {
+ boolean canSuper = super.canSupportPolicyType(policyTypeId);
+ if (canSuper) {
+ return canSuper;
+ }
+ if (MY_EXTRAGUARD_POLICY_TYPE.equals(policyTypeId.getName())) {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java
index 4619b2ae..c79ebb52 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpApplicationManagerTest.java
@@ -46,7 +46,6 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException;
import org.onap.policy.pdpx.main.parameters.CommonTestData;
import org.onap.policy.pdpx.main.parameters.XacmlApplicationParameters;
-import org.onap.policy.xacml.pdp.application.guard.GuardPdpApplication;
import org.onap.policy.xacml.pdp.application.nativ.NativePdpApplication;
import org.onap.policy.xacml.pdp.application.optimization.OptimizationPdpApplication;
import org.slf4j.Logger;
@@ -142,9 +141,11 @@ public class XacmlPdpApplicationManagerTest {
@Test
public void testXacmlPdpApplicationManagerSimple() {
+ final String[] exclusions = {"org.onap.policy.xacml.pdp.application.guard.GuardPdpApplication",
+ "org.onap.policy.xacml.pdp.application.match.MatchPdpApplication" };
final XacmlApplicationParameters xacmlApplicationParameters =
testData.toObject(testData.getXacmlapplicationParametersMap(false,
- appsDirectory.toString()), XacmlApplicationParameters.class);
+ appsDirectory.toString(), exclusions), XacmlApplicationParameters.class);
XacmlPdpApplicationManager manager = new XacmlPdpApplicationManager(xacmlApplicationParameters, params);
//
// Test the basics from the startup
@@ -162,7 +163,12 @@ public class XacmlPdpApplicationManagerTest {
request.setAction("optimize");
assertThat(manager.findApplication(request)).isInstanceOf(OptimizationPdpApplication.class);
request.setAction("guard");
- assertThat(manager.findApplication(request)).isInstanceOf(GuardPdpApplication.class);
+ assertThat(manager.findApplication(request)).isInstanceOf(TestGuardOverrideApplication.class);
+ //
+ // Test Exclusion
+ //
+ request.setAction("match");
+ assertThat(manager.findApplication(request)).isNull();
//
// Try to unload a policy that isn't loaded
//
diff --git a/main/src/test/resources/META-INF/services/org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider b/main/src/test/resources/META-INF/services/org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider
new file mode 100644
index 00000000..fe9e8788
--- /dev/null
+++ b/main/src/test/resources/META-INF/services/org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider
@@ -0,0 +1 @@
+org.onap.policy.pdpx.main.rest.TestGuardOverrideApplication
diff --git a/main/src/test/resources/parameters/XacmlPdpConfigParameters_Exclusions.json b/main/src/test/resources/parameters/XacmlPdpConfigParameters_Exclusions.json
new file mode 100644
index 00000000..1c3d8e88
--- /dev/null
+++ b/main/src/test/resources/parameters/XacmlPdpConfigParameters_Exclusions.json
@@ -0,0 +1,36 @@
+{
+ "name": "XacmlPdpParameters",
+ "pdpGroup": "XacmlPdpGroup",
+ "pdpType": "xacml",
+ "restServerParameters": {
+ "host": "0.0.0.0",
+ "port": 6969,
+ "userName": "healthcheck",
+ "password": "zb!XztG34"
+ },
+ "policyApiParameters": {
+ "hostname": "0.0.0.0",
+ "port": 6970,
+ "userName": "healthcheck",
+ "password": "zb!XztG34"
+ },
+ "applicationParameters": {
+ "applicationPath": "src/test/resources/apps",
+ "exclusions": [
+ "org.onap.policy.xacml.pdp.application.guard.GuardPdpApplication",
+ "org.onap.policy.xacml.pdp.application.monitoring.MonitoringPdpApplication"
+ ]
+ },
+ "topicParameterGroup": {
+ "topicSources" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "anyserver" ],
+ "topicCommInfrastructure" : "noop"
+ }],
+ "topicSinks" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "anyserver" ],
+ "topicCommInfrastructure" : "noop"
+ }]
+ }
+}