Monitoring policy creation foundation
[policy/xacml-pdp.git] / main / src / main / java / org / onap / policy / pdpx / main / rest / XacmlPdpRestServer.java
index eece1ff..f3b7a54 100644 (file)
 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}.
      */