From e034d785a227815f66138d1f83f49624c402aa97 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Mon, 8 Apr 2019 08:47:38 -0400 Subject: 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 --- .../pdp/application/guard/GuardPdpApplication.java | 36 ++++++++++++---------- .../guard/LegacyGuardPolicyRequest.java | 9 ------ .../src/main/resources/META-INF/persistence.xml | 9 +++++- .../guard/src/main/resources/RootGuardPolicy.xml | 21 ------------- .../src/main/resources/unused/RootGuardPolicy.xml | 21 +++++++++++++ .../application/guard/GuardPdpApplicationTest.java | 25 +++++++++------ 6 files changed, 63 insertions(+), 58 deletions(-) delete mode 100644 applications/guard/src/main/resources/RootGuardPolicy.xml create mode 100644 applications/guard/src/main/resources/unused/RootGuardPolicy.xml (limited to 'applications/guard/src') 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 supportedPolicyTypes = new HashMap<>(); + private List 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 supportedPolicyTypes() { - return Lists.newArrayList(supportedPolicyTypes.keySet()); + public List 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 toscaPolicies) { + public void loadPolicies(Map toscaPolicies) throws XacmlApplicationException { try { // // Convert the policies first // List 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 @@ org.eclipse.persistence.jpa.PersistenceProvider + org.onap.policy.pdp.xacml.application.common.OnapOperationsHistoryDbao - + + + + + + + diff --git a/applications/guard/src/main/resources/RootGuardPolicy.xml b/applications/guard/src/main/resources/RootGuardPolicy.xml deleted file mode 100644 index cc63792f..00000000 --- a/applications/guard/src/main/resources/RootGuardPolicy.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - The root policy for supporting onap.Guard policies. - - - - - guard - - - - - - - \ No newline at end of file diff --git a/applications/guard/src/main/resources/unused/RootGuardPolicy.xml b/applications/guard/src/main/resources/unused/RootGuardPolicy.xml new file mode 100644 index 00000000..cc63792f --- /dev/null +++ b/applications/guard/src/main/resources/unused/RootGuardPolicy.xml @@ -0,0 +1,21 @@ + + + The root policy for supporting onap.Guard policies. + + + + + guard + + + + + + + \ No newline at end of file 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 -- cgit 1.2.3-korg