diff options
Diffstat (limited to 'applications')
29 files changed, 269 insertions, 204 deletions
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<DecisionResponse, Response> 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<DecisionResponse, Response> 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/guard/src/main/resources/META-INF/persistence.xml b/applications/common/src/main/resources/persistence.xml index e01447e6..e3f4a2f6 100644 --- a/applications/guard/src/main/resources/META-INF/persistence.xml +++ b/applications/common/src/main/resources/persistence.xml @@ -23,12 +23,10 @@ <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> + + <class>org.onap.policy.pdp.xacml.application.common.operationshistory.Dbao</class> + <properties> - <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" /> diff --git a/applications/common/src/test/resources/META-INF/persistence.xml b/applications/common/src/test/resources/META-INF/persistence.xml index 65ecc624..d917c06b 100644 --- a/applications/common/src/test/resources/META-INF/persistence.xml +++ b/applications/common/src/test/resources/META-INF/persistence.xml @@ -29,11 +29,7 @@ <properties> <property name="eclipselink.ddl-generation" value="create-tables" /> <property name="eclipselink.logging.level" value="FINE" /> - <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> - <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" /> - <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb;DATABASE_TO_UPPER=FALSE" /> - <property name="javax.persistence.jdbc.user" value="policy" /> - <property name="javax.persistence.jdbc.password" value="P01icY" /> + <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/> <property name="javax.persistence.schema-generation.create-source" value="metadata"/> </properties> diff --git a/applications/common/src/test/resources/test.properties b/applications/common/src/test/resources/test.properties index fb3d3ce5..5f54209a 100644 --- a/applications/common/src/test/resources/test.properties +++ b/applications/common/src/test/resources/test.properties @@ -36,3 +36,11 @@ refstart4.file=src/test/resources/ref4.xml # count-recent-operations.persistenceunit=PipEngineTest get-operation-outcome.persistenceunit=PipEngineTest + +# +# JPA Properties +# +javax.persistence.jdbc.driver=org.h2.Driver +javax.persistence.jdbc.url=jdbc:h2:mem:testdb;DATABASE_TO_UPPER=FALSE +javax.persistence.jdbc.user=policy +javax.persistence.jdbc.password=P01icY diff --git a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java index c296526b..10456e9f 100644 --- a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java +++ b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java @@ -36,7 +36,6 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.UUID; import java.util.stream.Collectors; import java.util.stream.Stream; 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 55568c36..0073f74e 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 @@ -39,7 +39,6 @@ import org.slf4j.LoggerFactory; * */ public class GuardPdpApplication extends StdXacmlApplicationServiceProvider { - private static final Logger LOGGER = LoggerFactory.getLogger(GuardPdpApplication.class); private static final String STRING_VERSION100 = "1.0.0"; private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes = new ArrayList<>(); @@ -47,7 +46,8 @@ public class GuardPdpApplication extends StdXacmlApplicationServiceProvider { private CoordinationGuardTranslator coordinationTranslator = new CoordinationGuardTranslator(); - /** Constructor. + /** + * Constructor. * */ public GuardPdpApplication() { @@ -58,6 +58,9 @@ public class GuardPdpApplication extends StdXacmlApplicationServiceProvider { "onap.policies.controlloop.guard.MinMax", STRING_VERSION100)); this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier( + "onap.policies.controlloop.guard.Blacklist", + STRING_VERSION100)); + this.supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier( "onap.policies.controlloop.guard.coordination.FirstBlocksSecond", STRING_VERSION100)); } 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 7b6c37a6..bfbe4f64 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 @@ -34,7 +34,6 @@ import lombok.Setter; import lombok.ToString; import org.onap.policy.models.decisions.concepts.DecisionRequest; -import org.onap.policy.pdp.xacml.application.common.ToscaDictionary; @Getter @Setter @@ -43,7 +42,6 @@ import org.onap.policy.pdp.xacml.application.common.ToscaDictionary; public class LegacyGuardPolicyRequest { private static final String STR_GUARD = "guard"; - private static final String URN_ONAP = ToscaDictionary.URN_ONAP; @XACMLSubject(includeInResults = true) private String onapName; diff --git a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/LegacyGuardTranslator.java b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/LegacyGuardTranslator.java index 28e62b73..3cbfcf73 100644 --- a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/LegacyGuardTranslator.java +++ b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/LegacyGuardTranslator.java @@ -67,6 +67,7 @@ public class LegacyGuardTranslator implements ToscaPolicyTranslator { private static final String FIELD_GUARD_ACTIVE_START = "guardActiveStart"; private static final String FIELD_GUARD_ACTIVE_END = "guardActiveEnd"; + private static final String FIELD_TARGET = "targets"; public LegacyGuardTranslator() { super(); @@ -96,9 +97,10 @@ public class LegacyGuardTranslator implements ToscaPolicyTranslator { // newPolicyType.setRuleCombiningAlgId(XACML3.ID_RULE_DENY_UNLESS_PERMIT.stringValue()); // - // Generate the TargetType + // Generate the TargetType - add true if not blacklist // - newPolicyType.setTarget(this.generateTargetType(toscaPolicy.getProperties())); + newPolicyType.setTarget(this.generateTargetType(toscaPolicy.getProperties(), + ! "onap.policies.controlloop.guard.Blacklist".equals(toscaPolicy.getType()))); // // Now create the Permit Rule // @@ -196,7 +198,7 @@ public class LegacyGuardTranslator implements ToscaPolicyTranslator { return policy; } - protected TargetType generateTargetType(Map<String, Object> properties) { + protected TargetType generateTargetType(Map<String, Object> properties, boolean addTargets) { // // Go through potential properties // @@ -207,15 +209,14 @@ public class LegacyGuardTranslator implements ToscaPolicyTranslator { if (properties.containsKey("recipe")) { addMatch(allOf, properties.get("recipe"), ToscaDictionary.ID_RESOURCE_GUARD_RECIPE); } - if (properties.containsKey("targets")) { - addMatch(allOf, properties.get("targets"), ToscaDictionary.ID_RESOURCE_GUARD_TARGETID); + if (addTargets) { + if (properties.containsKey("targets")) { + addMatch(allOf, properties.get("targets"), ToscaDictionary.ID_RESOURCE_GUARD_TARGETID); + } } if (properties.containsKey("clname")) { addMatch(allOf, properties.get("clname"), ToscaDictionary.ID_RESOURCE_GUARD_CLNAME); } - if (properties.containsKey("targets")) { - addMatch(allOf, properties.get("targets"), ToscaDictionary.ID_RESOURCE_GUARD_TARGETID); - } // // Create target // @@ -265,6 +266,8 @@ public class LegacyGuardTranslator implements ToscaPolicyTranslator { return generateFrequencyPermit(policyName, properties); } else if ("onap.policies.controlloop.guard.MinMax".equals(policyType)) { return generateMinMaxPermit(policyName, properties); + } else if ("onap.policies.controlloop.guard.Blacklist".equals(policyType)) { + return generateBlacklistPermit(policyName, properties); } LOGGER.error("Missing policy type in the policy"); return null; @@ -475,6 +478,82 @@ public class LegacyGuardTranslator implements ToscaPolicyTranslator { return permit; } + private static RuleType generateBlacklistPermit(String policyName, Map<String, Object> properties) { + // + // Generate target + // + if (! properties.containsKey(FIELD_TARGET)) { + LOGGER.error("Missing target for blacklist policy"); + return null; + } + final ApplyType targetApply = generateTargetApply(properties.get(FIELD_TARGET)); + // + // Get the properties that are common among guards + // + String guardActiveStart = null; + if (properties.containsKey(FIELD_GUARD_ACTIVE_START)) { + guardActiveStart = properties.get(FIELD_GUARD_ACTIVE_START).toString(); + } + String guardActiveEnd = null; + if (properties.containsKey(FIELD_GUARD_ACTIVE_END)) { + guardActiveEnd = properties.get(FIELD_GUARD_ACTIVE_END).toString(); + } + // + // Generate the time in range + // + final ApplyType timeRange = generateTimeInRange(guardActiveStart, guardActiveEnd); + // + // Create our rule + // + RuleType permit = new RuleType(); + permit.setDescription("Default is to PERMIT if the policy matches."); + permit.setRuleId(policyName + ":rule"); + permit.setEffect(EffectType.PERMIT); + permit.setTarget(new TargetType()); + // + // Create our condition + // + ObjectFactory factory = new ObjectFactory(); + ApplyType innerApply; + if (timeRange != null) { + ApplyType applyAnd = new ApplyType(); + applyAnd.setDescription("Combine the timeRange with target to create AND"); + applyAnd.setFunctionId(XACML3.ID_FUNCTION_AND.stringValue()); + applyAnd.getExpression().add(factory.createApply(timeRange)); + applyAnd.getExpression().add(factory.createApply(targetApply)); + // + // Now we need to NOT this so the permit happens + // + ApplyType applyNot = new ApplyType(); + applyNot.setDescription("This should be false for a permit."); + applyNot.setFunctionId(XACML3.ID_FUNCTION_NOT.stringValue()); + applyNot.getExpression().add(factory.createApply(applyAnd)); + innerApply = applyNot; + } else { + // + // Just the target is needed + // + ApplyType applyNot = new ApplyType(); + applyNot.setDescription("This should be false for a permit."); + applyNot.setFunctionId(XACML3.ID_FUNCTION_NOT.stringValue()); + applyNot.getExpression().add(factory.createApply(targetApply)); + innerApply = applyNot; + } + // + // Create our condition + // + final ConditionType condition = new ConditionType(); + // + // Add into the condition + // + condition.setExpression(factory.createApply(innerApply)); + // + // Add the condition + // + permit.setCondition(condition); + return permit; + } + private static ApplyType generateTimeInRange(String start, String end) { if (start == null || end == null) { LOGGER.warn("Missing time range start {} end {}", start, end); @@ -521,11 +600,7 @@ public class LegacyGuardTranslator implements ToscaPolicyTranslator { designator.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE.stringValue()); designator.setDataType(XACML3.ID_DATATYPE_INTEGER.stringValue()); // - // TODO Add this back in when the operational database PIP is configured. - // The issuer indicates that the PIP will be providing this attribute during - // the decision making. - // - // Right now I am faking the count value by re-using the request-id field + // Setup issuer // String issuer = ToscaDictionary.GUARD_ISSUER_PREFIX + CountRecentOperationsPip.ISSUER_NAME @@ -627,6 +702,53 @@ public class LegacyGuardTranslator implements ToscaPolicyTranslator { return applyLessThanEqual; } + @SuppressWarnings("unchecked") + private static ApplyType generateTargetApply(Object targetObject) { + ObjectFactory factory = new ObjectFactory(); + // + // Create a bag of values + // + ApplyType applyStringBag = new ApplyType(); + applyStringBag.setDescription("Bag the target values"); + applyStringBag.setFunctionId(XACML3.ID_FUNCTION_STRING_BAG.stringValue()); + if (targetObject instanceof Collection) { + for (Object target : ((Collection<Object>) targetObject)) { + if (! (target instanceof String)) { + LOGGER.error("Collection of unsupported objects {}", target.getClass()); + return null; + } + AttributeValueType value = new AttributeValueType(); + value.setDataType(XACML3.ID_DATATYPE_STRING.stringValue()); + value.getContent().add(target.toString()); + applyStringBag.getExpression().add(factory.createAttributeValue(value)); + } + } else if (targetObject instanceof String) { + AttributeValueType value = new AttributeValueType(); + value.setDataType(XACML3.ID_DATATYPE_STRING.stringValue()); + value.getContent().add(targetObject.toString()); + applyStringBag.getExpression().add(factory.createAttributeValue(value)); + } else { + LOGGER.warn("Unsupported object for target {}", targetObject.getClass()); + return null; + } + // + // Create our designator + // + AttributeDesignatorType designator = new AttributeDesignatorType(); + designator.setAttributeId(ToscaDictionary.ID_RESOURCE_GUARD_TARGETID.stringValue()); + designator.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE.stringValue()); + designator.setDataType(XACML3.ID_DATATYPE_STRING.stringValue()); + // + // Create apply for our AnyOf + // + ApplyType applyAnyOf = new ApplyType(); + applyAnyOf.setDescription("Find designator as anyof the possible values"); + applyAnyOf.setFunctionId(XACML3.ID_FUNCTION_ANY_OF.stringValue()); + applyAnyOf.getExpression().add(factory.createAttributeDesignator(designator)); + applyAnyOf.getExpression().add(factory.createApply(applyStringBag)); + return applyAnyOf; + } + private static Integer parseInteger(String strInteger) { Integer theInt = null; try { diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java index e94ad712..9edf11dd 100644 --- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java +++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java @@ -24,6 +24,8 @@ package org.onap.policy.xacml.pdp.application.guard; import static org.assertj.core.api.Assertions.assertThat; +import com.att.research.xacml.api.Response; + import java.io.File; import java.io.IOException; import java.sql.Date; @@ -37,6 +39,7 @@ import java.util.UUID; import javax.persistence.EntityManager; import javax.persistence.Persistence; +import org.apache.commons.lang3.tuple.Pair; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -196,11 +199,11 @@ public class CoordinationTest { // // Ask for a decision // - DecisionResponse response = service.makeDecision(request); + Pair<DecisionResponse, Response> decision = service.makeDecision(request); // // Check decision // - checkDecision(expected, response); + checkDecision(expected, decision.getKey()); } @Test 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 c5cf0327..7f5a1cef 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 @@ -24,6 +24,8 @@ package org.onap.policy.xacml.pdp.application.guard; import static org.assertj.core.api.Assertions.assertThat; +import com.att.research.xacml.api.Response; + import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -39,6 +41,7 @@ import java.util.UUID; import javax.persistence.EntityManager; import javax.persistence.Persistence; +import org.apache.commons.lang3.tuple.Pair; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -191,11 +194,11 @@ public class GuardPdpApplicationTest { // // Ask for a decision // - DecisionResponse response = service.makeDecision(request); + Pair<DecisionResponse, Response> decision = service.makeDecision(request); // // Check decision // - checkDecision(expected, response); + checkDecision(expected, decision.getKey()); } @Test @@ -215,7 +218,7 @@ public class GuardPdpApplicationTest { // can support the correct policy types. // assertThat(service.supportedPolicyTypes()).isNotEmpty(); - assertThat(service.supportedPolicyTypes().size()).isEqualTo(3); + assertThat(service.supportedPolicyTypes().size()).isEqualTo(4); assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier( "onap.policies.controlloop.guard.FrequencyLimiter", "1.0.0"))).isTrue(); assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier( @@ -225,6 +228,10 @@ public class GuardPdpApplicationTest { assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier( "onap.policies.controlloop.guard.MinMax", "1.0.1"))).isFalse(); assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier( + "onap.policies.controlloop.guard.Blacklist", "1.0.0"))).isTrue(); + assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier( + "onap.policies.controlloop.guard.Blacklist", "1.0.1"))).isFalse(); + assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier( "onap.policies.controlloop.guard.coordination.FirstBlocksSecond", "1.0.0"))).isTrue(); assertThat(service.canSupportPolicyType(new ToscaPolicyTypeIdentifier( "onap.policies.controlloop.guard.coordination.FirstBlocksSecond", "1.0.1"))).isFalse(); @@ -335,22 +342,43 @@ public class GuardPdpApplicationTest { // // Ask for a decision - should get permit // - DecisionResponse response = service.makeDecision(request); - LOGGER.info("Looking for Permit Decision {}", response); - assertThat(response).isNotNull(); - assertThat(response.getStatus()).isNotNull(); - assertThat(response.getStatus()).isEqualTo("Permit"); + Pair<DecisionResponse, Response> decision = service.makeDecision(request); + LOGGER.info("Looking for Permit Decision {}", decision.getKey()); + assertThat(decision.getKey()).isNotNull(); + assertThat(decision.getKey().getStatus()).isNotNull(); + assertThat(decision.getKey().getStatus()).isEqualTo("Permit"); // // Try a deny // guard.put("vfCount", "10"); resource.put("guard", guard); request.setResource(resource); - response = service.makeDecision(request); - LOGGER.info("Looking for Deny Decision {}", response); - assertThat(response).isNotNull(); - assertThat(response.getStatus()).isNotNull(); - assertThat(response.getStatus()).isEqualTo("Deny"); + decision = service.makeDecision(request); + LOGGER.info("Looking for Deny Decision {}", decision.getKey()); + assertThat(decision.getKey()).isNotNull(); + assertThat(decision.getKey().getStatus()).isNotNull(); + assertThat(decision.getKey().getStatus()).isEqualTo("Deny"); + } + + @Test + public void test6Blacklist() throws CoderException, XacmlApplicationException { + LOGGER.info("**************** Running test4 ****************"); + // + // Setup requestVfCount1 to point to another target for this test + // + ((Map<String, Object>)requestVfCount3.getResource().get("guard")).put("targets", "vLoadBalancer-01"); + // + // vfcount=1 above min of 2: should get a permit + // + requestAndCheckDecision(requestVfCount3, PERMIT); + // + // Now load the vDNS blacklist policy + // + TestUtils.loadPolicies("src/test/resources/vDNS.policy.guard.blacklist.output.tosca.yaml", service); + // + // vfcount=1 above min of 2: should get a permit + // + requestAndCheckDecision(requestVfCount3, DENY); } @SuppressWarnings("unchecked") diff --git a/applications/guard/src/test/resources/META-INF/createtest.sql b/applications/guard/src/test/resources/META-INF/createtest.sql deleted file mode 100644 index c7389f33..00000000 --- a/applications/guard/src/test/resources/META-INF/createtest.sql +++ /dev/null @@ -1,16 +0,0 @@ -# -# Create the operations history table -# -CREATE TABLE `operationshistory` - ( - `id` bigint not null, - `closedLoopName` varchar(255) not null, - `requestId` varchar(50) not null, - `subrequestId` varchar(50) not null, - `actor` varchar(50) not null, - `operation` varchar(50) not null, - `target` varchar(50) not null, - `starttime` timestamp not null, - `outcome` varchar(50) not null, - `message` varchar(255) not null, - `endtime` timestamp not null); diff --git a/applications/guard/src/test/resources/META-INF/persistence.xml b/applications/guard/src/test/resources/META-INF/persistence.xml index 8d1e08ad..41b25b42 100644 --- a/applications/guard/src/test/resources/META-INF/persistence.xml +++ b/applications/guard/src/test/resources/META-INF/persistence.xml @@ -27,14 +27,9 @@ <properties> <property name="eclipselink.ddl-generation" value="create-tables" /> <property name="eclipselink.logging.level" value="FINE" /> - <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> - <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" /> - <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb;DATABASE_TO_UPPER=FALSE" /> - <property name="javax.persistence.jdbc.user" value="policy" /> - <property name="javax.persistence.jdbc.password" value="P01icY" /> + <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/> <property name="javax.persistence.schema-generation.create-source" value="script"/> - <property name="javax.persistence.schema-generation.create-script-source" value="META-INF/createtest.sql"/> </properties> </persistence-unit> diff --git a/applications/guard/src/test/resources/vDNS.policy.guard.blacklist.output.tosca.yaml b/applications/guard/src/test/resources/vDNS.policy.guard.blacklist.output.tosca.yaml new file mode 100644 index 00000000..94471fb4 --- /dev/null +++ b/applications/guard/src/test/resources/vDNS.policy.guard.blacklist.output.tosca.yaml @@ -0,0 +1,18 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +topology_template: + policies: + - + guard.blacklist.scaleout: + type: onap.policies.controlloop.guard.Blacklist + version: 1.0.0 + metadata: + policy-id: guard.frequency.scaleout + policy-version: 1 + properties: + actor: SO + recipe: VF Module Create + targets: vLoadBalancer-01 + clname: ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3 + limit: 2 + guardActiveStart: 00:00:00-05:00 + guardActiveEnd: 23:59:59-05:00 diff --git a/applications/guard/src/test/resources/xacml.properties b/applications/guard/src/test/resources/xacml.properties index 534c538c..3d4d025c 100644 --- a/applications/guard/src/test/resources/xacml.properties +++ b/applications/guard/src/test/resources/xacml.properties @@ -42,4 +42,12 @@ get-operation-outcome.persistenceunit=OperationsHistoryPUTest # # Make pips available to finder # -xacml.pip.engines=count-recent-operations,get-operation-outcome
\ No newline at end of file +xacml.pip.engines=count-recent-operations,get-operation-outcome + +# +# JPA Properties +# +javax.persistence.jdbc.driver=org.h2.Driver +javax.persistence.jdbc.url=jdbc:h2:mem:testdb;DATABASE_TO_UPPER=FALSE +javax.persistence.jdbc.user=policy +javax.persistence.jdbc.password=P01icY diff --git a/applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java b/applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java index bcdfd987..7d0c5f1f 100644 --- a/applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java +++ b/applications/monitoring/src/main/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplication.java @@ -30,8 +30,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifi import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator; import org.onap.policy.pdp.xacml.application.common.std.StdCombinedPolicyResultsTranslator; import org.onap.policy.pdp.xacml.application.common.std.StdXacmlApplicationServiceProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * This is the engine class that manages the instance of the XACML PDP engine. @@ -44,7 +42,6 @@ import org.slf4j.LoggerFactory; */ public class MonitoringPdpApplication extends StdXacmlApplicationServiceProvider { - private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPdpApplication.class); private static final String ONAP_MONITORING_BASE_POLICY_TYPE = "onap.Monitoring"; private static final String ONAP_MONITORING_DERIVED_POLICY_TYPE = "onap.policies.monitoring"; diff --git a/applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java b/applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java index 9b26df16..04c9d20b 100644 --- a/applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java +++ b/applications/monitoring/src/test/java/org/onap/policy/xacml/pdp/application/monitoring/MonitoringPdpApplicationTest.java @@ -24,6 +24,8 @@ package org.onap.policy.xacml.pdp.application.monitoring; import static org.assertj.core.api.Assertions.assertThat; +import com.att.research.xacml.api.Response; + import java.io.File; import java.io.IOException; import java.util.Iterator; @@ -31,6 +33,7 @@ import java.util.List; import java.util.Properties; import java.util.ServiceLoader; +import org.apache.commons.lang3.tuple.Pair; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.FixMethodOrder; @@ -146,11 +149,11 @@ public class MonitoringPdpApplicationTest { // // Ask for a decision // - DecisionResponse response = service.makeDecision(requestSinglePolicy); - LOGGER.info("Decision {}", response); + Pair<DecisionResponse, Response> decision = service.makeDecision(requestSinglePolicy); + LOGGER.info("Decision {}", decision); - assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(0); + assertThat(decision.getKey()).isNotNull(); + assertThat(decision.getKey().getPolicies().size()).isEqualTo(0); } @Test @@ -168,15 +171,15 @@ public class MonitoringPdpApplicationTest { // // Ask for a decision // - DecisionResponse response = service.makeDecision(requestSinglePolicy); - LOGGER.info("Decision {}", response); + Pair<DecisionResponse, Response> decision = service.makeDecision(requestSinglePolicy); + LOGGER.info("Decision {}", decision); - assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(1); + assertThat(decision.getKey()).isNotNull(); + assertThat(decision.getKey().getPolicies().size()).isEqualTo(1); // // Dump it out as Json // - LOGGER.info(gson.encode(response)); + LOGGER.info(gson.encode(decision.getKey())); LOGGER.info("Now testing unloading of policy"); // // Now unload it @@ -187,61 +190,11 @@ public class MonitoringPdpApplicationTest { // // Ask for a decision // - response = service.makeDecision(requestSinglePolicy); - LOGGER.info("Decision {}", response); - - assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(0); - } - - @Test - public void test4BadPolicies() { - /* - * - * THESE TEST SHOULD BE MOVED INTO THE API PROJECT - * - // - // No need for service, just test some of the methods - // for bad policies - // - MonitoringPdpApplication onapPdpEngine = new MonitoringPdpApplication(); - - assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() -> { - try (InputStream is = - new FileInputStream("src/test/resources/test.monitoring.policy.missingmetadata.yaml")) { - onapPdpEngine.convertPolicies(is); - } - }).withMessageContaining("missing metadata section"); - - assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() -> { - try (InputStream is = - new FileInputStream("src/test/resources/test.monitoring.policy.missingtype.yaml")) { - onapPdpEngine.convertPolicies(is); - } - }).withMessageContaining("missing type value"); - - assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() -> { - try (InputStream is = - new FileInputStream("src/test/resources/test.monitoring.policy.missingversion.yaml")) { - onapPdpEngine.convertPolicies(is); - } - }).withMessageContaining("missing version value"); - - assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() -> { - try (InputStream is = - new FileInputStream("src/test/resources/test.monitoring.policy.badmetadata.1.yaml")) { - onapPdpEngine.convertPolicies(is); - } - }).withMessageContaining("missing metadata policy-version"); - - assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() -> { - try (InputStream is = - new FileInputStream("src/test/resources/test.monitoring.policy.badmetadata.2.yaml")) { - onapPdpEngine.convertPolicies(is); - } - }).withMessageContaining("missing metadata policy-id"); + decision = service.makeDecision(requestSinglePolicy); + LOGGER.info("Decision {}", decision.getKey()); - */ + assertThat(decision.getKey()).isNotNull(); + assertThat(decision.getKey().getPolicies().size()).isEqualTo(0); } } diff --git a/applications/monitoring/src/test/resources/test.monitoring.policy.badmetadata.1.yaml b/applications/monitoring/src/test/resources/test.monitoring.policy.badmetadata.1.yaml deleted file mode 100644 index a2631848..00000000 --- a/applications/monitoring/src/test/resources/test.monitoring.policy.badmetadata.1.yaml +++ /dev/null @@ -1,10 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0_0 -policies: - - - test.monitoring.policy.badmetadata.1: - type: onap.policies.monitoring.cdap.tca.hi.lo.app - version: 1.0.0 - metadata: - policy-id: test.monitoring.policy.badmetadata.1 - properties: - domain: measurementsForVfScaling diff --git a/applications/monitoring/src/test/resources/test.monitoring.policy.badmetadata.2.yaml b/applications/monitoring/src/test/resources/test.monitoring.policy.badmetadata.2.yaml deleted file mode 100644 index 7da2db38..00000000 --- a/applications/monitoring/src/test/resources/test.monitoring.policy.badmetadata.2.yaml +++ /dev/null @@ -1,10 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0_0 -policies: - - - onap.scaleout.tca: - type: onap.policies.monitoring.cdap.tca.hi.lo.app - version: 1.0.0 - metadata: - policy-version: 1 - properties: - domain: measurementsForVfScaling diff --git a/applications/monitoring/src/test/resources/test.monitoring.policy.missingmetadata.yaml b/applications/monitoring/src/test/resources/test.monitoring.policy.missingmetadata.yaml deleted file mode 100644 index 4984a1c3..00000000 --- a/applications/monitoring/src/test/resources/test.monitoring.policy.missingmetadata.yaml +++ /dev/null @@ -1,9 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0_0 -policies: - - - onap.scaleout.tca: - type: onap.policies.monitoring.test - description: I am a test policy - version: 1.0.0 - properties: - domain: measurementsForVfScaling diff --git a/applications/monitoring/src/test/resources/test.monitoring.policy.missingtype.yaml b/applications/monitoring/src/test/resources/test.monitoring.policy.missingtype.yaml deleted file mode 100644 index 309d08c5..00000000 --- a/applications/monitoring/src/test/resources/test.monitoring.policy.missingtype.yaml +++ /dev/null @@ -1,11 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0_0 -policies: - - - onap.scaleout.tca: - description: I am a test policy - version: 1.0.0 - metadata: - policy-id: onap.scaleout.tca - policy-version: 10 - properties: - domain: measurementsForVfScaling diff --git a/applications/monitoring/src/test/resources/test.monitoring.policy.missingversion.yaml b/applications/monitoring/src/test/resources/test.monitoring.policy.missingversion.yaml deleted file mode 100644 index ff378d92..00000000 --- a/applications/monitoring/src/test/resources/test.monitoring.policy.missingversion.yaml +++ /dev/null @@ -1,11 +0,0 @@ -tosca_definitions_version: tosca_simple_yaml_1_0_0 -policies: - - - onap.scaleout.tca: - type: onap.policies.monitoring.test - description: I am a test policy - metadata: - policy-id: onap.scaleout.tca - policy-version: 10 - properties: - domain: measurementsForVfScaling diff --git a/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java b/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java index 337b40d7..91c46746 100644 --- a/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java +++ b/applications/optimization/src/main/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplication.java @@ -93,6 +93,7 @@ public class OptimizationPdpApplication extends StdXacmlApplicationServiceProvid // for (ToscaPolicyTypeIdentifier supported : this.supportedPolicyTypes) { if (policyTypeId.equals(supported)) { + LOGGER.info("optimization can support {}", supported); return true; } } diff --git a/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java b/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java index 046aaa66..6d1afda6 100644 --- a/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java +++ b/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java @@ -24,6 +24,8 @@ package org.onap.policy.xacml.pdp.application.optimization; import static org.assertj.core.api.Assertions.assertThat; +import com.att.research.xacml.api.Response; + import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -31,6 +33,7 @@ import java.util.Iterator; import java.util.Properties; import java.util.ServiceLoader; +import org.apache.commons.lang3.tuple.Pair; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.FixMethodOrder; @@ -147,11 +150,11 @@ public class OptimizationPdpApplicationTest { // // Ask for a decision // - DecisionResponse response = service.makeDecision(requestAffinity); - LOGGER.info("Decision {}", response); + Pair<DecisionResponse, Response> decision = service.makeDecision(requestAffinity); + LOGGER.info("Decision {}", decision.getKey()); - assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(0); + assertThat(decision.getKey()).isNotNull(); + assertThat(decision.getKey().getPolicies().size()).isEqualTo(0); } @Test @@ -164,14 +167,14 @@ public class OptimizationPdpApplicationTest { // // Ask for a decision // - DecisionResponse response = service.makeDecision(requestAffinity); - LOGGER.info("Decision {}", response); + Pair<DecisionResponse, Response> decision = service.makeDecision(requestAffinity); + LOGGER.info("Decision {}", decision.getKey()); - assertThat(response).isNotNull(); - assertThat(response.getPolicies().size()).isEqualTo(1); + assertThat(decision.getKey()).isNotNull(); + assertThat(decision.getKey().getPolicies().size()).isEqualTo(1); // // Dump it out as Json // - LOGGER.info(gson.encode(response)); + LOGGER.info(gson.encode(decision.getKey())); } } |