aboutsummaryrefslogtreecommitdiffstats
path: root/applications/common
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2020-03-10 07:54:05 -0400
committerPamela Dragosh <pdragosh@research.att.com>2020-03-10 09:37:44 -0400
commitb0a27abb7d8812d5a73f65645df0bdbf06e4d64d (patch)
tree966f321e7d7259a6816ebeac28680ca1571752b6 /applications/common
parenta0ad29cdb6d6f541aac59f9e265f79d3ad085560 (diff)
Fix optimization bug add coverage plus
Fix a NPE bug and add more code coverage. Also is missing returning of context details for subscriber policies. This code is a bit ad-hoc and there is a separate JIRA POLICY-2147 to support re-factoring this codebase. Added scanning for advice to be returned. For optimization, because of the need for some changes in XACML github dependency, we are stuck with a little narly code to get it to fully work. POLICY-2417 is created to address this in Guilen. Upgraded to released XACML artifact - this has been tested locally for a few weeks with naming, guard and this optimzation code. It removed Jackson in lieu of Json, cleaned up some security fixes, upgraded dependencies, and added more code coverage. Issue-ID: POLICY-2066 Change-Id: I3cae99de265c815200ec2ce71e471338772bdb5b Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'applications/common')
-rw-r--r--applications/common/pom.xml6
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java17
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java18
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java4
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java30
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java11
6 files changed, 68 insertions, 18 deletions
diff --git a/applications/common/pom.xml b/applications/common/pom.xml
index dbde0ae1..5a359e67 100644
--- a/applications/common/pom.xml
+++ b/applications/common/pom.xml
@@ -7,9 +7,9 @@
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -76,7 +76,7 @@
<dependency>
<groupId>com.att.research.xacml</groupId>
<artifactId>xacml-pdp</artifactId>
- <version>2.0.1</version>
+ <version>2.1.0</version>
</dependency>
</dependencies>
</project>
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java
index 508bc245..34936b06 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslator.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
package org.onap.policy.pdp.xacml.application.common.std;
+import com.att.research.xacml.api.Advice;
import com.att.research.xacml.api.Decision;
import com.att.research.xacml.api.Obligation;
import com.att.research.xacml.api.Request;
@@ -92,6 +93,10 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
// Go through obligations
//
scanObligations(xacmlResult.getObligations(), decisionResponse);
+ //
+ // Go through advice
+ //
+ scanAdvice(xacmlResult.getAssociatedAdvice(), decisionResponse);
} else {
//
// TODO we have to return an ErrorResponse object instead
@@ -114,6 +119,16 @@ public abstract class StdBaseTranslator implements ToscaPolicyTranslator {
protected abstract void scanObligations(Collection<Obligation> obligations, DecisionResponse decisionResponse);
/**
+ * scanAdvice - scans the list of advice and make appropriate call to process the advice. This method
+ * can be overridden for each specific application as advice may have different expected attributes per
+ * application.
+ *
+ * @param advice Collection of Advice objects
+ * @param decisionResponse DecisionResponse object used to store any results from advice.
+ */
+ protected abstract void scanAdvice(Collection<Advice> advice, DecisionResponse decisionResponse);
+
+ /**
* From the TOSCA metadata section, pull in values that are needed into the XACML policy.
*
* @param policy Policy Object to store the metadata
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java
index bcd594fb..0a1ace2b 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
package org.onap.policy.pdp.xacml.application.common.std;
+import com.att.research.xacml.api.Advice;
import com.att.research.xacml.api.DataTypeException;
import com.att.research.xacml.api.Identifier;
import com.att.research.xacml.api.Obligation;
@@ -158,6 +159,21 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator {
}
/**
+ * scanAdvice - not implemented in this class.
+ *
+ * @param advice Collection of advice objects
+ * @param DecisionResponse DecisionResponse object
+ */
+ @Override
+ protected void scanAdvice(Collection<Advice> advice, DecisionResponse decisionResponse) {
+ //
+ // By default there are no advice supported in this object. Please override and provide
+ // any needed functionality.
+ //
+ LOGGER.warn("Advice found - not supported in this class {}", this.getClass());
+ }
+
+ /**
* scanContentObligation - scans the specific obligation for policy-id and policy-content.
*
* @param obligation Obligation incoming obligation object
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java
index 2d83b897..2cb82942 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -92,7 +92,7 @@ public class StdMatchablePolicyRequest {
}
/**
- * Parses the DecisionRequest into a MonitoringRequest.
+ * Parses the DecisionRequest into a XAML request.
*
* @param decisionRequest Input DecisionRequest
* @return Request XACML Request object
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 0d1daaa6..e84a9e77 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
@@ -22,6 +22,7 @@
package org.onap.policy.pdp.xacml.application.common.std;
+import com.att.research.xacml.api.Advice;
import com.att.research.xacml.api.Identifier;
import com.att.research.xacml.api.Obligation;
import com.att.research.xacml.api.Request;
@@ -84,6 +85,10 @@ public class StdMatchableTranslator extends StdBaseTranslator {
private static final Logger LOGGER = LoggerFactory.getLogger(StdMatchableTranslator.class);
private static final StandardYamlCoder standardYamlCoder = new StandardYamlCoder();
+ private static final String MSG_WEIGHT = "Weight is {}";
+ private static final String MSG_WEIGHT_LIST = "Weight list is {}";
+ private static final String MSG_WEIGHT_MAP = "Weight map is {}";
+
private final Map<ToscaPolicyTypeIdentifier, ToscaServiceTemplate> matchablePolicyTypes = new HashMap<>();
@Setter
private RestServerParameters apiRestParameters;
@@ -155,6 +160,10 @@ public class StdMatchableTranslator extends StdBaseTranslator {
);
}
+ protected void scanAdvice(Collection<Advice> advice, DecisionResponse decisionResponse) {
+ LOGGER.warn("scanAdvice not supported by {}", this.getClass());
+ }
+
/**
* scanClosestMatchObligation - scans for the obligation specifically holding policy
* contents and their details.
@@ -384,7 +393,7 @@ public class StdMatchableTranslator extends StdBaseTranslator {
//
int weight = generateMatchable(targetType, entrySet.getKey(), entrySet.getValue(),
property.getLeft(), property.getRight());
- LOGGER.info("Weight is {}", weight);
+ LOGGER.info(MSG_WEIGHT, weight);
totalWeight += weight;
} else {
//
@@ -394,12 +403,12 @@ public class StdMatchableTranslator extends StdBaseTranslator {
if ("list".equals(toscaProperty.getType())) {
int weight = findMatchablesInList(entrySet.getKey(), entrySet.getValue(), toscaProperty,
policyTemplate, targetType);
- LOGGER.info("Weight list is {}", weight);
+ LOGGER.info(MSG_WEIGHT_LIST, weight);
totalWeight += weight;
} else if ("map".equals(toscaProperty.getType())) {
int weight = findMatchablesInMap(entrySet.getKey(), entrySet.getValue(), toscaProperty,
policyTemplate, targetType);
- LOGGER.info("Weight map is {}", weight);
+ LOGGER.info(MSG_WEIGHT_MAP, weight);
totalWeight += weight;
}
}
@@ -460,7 +469,7 @@ public class StdMatchableTranslator extends StdBaseTranslator {
//
int weight = generateMatchable(targetType, entrySet.getKey(), entrySet.getValue(),
toscaProperty, listTemplate);
- LOGGER.info("Weight is {}", weight);
+ LOGGER.info(MSG_WEIGHT, weight);
totalWeight += weight;
} else {
//
@@ -470,12 +479,12 @@ public class StdMatchableTranslator extends StdBaseTranslator {
if ("list".equals(toscaProperty.getType())) {
int weight = findMatchablesInList(entrySet.getKey(), entrySet.getValue(), toscaProperty,
listTemplate, targetType);
- LOGGER.info("Weight list is {}", weight);
+ LOGGER.info(MSG_WEIGHT_LIST, weight);
totalWeight += weight;
} else if ("map".equals(toscaProperty.getType())) {
int weight = findMatchablesInMap(entrySet.getKey(), entrySet.getValue(), toscaProperty,
listTemplate, targetType);
- LOGGER.info("Weight map is {}", weight);
+ LOGGER.info(MSG_WEIGHT_MAP, weight);
totalWeight += weight;
}
}
@@ -529,7 +538,7 @@ public class StdMatchableTranslator extends StdBaseTranslator {
//
int weight = generateMatchable(targetType, entrySet.getKey(), entrySet.getValue(),
toscaProperty, mapTemplate);
- LOGGER.info("Weight is {}", weight);
+ LOGGER.info(MSG_WEIGHT, weight);
totalWeight += weight;
} else {
//
@@ -539,12 +548,12 @@ public class StdMatchableTranslator extends StdBaseTranslator {
if ("list".equals(toscaProperty.getType())) {
int weight = findMatchablesInList(entrySet.getKey(), entrySet.getValue(), toscaProperty,
mapTemplate, targetType);
- LOGGER.info("Weight list is {}", weight);
+ LOGGER.info(MSG_WEIGHT_LIST, weight);
totalWeight += weight;
} else if ("map".equals(toscaProperty.getType())) {
int weight = findMatchablesInMap(entrySet.getKey(), entrySet.getValue(), toscaProperty,
mapTemplate, targetType);
- LOGGER.info("Weight map is {}", weight);
+ LOGGER.info(MSG_WEIGHT_MAP, weight);
totalWeight += weight;
}
}
@@ -721,7 +730,8 @@ public class StdMatchableTranslator extends StdBaseTranslator {
int weight = 0;
if (isYamlType(toscaProperty.getEntrySchema().getType())) {
//
- // PLD TODO - this won't work
+ // PLD TODO - this won't work. Right now there are no maps being used to match.
+ // need to investigate whether we really can support that situation.
//
AnyOfType anyOf = generateMatches((Collection<Object>) value,
new IdentifierImpl(ToscaDictionary.ID_RESOURCE_MATCHABLE + key));
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java
index a7391fab..8039a9cf 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdBaseTranslatorTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import com.att.research.xacml.api.Advice;
import com.att.research.xacml.api.AttributeAssignment;
import com.att.research.xacml.api.Decision;
import com.att.research.xacml.api.IdReference;
@@ -249,6 +250,10 @@ public class StdBaseTranslatorTest {
protected void scanObligations(Collection<Obligation> obligations, DecisionResponse decisionResponse) {
}
+ @Override
+ protected void scanAdvice(Collection<Advice> advice, DecisionResponse decisionResponse) {
+ }
+
}
private class TestTranslator extends StdBaseTranslator {
@@ -259,6 +264,10 @@ public class StdBaseTranslatorTest {
}
@Override
+ protected void scanAdvice(Collection<Advice> advice, DecisionResponse decisionResponse) {
+ }
+
+ @Override
public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
PolicyType xacmlPolicy = new PolicyType();
this.fillMetadataSection(xacmlPolicy, metadata);