diff options
author | Jorge Hernandez <jorge.hernandez-herrero@att.com> | 2019-04-10 14:20:47 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-10 14:20:47 +0000 |
commit | bfb8d12818346b96c9ab918e72327e1d13662321 (patch) | |
tree | 1f55b2dd72d4629593d20fd3d3cee52db231c25b /applications/guard | |
parent | ccb1828ec3e1a1c9071256f85f3876a8d1c8ecdf (diff) | |
parent | e034d785a227815f66138d1f83f49624c402aa97 (diff) |
Merge "Test decision from main entry"
Diffstat (limited to 'applications/guard')
-rw-r--r-- | applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardPdpApplication.java | 36 | ||||
-rw-r--r-- | applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/LegacyGuardPolicyRequest.java | 9 | ||||
-rw-r--r-- | applications/guard/src/main/resources/META-INF/persistence.xml | 9 | ||||
-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.java | 25 |
5 files changed, 42 insertions, 37 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 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 |