[POLICY-11] Fact queries with variables + features 71/4071/2
authorJorge Hernandez <jh1730@att.com>
Wed, 10 May 2017 04:42:38 +0000 (23:42 -0500)
committerJorge Hernandez <jh1730@att.com>
Wed, 10 May 2017 05:02:56 +0000 (00:02 -0500)
GET/PUT/DELETE operations through REST API.
Report on optional features (modules) attached to the engine.
Added javadoc comments in Healthcheck module.

Change-Id: Ic8d2c06779dda4024e94ad39bb316211522e4e4c
Signed-off-by: Jorge Hernandez <jh1730@att.com>
policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheck.java
policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java
policy-management/src/main/java/org/openecomp/policy/drools/controller/DroolsController.java
policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java
policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/NullDroolsController.java
policy-management/src/main/java/org/openecomp/policy/drools/server/restful/RestManager.java
policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyController.java
policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyControllerFactory.java
policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java
policy-management/src/main/java/org/openecomp/policy/drools/system/internal/AggregatedPolicyController.java
policy-utils/src/main/java/org/openecomp/policy/drools/utils/OrderedService.java

index 2ed2e07..68f9fdb 100644 (file)
@@ -11,13 +11,38 @@ import org.openecomp.policy.drools.persistence.SystemPersistence;
 import org.openecomp.policy.drools.properties.Startable;
 import org.openecomp.policy.drools.system.PolicyEngine;
 
+/**
+ * Healthcheck
+ */
 public interface HealthCheck extends Startable {
        
+       /**
+        * Healthcheck Report
+        */
        public static class Report {
+               /**
+                * Named Entity in the report
+                */
                public String name;
+               
+               /**
+                * URL queried
+                */
                public String url;
+               
+               /**
+                * healthy?
+                */
                public boolean healthy;
+               
+               /**
+                * return code
+                */
                public int code;
+               
+               /**
+                * Message from remote entity
+                */
                public String message;
                
                @Override
@@ -38,6 +63,9 @@ public interface HealthCheck extends Startable {
                }
        }
        
+       /**
+        * Report aggregation
+        */
        public static class Reports {
                public boolean healthy;
                public ArrayList<Report> details = new ArrayList<>();
@@ -54,17 +82,41 @@ public interface HealthCheck extends Startable {
                }
        }
        
+       /**
+        * perform a healthcheck
+        * @return a report
+        */
        public Reports healthCheck();
 
+       /**
+        * Healthcheck Monitor
+        */
        public static final HealthCheck monitor = new HealthCheckMonitor();
 }
 
