From 70736cfbf6ad1a068f8ee53adddd4faa3b6fa8a8 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Fri, 12 Apr 2019 11:03:44 -0400 Subject: Add statistics and sonar cleanup and blacklist * Adding in the statistics for decisions and errors. * Cleaned up sonar issues and added code coverage. * Sped up JUnit tests * Fix JUnit issues with not finding application path * Fix TestDecision not finding persistence.xml * Fix for lingering statistics from previous runs. That needs to be addressed at a later time. * Changed persistence to use properties for configuration of database rather than hard coding the persistence.xml * Fix for Josh's comment to use else-if * Changed to use apache Pair * Added blacklist guard policy Issue-ID: POLICY-1440 Change-Id: I56af8c3dcc82463f7381f1eaea7f1440b76200bd Signed-off-by: Pamela Dragosh --- .../pdp/xacml/application/common/TestUtils.java | 1 - .../common/XacmlApplicationServiceProvider.java | 5 ++- .../CountRecentOperationsPip.java | 3 +- .../operationshistory/GetOperationOutcomePip.java | 4 +-- .../common/std/StdMatchableTranslator.java | 7 ++-- .../xacml/application/common/std/StdOnapPip.java | 1 - .../std/StdXacmlApplicationServiceProvider.java | 5 +-- .../common/src/main/resources/persistence.xml | 38 ++++++++++++++++++++++ 8 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 applications/common/src/main/resources/persistence.xml (limited to 'applications/common/src/main') diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/TestUtils.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/TestUtils.java index 50eb50bf..c48dd360 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/TestUtils.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/TestUtils.java @@ -25,7 +25,6 @@ package org.onap.policy.pdp.xacml.application.common; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationServiceProvider.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationServiceProvider.java index d4cce5c1..b20ce32f 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationServiceProvider.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/XacmlApplicationServiceProvider.java @@ -21,9 +21,12 @@ package org.onap.policy.pdp.xacml.application.common; +import com.att.research.xacml.api.Response; + import java.nio.file.Path; import java.util.List; +import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.models.decisions.concepts.DecisionRequest; import org.onap.policy.models.decisions.concepts.DecisionResponse; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; @@ -98,6 +101,6 @@ public interface XacmlApplicationServiceProvider { * @param request Incoming DecisionRequest object * @return response Responding DecisionResponse object */ - DecisionResponse makeDecision(DecisionRequest request); + Pair makeDecision(DecisionRequest request); } diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java index c18ad5fa..00f7680b 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java @@ -68,7 +68,8 @@ public class CountRecentOperationsPip extends StdOnapPip { // // In case there are any overloaded properties for the JPA // - Properties emProperties = new Properties(properties); + Properties emProperties = new Properties(); + emProperties.putAll(properties); // // Create the entity manager factory // diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java index 717e537d..4f327cf5 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java @@ -32,7 +32,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Properties; -import javax.persistence.NoResultException; import javax.persistence.Persistence; import org.onap.policy.pdp.xacml.application.common.ToscaDictionary; @@ -65,7 +64,8 @@ public class GetOperationOutcomePip extends StdOnapPip { // // In case there are any overloaded properties for the JPA // - Properties emProperties = new Properties(properties); + Properties emProperties = new Properties(); + emProperties.putAll(properties); // // Create the entity manager factory // diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java index 9d3c6264..ae144211 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java @@ -200,8 +200,7 @@ public class StdMatchableTranslator implements ToscaPolicyTranslator { try { jsonPolicy = coder.encode(toscaPolicy); } catch (CoderException e) { - LOGGER.error("Failed to encode policy to json", e); - throw new ToscaPolicyConversionException(e); + throw new ToscaPolicyConversionException("Failed to encode policy to json", e); } addObligation(rule, jsonPolicy); // @@ -237,7 +236,7 @@ public class StdMatchableTranslator implements ToscaPolicyTranslator { // // Add in the Policy Version // - policy.setVersion(map.get("policy-version").toString()); + policy.setVersion(map.get("policy-version")); } return policy; } @@ -325,7 +324,7 @@ public class StdMatchableTranslator implements ToscaPolicyTranslator { // AttributeValueType value = new AttributeValueType(); value.setDataType(ToscaDictionary.ID_OBLIGATION_POLICY_MONITORING_DATATYPE.stringValue()); - value.getContent().add(jsonPolicy.toString()); + value.getContent().add(jsonPolicy); // // Create our AttributeAssignmentExpression where we will // store the contents of the policy in JSON format. diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java index 70d49418..739ccba9 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java @@ -35,7 +35,6 @@ import com.att.research.xacml.std.pip.StdPIPRequest; import com.att.research.xacml.std.pip.engines.StdConfigurableEngine; import java.math.BigInteger; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Iterator; diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java index 95a642e9..2b8048c4 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java @@ -44,6 +44,7 @@ import java.util.Properties; import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; +import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.models.decisions.concepts.DecisionRequest; import org.onap.policy.models.decisions.concepts.DecisionResponse; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; @@ -240,7 +241,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica } @Override - public DecisionResponse makeDecision(DecisionRequest request) { + public Pair makeDecision(DecisionRequest request) { // // Convert to a XacmlRequest // @@ -252,7 +253,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica // // Convert to a DecisionResponse // - return this.getTranslator().convertResponse(xacmlResponse); + return Pair.of(this.getTranslator().convertResponse(xacmlResponse), xacmlResponse); } protected abstract ToscaPolicyTranslator getTranslator(String type); diff --git a/applications/common/src/main/resources/persistence.xml b/applications/common/src/main/resources/persistence.xml new file mode 100644 index 00000000..e3f4a2f6 --- /dev/null +++ b/applications/common/src/main/resources/persistence.xml @@ -0,0 +1,38 @@ + + + + + + + org.eclipse.persistence.jpa.PersistenceProvider + + org.onap.policy.pdp.xacml.application.common.operationshistory.Dbao + + + + + + + + + + + \ No newline at end of file -- cgit 1.2.3-korg