aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpRestServer.java43
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpStatisticsManager.java22
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/rest/model/Decision.java10
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/rest/model/StatisticsReport.java21
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/rest/provider/StatisticsProvider.java1
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java2
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java11
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java9
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java11
9 files changed, 127 insertions, 3 deletions
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpRestServer.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpRestServer.java
index eece1ffc..f3b7a54e 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpRestServer.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/rest/XacmlPdpRestServer.java
@@ -21,11 +21,14 @@
package org.onap.policy.pdpx.main.rest;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.Properties;
+import java.util.ServiceLoader;
+
import org.onap.policy.common.capabilities.Startable;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
-import org.onap.policy.common.gson.JacksonHandler;
+import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
import org.onap.policy.pdpx.main.parameters.RestServerParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,6 +47,8 @@ public class XacmlPdpRestServer implements Startable {
private RestServerParameters restServerParameters;
+ private ServiceLoader<XacmlApplicationServiceProvider> applicationLoader;
+
/**
* Constructor for instantiating XacmlPdpRestServer.
*
@@ -59,7 +64,17 @@ public class XacmlPdpRestServer implements Startable {
@Override
public boolean start() {
try {
+ //
+ // Look for existing policy types loaded into the system
+ //
+ locateExistingPolicyTypes();
+ //
+ // Get the server properties
+ //
servers = HttpServletServer.factory.build(getServerProperties());
+ //
+ // Start all the servers
+ //
for (final HttpServletServer server : servers) {
if (server.isAaf()) {
server.addFilterClass(null, XacmlPdpAafFilter.class.getCanonicalName());
@@ -100,6 +115,32 @@ public class XacmlPdpRestServer implements Startable {
return props;
}
+ private void locateExistingPolicyTypes() {
+ //
+ // Load service
+ //
+ applicationLoader = ServiceLoader.load(XacmlApplicationServiceProvider.class);
+ //
+ // Iterate through them
+ //
+ StringBuilder strDump = new StringBuilder("Loaded applications:" + System.lineSeparator());
+ Iterator<XacmlApplicationServiceProvider> iterator = applicationLoader.iterator();
+ long types = 0;
+ while (iterator.hasNext()) {
+ XacmlApplicationServiceProvider application = iterator.next();
+ strDump.append(application.applicationName());
+ strDump.append(" supports ");
+ strDump.append(application.supportedPolicyTypes());
+ types += application.supportedPolicyTypes().size();
+ strDump.append(System.lineSeparator());
+ }
+ LOGGER.debug("{}", strDump);
+ //
+ // Update statistics manager
+ //
+ XacmlPdpStatisticsManager.setTotalPolicyTypesCount(types);
+ }
+
/**
* {@inheritDoc}.
*/
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 471ffca4..cfdfa3d8 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
@@ -26,6 +26,7 @@ package org.onap.policy.pdpx.main.rest;
*/
public class XacmlPdpStatisticsManager {
+ private static long totalPolicyTypesCount;
private static long totalPoliciesCount;
private static long permitDecisionsCount;
private static long denyDecisionsCount;
@@ -37,6 +38,18 @@ public class XacmlPdpStatisticsManager {
}
/**
+ * Method to set the xacml pdp total policy types count. This
+ * doesn't really increment, it depends on the applications
+ * that are loaded. Which can be dynamic.
+ *
+ * @return the total
+ */
+ public static long setTotalPolicyTypesCount(long newCount) {
+ totalPolicyTypesCount = newCount;
+ return totalPolicyTypesCount;
+ }
+
+ /**
* Method to update the xacml pdp total policies count.
*
* @return the total
@@ -82,6 +95,15 @@ public class XacmlPdpStatisticsManager {
}
/**
+ * Returns the current value of totalPolicyTypesCount.
+
+ * @return the totalPolicyTypesCount
+ */
+ public static long getTotalPolicyTypesCount() {
+ return totalPolicyTypesCount;
+ }
+
+ /**
* Returns the current value of totalPoliciesCount.
* @return the totalPoliciesCount
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/model/Decision.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/model/Decision.java
index d09dac9c..4504cb1b 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/rest/model/Decision.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/rest/model/Decision.java
@@ -20,8 +20,16 @@
package org.onap.policy.pdpx.main.rest.model;
+import java.util.List;
+import java.util.Map;
+
public class Decision {
- //TODO
+ String onapName;
+
+ String onapInstance;
+
+ String action;
+ List<Map<String, Object>> resource;
}
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/model/StatisticsReport.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/model/StatisticsReport.java
index 36177034..05933399 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/rest/model/StatisticsReport.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/rest/model/StatisticsReport.java
@@ -27,6 +27,7 @@ package org.onap.policy.pdpx.main.rest.model;
public class StatisticsReport {
private int code;
+ private long totalPolicyTypesCount;
private long totalPoliciesCount;
private long permitDecisionsCount;
private long denyDecisionsCount;
@@ -53,6 +54,24 @@ public class StatisticsReport {
}
/**
+ * Returns the totalPolicyTypesCount of this {@link StatisticsReport} instance.
+ *
+ * @return the totalPolicyTypesCount
+ */
+ public long getTotalPolicyTypesCount() {
+ return totalPolicyTypesCount;
+ }
+
+ /**
+ * Set totalPolicyTypesCount in this {@link StatisticsReport} instance.
+ *
+ * @param totalPolicyTypesCount the totalPolicyTypesCount to set
+ */
+ public void setTotalPolicyTypesCount(long totalPolicyTypesCount) {
+ this.totalPolicyTypesCount = totalPolicyTypesCount;
+ }
+
+ /**
* Returns the totalPoliciesCount of this {@link StatisticsReport} instance.
*
* @return the totalPoliciesCount
@@ -150,6 +169,8 @@ public class StatisticsReport {
final StringBuilder builder = new StringBuilder();
builder.append("StatisticsReport [code=");
builder.append(getCode());
+ builder.append(", totalPolicyTypesCount=");
+ builder.append(getTotalPolicyTypesCount());
builder.append(", totalPoliciesCount=");
builder.append(getTotalPoliciesCount());
builder.append(", permitDecisionsCount=");
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/rest/provider/StatisticsProvider.java b/main/src/main/java/org/onap/policy/pdpx/main/rest/provider/StatisticsProvider.java
index 7b883280..1b90f6b8 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/rest/provider/StatisticsProvider.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/rest/provider/StatisticsProvider.java
@@ -38,6 +38,7 @@ public class StatisticsProvider {
public StatisticsReport fetchCurrentStatistics() {
final StatisticsReport report = new StatisticsReport();
report.setCode(XacmlPdpActivator.isAlive() ? 200 : 500);
+ report.setTotalPolicyTypesCount(XacmlPdpStatisticsManager.getTotalPolicyTypesCount());
report.setTotalPoliciesCount(XacmlPdpStatisticsManager.getTotalPoliciesCount());
report.setPermitDecisionsCount(XacmlPdpStatisticsManager.getPermitDecisionsCount());
report.setDenyDecisionsCount(XacmlPdpStatisticsManager.getDenyDecisionsCount());
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java
index 3955031a..ef85a762 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java
@@ -142,7 +142,7 @@ public class TestXacmlPdpParameterHandler {
final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
arguments.parse(xacmlPdpConfigParameters);
- final String expectedResult = new String(Files.readAllBytes(
+ new String(Files.readAllBytes(
Paths.get("src/test/resources/expectedValidationResults/InvalidRestServerParameters.txt")));
assertThatThrownBy(() -> new XacmlPdpParameterHandler().getParameters(arguments))
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java
index 0f608e29..1ec649cb 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpRestServer.java
@@ -41,6 +41,7 @@ import javax.ws.rs.core.MediaType;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.junit.After;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
import org.onap.policy.common.utils.network.NetworkUtil;
@@ -70,6 +71,16 @@ public class TestXacmlPdpRestServer {
private XacmlPdpRestServer restServer;
/**
+ * setup.
+ */
+ @BeforeClass
+ public static void setUp() {
+ System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StdErrLog");
+ System.setProperty("org.eclipse.jetty.LEVEL", "OFF");
+
+ }
+
+ /**
* Method for cleanup after each test.
*/
@After
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java
index ee05ff06..595301de 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestXacmlPdpStatistics.java
@@ -21,6 +21,7 @@
package org.onap.policy.pdpx.main.rest;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -32,6 +33,7 @@ import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
@@ -51,12 +53,19 @@ public class TestXacmlPdpStatistics {
private static final Logger LOGGER = LoggerFactory.getLogger(TestXacmlPdpStatistics.class);
+ @BeforeClass
+ public static void beforeClass() {
+ System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StdErrLog");
+ System.setProperty("org.eclipse.jetty.LEVEL", "OFF");
+ }
+
@Test
public void testXacmlPdpStatistics_200() throws PolicyXacmlPdpException, InterruptedException {
try {
final Main main = startXacmlPdpService();
StatisticsReport report = getXacmlPdpStatistics();
validateReport(report, 0, 200);
+ assertThat(report.getTotalPolicyTypesCount()).isGreaterThan(0);
updateXacmlPdpStatistics();
report = getXacmlPdpStatistics();
validateReport(report, 1, 200);
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java
index bfc8a2a4..8c37acb7 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Assert;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
import org.onap.policy.pdpx.main.parameters.CommonTestData;
@@ -35,6 +36,16 @@ import org.onap.policy.pdpx.main.parameters.CommonTestData;
*/
public class TestMain {
+ /**
+ * setup.
+ */
+ @BeforeClass
+ public static void setUp() {
+ System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StdErrLog");
+ System.setProperty("org.eclipse.jetty.LEVEL", "OFF");
+
+ }
+
@Test
public void testMain() throws PolicyXacmlPdpException {
final String[] xacmlPdpConfigParameters = {"-c", "parameters/XacmlPdpConfigParameters.json"};