summaryrefslogtreecommitdiffstats
path: root/applications/guard/src/main
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 /applications/guard/src/main
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>
Diffstat (limited to 'applications/guard/src/main')
-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
4 files changed, 27 insertions, 27 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