* ============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");
*/
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();
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;
@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);
+ }
+
}
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.
//
* @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();
}
/**
*
* @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;
}
assertEquals("flavor", pdpxParameters.getPdpType());
assertFalse(pdpxParameters.getRestServerParameters().isHttps());
assertFalse(pdpxParameters.getRestServerParameters().isAaf());
+ assertThat(pdpxParameters.getApplicationParameters().getExclusions()).isEmpty();
}
@Test
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;
+ "\"parameters/XacmlPdpConfigParameters_InvalidRestServerParameters.json\"");
}
+ @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"};
--- /dev/null
+/*-
+ * ============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;
+ }
+}
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;
@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
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
//
--- /dev/null
+org.onap.policy.pdpx.main.rest.TestGuardOverrideApplication
--- /dev/null
+{
+ "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"
+ }]
+ }
+}