aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java45
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java60
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCallerTest.java3
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java28
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java1
-rw-r--r--applications/common/src/test/resources/META-INF/persistence.xml6
-rw-r--r--applications/common/src/test/resources/test.properties1
-rw-r--r--applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java189
-rw-r--r--applications/guard/src/test/resources/META-INF/persistence.xml8
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java3
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpAafFilter.java38
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpStatisticsManager.java3
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java5
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java29
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java17
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java29
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpAafFilterTest.java37
-rw-r--r--packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json4
-rw-r--r--packages/policy-xacmlpdp-tarball/src/main/resources/etc/s3pConfig.json3
19 files changed, 188 insertions, 321 deletions
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 0d2b1ddd..d00df3b7 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
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +34,7 @@ import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Objects;
import org.onap.policy.pdp.xacml.application.common.ToscaDictionary;
import org.onap.policy.pdp.xacml.application.common.std.StdOnapPip;
import org.slf4j.Logger;
@@ -41,7 +43,7 @@ import org.slf4j.LoggerFactory;
public class CountRecentOperationsPip extends StdOnapPip {
public static final String ISSUER_NAME = "count-recent-operations";
- private static Logger logger = LoggerFactory.getLogger(CountRecentOperationsPip.class);
+ private static final Logger logger = LoggerFactory.getLogger(CountRecentOperationsPip.class);
public CountRecentOperationsPip() {
super();
@@ -57,7 +59,7 @@ public class CountRecentOperationsPip extends StdOnapPip {
* getAttributes.
*
* @param pipRequest the request
- * @param pipFinder the pip finder
+ * @param pipFinder the pip finder
* @return PIPResponse
*/
@Override
@@ -66,21 +68,21 @@ public class CountRecentOperationsPip extends StdOnapPip {
throw new PIPException("Engine is shutdown");
}
logger.debug("getAttributes requesting attribute {} of type {} for issuer {}",
- pipRequest.getAttributeId(), pipRequest.getDataTypeId(), pipRequest.getIssuer());
+ pipRequest.getAttributeId(), pipRequest.getDataTypeId(), pipRequest.getIssuer());
//
// Determine if the issuer is correct
//
if (Strings.isNullOrEmpty(pipRequest.getIssuer())) {
logger.debug("issuer is null - returning empty response");
//
- // We only respond to ourself as the issuer
+ // We only respond to ourselves as the issuer
//
return StdPIPResponse.PIP_RESPONSE_EMPTY;
}
- if (! pipRequest.getIssuer().startsWith(ToscaDictionary.GUARD_ISSUER_PREFIX)) {
+ if (!pipRequest.getIssuer().startsWith(ToscaDictionary.GUARD_ISSUER_PREFIX)) {
logger.debug("Issuer does not start with guard");
//
- // We only respond to ourself as the issuer
+ // We only respond to ourselves as the issuer
//
return StdPIPResponse.PIP_RESPONSE_EMPTY;
}
@@ -100,7 +102,7 @@ public class CountRecentOperationsPip extends StdOnapPip {
String target = getAttribute(pipFinder, PIP_REQUEST_TARGET);
String timeWindow = timeWindowVal + " " + timeWindowScale;
logger.info("Going to query DB about: actor {} operation {} target {} time window {}",
- actor, operation, target, timeWindow);
+ actor, operation, target, timeWindow);
//
// Sanity check
//
@@ -120,17 +122,17 @@ public class CountRecentOperationsPip extends StdOnapPip {
//
var pipResponse = new StdMutablePIPResponse();
this.addLongAttribute(pipResponse,
- XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
- ToscaDictionary.ID_RESOURCE_GUARD_OPERATIONCOUNT,
- operationCount,
- pipRequest);
+ XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
+ ToscaDictionary.ID_RESOURCE_GUARD_OPERATIONCOUNT,
+ operationCount,
+ pipRequest);
return new StdPIPResponse(pipResponse);
}
private long doDatabaseQuery(String actor, String operation, String target, int timeWindowVal,
- String timeWindowScale) {
+ String timeWindowScale) {
logger.info("Querying operations history for {} {} {} {} {}",
- actor, operation, target, timeWindowVal, timeWindowScale);
+ actor, operation, target, timeWindowVal, timeWindowScale);
//
// Only can query if we have an EntityManager
//
@@ -146,19 +148,18 @@ public class CountRecentOperationsPip extends StdOnapPip {
// We are expecting a single result
//
return em.createQuery("select count(e) from OperationsHistory e"
- + " where e.outcome<>'Failure_Guard'"
- + " and e.actor= ?1"
- + " and e.operation= ?2"
- + " and e.target= ?3"
- + " and e.endtime between"
- + " ?4 and CURRENT_TIMESTAMP",
- Long.class)
+ + " where e.outcome<>'Failure_Guard'"
+ + " and e.actor= ?1"
+ + " and e.operation= ?2"
+ + " and e.target= ?3"
+ + " and e.endtime between"
+ + " ?4 and CURRENT_TIMESTAMP",
+ Long.class)
.setParameter(1, actor)
.setParameter(2, operation)
.setParameter(3, target)
.setParameter(4, Timestamp.from(Instant.now()
- .minus(timeWindowVal,
- stringToChronoUnit(timeWindowScale))))
+ .minus(timeWindowVal, Objects.requireNonNull(stringToChronoUnit(timeWindowScale)))))
.getSingleResult();
} catch (Exception e) {
logger.error("Typed query failed ", e);
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 e0705f80..9dff0599 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
@@ -37,6 +37,7 @@ import com.att.research.xacml.std.pip.StdMutablePIPResponse;
import com.att.research.xacml.std.pip.StdPIPRequest;
import com.att.research.xacml.std.pip.engines.StdConfigurableEngine;
import jakarta.persistence.EntityManager;
+import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import java.math.BigInteger;
import java.util.Collection;
@@ -53,22 +54,23 @@ import org.slf4j.LoggerFactory;
public abstract class StdOnapPip extends StdConfigurableEngine {
protected static Logger logger = LoggerFactory.getLogger(StdOnapPip.class);
- protected static final PIPRequest PIP_REQUEST_ACTOR = new StdPIPRequest(
- XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
- ToscaDictionary.ID_RESOURCE_GUARD_ACTOR,
- XACML3.ID_DATATYPE_STRING);
+ protected static final PIPRequest PIP_REQUEST_ACTOR = new StdPIPRequest(
+ XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
+ ToscaDictionary.ID_RESOURCE_GUARD_ACTOR,
+ XACML3.ID_DATATYPE_STRING);
- protected static final PIPRequest PIP_REQUEST_RECIPE = new StdPIPRequest(
- XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
- ToscaDictionary.ID_RESOURCE_GUARD_RECIPE,
- XACML3.ID_DATATYPE_STRING);
+ protected static final PIPRequest PIP_REQUEST_RECIPE = new StdPIPRequest(
+ XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
+ ToscaDictionary.ID_RESOURCE_GUARD_RECIPE,
+ XACML3.ID_DATATYPE_STRING);
- protected static final PIPRequest PIP_REQUEST_TARGET = new StdPIPRequest(
- XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
- ToscaDictionary.ID_RESOURCE_GUARD_TARGETID,
- XACML3.ID_DATATYPE_STRING);
+ protected static final PIPRequest PIP_REQUEST_TARGET = new StdPIPRequest(
+ XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE,
+ ToscaDictionary.ID_RESOURCE_GUARD_TARGETID,
+ XACML3.ID_DATATYPE_STRING);
protected Properties properties;
+ protected EntityManagerFactory emf;
protected EntityManager em;
protected String issuer;
protected boolean shutdown = false;
@@ -104,9 +106,9 @@ public abstract class StdOnapPip extends StdConfigurableEngine {
//
// Create the entity manager factory
//
- em = Persistence.createEntityManagerFactory(
- properties.getProperty(this.issuer + ".persistenceunit"),
- emProperties).createEntityManager();
+ emf = Persistence.createEntityManagerFactory(
+ properties.getProperty(this.issuer + ".persistenceunit"), emProperties);
+ em = emf.createEntityManager();
} catch (Exception e) {
logger.error("Persistence failed {} operations history db", e.getLocalizedMessage(), e);
}
@@ -142,7 +144,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine {
pipResponse = pipFinder.getMatchingAttributes(pipRequest, this);
if (pipResponse.getStatus() != null && !pipResponse.getStatus().isOk()) {
logger.info("get attribute error retrieving {}: {}", pipRequest.getAttributeId(),
- pipResponse.getStatus());
+ pipResponse.getStatus());
pipResponse = null;
}
if (pipResponse != null && pipResponse.getAttributes().isEmpty()) {
@@ -156,10 +158,10 @@ public abstract class StdOnapPip extends StdConfigurableEngine {
}
protected String findFirstAttributeValue(PIPResponse pipResponse) {
- for (Attribute attribute: pipResponse.getAttributes()) {
- Iterator<AttributeValue<String>> iterAttributeValues = attribute.findValues(DataTypes.DT_STRING);
+ for (Attribute attribute : pipResponse.getAttributes()) {
+ Iterator<AttributeValue<String>> iterAttributeValues = attribute.findValues(DataTypes.DT_STRING);
while (iterAttributeValues.hasNext()) {
- String value = iterAttributeValues.next().getValue();
+ String value = iterAttributeValues.next().getValue();
if (value != null) {
return value;
}
@@ -169,35 +171,35 @@ public abstract class StdOnapPip extends StdConfigurableEngine {
}
protected void addIntegerAttribute(StdMutablePIPResponse stdPipResponse, Identifier category,
- Identifier attributeId, int value, PIPRequest pipRequest) {
- AttributeValue<BigInteger> attributeValue = null;
+ Identifier attributeId, int value, PIPRequest pipRequest) {
+ AttributeValue<BigInteger> attributeValue = null;
try {
- attributeValue = makeInteger(value);
+ attributeValue = makeInteger(value);
} catch (Exception e) {
logger.error("Failed to convert {} to integer", value, e);
}
if (attributeValue != null) {
stdPipResponse.addAttribute(new StdMutableAttribute(category, attributeId, attributeValue,
- pipRequest.getIssuer(), false));
+ pipRequest.getIssuer(), false));
}
}
protected void addLongAttribute(StdMutablePIPResponse stdPipResponse, Identifier category,
- Identifier attributeId, long value, PIPRequest pipRequest) {
- AttributeValue<BigInteger> attributeValue = null;
+ Identifier attributeId, long value, PIPRequest pipRequest) {
+ AttributeValue<BigInteger> attributeValue = null;
try {
- attributeValue = makeLong(value);
+ attributeValue = makeLong(value);
} catch (Exception e) {
logger.error("Failed to convert {} to long", value, e);
}
if (attributeValue != null) {
stdPipResponse.addAttribute(new StdMutableAttribute(category, attributeId, attributeValue,
- pipRequest.getIssuer(), false));
+ pipRequest.getIssuer(), false));
}
}
protected void addStringAttribute(StdMutablePIPResponse stdPipResponse, Identifier category, Identifier attributeId,
- String value, PIPRequest pipRequest) {
+ String value, PIPRequest pipRequest) {
AttributeValue<String> attributeValue = null;
try {
attributeValue = makeString(value);
@@ -206,7 +208,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine {
}
if (attributeValue != null) {
stdPipResponse.addAttribute(new StdMutableAttribute(category, attributeId, attributeValue,
- pipRequest.getIssuer(), false));
+ pipRequest.getIssuer(), false));
}
}
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCallerTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCallerTest.java
index 0231c058..bd42933c 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCallerTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/PolicyApiCallerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021,2023 Nordix Foundation.
+ * Modifications Copyright (C) 2021, 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -102,7 +102,6 @@ public class PolicyApiCallerTest {
ApiRestController.class.getName());
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, "false");
- props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_AAF_SUFFIX, "false");
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER,
GsonMessageBodyHandler.class.getName());
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java
index e564cd96..c38ab716 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java
@@ -26,13 +26,13 @@ import static org.mockito.Mockito.when;
import com.att.research.xacml.api.Attribute;
import com.att.research.xacml.api.AttributeValue;
-import com.att.research.xacml.api.Status;
import com.att.research.xacml.api.pip.PIPException;
import com.att.research.xacml.api.pip.PIPFinder;
import com.att.research.xacml.api.pip.PIPRequest;
import com.att.research.xacml.api.pip.PIPResponse;
import com.att.research.xacml.std.pip.StdPIPResponse;
import jakarta.persistence.EntityManager;
+import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import jakarta.persistence.Query;
import java.io.FileInputStream;
@@ -44,6 +44,7 @@ import java.util.LinkedList;
import java.util.Properties;
import java.util.Queue;
import java.util.UUID;
+import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -64,6 +65,7 @@ public class CountRecentOperationsPipTest {
private static final String TARGET = "my-target";
private static final String TEST_PROPERTIES = "src/test/resources/test.properties";
+ private static EntityManagerFactory emf;
private static EntityManager em;
@Mock
@@ -81,9 +83,6 @@ public class CountRecentOperationsPipTest {
@Mock
private PIPResponse resp3;
- @Mock
- private Status okStatus;
-
private Properties properties;
private Queue<PIPResponse> responses;
private Queue<String> attributes;
@@ -110,11 +109,12 @@ public class CountRecentOperationsPipTest {
//
String persistenceUnit = CountRecentOperationsPip.ISSUER_NAME + ".persistenceunit";
LOGGER.info("persistenceunit {}", persistenceUnit);
- em = Persistence.createEntityManagerFactory(props2.getProperty(persistenceUnit), props2).createEntityManager();
+ emf = Persistence.createEntityManagerFactory(props2.getProperty(persistenceUnit), props2);
+ em = emf.createEntityManager();
//
//
//
- LOGGER.info("Configured own entity manager", em.toString());
+ LOGGER.info("Configured own entity manager {}", em.toString());
}
/**
@@ -153,7 +153,7 @@ public class CountRecentOperationsPipTest {
}
@Test
- public void testConfigure_DbException() throws Exception {
+ public void testConfigure_DbException() {
properties.put("jakarta.persistence.jdbc.url", "invalid");
assertThatCode(() ->
pipEngine.configure("issuer", properties)
@@ -208,7 +208,7 @@ public class CountRecentOperationsPipTest {
//
// create entry
//
- OperationsHistory newEntry = createEntry("cl-foobar-1", "vnf-1", "SUCCESS");
+ OperationsHistory newEntry = createEntry();
//
// No entries yet
//
@@ -231,9 +231,9 @@ public class CountRecentOperationsPipTest {
}
@Test
- public void testStringToChronoUnit() throws PIPException {
+ public void testStringToChronosUnit() throws PIPException {
// not configured yet
- OperationsHistory newEntry = createEntry("cl-foobar-1", "vnf-1", "SUCCESS");
+ OperationsHistory newEntry = createEntry();
assertEquals(-1, getCount(newEntry));
// now configure it
@@ -271,14 +271,14 @@ public class CountRecentOperationsPipTest {
return ((Number) value.getValue()).longValue();
}
- private OperationsHistory createEntry(String cl, String target, String outcome) {
+ private OperationsHistory createEntry() {
//
// Create entry
//
OperationsHistory newEntry = new OperationsHistory();
- newEntry.setClosedLoopName(cl);
- newEntry.setTarget(target);
- newEntry.setOutcome(outcome);
+ newEntry.setClosedLoopName("cl-foobar-1");
+ newEntry.setTarget("vnf-1");
+ newEntry.setOutcome("SUCCESS");
newEntry.setActor("Controller");
newEntry.setOperation("operationA");
newEntry.setStarttime(Date.from(Instant.now().minusMillis(20000)));
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java
index 2edaf0e5..95880efe 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslatorTest.java
@@ -128,7 +128,6 @@ public class StdMatchableTranslatorTest {
ApiRestController.class.getName());
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, "false");
- props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_AAF_SUFFIX, "false");
props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER,
GsonMessageBodyHandler.class.getName());
diff --git a/applications/common/src/test/resources/META-INF/persistence.xml b/applications/common/src/test/resources/META-INF/persistence.xml
index 87896a60..53597b91 100644
--- a/applications/common/src/test/resources/META-INF/persistence.xml
+++ b/applications/common/src/test/resources/META-INF/persistence.xml
@@ -20,16 +20,18 @@
============LICENSE_END=========================================================
-->
-<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0">
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0">
<persistence-unit name="PipEngineTest" transaction-type="RESOURCE_LOCAL">
+ <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>org.onap.policy.guard.OperationsHistory</class>
<properties>
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="jakarta.persistence.schema-generation.create-source" value="metadata"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
- <property name="hibernate.show_sql" value="false" />
+ <property name="hibernate.show_sql" value="false"/>
</properties>
</persistence-unit>
diff --git a/applications/common/src/test/resources/test.properties b/applications/common/src/test/resources/test.properties
index 77939c35..58aa5b16 100644
--- a/applications/common/src/test/resources/test.properties
+++ b/applications/common/src/test/resources/test.properties
@@ -40,7 +40,6 @@ get-operation-outcome.persistenceunit=PipEngineTest
#
# JPA Properties
#
-eclipselink.target-database=Auto
jakarta.persistence.jdbc.driver=org.h2.Driver
jakarta.persistence.jdbc.url=jdbc:h2:mem:testdb;DATABASE_TO_UPPER=FALSE
jakarta.persistence.jdbc.user=policy
diff --git a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java
index 45caf21c..184db863 100644
--- a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java
+++ b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/GuardTranslator.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -153,7 +153,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
// Generate the TargetType - add true if not blacklist
//
newPolicyType.setTarget(this.generateTargetType(toscaPolicy.getProperties(),
- ! POLICYTYPE_BLACKLIST.equals(toscaPolicy.getType())));
+ !POLICYTYPE_BLACKLIST.equals(toscaPolicy.getType())));
//
// Add specific's per guard policy type
//
@@ -190,17 +190,16 @@ public class GuardTranslator implements ToscaPolicyTranslator {
* whether the Variable is true or false. Any existing ConditionType will be updated to AND with the
* Variable.
*
- * @param variable VariableDefinitionType to add
+ * @param variable VariableDefinitionType to add
* @param newPolicyType PolicyType that will be updated
*/
protected void addVariableToConditionTypes(VariableReferenceType variable,
- PolicyType newPolicyType) {
+ PolicyType newPolicyType) {
//
// Iterate through the rules
//
for (Object objectType : newPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()) {
- if (objectType instanceof RuleType) {
- RuleType rule = (RuleType) objectType;
+ if (objectType instanceof RuleType rule) {
if (rule.getCondition() == null) {
//
// No condition already, just create and add a new one
@@ -214,7 +213,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
// with the Variable.
//
rule.setCondition(ToscaPolicyTranslatorUtils.addVariableToCondition(rule.getCondition(), variable,
- XACML3.ID_FUNCTION_AND));
+ XACML3.ID_FUNCTION_AND));
}
}
}
@@ -272,7 +271,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
* From the TOSCA metadata section, pull in values that are needed into the XACML policy.
*
* @param policy Policy Object to store the metadata
- * @param map The Metadata TOSCA Map
+ * @param map The Metadata TOSCA Map
* @return Same Policy Object
*/
protected PolicyType fillMetadataSection(PolicyType policy, Map<String, Object> map) {
@@ -287,7 +286,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
}
/**
- * Generate the targettype for the policy. Optional to add MatchType for the target. eg. the
+ * Generate the targetType for the policy. Optional to add MatchType for the target. eg. the
* blacklist policy type uses the target in a different manner.
*
* @param properties TOSCA properties object
@@ -296,12 +295,12 @@ public class GuardTranslator implements ToscaPolicyTranslator {
* @throws ToscaPolicyConversionException if there is a missing property
*/
protected TargetType generateTargetType(Map<String, Object> properties, boolean addTargets)
- throws ToscaPolicyConversionException {
+ throws ToscaPolicyConversionException {
//
// Decode the definition from the policy's properties
//
TargetTypeDefinition targetTypeDef =
- ToscaPolicyTranslatorUtils.decodeProperties(properties, TargetTypeDefinition.class);
+ ToscaPolicyTranslatorUtils.decodeProperties(properties, TargetTypeDefinition.class);
//
// Go through potential properties
//
@@ -354,11 +353,11 @@ public class GuardTranslator implements ToscaPolicyTranslator {
if (value instanceof Collection) {
((Collection<String>) value).forEach(val -> {
var match = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
- XACML3.ID_FUNCTION_STRING_EQUAL,
- val,
- XACML3.ID_DATATYPE_STRING,
- attributeId,
- XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
+ XACML3.ID_FUNCTION_STRING_EQUAL,
+ val,
+ XACML3.ID_DATATYPE_STRING,
+ attributeId,
+ XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
allOf.getMatch().add(match);
});
@@ -366,35 +365,34 @@ public class GuardTranslator implements ToscaPolicyTranslator {
return allOf;
}
- protected void addTimeRangeMatch(AllOfType allOf, TimeRange timeRange)
- throws ToscaPolicyConversionException {
+ protected void addTimeRangeMatch(AllOfType allOf, TimeRange timeRange) {
var matchStart = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
- XACML3.ID_FUNCTION_TIME_GREATER_THAN_OR_EQUAL,
- timeRange.getStartTime(),
- XACML3.ID_DATATYPE_TIME,
- XACML3.ID_ENVIRONMENT_CURRENT_TIME,
- XACML3.ID_ATTRIBUTE_CATEGORY_ENVIRONMENT);
+ XACML3.ID_FUNCTION_TIME_GREATER_THAN_OR_EQUAL,
+ timeRange.getStartTime(),
+ XACML3.ID_DATATYPE_TIME,
+ XACML3.ID_ENVIRONMENT_CURRENT_TIME,
+ XACML3.ID_ATTRIBUTE_CATEGORY_ENVIRONMENT);
allOf.getMatch().add(matchStart);
var matchEnd = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
- XACML3.ID_FUNCTION_TIME_LESS_THAN_OR_EQUAL,
- timeRange.getEndTime(),
- XACML3.ID_DATATYPE_TIME,
- XACML3.ID_ENVIRONMENT_CURRENT_TIME,
- XACML3.ID_ATTRIBUTE_CATEGORY_ENVIRONMENT);
+ XACML3.ID_FUNCTION_TIME_LESS_THAN_OR_EQUAL,
+ timeRange.getEndTime(),
+ XACML3.ID_DATATYPE_TIME,
+ XACML3.ID_ENVIRONMENT_CURRENT_TIME,
+ XACML3.ID_ATTRIBUTE_CATEGORY_ENVIRONMENT);
allOf.getMatch().add(matchEnd);
}
protected VariableReferenceType createTimeRangeVariable(Map<String, Object> properties, PolicyType newPolicyType)
- throws ToscaPolicyConversionException {
+ throws ToscaPolicyConversionException {
//
// Decode the definition from the policy's properties
//
TimeRangeDefinition timeRangeDef =
- ToscaPolicyTranslatorUtils.decodeProperties(properties, TimeRangeDefinition.class);
+ ToscaPolicyTranslatorUtils.decodeProperties(properties, TimeRangeDefinition.class);
TimeRange timeRange = timeRangeDef.getTimeRange();
if (timeRange == null) {
return null;
@@ -408,14 +406,14 @@ public class GuardTranslator implements ToscaPolicyTranslator {
// They should be the same object types. We cannot establish a range
// between an OffsetDateTime and an OffsetTime
//
- if (! startTimeObject.getClass().equals(endTimeObject.getClass())) {
+ if (!startTimeObject.getClass().equals(endTimeObject.getClass())) {
throw new ToscaPolicyConversionException("start_time and end_time class types do not match");
}
//
// Create the inner timeInRange ApplyType
//
ApplyType timeInRange = ToscaPolicyTranslatorUtils.generateTimeInRange(timeRange.getStartTime(),
- timeRange.getEndTime(), true);
+ timeRange.getEndTime(), true);
var variable = new VariableDefinitionType();
variable.setVariableId(VARIABLE_TIMEINRANGE);
variable.setExpression(new ObjectFactory().createApply(timeInRange));
@@ -451,12 +449,12 @@ public class GuardTranslator implements ToscaPolicyTranslator {
}
protected void generateFrequencyRules(ToscaPolicy toscaPolicy, String policyName, PolicyType newPolicyType)
- throws ToscaPolicyConversionException {
+ throws ToscaPolicyConversionException {
//
// Decode the definition from the policy's properties
//
FrequencyDefinition frequencyDef = ToscaPolicyTranslatorUtils.decodeProperties(toscaPolicy.getProperties(),
- FrequencyDefinition.class);
+ FrequencyDefinition.class);
//
// See if its possible to generate a count
//
@@ -468,7 +466,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
// Generate a count
//
final ApplyType countCheck =
- generateCountCheck(frequencyDef.getLimit(), timeWindow, frequencyDef.getTimeUnits());
+ generateCountCheck(frequencyDef.getLimit(), timeWindow, frequencyDef.getTimeUnits());
//
// Create our condition
//
@@ -533,46 +531,46 @@ public class GuardTranslator implements ToscaPolicyTranslator {
}
protected void generateMinMaxRules(ToscaPolicy toscaPolicy, String policyName, PolicyType newPolicyType)
- throws ToscaPolicyConversionException {
+ throws ToscaPolicyConversionException {
//
// Decode the definition from the policy's properties
//
MinMaxDefinition minMaxDef = ToscaPolicyTranslatorUtils.decodeProperties(toscaPolicy.getProperties(),
- MinMaxDefinition.class);
+ MinMaxDefinition.class);
//
// Add the target
//
var matchTarget = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
- XACML3.ID_FUNCTION_STRING_EQUAL,
- minMaxDef.getTarget(),
- XACML3.ID_DATATYPE_STRING,
- ToscaDictionary.ID_RESOURCE_GUARD_TARGETID,
- XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
+ XACML3.ID_FUNCTION_STRING_EQUAL,
+ minMaxDef.getTarget(),
+ XACML3.ID_DATATYPE_STRING,
+ ToscaDictionary.ID_RESOURCE_GUARD_TARGETID,
+ XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
//
// For the min, if the # of instances is less than the minimum
// then allow the scale.
//
if (minMaxDef.getMin() != null) {
var matchMin = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
- XACML3.ID_FUNCTION_INTEGER_GREATER_THAN,
- minMaxDef.getMin().toString(),
- XACML3.ID_DATATYPE_INTEGER,
- ToscaDictionary.ID_RESOURCE_GUARD_VFCOUNT,
- XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
+ XACML3.ID_FUNCTION_INTEGER_GREATER_THAN,
+ minMaxDef.getMin().toString(),
+ XACML3.ID_DATATYPE_INTEGER,
+ ToscaDictionary.ID_RESOURCE_GUARD_VFCOUNT,
+ XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
newPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(
- generateMinMaxRule(matchTarget, matchMin, policyName + ":minrule", "check minimum"));
+ generateMinMaxRule(matchTarget, matchMin, policyName + ":minrule", "check minimum"));
}
if (minMaxDef.getMax() != null) {
var matchMax = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
- XACML3.ID_FUNCTION_INTEGER_GREATER_THAN,
- minMaxDef.getMax().toString(),
- XACML3.ID_DATATYPE_INTEGER,
- ToscaDictionary.ID_RESOURCE_GUARD_VFCOUNT,
- XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
+ XACML3.ID_FUNCTION_INTEGER_GREATER_THAN,
+ minMaxDef.getMax().toString(),
+ XACML3.ID_DATATYPE_INTEGER,
+ ToscaDictionary.ID_RESOURCE_GUARD_VFCOUNT,
+ XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE);
newPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(
- generateMinMaxRule(matchTarget, matchMax, policyName + ":maxrule", "check maximum"));
+ generateMinMaxRule(matchTarget, matchMax, policyName + ":maxrule", "check maximum"));
}
//
// Do we have at least a min or max?
@@ -599,12 +597,12 @@ public class GuardTranslator implements ToscaPolicyTranslator {
}
protected void generateBlacklistRules(ToscaPolicy toscaPolicy, String policyName, PolicyType newPolicyType)
- throws ToscaPolicyConversionException {
+ throws ToscaPolicyConversionException {
//
// Decode the definition from the policy's properties
//
BlacklistDefinition blacklistDef = ToscaPolicyTranslatorUtils.decodeProperties(toscaPolicy.getProperties(),
- BlacklistDefinition.class);
+ BlacklistDefinition.class);
//
// Iterate the entries and create individual AnyOf so each entry is
// treated as an OR.
@@ -632,12 +630,12 @@ public class GuardTranslator implements ToscaPolicyTranslator {
}
protected void generateFilterRules(ToscaPolicy toscaPolicy, String policyName, PolicyType newPolicyType)
- throws ToscaPolicyConversionException {
+ throws ToscaPolicyConversionException {
//
// Decode the definition from the policy's properties
//
FilterDefinition filterDef = ToscaPolicyTranslatorUtils.decodeProperties(toscaPolicy.getProperties(),
- FilterDefinition.class);
+ FilterDefinition.class);
//
// Set the combining algorithm
//
@@ -650,7 +648,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
break;
default:
throw new ToscaPolicyConversionException(
- "Unexpected value for algorithm, should be whitelist-overrides or blacklist-overrides");
+ "Unexpected value for algorithm, should be whitelist-overrides or blacklist-overrides");
}
//
// Iterate the filters
@@ -666,7 +664,7 @@ public class GuardTranslator implements ToscaPolicyTranslator {
// Create our filter rule
//
RuleType filterRule = createFilterRule(policyName + ":rule" + ruleId++, field, filterAttributes.getFilter(),
- function, filterAttributes.getBlacklist());
+ function, filterAttributes.getBlacklist());
//
// Add the rule to the policy
//
@@ -675,51 +673,34 @@ public class GuardTranslator implements ToscaPolicyTranslator {
}
protected String validateFilterPropertyField(String field)
- throws ToscaPolicyConversionException {
+ throws ToscaPolicyConversionException {
String fieldLowerCase = field.toLowerCase();
- switch (fieldLowerCase) {
- case "generic-vnf.vnf-name":
- case "generic-vnf.vnf-id":
- case "generic-vnf.vnf-type":
- case "generic-vnf.nf-naming-code":
- case "vserver.vserver-id":
- case "cloud-region.cloud-region-id":
- return fieldLowerCase;
- default:
- throw new ToscaPolicyConversionException("Unexpected value for field in filter");
- }
+ return switch (fieldLowerCase) {
+ case "generic-vnf.vnf-name", "generic-vnf.vnf-id", "generic-vnf.vnf-type", "generic-vnf.nf-naming-code",
+ "vserver.vserver-id", "cloud-region.cloud-region-id" -> fieldLowerCase;
+ default -> throw new ToscaPolicyConversionException("Unexpected value for field in filter");
+ };
}
protected Identifier validateFilterPropertyFunction(String function)
- throws ToscaPolicyConversionException {
- switch (function.toLowerCase()) {
- case "string-equal":
- return XACML3.ID_FUNCTION_STRING_EQUAL;
- case "string-equal-ignore-case":
- return XACML3.ID_FUNCTION_STRING_EQUAL_IGNORE_CASE;
- case "string-regexp-match":
- return XACML3.ID_FUNCTION_STRING_REGEXP_MATCH;
- case "string-contains":
- return XACML3.ID_FUNCTION_STRING_CONTAINS;
- case "string-greater-than":
- return XACML3.ID_FUNCTION_STRING_GREATER_THAN;
- case "string-greater-than-or-equal":
- return XACML3.ID_FUNCTION_STRING_GREATER_THAN_OR_EQUAL;
- case "string-less-than":
- return XACML3.ID_FUNCTION_STRING_LESS_THAN;
- case "string-less-than-or-equal":
- return XACML3.ID_FUNCTION_STRING_LESS_THAN_OR_EQUAL;
- case "string-starts-with":
- return XACML3.ID_FUNCTION_STRING_STARTS_WITH;
- case "string-ends-with":
- return XACML3.ID_FUNCTION_STRING_ENDS_WITH;
- default:
- throw new ToscaPolicyConversionException("Unexpected value for function in filter");
- }
+ throws ToscaPolicyConversionException {
+ return switch (function.toLowerCase()) {
+ case "string-equal" -> XACML3.ID_FUNCTION_STRING_EQUAL;
+ case "string-equal-ignore-case" -> XACML3.ID_FUNCTION_STRING_EQUAL_IGNORE_CASE;
+ case "string-regexp-match" -> XACML3.ID_FUNCTION_STRING_REGEXP_MATCH;
+ case "string-contains" -> XACML3.ID_FUNCTION_STRING_CONTAINS;
+ case "string-greater-than" -> XACML3.ID_FUNCTION_STRING_GREATER_THAN;
+ case "string-greater-than-or-equal" -> XACML3.ID_FUNCTION_STRING_GREATER_THAN_OR_EQUAL;
+ case "string-less-than" -> XACML3.ID_FUNCTION_STRING_LESS_THAN;
+ case "string-less-than-or-equal" -> XACML3.ID_FUNCTION_STRING_LESS_THAN_OR_EQUAL;
+ case "string-starts-with" -> XACML3.ID_FUNCTION_STRING_STARTS_WITH;
+ case "string-ends-with" -> XACML3.ID_FUNCTION_STRING_ENDS_WITH;
+ default -> throw new ToscaPolicyConversionException("Unexpected value for function in filter");
+ };
}
protected RuleType createFilterRule(String ruleId, String field, String filter, Identifier function,
- boolean isBlacklisted) {
+ boolean isBlacklisted) {
var rule = new RuleType();
rule.setRuleId(ruleId);
@@ -727,12 +708,12 @@ public class GuardTranslator implements ToscaPolicyTranslator {
// Create the Match
//
var matchFilter = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
- function,
- filter,
- XACML3.ID_DATATYPE_STRING,
- new IdentifierImpl(GuardPolicyRequest.PREFIX_RESOURCE_ATTRIBUTE_ID + field),
- XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE
- );
+ function,
+ filter,
+ XACML3.ID_DATATYPE_STRING,
+ new IdentifierImpl(GuardPolicyRequest.PREFIX_RESOURCE_ATTRIBUTE_ID + field),
+ XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE
+ );
var allOf = new AllOfType();
allOf.getMatch().add(matchFilter);
var anyOf = new AnyOfType();
diff --git a/applications/guard/src/test/resources/META-INF/persistence.xml b/applications/guard/src/test/resources/META-INF/persistence.xml
index 2b560062..569d3da7 100644
--- a/applications/guard/src/test/resources/META-INF/persistence.xml
+++ b/applications/guard/src/test/resources/META-INF/persistence.xml
@@ -20,15 +20,17 @@
============LICENSE_END=========================================================
-->
-<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0">
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0">
<persistence-unit name="OperationsHistoryPUTest" transaction-type="RESOURCE_LOCAL">
+ <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>org.onap.policy.guard.OperationsHistory</class>
<properties>
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
- <property name="hibernate.show_sql" value="false" />
- <property name="hibernate.format_sql" value="false" />
+ <property name="hibernate.show_sql" value="false"/>
+ <property name="hibernate.format_sql" value="false"/>
</properties>
</persistence-unit>
</persistence>
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java b/main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java
index d67a1fad..6728f6e8 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/XacmlState.java
@@ -93,8 +93,7 @@ public class XacmlState {
status.setHealthy(XacmlPdpActivator.getCurrent().isAlive() ? PdpHealthStatus.HEALTHY
: PdpHealthStatus.NOT_HEALTHY);
- PdpStatus heartbeat = new PdpStatus(status);
- return heartbeat;
+ return new PdpStatus(status);
}
/**
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpAafFilter.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpAafFilter.java
deleted file mode 100644
index 5a4c3bc6..00000000
--- a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpAafFilter.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.pdpx.main.rest;
-
-import org.onap.policy.common.endpoints.http.server.aaf.AafGranularAuthFilter;
-
-/**
- * Class to manage aaf filters for Xacml PDP component.
- *
- */
-public class XacmlPdpAafFilter extends AafGranularAuthFilter {
-
- public static final String AAF_NODETYPE = "policy-pdpx";
- public static final String AAF_ROOT_PERMISSION = DEFAULT_NAMESPACE + "." + AAF_NODETYPE;
-
- @Override
- public String getPermissionTypeRoot() {
- return AAF_ROOT_PERMISSION;
- }
-} \ No newline at end of file
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpStatisticsManager.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpStatisticsManager.java
index 253a0095..ab0ebd6c 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpStatisticsManager.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpStatisticsManager.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019, 2021-2022 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,7 +71,7 @@ public class XacmlPdpStatisticsManager {
private long undeployFailureCount;
private long indeterminantDecisionsCount;
private long notApplicableDecisionsCount;
- private Map<String, Map<String, Integer>> applicationMetrics = new HashMap<>();
+ private final Map<String, Map<String, Integer>> applicationMetrics = new HashMap<>();
/**
* Used to update our Map of ApplicationNames to statistics.
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java b/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java
index 531374d0..d421ba75 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/startstop/XacmlPdpActivator.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +43,6 @@ import org.onap.policy.pdpx.main.comm.XacmlPdpHearbeatPublisher;
import org.onap.policy.pdpx.main.comm.listeners.XacmlPdpStateChangeListener;
import org.onap.policy.pdpx.main.comm.listeners.XacmlPdpUpdateListener;
import org.onap.policy.pdpx.main.parameters.XacmlPdpParameterGroup;
-import org.onap.policy.pdpx.main.rest.XacmlPdpAafFilter;
import org.onap.policy.pdpx.main.rest.XacmlPdpApplicationManager;
import org.onap.policy.pdpx.main.rest.XacmlPdpRestController;
import org.onap.policy.pdpx.main.rest.XacmlPdpServiceFilter;
@@ -132,8 +132,7 @@ public class XacmlPdpActivator extends ServiceManagerContainer {
XacmlPdpServiceFilter.disableApi();
restServer = new XacmlPdpRestServer(xacmlPdpParameterGroup.getRestServerParameters(),
- List.of(XacmlPdpServiceFilter.class, XacmlPdpAafFilter.class),
- List.of(XacmlPdpRestController.class));
+ List.of(XacmlPdpServiceFilter.class), List.of(XacmlPdpRestController.class));
} catch (RuntimeException | HttpClientConfigException | BidirectionalTopicClientException e) {
throw new PolicyXacmlPdpRuntimeException(e.getMessage(), e);
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
index 8c412386..62c90f54 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019, 2021-2022 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021,2023 Nordix Foundation.
+ * Modifications Copyright (C) 2021, 2023 Nordix Foundation.
* Modifications Copyright (C) 2023 Bell Canada.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,19 +27,15 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.util.Arrays;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
@@ -47,11 +43,7 @@ import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.pdp.enums.PdpHealthStatus;
import org.onap.policy.models.pdp.enums.PdpResponseStatus;
import org.onap.policy.models.pdp.enums.PdpState;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.pdpx.main.comm.XacmlPdpUpdatePublisher;
import org.onap.policy.pdpx.main.rest.XacmlPdpApplicationManager;
-import org.onap.policy.pdpx.main.rest.XacmlPdpStatisticsManager;
import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator;
@RunWith(MockitoJUnitRunner.class)
@@ -115,25 +107,6 @@ public class XacmlStateTest {
}
@Test
- public void testGetStatistics() {
- XacmlPdpStatisticsManager statmgr = new XacmlPdpStatisticsManager();
- XacmlPdpStatisticsManager.setCurrent(statmgr);
-
- ToscaPolicy policy1 = mock(ToscaPolicy.class);
- ToscaPolicy policy2 = mock(ToscaPolicy.class);
- ToscaConceptIdentifier ident = new ToscaConceptIdentifier("undeployed", "2.3.4");
- when(policy2.getIdentifier()).thenReturn(ident);
-
- PdpUpdate message = new PdpUpdate();
- message.setPoliciesToBeDeployed(Arrays.asList(policy1));
- message.setPoliciesToBeUndeployed(Arrays.asList(policy2.getIdentifier()));
-
- TopicSinkClient client = Mockito.mock(TopicSinkClient.class);
- XacmlPdpUpdatePublisher publisher = new XacmlPdpUpdatePublisher(client, state, appmgr);
- publisher.handlePdpUpdate(message);
- }
-
- @Test
public void testUpdateInternalStatePdpStateChange() {
PdpStateChange req = new PdpStateChange();
req.setName(pdpName);
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
index e4352181..ef338cd8 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/CommonTestData.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,8 +21,6 @@
package org.onap.policy.pdpx.main.parameters;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -43,7 +41,6 @@ public class CommonTestData {
private static final String PORT_KEY = "port";
private static final String SERVER_HOST_KEY = "host";
private static final String API_HOST_KEY = "hostname";
- private static final String AAF_KEY = "aaf";
private static final String HTTPS_KEY = "useHttps";
private static final String REST_SERVER_PASS = "zb!XztG34";
@@ -51,20 +48,15 @@ public class CommonTestData {
private static final int REST_SERVER_PORT = 6969;
private static final String REST_SERVER_HOST = "0.0.0.0";
private static final boolean REST_SERVER_HTTPS = false;
- private static final boolean REST_SERVER_AAF = false;
-
private static final String POLICY_API_PASS = "zb!XztG34";
private static final String POLICY_API_USER = "healthcheck";
private static final int POLICY_API_PORT = 6970;
private static final String POLICY_API_HOST = "0.0.0.0";
private static final boolean POLICY_API_HTTPS = false;
- private static final boolean POLICY_API_AAF = false;
-
public static final String PDPX_PARAMETER_GROUP_NAME = "XacmlPdpParameters";
public static final String PDPX_GROUP = "XacmlPdpGroup";
public static final String PDPX_TYPE = "xacml";
- public static final List<TopicParameters> TOPIC_PARAMS =
- Collections.unmodifiableList(Arrays.asList(getTopicParams()));
+ public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams());
public static final Coder coder = new StandardCoder();
@@ -77,7 +69,7 @@ public class CommonTestData {
final TopicParameters topicParams = new TopicParameters();
topicParams.setTopic("POLICY-PDP-PAP");
topicParams.setTopicCommInfrastructure("noop");
- topicParams.setServers(Arrays.asList("message-router"));
+ topicParams.setServers(List.of("message-router"));
return topicParams;
}
@@ -90,7 +82,6 @@ public class CommonTestData {
public Map<String, Object> getRestServerParametersMap(final boolean isEmpty) {
final Map<String, Object> map = new TreeMap<>();
map.put(HTTPS_KEY, REST_SERVER_HTTPS);
- map.put(AAF_KEY, REST_SERVER_AAF);
if (!isEmpty) {
map.put(SERVER_HOST_KEY, REST_SERVER_HOST);
@@ -111,7 +102,6 @@ public class CommonTestData {
public Map<String, Object> getRestServerParametersMap(final int port) {
final Map<String, Object> map = new TreeMap<>();
map.put(HTTPS_KEY, REST_SERVER_HTTPS);
- map.put(AAF_KEY, REST_SERVER_AAF);
map.put(SERVER_HOST_KEY, REST_SERVER_HOST);
map.put(PORT_KEY, port);
map.put(USER_KEY, REST_SERVER_USER);
@@ -146,7 +136,6 @@ public class CommonTestData {
final Map<String, Object> map = new TreeMap<>();
map.put(CLIENT_NAME, XacmlPdpParameterGroup.PARAM_POLICY_API);
map.put(HTTPS_KEY, POLICY_API_HTTPS);
- map.put(AAF_KEY, POLICY_API_AAF);
if (!isEmpty) {
map.put(API_HOST_KEY, POLICY_API_HOST);
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
index a9f3f12d..f39061a6 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterGroup.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ package org.onap.policy.pdpx.main.parameters;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
@@ -43,9 +44,8 @@ import org.onap.policy.common.parameters.ValidationResult;
*
*/
public class TestXacmlPdpParameterGroup {
- CommonTestData commonTestData = new CommonTestData();
private static File applicationPath;
- private static CommonTestData testData = new CommonTestData();
+ private static final CommonTestData testData = new CommonTestData();
@ClassRule
public static final TemporaryFolder applicationFolder = new TemporaryFolder();
@@ -65,7 +65,7 @@ public class TestXacmlPdpParameterGroup {
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlApplicationParameters xacmlApplicationParameters =
testData.toObject(testData.getXacmlapplicationParametersMap(false,
- applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class);
+ applicationPath.getAbsolutePath()), XacmlApplicationParameters.class);
final XacmlPdpParameterGroup pdpxParameters =
new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME,
CommonTestData.PDPX_GROUP, "flavor", restServerParameters, policyApiParameters,
@@ -80,7 +80,6 @@ public class TestXacmlPdpParameterGroup {
assertEquals(CommonTestData.PDPX_PARAMETER_GROUP_NAME, pdpxParameters.getName());
assertEquals("flavor", pdpxParameters.getPdpType());
assertFalse(pdpxParameters.getRestServerParameters().isHttps());
- assertFalse(pdpxParameters.getRestServerParameters().isAaf());
assertThat(pdpxParameters.getApplicationParameters().getExclusions()).isEmpty();
}
@@ -94,12 +93,12 @@ public class TestXacmlPdpParameterGroup {
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlApplicationParameters xacmlApplicationParameters =
testData.toObject(testData.getXacmlapplicationParametersMap(false,
- applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class);
+ applicationPath.getAbsolutePath()), XacmlApplicationParameters.class);
final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup(null, CommonTestData.PDPX_GROUP,
null, restServerParameters, policyApiParameters, topicParameterGroup, xacmlApplicationParameters);
final ValidationResult validationResult = pdpxParameters.validate();
assertFalse(validationResult.isValid());
- assertEquals(null, pdpxParameters.getName());
+ assertNull(pdpxParameters.getName());
assertThat(validationResult.getResult()).contains("\"name\" value \"null\" INVALID, is null");
}
@@ -113,7 +112,7 @@ public class TestXacmlPdpParameterGroup {
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlApplicationParameters xacmlApplicationParameters =
testData.toObject(testData.getXacmlapplicationParametersMap(false,
- applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class);
+ applicationPath.getAbsolutePath()), XacmlApplicationParameters.class);
final XacmlPdpParameterGroup pdpxParameters = new XacmlPdpParameterGroup("", CommonTestData.PDPX_GROUP,
CommonTestData.PDPX_TYPE, restServerParameters, policyApiParameters, topicParameterGroup,
xacmlApplicationParameters);
@@ -133,13 +132,13 @@ public class TestXacmlPdpParameterGroup {
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlApplicationParameters xacmlApplicationParameters =
testData.toObject(testData.getXacmlapplicationParametersMap(false,
- applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class);
+ applicationPath.getAbsolutePath()), XacmlApplicationParameters.class);
final XacmlPdpParameterGroup pdpxParameters =
new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, null, null, restServerParameters,
policyApiParameters, topicParameterGroup, xacmlApplicationParameters);
final ValidationResult validationResult = pdpxParameters.validate();
assertFalse(validationResult.isValid());
- assertEquals(null, pdpxParameters.getPdpGroup());
+ assertNull(pdpxParameters.getPdpGroup());
assertThat(validationResult.getResult()).contains("\"pdpGroup\" value \"null\" INVALID, is null");
}
@@ -153,7 +152,7 @@ public class TestXacmlPdpParameterGroup {
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlApplicationParameters xacmlApplicationParameters =
testData.toObject(testData.getXacmlapplicationParametersMap(false,
- applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class);
+ applicationPath.getAbsolutePath()), XacmlApplicationParameters.class);
final XacmlPdpParameterGroup pdpxParameters =
new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, "", null, restServerParameters,
policyApiParameters, topicParameterGroup, xacmlApplicationParameters);
@@ -173,7 +172,7 @@ public class TestXacmlPdpParameterGroup {
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlApplicationParameters xacmlApplicationParameters =
testData.toObject(testData.getXacmlapplicationParametersMap(false,
- applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class);
+ applicationPath.getAbsolutePath()), XacmlApplicationParameters.class);
final XacmlPdpParameterGroup pdpxParameters =
new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP,
null, restServerParameters, policyApiParameters,
@@ -193,7 +192,7 @@ public class TestXacmlPdpParameterGroup {
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlApplicationParameters xacmlApplicationParameters =
testData.toObject(testData.getXacmlapplicationParametersMap(false,
- applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class);
+ applicationPath.getAbsolutePath()), XacmlApplicationParameters.class);
final XacmlPdpParameterGroup pdpxParameters =
new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP,
null, restServerParameters, policyApiParameters,
@@ -213,7 +212,7 @@ public class TestXacmlPdpParameterGroup {
testData.toObject(testData.getTopicParametersMap(true), TopicParameterGroup.class);
final XacmlApplicationParameters xacmlApplicationParameters =
testData.toObject(testData.getXacmlapplicationParametersMap(false,
- applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class);
+ applicationPath.getAbsolutePath()), XacmlApplicationParameters.class);
final XacmlPdpParameterGroup pdpxParameters =
new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP,
null, restServerParameters, policyApiParameters,
@@ -233,7 +232,7 @@ public class TestXacmlPdpParameterGroup {
testData.toObject(testData.getTopicParametersMap(false), TopicParameterGroup.class);
final XacmlApplicationParameters xacmlApplicationParameters =
testData.toObject(testData.getXacmlapplicationParametersMap(true,
- applicationPath.getAbsolutePath().toString()), XacmlApplicationParameters.class);
+ applicationPath.getAbsolutePath()), XacmlApplicationParameters.class);
final XacmlPdpParameterGroup pdpxParameters =
new XacmlPdpParameterGroup(CommonTestData.PDPX_PARAMETER_GROUP_NAME, CommonTestData.PDPX_GROUP,
null, restServerParameters, policyApiParameters,
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpAafFilterTest.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpAafFilterTest.java
deleted file mode 100644
index 088ca927..00000000
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/XacmlPdpAafFilterTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 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.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.pdpx.main.rest;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-
-public class XacmlPdpAafFilterTest {
-
- @Test
- public void testAafFilter() {
- XacmlPdpAafFilter filter = new XacmlPdpAafFilter();
- assertNotNull(filter);
- assertEquals(XacmlPdpAafFilter.AAF_ROOT_PERMISSION, filter.getPermissionTypeRoot());
- }
-
-}
diff --git a/packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json b/packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json
index 9fee0d97..d5b021b4 100644
--- a/packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json
+++ b/packages/policy-xacmlpdp-tarball/src/main/resources/etc/defaultConfig.json
@@ -8,7 +8,6 @@
"userName": "healthcheck",
"password": "zb!XztG34",
"https": true,
- "aaf": false,
"prometheus": true
},
"policyApiParameters": {
@@ -16,8 +15,7 @@
"port": 6969,
"userName": "healthcheck",
"password": "zb!XztG34",
- "useHttps": true,
- "aaf": false
+ "useHttps": true
},
"applicationParameters": {
"applicationPath": "/opt/app/policy/pdpx/apps"
diff --git a/packages/policy-xacmlpdp-tarball/src/main/resources/etc/s3pConfig.json b/packages/policy-xacmlpdp-tarball/src/main/resources/etc/s3pConfig.json
index 4b6ad685..9aa2c6f9 100644
--- a/packages/policy-xacmlpdp-tarball/src/main/resources/etc/s3pConfig.json
+++ b/packages/policy-xacmlpdp-tarball/src/main/resources/etc/s3pConfig.json
@@ -7,7 +7,6 @@
"port":6969,
"userName":"healthcheck",
"password":"zb!XztG34",
- "https": true,
- "aaf": false
+ "https": true
}
}