+/**
+ * Healthcheck Monitor
+ */
 class HealthCheckMonitor implements HealthCheck {
 
+       /**
+        * attached http servers
+        */
        protected volatile ArrayList<HttpServletServer> servers = new ArrayList<>();
+       
+       /**
+        * attached http clients
+        */
        protected volatile ArrayList<HttpClient> clients = new ArrayList<>();
+       
+       /**
+        * healthcheck configuration
+        */
        protected volatile Properties healthCheckProperties = null; 
        
+       /**
+        * {@inheritDoc}
+        */
        public Reports healthCheck() {
                Reports reports = new Reports();
                reports.healthy = PolicyEngine.manager.isAlive();
@@ -104,6 +156,9 @@ class HealthCheckMonitor implements HealthCheck {
                return reports;
        }
        
+       /**
+        * {@inheritDoc}
+        */
        @Override
        public boolean start() throws IllegalStateException {
                try {
@@ -125,6 +180,9 @@ class HealthCheckMonitor implements HealthCheck {
                return true;
        }
 
+       /**
+        * {@inheritDoc}
+        */
        @Override
        public boolean stop() throws IllegalStateException {
                for (HttpServletServer server : servers) {
@@ -146,20 +204,32 @@ class HealthCheckMonitor implements HealthCheck {
                return true;
        }
 
+       /**
+        * {@inheritDoc}
+        */
        @Override
        public void shutdown() throws IllegalStateException {
                this.stop();
        }
 
+       /**
+        * {@inheritDoc}
+        */
        @Override
        public synchronized boolean isAlive() {
                return this.healthCheckProperties != null;
        }
        
+       /**
+        * @return list of attached Http Servers
+        */
        public ArrayList<HttpServletServer> getServers() {
                return this.servers;
        }
        
+       /**
+        * @return list of attached Http Clients
+        */
        public ArrayList<HttpClient> getClients() {
                return this.clients;
        }
index 321d1e7..1d73614 100644 (file)
@@ -156,5 +156,13 @@ public class HealthCheckFeature implements PolicyEngineFeatureAPI {
        public boolean afterUnlock(PolicyEngine engine) {
                return false;
        }
+       
+       /**
+        * gets the monitor
+        * @return the healthcheck monitor
+        */
+       public HealthCheck getMonitor() {
+               return HealthCheck.monitor;
+       }
 
 }
index 0904d43..5a5f312 100644 (file)
@@ -180,9 +180,10 @@ public interface DroolsController extends Startable, Lockable {
         *  
         * @param sessionName the session identifier
         * @param className the class type
+        * @param delete retract from drools the results of the query?
         * @return the list of facts returned by the query
         */
-       public List<Object> facts(String sessionName, String className);
+       public List<Object> facts(String sessionName, String className, boolean delete);
 
        /**
         * gets the facts associated with a query for a give session for a given queried entity
@@ -190,9 +191,12 @@ public interface DroolsController extends Startable, Lockable {
         * @param sessionName the session
         * @param queryName the query identifier
         * @param queriedEntity the queried entity
+        * @param delete retract from drools the results of the query?
+        * @param queryParams query parameters
         * @return list of facts returned by the query
         */
-       public List<Object> factQuery(String sessionName, String queryName, String queriedEntity);
+       public List<Object> factQuery(String sessionName, String queryName, String queriedEntity, 
+                                             boolean delete, Object... queryParams);
        
        /**
         * halts and permanently releases all resources
index 62ad684..4396a0c 100644 (file)
@@ -780,7 +780,7 @@ public class MavenDroolsController implements DroolsController {
         * {@inheritDoc}
         */
        @Override
-       public List<Object> facts(String sessionName, String className) {               
+       public List<Object> facts(String sessionName, String className, boolean delete) {               
                if (sessionName == null || sessionName.isEmpty())
                        throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
                
@@ -801,6 +801,8 @@ public class MavenDroolsController implements DroolsController {
                for (FactHandle factHandle : factHandles) {
                        try {
                                factObjects.add(kieSession.getObject(factHandle));
+                               if (delete)
+                                       kieSession.delete(factHandle);                                  
                        } catch (Exception e) {
                                if (logger.isInfoEnabled())
                                        logger.info("Object cannot be retrieved from fact: " + factHandle);
@@ -814,7 +816,7 @@ public class MavenDroolsController implements DroolsController {
         * {@inheritDoc}
         */
        @Override
-       public List<Object> factQuery(String sessionName, String queryName, String queriedEntity) {             
+       public List<Object> factQuery(String sessionName, String queryName, String queriedEntity, boolean delete, Object... queryParams) {              
                if (sessionName == null || sessionName.isEmpty())
                        throw new IllegalArgumentException("Invalid Session Name: " + sessionName);
                
@@ -829,10 +831,12 @@ public class MavenDroolsController implements DroolsController {
                
                List<Object> factObjects = new ArrayList<>();
                
-               QueryResults queryResults = kieSession.getQueryResults(queryName);
+               QueryResults queryResults = kieSession.getQueryResults(queryName, queryParams);
                for (QueryResultsRow row : queryResults) {
                        try {
                                factObjects.add(row.get(queriedEntity));
+                               if (delete)
+                                       kieSession.delete(row.getFactHandle(queriedEntity));
                        } catch (Exception e) {
                                if (logger.isInfoEnabled())
                                        logger.info("Object cannot be retrieved from fact: " + row);
index ac07bb7..4019bee 100644 (file)
@@ -220,7 +220,8 @@ public class NullDroolsController implements DroolsController {
         * {@inheritDoc}
         */
        @Override
-       public Map<String, Integer> factClassNames(String sessionName) throws IllegalArgumentException {
+       public Map<String, Integer> factClassNames(String sessionName) 
+                  throws IllegalArgumentException {
                return new HashMap<String,Integer>();
        }
 
@@ -236,7 +237,7 @@ public class NullDroolsController implements DroolsController {
         * {@inheritDoc}
         */
        @Override
-       public List<Object> facts(String sessionName, String className) {
+       public List<Object> facts(String sessionName, String className, boolean delete) {
                return new ArrayList<Object>();
        }
 
@@ -244,7 +245,9 @@ public class NullDroolsController implements DroolsController {
         * {@inheritDoc}
         */
        @Override
-       public List<Object> factQuery(String sessionName, String queryName, String queriedEntity) {
+       public List<Object> factQuery(String sessionName, String queryName, 
+                                             String queriedEntity, 
+                                             boolean delete, Object... queryParams) {
                return new ArrayList<Object>();
        }
 
index cb5d368..a4aaa85 100644 (file)
@@ -51,6 +51,8 @@ import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSink;
 import org.openecomp.policy.drools.event.comm.bus.DmaapTopicSource;
 import org.openecomp.policy.drools.event.comm.bus.UebTopicSink;
 import org.openecomp.policy.drools.event.comm.bus.UebTopicSource;
+import org.openecomp.policy.drools.features.PolicyControllerFeatureAPI;
+import org.openecomp.policy.drools.features.PolicyEngineFeatureAPI;
 import org.openecomp.policy.drools.properties.PolicyProperties;
 import org.openecomp.policy.drools.protocol.coders.EventProtocolCoder;
 import org.openecomp.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters;
@@ -113,6 +115,33 @@ public class RestManager {
                else
                        return Response.status(Response.Status.OK).entity(controller).build();
     }
+     
+    @GET
+    @Path("engine/features")
+    @Produces(MediaType.APPLICATION_JSON)
+    public List<PolicyEngineFeatureAPI> engineFeatures() {
+        return PolicyEngine.manager.getFeatureProviders();
+    }
+    
+    @GET
+    @Path("engine/features/{featureName}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response engineFeature(@PathParam("featureName") String featureName) {
+       try {
+               return Response.status(Response.Status.OK).
+                               entity(PolicyEngine.manager.getFeatureProvider(featureName)).build();
+       } catch(IllegalArgumentException iae) {
+               return Response.status(Response.Status.NOT_FOUND).
+                    entity(new Error(iae.getMessage())).build();
+       }
+    }
+    
+    @GET
+    @Path("engine/properties")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Properties engineProperties() {
+        return PolicyEngine.manager.getProperties();
+    }
     
     /**
      * Activates the Policy Engine
@@ -288,29 +317,72 @@ public class RestManager {
                 build();
     }    
     
+    @GET
+    @Path("engine/controllers/features")
+    @Produces(MediaType.APPLICATION_JSON)
+    public List<PolicyControllerFeatureAPI> controllerFeatures() {
+        return PolicyController.factory.getFeatureProviders();
+    }
+    
+    @GET
+    @Path("engine/controllers/features/{featureName}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response controllerFeature(@PathParam("controllerName") String controllerName,
+                                         @PathParam("featureName") String featureName) {
+       try {
+               return Response.status(Response.Status.OK).
+                                       entity(PolicyController.factory.getFeatureProvider(featureName)).
+                                       build();
+       } catch(IllegalArgumentException iae) {
+               return Response.status(Response.Status.NOT_FOUND).
+                    entity(new Error(iae.getMessage())).build();
+       }
+    }
+
     @GET
     @Path("engine/controllers/{controllerName}")
     @Produces(MediaType.APPLICATION_JSON)
     public Response controller(@PathParam("controllerName") String controllerName) {
-       PolicyController controller = null;
                try {
-                       controller = PolicyController.factory.get(controllerName);
+               return Response.status(Response.Status.OK).
+                                       entity(PolicyController.factory.get(controllerName)).
+                                       build();
                } catch (IllegalArgumentException e) {
-                       logger.info("Can't retrieve controller " + controllerName + 
-                                                 ".  Reason: " + e.getMessage());
+                       return Response.status(Response.Status.NOT_FOUND).
+                            entity(new Error(controllerName + " not found")).
+                            build();
                } catch (IllegalStateException e) {
-                       logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
-                              controllerName, this.toString());
                        return Response.status(Response.Status.NOT_ACCEPTABLE).
-                            entity(new Error(controllerName + " not acceptable")).build();
+                            entity(new Error(controllerName + " not acceptable")).
+                            build();
+               } catch (Exception e) {
+                       return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
+                            entity(new Error(controllerName + " not acceptable")).
+                            build();
                }
-       
-               if (controller != null)
+    }
+    @GET
+    @Path("engine/controllers/{controllerName}/properties")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response controllerProperties(@PathParam("controllerName") String controllerName) {
+               try {
+                       PolicyController controller = PolicyController.factory.get(controllerName);
                return Response.status(Response.Status.OK).
-                               entity(controller).build();
-               else
+                                       entity(controller.getProperties()).
+                                       build();
+               } catch (IllegalArgumentException e) {
                        return Response.status(Response.Status.NOT_FOUND).
-                                          entity(new Error(controllerName + " not found")).build();
+                            entity(new Error(controllerName + " not found")).
+                            build();
+               } catch (IllegalStateException e) {
+                       return Response.status(Response.Status.NOT_ACCEPTABLE).
+                            entity(new Error(controllerName + " not acceptable")).
+                            build();
+               } catch (Exception e) {
+                       return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
+                            entity(new Error(controllerName + " not acceptable")).
+                            build();
+               }
     }
     
     @DELETE
@@ -457,7 +529,7 @@ public class RestManager {
                                    @PathParam("className") String className) {
                try {
                        DroolsController drools = getDroolsController(controllerName);
-                       List<Object> facts = drools.facts(sessionName, className);
+                       List<Object> facts = drools.facts(sessionName, className, false);
                        if (!count)
                                return Response.status(Response.Status.OK).entity(facts).build();
                        else
@@ -471,6 +543,27 @@ public class RestManager {
                }
     }
     
+    @DELETE
+    @Path("engine/controllers/{controllerName}/drools/facts/{sessionName}/{className}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response deleteDroolsFacts(@PathParam("controllerName") String controllerName,
+                                         @PathParam("sessionName") String sessionName,
+                                         @PathParam("className") String className) {
+               try {
+                       DroolsController drools = getDroolsController(controllerName);
+                       List<Object> facts = drools.facts(sessionName, className, true);
+                       return Response.status(Response.Status.OK).entity(facts).build();
+               } catch (IllegalArgumentException | IllegalStateException e) {
+                       return Response.status(Response.Status.BAD_REQUEST).
+                                                      entity(new Error(e.getMessage())).
+                                                      build();
+               } catch (Exception e) {
+                       return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
+                                   entity(new Error(e.getMessage())).
+                                   build();                    
+               }
+    }
+    
     @GET
     @Path("engine/controllers/{controllerName}/drools/facts/{sessionName}/{queryName}/{queriedEntity}")
     @Produces(MediaType.APPLICATION_JSON)
@@ -481,17 +574,73 @@ public class RestManager {
                                    @PathParam("queriedEntity") String queriedEntity) {
                try {
                        DroolsController drools = getDroolsController(controllerName);
-                       List<Object> facts = drools.factQuery(sessionName, queryName, queriedEntity);
+                       List<Object> facts = drools.factQuery(sessionName, queryName, queriedEntity, false);
                        if (!count)
                                return Response.status(Response.Status.OK).entity(facts).build();
                        else
                                return Response.status(Response.Status.OK).entity(facts.size()).build();
                } catch (IllegalArgumentException | IllegalStateException e) {
-                       logger.warn(MessageCodes.EXCEPTION_ERROR, e, 
-                         controllerName, this.toString());
                        return Response.status(Response.Status.BAD_REQUEST).
                                                       entity(new Error(e.getMessage())).
                                                       build();
+               } catch (Exception e) {
+                       return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
+                                   entity(new Error(e.getMessage())).
+                                   build();                    
+               }
+    }
+    
+    @PUT
+    @Path("engine/controllers/{controllerName}/drools/facts/{sessionName}/{queryName}/{queriedEntity}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response droolsFacts(@PathParam("controllerName") String controllerName,
+                                   @PathParam("sessionName") String sessionName,
+                                   @PathParam("queryName") String queryName,
+                                   @PathParam("queriedEntity") String queriedEntity,
+                                   List<Object> queryParameters) {
+               try {
+                       DroolsController drools = getDroolsController(controllerName);
+                       List<Object> facts;
+                       if (queryParameters == null || queryParameters.isEmpty())
+                               facts = drools.factQuery(sessionName, queryName, queriedEntity, false);
+                       else
+                               facts = drools.factQuery(sessionName, queryName, queriedEntity, false, queryParameters.toArray());
+                       return Response.status(Response.Status.OK).entity(facts).build();
+               } catch (IllegalArgumentException | IllegalStateException e) {
+                       return Response.status(Response.Status.BAD_REQUEST).
+                                                      entity(new Error(e.getMessage())).
+                                                      build();
+               } catch (Exception e) {
+                       return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
+                                   entity(new Error(e.getMessage())).
+                                   build();                    
+               }
+    }
+    
+    @DELETE
+    @Path("engine/controllers/{controllerName}/drools/facts/{sessionName}/{queryName}/{queriedEntity}")
+    @Produces(MediaType.APPLICATION_JSON)
+    public Response deleteDroolsFacts(@PathParam("controllerName") String controllerName,
+                                         @PathParam("sessionName") String sessionName,
+                                         @PathParam("queryName") String queryName,
+                                         @PathParam("queriedEntity") String queriedEntity,
+                                         List<Object> queryParameters) {
+               try {
+                       DroolsController drools = getDroolsController(controllerName);
+                       List<Object> facts;
+                       if (queryParameters == null || queryParameters.isEmpty())
+                               facts = drools.factQuery(sessionName, queryName, queriedEntity, true);
+                       else
+                               facts = drools.factQuery(sessionName, queryName, queriedEntity, true, queryParameters.toArray());                       
+                       return Response.status(Response.Status.OK).entity(facts).build();
+               } catch (IllegalArgumentException | IllegalStateException e) {
+                       return Response.status(Response.Status.BAD_REQUEST).
+                                                      entity(new Error(e.getMessage())).
+                                                      build();
+               } catch (Exception e) {
+                       return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
+                                   entity(new Error(e.getMessage())).
+                                   build();                    
                }
     }
     
@@ -1031,7 +1180,24 @@ public class RestManager {
                        build();
     }
     
-    @GET
+    @DELETE
+       @Path("engine/topics/lock")
+       @Produces(MediaType.APPLICATION_JSON)
+       @Consumes(MediaType.APPLICATION_JSON)
+       public Response unlockTopics() {
+               boolean success = TopicEndpoint.manager.unlock();
+               if (success)
+                       return Response.status(Status.OK).
+                                               entity("Endpoints are unlocked").
+                                               build();
+               else
+                       return Response.status(Status.SERVICE_UNAVAILABLE).
+                                               entity("Endpoints cannot be unlocked").
+                                               build();
+       }
+
+
+       @GET
     @Path("engine/topics/{topic}/dmaap/sink/events")
     @Produces(MediaType.APPLICATION_JSON)
     public Response dmaapSinkEvent(@PathParam("topic") String topicName) {
@@ -1054,11 +1220,10 @@ public class RestManager {
                        boolean success = uebReader.offer(json);
                        if (success)
                                return Response.status(Status.OK).
-                                                       entity("Successfully injected event over " + topicName).
                                                        build();
                        else
                                return Response.status(Status.NOT_ACCEPTABLE).
-                                                       entity("Failure to inject event over " + topicName).
+                                                       entity(new Error("Failure to inject event over " + topicName)).
                                                        build();
                } catch (Exception e) {
                return Response.status(Response.Status.BAD_REQUEST).
@@ -1078,17 +1243,16 @@ public class RestManager {
                        boolean success = dmaapReader.offer(json);
                        if (success)
                                return Response.status(Status.OK).
-                                                       entity("Successfully injected event over " + topicName).
                                                        build();
                        else
                                return Response.status(Status.NOT_ACCEPTABLE).
-                                                       entity("Failure to inject event over " + topicName).
+                                                       entity(new Error("Failure to inject event over " + topicName)).
                                                        build();
                } catch (Exception e) {
                return Response.status(Response.Status.BAD_REQUEST).
                                entity(new Error(e.getMessage())).
                                build();
-               } 
+               }
     }
     
     @PUT
@@ -1107,22 +1271,6 @@ public class RestManager {
                                        build();
     }
     
-    @DELETE
-    @Path("engine/topics/lock")
-    @Produces(MediaType.APPLICATION_JSON)
-    @Consumes(MediaType.APPLICATION_JSON)
-    public Response unlockTopics() {
-       boolean success = TopicEndpoint.manager.unlock();
-       if (success)
-               return Response.status(Status.OK).
-                                       entity("Endpoints are unlocked").
-                                       build();
-       else
-               return Response.status(Status.SERVICE_UNAVAILABLE).
-                                       entity("Endpoints cannot be unlocked").
-                                       build();
-    }
-    
     @PUT
     @Path("engine/topics/{topic}/ueb/sources/lock")
     @Produces(MediaType.APPLICATION_JSON)
@@ -1212,7 +1360,12 @@ public class RestManager {
                        build();
     }
     
-    
+    /**
+     * gets the underlying drools controller from the named policy controller
+     * @param controllerName the policy controller name
+     * @return the underlying drools controller
+     * @throws IllegalArgumentException if an invalid controller name has been passed in
+     */
     protected DroolsController getDroolsController(String controllerName) throws IllegalArgumentException {
                PolicyController controller = PolicyController.factory.get(controllerName);
        if (controller == null)
@@ -1230,6 +1383,9 @@ public class RestManager {
      */
     
     
+    /**
+     * Endpoints aggregation Helper class
+     */
        public static class Endpoints {
                public List<TopicSource> sources;
                public List<TopicSink> sinks;
@@ -1241,6 +1397,9 @@ public class RestManager {
                }
        }
        
+       /**
+        * Endpoint Helper Class
+        */
        public static class Endpoint {
                public TopicSource source;
                public TopicSink sink;
@@ -1252,6 +1411,9 @@ public class RestManager {
                }
        }
        
+       /**
+        * Coding (Encoding) Helper class 
+        */
        public static class CodingResult {
                public String jsonEncoding;
                public Boolean encoding;
index 543fd0e..15d1acf 100644 (file)
@@ -69,9 +69,9 @@ public interface PolicyController extends Startable, Lockable {
        public boolean updateDrools(DroolsConfiguration newDroolsConfiguration);
        
        /**
-        * Get the Initialization Properties
+        * Get the Properties
         */
-       public Properties getInitializationProperties();
+       public Properties getProperties();
        
        /**
         * Attempts delivering of an String over communication 
index e105bbb..c6020ea 100644 (file)
@@ -25,12 +25,15 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Properties;
 
-import org.openecomp.policy.drools.controller.DroolsController;
 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
 import org.openecomp.policy.common.logging.flexlogger.Logger;
+import org.openecomp.policy.drools.controller.DroolsController;
+import org.openecomp.policy.drools.features.PolicyControllerFeatureAPI;
 import org.openecomp.policy.drools.protocol.configuration.DroolsConfiguration;
 import org.openecomp.policy.drools.system.internal.AggregatedPolicyController;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
 /**
  * Policy Controller Factory to manage controller creation, destruction,
  * and retrieval for management interfaces
@@ -149,6 +152,25 @@ public interface PolicyControllerFactory {
        public PolicyController get(String groupId, String artifactId)
                   throws IllegalArgumentException, IllegalStateException;
        
+       /**
+        * get features attached to the Policy Controllers
+        * @return list of features
+        */
+       public List<PolicyControllerFeatureAPI> getFeatureProviders();
+       
+       /**
+        * get named feature attached to the Policy Controllers
+        * @return the feature
+        */
+       public PolicyControllerFeatureAPI getFeatureProvider(String featureName) 
+                       throws IllegalArgumentException;
+       
+       /**
+        * get features attached to the Policy Controllers
+        * @return list of features
+        */
+       public List<String> getFeatures();
+       
        /**
         * returns the current inventory of Policy Controllers
         * 
@@ -461,4 +483,40 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory {
                 return controllers;
        }
        
+       /**
+        * {@inheritDoc}
+        */
+       @Override 
+       public List<String> getFeatures() {
+               List<String> features = new ArrayList<String>();
+               for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) {
+                       features.add(feature.getName());
+               }
+               return features;
+       }
+       
+       /**
+        * {@inheritDoc}
+        */
+       @JsonIgnore
+       @Override
+       public List<PolicyControllerFeatureAPI> getFeatureProviders() {
+               return PolicyControllerFeatureAPI.providers.getList();
+       }
+       
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public PolicyControllerFeatureAPI getFeatureProvider(String featureName) throws IllegalArgumentException {
+               if (featureName == null || featureName.isEmpty())
+                       throw new IllegalArgumentException("A feature name must be provided");
+               
+               for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) {
+                       if (feature.getName().equals(featureName))
+                               return feature;
+               }
+               
+               throw new IllegalArgumentException("Invalid Feature Name: " + featureName);
+       }
 }
index 6933003..d213337 100644 (file)
@@ -189,6 +189,25 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
         */
        public Properties getProperties();
        
+       /**
+        * get features attached to the Policy Engine
+        * @return list of features
+        */
+       public List<PolicyEngineFeatureAPI> getFeatureProviders();
+       
+       /**
+        * get named feature attached to the Policy Engine
+        * @return the feature
+        */
+       public PolicyEngineFeatureAPI getFeatureProvider(String featureName) 
+                       throws IllegalArgumentException;
+       
+       /**
+        * get features attached to the Policy Engine
+        * @return list of features
+        */
+       public List<String> getFeatures();
+       
        /**
         * Attempts the dispatching of an "event" object
         * 
@@ -1031,6 +1050,7 @@ class PolicyEngineManager implements PolicyEngine {
         * {@inheritDoc}
         */
        @Override
+       @JsonIgnore
        public Properties getProperties() {
                return this.properties;
        }
@@ -1062,6 +1082,44 @@ class PolicyEngineManager implements PolicyEngine {
                return this.httpServers;
        }
        
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public List<String> getFeatures() {
+               List<String> features = new ArrayList<String>();
+               for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) {
+                       features.add(feature.getName());
+               }
+               return features;
+       }
+       
+       /**
+        * {@inheritDoc}
+        */
+       @JsonIgnore
+       @Override
+       public List<PolicyEngineFeatureAPI> getFeatureProviders() {
+               return PolicyEngineFeatureAPI.providers.getList();
+       }
+       
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public PolicyEngineFeatureAPI getFeatureProvider(String featureName) throws IllegalArgumentException {
+               if (featureName == null || featureName.isEmpty())
+                       throw new IllegalArgumentException("A feature name must be provided");
+               
+               for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) {
+                       if (feature.getName().equals(featureName))
+                               return feature;
+               }
+               
+               throw new IllegalArgumentException("Invalid Feature Name: " + featureName);
+       }
+       
        /**
         * {@inheritDoc}
         */
index 3badbd0..e41a889 100644 (file)
@@ -24,18 +24,19 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Properties;
 
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.common.logging.flexlogger.Logger;
 import org.openecomp.policy.drools.controller.DroolsController;
 import org.openecomp.policy.drools.event.comm.Topic;
 import org.openecomp.policy.drools.event.comm.TopicEndpoint;
 import org.openecomp.policy.drools.event.comm.TopicListener;
 import org.openecomp.policy.drools.event.comm.TopicSink;
 import org.openecomp.policy.drools.event.comm.TopicSource;
-import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
-import org.openecomp.policy.common.logging.flexlogger.Logger;
 import org.openecomp.policy.drools.persistence.SystemPersistence;
 import org.openecomp.policy.drools.properties.PolicyProperties;
 import org.openecomp.policy.drools.protocol.configuration.DroolsConfiguration;
 import org.openecomp.policy.drools.system.PolicyController;
+
 import com.fasterxml.jackson.annotation.JsonIgnore;
 
 /**
@@ -440,6 +441,16 @@ public class AggregatedPolicyController implements PolicyController,
        public DroolsController getDrools() {
                return this.droolsController;
        }
+       
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       @JsonIgnore
+       public Properties getProperties() {
+               return this.properties;
+       }
 
        @Override
        public String toString() {
@@ -449,13 +460,5 @@ public class AggregatedPolicyController implements PolicyController,
                return builder.toString();
        }
 
-       /**
-        * {@inheritDoc}
-        */
-       @Override
-       public Properties getInitializationProperties() {
-               return this.properties;
-       }
-
 }
 
index b50e6e8..0851413 100644 (file)
@@ -32,4 +32,10 @@ public interface OrderedService
    *   of objects implementing this interface
    */
   public int getSequenceNumber();
+  
+  
+  /**
+   * @return the name of the ordered service
+   */
+  public default String getName() {return this.getClass().getName();}
 }