Monitoring policy creation foundation

Upgrde to xacml v2.0.0 release artifact.

Some re-arrangement of classes. New class to support a
common dictionary among the monitoring applications. I
may move it to a common under the main since some of the
values are shareable.

Created application service provider, so the XACML
main knows what policy types are pre-loaded and can
report them back to the PAP.

struggled with cucumber, which does not create
TemporaryFolder although the documentation says its
supported.

Added a new Policy Finder specific to ONAP which does
quicker job to load policies.

Issue-ID: POLICY-1273
Change-Id: I4af15a64da3b42d48f29809710421b1649625adc
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
diff --git a/main/pom.xml b/main/pom.xml
index 2a6677d..b769f37 100644
--- a/main/pom.xml
+++ b/main/pom.xml
@@ -56,6 +56,16 @@
             <artifactId>common-parameters</artifactId>
             <version>${policy.common.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.xacml-pdp.applications</groupId>
+            <artifactId>common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.xacml-pdp.applications</groupId>
+            <artifactId>monitoring</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 
     <build>
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 eece1ff..f3b7a54 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 @@
 
     private RestServerParameters restServerParameters;
 
+    private ServiceLoader<XacmlApplicationServiceProvider> applicationLoader;
+
     /**
      * Constructor for instantiating XacmlPdpRestServer.
      *
@@ -59,7 +64,17 @@
     @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 @@
         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 471ffca..cfdfa3d 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 @@
  */
 public class XacmlPdpStatisticsManager {
 
+    private static long totalPolicyTypesCount;
     private static long totalPoliciesCount;
     private static long permitDecisionsCount;
     private static long denyDecisionsCount;
@@ -37,6 +38,18 @@
     }
 
     /**
+     * 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 @@
     }
 
     /**
+     * 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 d09dac9..4504cb1 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 3617703..0593339 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 @@
 public class StatisticsReport {
 
     private int code;
+    private long totalPolicyTypesCount;
     private long totalPoliciesCount;
     private long permitDecisionsCount;
     private long denyDecisionsCount;
@@ -53,6 +54,24 @@
     }
 
     /**
+     * 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 @@
         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 7b88328..1b90f6b 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 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 3955031..ef85a76 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 @@
         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 0f608e2..1ec649c 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 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 @@
     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 ee05ff0..595301d 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.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 @@
 
     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 bfc8a2a..8c37acb 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.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 @@
  */
 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"};