aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java21
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java932
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java147
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java30
4 files changed, 556 insertions, 574 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java
index 9e01634b..dcd4d11a 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyController.java
@@ -43,27 +43,27 @@ public interface PolicyController extends Startable, Lockable {
/**
* Factory that tracks and manages Policy Controllers
*/
- public static PolicyControllerFactory factory = new IndexedPolicyControllerFactory();
+ static PolicyControllerFactory factory = new IndexedPolicyControllerFactory();
/**
* name of this Policy Controller
*/
- public String getName();
+ String getName();
/**
* Get the topic readers of interest for this controller
*/
- public List<? extends TopicSource> getTopicSources();
+ List<? extends TopicSource> getTopicSources();
/**
* Get the topic readers of interest for this controller
*/
- public List<? extends TopicSink> getTopicSinks();
+ List<? extends TopicSink> getTopicSinks();
/**
* Get the Drools Controller
*/
- public DroolsController getDrools();
+ DroolsController getDrools();
/**
* update maven configuration
@@ -71,17 +71,18 @@ public interface PolicyController extends Startable, Lockable {
* @param newDroolsConfiguration new drools configuration
* @return true if the update was successful, false otherwise
*/
- public boolean updateDrools(DroolsConfiguration newDroolsConfiguration);
+ boolean updateDrools(DroolsConfiguration newDroolsConfiguration);
/**
* Get the Properties
*/
- public Properties getProperties();
+ Properties getProperties();
/**
* Attempts delivering of an String over communication infrastructure "busType"
*
- * @param eventBus Communication infrastructure identifier
+ * @param event Communication infrastructure identifier
+ * @param busType
* @param topic topic
* @param event the event object to send
*
@@ -92,13 +93,13 @@ public interface PolicyController extends Startable, Lockable {
* @throws UnsupportedOperationException when the engine cannot deliver due to the functionality
* missing (ie. communication infrastructure not supported.
*/
- public boolean deliver(CommInfrastructure busType, String topic, Object event);
+ boolean deliver(CommInfrastructure busType, String topic, Object event);
/**
* halts and permanently releases all resources
*
* @throws IllegalStateException
*/
- public void halt();
+ void halt();
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java
index c5787dda..e2af0fbc 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java
@@ -39,477 +39,475 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
* and retrieval for management interfaces
*/
public interface PolicyControllerFactory {
- /**
- * Build a controller from a properties file
- *
- * @param name the global name of this controller
- * @param properties input parameters in form of properties for controller
- * initialization.
- *
- * @return a Policy Controller
- *
- * @throws IllegalArgumentException invalid values provided in properties
- */
- public PolicyController build(String name, Properties properties);
-
- /**
- * patches (updates) a controller from a critical configuration update.
- *
- * @param name
- * @param configController
- *
- * @return a Policy Controller
- */
- public PolicyController patch(String name, DroolsConfiguration configController);
-
- /**
- * rebuilds (updates) a controller from a configuration update.
- *
- * @param controller
- * @param configController
- *
- * @return a Policy Controller
- */
- public PolicyController patch(PolicyController controller,
- DroolsConfiguration configController);
-
- /**
- * get PolicyController from DroolsController
- *
- * @param droolsController
- * @return
- * @throws IllegalArgumentException
- * @throws IllegalStateException
- */
- public PolicyController get(DroolsController droolsController);
-
- /**
- * Makes the Policy Controller identified by controllerName not operational, but
- * does not delete its associated data
- *
- * @param controllerName name of the policy controller
- * @throws IllegalArgumentException invalid arguments
- */
- public void shutdown(String controllerName);
-
- /**
- * Makes the Policy Controller identified by controller not operational, but
- * does not delete its associated data
- *
- * @param controller a Policy Controller
- * @throws IllegalArgumentException invalid arguments
- */
- public void shutdown(PolicyController controller);
-
- /**
- * Releases all Policy Controllers from operation
- */
- public void shutdown();
-
- /**
- * Destroys this Policy Controller
- *
- * @param controllerName name of the policy controller
- * @throws IllegalArgumentException invalid arguments
- */
- public void destroy(String controllerName);
-
- /**
- * Destroys this Policy Controller
- *
- * @param controller a Policy Controller
- * @throws IllegalArgumentException invalid arguments
- */
- public void destroy(PolicyController controller);
-
- /**
- * Releases all Policy Controller resources
- */
- public void destroy();
-
- /**
- * gets the Policy Controller identified by its name
- *
- * @param policyControllerName
- * @return
- * @throws IllegalArgumentException
- * @throws IllegalStateException
- */
- public PolicyController get(String policyControllerName);
-
- /**
- * gets the Policy Controller identified by group and artifact ids
- *
- * @param groupId group id
- * @param artifactId artifact id
- * @return
- * @throws IllegalArgumentException
- * @throws IllegalStateException
- */
- public PolicyController get(String groupId, String artifactId);
-
- /**
- * 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);
-
- /**
- * get features attached to the Policy Controllers
- * @return list of features
- */
- public List<String> getFeatures();
-
- /**
- * returns the current inventory of Policy Controllers
- *
- * @return a list of Policy Controllers
- */
- public List<PolicyController> inventory();
+ /**
+ * Build a controller from a properties file
+ *
+ * @param name the global name of this controller
+ * @param properties input parameters in form of properties for controller
+ * initialization.
+ *
+ * @return a Policy Controller
+ *
+ * @throws IllegalArgumentException invalid values provided in properties
+ */
+ PolicyController build(String name, Properties properties);
+
+ /**
+ * patches (updates) a controller from a critical configuration update.
+ *
+ * @param name
+ * @param configController
+ *
+ * @return a Policy Controller
+ */
+ PolicyController patch(String name, DroolsConfiguration configController);
+
+ /**
+ * rebuilds (updates) a controller from a configuration update.
+ *
+ * @param controller
+ * @param configController
+ *
+ * @return a Policy Controller
+ */
+ void patch(PolicyController controller,
+ DroolsConfiguration configController);
+
+ /**
+ * get PolicyController from DroolsController
+ *
+ * @param droolsController
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IllegalStateException
+ */
+ PolicyController get(DroolsController droolsController);
+
+ /**
+ * Makes the Policy Controller identified by controllerName not operational, but
+ * does not delete its associated data
+ *
+ * @param controllerName name of the policy controller
+ * @throws IllegalArgumentException invalid arguments
+ */
+ void shutdown(String controllerName);
+
+ /**
+ * Makes the Policy Controller identified by controller not operational, but
+ * does not delete its associated data
+ *
+ * @param controller a Policy Controller
+ * @throws IllegalArgumentException invalid arguments
+ */
+ void shutdown(PolicyController controller);
+
+ /**
+ * Releases all Policy Controllers from operation
+ */
+ void shutdown();
+
+ /**
+ * Destroys this Policy Controller
+ *
+ * @param controllerName name of the policy controller
+ * @throws IllegalArgumentException invalid arguments
+ */
+ void destroy(String controllerName);
+
+ /**
+ * Destroys this Policy Controller
+ *
+ * @param controller a Policy Controller
+ * @throws IllegalArgumentException invalid arguments
+ */
+ void destroy(PolicyController controller);
+
+ /**
+ * Releases all Policy Controller resources
+ */
+ void destroy();
+
+ /**
+ * gets the Policy Controller identified by its name
+ *
+ * @param policyControllerName
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IllegalStateException
+ */
+ PolicyController get(String policyControllerName);
+
+ /**
+ * gets the Policy Controller identified by group and artifact ids
+ *
+ * @param groupId group id
+ * @param artifactId artifact id
+ * @return
+ * @throws IllegalArgumentException
+ * @throws IllegalStateException
+ */
+ PolicyController get(String groupId, String artifactId);
+
+ /**
+ * get features attached to the Policy Controllers
+ * @return list of features
+ */
+ List<PolicyControllerFeatureAPI> getFeatureProviders();
+
+ /**
+ * get named feature attached to the Policy Controllers
+ * @return the feature
+ */
+ PolicyControllerFeatureAPI getFeatureProvider(String featureName);
+
+ /**
+ * get features attached to the Policy Controllers
+ * @return list of features
+ */
+ List<String> getFeatures();
+
+ /**
+ * returns the current inventory of Policy Controllers
+ *
+ * @return a list of Policy Controllers
+ */
+ List<PolicyController> inventory();
}
/**
* Factory of Policy Controllers indexed by the name of the Policy Controller
*/
class IndexedPolicyControllerFactory implements PolicyControllerFactory {
- // get an instance of logger
- private static Logger logger = LoggerFactory.getLogger(PolicyControllerFactory.class);
-
- /**
- * Policy Controller Name Index
- */
- protected HashMap<String,PolicyController> policyControllers =
- new HashMap<>();
-
- /**
- * Group/Artifact Ids Index
- */
- protected HashMap<String,PolicyController> coordinates2Controller =
- new HashMap<>();
-
- /**
- * produces key for indexing controller names
- *
- * @param group group id
- * @param artifactId artifact id
- * @return index key
- */
- protected String toKey(String groupId, String artifactId) {
- return groupId + ":" + artifactId;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public synchronized PolicyController build(String name, Properties properties) {
-
- if (this.policyControllers.containsKey(name)) {
- return this.policyControllers.get(name);
- }
-
- /* A PolicyController does not exist */
-
- PolicyController controller =
- new AggregatedPolicyController(name, properties);
-
- String coordinates = toKey(controller.getDrools().getGroupId(),
- controller.getDrools().getArtifactId());
-
- this.policyControllers.put(name, controller);
-
-
- if (controller.getDrools().isBrained())
- this.coordinates2Controller.put(coordinates, controller);
-
- return controller;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public synchronized PolicyController patch(String name, DroolsConfiguration droolsConfig) {
-
- if (name == null || name.isEmpty() || !this.policyControllers.containsKey(name)) {
- throw makeArgEx(name);
- }
-
- if (droolsConfig == null)
- throw new IllegalArgumentException("Invalid Drools Configuration");
-
- PolicyController controller = this.get(name);
-
- if (controller == null) {
- logger.warn("A POLICY CONTROLLER of name " + name +
- "does not exist for patch operation: " + droolsConfig);
-
- throw new IllegalArgumentException("Not a valid controller of name " + name);
- }
-
- this.patch(controller, droolsConfig);
-
- if (logger.isInfoEnabled())
- logger.info("UPDATED drools configuration: " + droolsConfig + " on " + this);
-
- return controller;
- }
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public PolicyController patch(PolicyController controller, DroolsConfiguration droolsConfig) {
-
- if (controller == null)
- throw new IllegalArgumentException("Not a valid controller: null");
-
- if (!controller.updateDrools(droolsConfig)) {
- logger.warn("Cannot update drools configuration: " + droolsConfig + " on " + this);
- throw new IllegalArgumentException("Cannot update drools configuration Drools Configuration");
- }
-
- if (logger.isInfoEnabled())
- logger.info("UPDATED drools configuration: " + droolsConfig + " on " + this);
-
- String coordinates = toKey(controller.getDrools().getGroupId(),
- controller.getDrools().getArtifactId());
-
- if (controller.getDrools().isBrained())
- this.coordinates2Controller.put(coordinates, controller);
-
- return controller;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void shutdown(String controllerName) {
-
- if (controllerName == null || controllerName.isEmpty()) {
- throw makeArgEx(controllerName);
- }
-
- synchronized(this) {
- if (!this.policyControllers.containsKey(controllerName)) {
- return;
- }
-
- PolicyController controller = this.policyControllers.get(controllerName);
- this.shutdown(controller);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void shutdown(PolicyController controller) {
- this.unmanage(controller);
- controller.shutdown();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void shutdown() {
- List<PolicyController> controllers = this.inventory();
- for (PolicyController controller: controllers) {
- controller.shutdown();
- }
-
- synchronized(this) {
- this.policyControllers.clear();
- this.coordinates2Controller.clear();
- }
- }
-
- /**
- * unmanage the controller
- *
- * @param controller
- * @return
- * @throws IllegalArgumentException
- */
- protected void unmanage(PolicyController controller) {
- PolicyController tempController = controller;
- if (tempController == null) {
- throw new IllegalArgumentException("Invalid Controller");
- }
-
- synchronized(this) {
- if (!this.policyControllers.containsKey(tempController.getName())) {
- return;
- }
- tempController = this.policyControllers.remove(tempController.getName());
-
- String coordinates = toKey(tempController.getDrools().getGroupId(),
- tempController.getDrools().getArtifactId());
- this.coordinates2Controller.remove(coordinates);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void destroy(String controllerName) {
-
- if (controllerName == null || controllerName.isEmpty()) {
- throw makeArgEx(controllerName);
- }
-
- synchronized(this) {
- if (!this.policyControllers.containsKey(controllerName)) {
- return;
- }
-
- PolicyController controller = this.policyControllers.get(controllerName);
- this.destroy(controller);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void destroy(PolicyController controller) {
- this.unmanage(controller);
- controller.halt();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void destroy() {
- List<PolicyController> controllers = this.inventory();
- for (PolicyController controller: controllers) {
- controller.halt();
- }
-
- synchronized(this) {
- this.policyControllers.clear();
- this.coordinates2Controller.clear();
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public PolicyController get(String name) {
-
- if (name == null || name.isEmpty()) {
- throw makeArgEx(name);
- }
-
- synchronized(this) {
- if (this.policyControllers.containsKey(name)) {
- return this.policyControllers.get(name);
- } else {
- throw makeArgEx(name);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public PolicyController get(String groupId, String artifactId) {
-
- if (groupId == null || groupId.isEmpty() ||
- artifactId == null || artifactId.isEmpty()) {
- throw new IllegalArgumentException("Invalid group/artifact ids");
- }
-
- synchronized(this) {
- String key = toKey(groupId,artifactId);
- if (this.coordinates2Controller.containsKey(key)) {
- return this.coordinates2Controller.get(key);
- } else {
- throw makeArgEx(key);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public PolicyController get(DroolsController droolsController) {
-
- if (droolsController == null) {
- throw new IllegalArgumentException("No Drools Controller provided");
- }
-
- synchronized(this) {
- String key = toKey(droolsController.getGroupId(), droolsController.getArtifactId());
- if (this.coordinates2Controller.containsKey(key)) {
- return this.coordinates2Controller.get(key);
- } else {
- logger.error("Drools Controller not associated with Policy Controller " + droolsController + ":" + this);
- throw new IllegalStateException("Drools Controller not associated with Policy Controller " + droolsController + ":" + this);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List<PolicyController> inventory() {
- return new ArrayList<>(this.policyControllers.values());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List<String> getFeatures() {
- List<String> features = new ArrayList<>();
- 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) {
- 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);
- }
-
- private IllegalArgumentException makeArgEx(String argName) {
- return new IllegalArgumentException("Invalid " + argName);
- }
+ // get an instance of logger
+ private static final Logger logger = LoggerFactory.getLogger(PolicyControllerFactory.class);
+
+ /**
+ * Policy Controller Name Index
+ */
+ private final HashMap<String,PolicyController> policyControllers =
+ new HashMap<>();
+
+ /**
+ * Group/Artifact Ids Index
+ */
+ private final HashMap<String,PolicyController> coordinates2Controller =
+ new HashMap<>();
+
+ /**
+ * produces key for indexing controller names
+ *
+ * @param groupId group id
+ * @param artifactId artifact id
+ * @return index key
+ */
+ private String toKey(String groupId, String artifactId) {
+ return groupId + ":" + artifactId;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public synchronized PolicyController build(String name, Properties properties) {
+
+ if (this.policyControllers.containsKey(name)) {
+ return this.policyControllers.get(name);
+ }
+
+ /* A PolicyController does not exist */
+
+ PolicyController controller =
+ new AggregatedPolicyController(name, properties);
+
+ String coordinates = toKey(controller.getDrools().getGroupId(),
+ controller.getDrools().getArtifactId());
+
+ this.policyControllers.put(name, controller);
+
+
+ if (controller.getDrools().isBrained())
+ this.coordinates2Controller.put(coordinates, controller);
+
+ return controller;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public synchronized PolicyController patch(String name, DroolsConfiguration droolsConfig) {
+
+ if (name == null || name.isEmpty() || !this.policyControllers.containsKey(name)) {
+ throw makeArgEx(name);
+ }
+
+ if (droolsConfig == null)
+ throw new IllegalArgumentException("Invalid Drools Configuration");
+
+ PolicyController controller = this.get(name);
+
+ if (controller == null) {
+ logger.warn("A POLICY CONTROLLER of name " + name +
+ "does not exist for patch operation: " + droolsConfig);
+
+ throw new IllegalArgumentException("Not a valid controller of name " + name);
+ }
+
+ this.patch(controller, droolsConfig);
+
+ if (logger.isInfoEnabled())
+ logger.info("UPDATED drools configuration: " + droolsConfig + " on " + this);
+
+ return controller;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void patch(PolicyController controller, DroolsConfiguration droolsConfig) {
+
+ if (controller == null)
+ throw new IllegalArgumentException("Not a valid controller: null");
+
+ if (!controller.updateDrools(droolsConfig)) {
+ logger.warn("Cannot update drools configuration: " + droolsConfig + " on " + this);
+ throw new IllegalArgumentException("Cannot update drools configuration Drools Configuration");
+ }
+
+ if (logger.isInfoEnabled())
+ logger.info("UPDATED drools configuration: " + droolsConfig + " on " + this);
+
+ String coordinates = toKey(controller.getDrools().getGroupId(),
+ controller.getDrools().getArtifactId());
+
+ if (controller.getDrools().isBrained())
+ this.coordinates2Controller.put(coordinates, controller);
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void shutdown(String controllerName) {
+
+ if (controllerName == null || controllerName.isEmpty()) {
+ throw makeArgEx(controllerName);
+ }
+
+ synchronized(this) {
+ if (!this.policyControllers.containsKey(controllerName)) {
+ return;
+ }
+
+ PolicyController controller = this.policyControllers.get(controllerName);
+ this.shutdown(controller);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void shutdown(PolicyController controller) {
+ this.unmanage(controller);
+ controller.shutdown();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void shutdown() {
+ List<PolicyController> controllers = this.inventory();
+ for (PolicyController controller: controllers) {
+ controller.shutdown();
+ }
+
+ synchronized(this) {
+ this.policyControllers.clear();
+ this.coordinates2Controller.clear();
+ }
+ }
+
+ /**
+ * unmanage the controller
+ *
+ * @param controller
+ * @throws IllegalArgumentException
+ */
+ private void unmanage(PolicyController controller) {
+ PolicyController tempController = controller;
+ if (tempController == null) {
+ throw new IllegalArgumentException("Invalid Controller");
+ }
+
+ synchronized(this) {
+ if (!this.policyControllers.containsKey(tempController.getName())) {
+ return;
+ }
+ tempController = this.policyControllers.remove(tempController.getName());
+
+ String coordinates = toKey(tempController.getDrools().getGroupId(),
+ tempController.getDrools().getArtifactId());
+ this.coordinates2Controller.remove(coordinates);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void destroy(String controllerName) {
+
+ if (controllerName == null || controllerName.isEmpty()) {
+ throw makeArgEx(controllerName);
+ }
+
+ synchronized(this) {
+ if (!this.policyControllers.containsKey(controllerName)) {
+ return;
+ }
+
+ PolicyController controller = this.policyControllers.get(controllerName);
+ this.destroy(controller);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void destroy(PolicyController controller) {
+ this.unmanage(controller);
+ controller.halt();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void destroy() {
+ List<PolicyController> controllers = this.inventory();
+ for (PolicyController controller: controllers) {
+ controller.halt();
+ }
+
+ synchronized(this) {
+ this.policyControllers.clear();
+ this.coordinates2Controller.clear();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public PolicyController get(String name) {
+
+ if (name == null || name.isEmpty()) {
+ throw makeArgEx(name);
+ }
+
+ synchronized(this) {
+ if (this.policyControllers.containsKey(name)) {
+ return this.policyControllers.get(name);
+ } else {
+ throw makeArgEx(name);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public PolicyController get(String groupId, String artifactId) {
+
+ if (groupId == null || groupId.isEmpty() ||
+ artifactId == null || artifactId.isEmpty()) {
+ throw new IllegalArgumentException("Invalid group/artifact ids");
+ }
+
+ synchronized(this) {
+ String key = toKey(groupId,artifactId);
+ if (this.coordinates2Controller.containsKey(key)) {
+ return this.coordinates2Controller.get(key);
+ } else {
+ throw makeArgEx(key);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public PolicyController get(DroolsController droolsController) {
+
+ if (droolsController == null) {
+ throw new IllegalArgumentException("No Drools Controller provided");
+ }
+
+ synchronized(this) {
+ String key = toKey(droolsController.getGroupId(), droolsController.getArtifactId());
+ if (this.coordinates2Controller.containsKey(key)) {
+ return this.coordinates2Controller.get(key);
+ } else {
+ logger.error("Drools Controller not associated with Policy Controller " + droolsController + ":" + this);
+ throw new IllegalStateException("Drools Controller not associated with Policy Controller " + droolsController + ":" + this);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<PolicyController> inventory() {
+ return new ArrayList<>(this.policyControllers.values());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<String> getFeatures() {
+ List<String> features = new ArrayList<>();
+ 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) {
+ 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);
+ }
+
+ private IllegalArgumentException makeArgEx(String argName) {
+ return new IllegalArgumentException("Invalid " + argName);
+ }
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java
index 4be85022..5b8cb2f0 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java
@@ -71,29 +71,29 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
/**
* Policy Engine Manager
*/
- public static final PolicyEngine manager = new PolicyEngineManager();
+ PolicyEngine manager = new PolicyEngineManager();
/**
* Default Telemetry Server Port
*/
- public static final int TELEMETRY_SERVER_DEFAULT_PORT = 9696;
+ int TELEMETRY_SERVER_DEFAULT_PORT = 9696;
/**
* Default Telemetry Server Hostname
*/
- public static final String TELEMETRY_SERVER_DEFAULT_HOST = "localhost";
+ String TELEMETRY_SERVER_DEFAULT_HOST = "localhost";
/**
* Default Telemetry Server Name
*/
- public static final String TELEMETRY_SERVER_DEFAULT_NAME = "TELEMETRY";
+ String TELEMETRY_SERVER_DEFAULT_NAME = "TELEMETRY";
/**
* Boot the engine
*
* @param cliArgs command line arguments
*/
- public void boot(String[] cliArgs);
+ void boot(String[] cliArgs);
/**
* configure the policy engine according to the given properties
@@ -101,7 +101,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* @param properties Policy Engine properties
* @throws IllegalArgumentException when invalid or insufficient properties are provided
*/
- public void configure(Properties properties);
+ void configure(Properties properties);
/**
* configure the engine's environment. General lab installation configuration is made available
@@ -111,14 +111,14 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
*
* @param properties an environment properties
*/
- public void setEnvironment(Properties properties);
+ void setEnvironment(Properties properties);
/**
* gets the engine's environment
*
* @return
*/
- public Properties getEnvironment();
+ Properties getEnvironment();
/**
* gets an environment's value, by 1) first from the engine's environment, and 2) from the OS
@@ -127,7 +127,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* @param key environment key
* @return environment value or null if absent
*/
- public String getEnvironmentProperty(String key);
+ String getEnvironmentProperty(String key);
/**
* sets an engine's environment property
@@ -136,18 +136,18 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* @param value
* @return
*/
- public String setEnvironmentProperty(String key, String value);
+ String setEnvironmentProperty(String key, String value);
/**
* registers a new Policy Controller with the Policy Engine initialized per properties.
*
* @param properties properties to initialize the Policy Controller
- * @throws IllegalArgumentException when invalid or insufficient properties are provided
- * @throws IllegalStateException when the engine is in a state where this operation is not
- * permitted.
* @return the newly instantiated Policy Controller
+ * @throws IllegalArgumentException when invalid or insufficient properties are provided
+ * @throws IllegalStateException when the engine is in a state where this operation is not
+ * permitted.
*/
- public PolicyController createPolicyController(String name, Properties properties);
+ PolicyController createPolicyController(String name, Properties properties);
/**
* updates the Policy Engine with the given configuration
@@ -155,9 +155,9 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* @param configuration the configuration
* @return success or failure
* @throws IllegalArgumentException if invalid argument provided
- * @throws IllegalStateException if the system is in an invalid state
+ * @throws IllegalStateException if the system is in an invalid state
*/
- public boolean configure(PdpdConfiguration configuration);
+ boolean configure(PdpdConfiguration configuration);
/**
* updates a set of Policy Controllers with configuration information
@@ -167,19 +167,18 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* @throws IllegalArgumentException
* @throws IllegalStateException
*/
- public List<PolicyController> updatePolicyControllers(List<ControllerConfiguration> configuration);
+ List<PolicyController> updatePolicyControllers(List<ControllerConfiguration> configuration);
/**
* updates an already existing Policy Controller with configuration information
*
* @param configuration configuration
- *
* @return the updated Policy Controller
* @throws IllegalArgumentException in the configuration is invalid
- * @throws IllegalStateException if the controller is in a bad state
- * @throws Exception any other reason
+ * @throws IllegalStateException if the controller is in a bad state
+ * @throws Exception any other reason
*/
- public PolicyController updatePolicyController(ControllerConfiguration configuration);
+ PolicyController updatePolicyController(ControllerConfiguration configuration);
/**
* removes the Policy Controller identified by its name from the Policy Engine
@@ -187,21 +186,21 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
* @param name name of the Policy Controller
* @return the removed Policy Controller
*/
- public void removePolicyController(String name);
+ void removePolicyController(String name);
/**
* removes a Policy Controller from the Policy Engine
*
* @param controller the Policy Controller to remove from the Policy Engine
*/
- public void removePolicyController(PolicyController controller);
+ void removePolicyController(PolicyController controller);
/**
* returns a list of the available Policy Controllers
*
* @return list of Policy Controllers
*/
- public List<PolicyController> getPolicyControllers();
+ List<PolicyController> getPolicyControllers();
/**
@@ -209,131 +208,127 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener {
*
* @return list of controller names
*/
- public List<String> getPolicyControllerIds();
+ List<String> getPolicyControllerIds();
/**
* get unmanaged sources
*
* @return unmanaged sources
*/
- public List<TopicSource> getSources();
+ List<TopicSource> getSources();
/**
* get unmanaged sinks
*
* @return unmanaged sinks
*/
- public List<TopicSink> getSinks();
+ List<TopicSink> getSinks();
/**
* get unmmanaged http servers list
*
* @return http servers
*/
- public List<HttpServletServer> getHttpServers();
+ List<HttpServletServer> getHttpServers();
/**
* get properties configuration
*
* @return properties objects
*/
- public Properties getProperties();
+ Properties getProperties();
/**
* get features attached to the Policy Engine
*
* @return list of features
*/
- public List<PolicyEngineFeatureAPI> getFeatureProviders();
+ List<PolicyEngineFeatureAPI> getFeatureProviders();
/**
* get named feature attached to the Policy Engine
*
* @return the feature
*/
- public PolicyEngineFeatureAPI getFeatureProvider(String featureName);
+ PolicyEngineFeatureAPI getFeatureProvider(String featureName);
/**
* get features attached to the Policy Engine
*
* @return list of features
*/
- public List<String> getFeatures();
+ List<String> getFeatures();
/**
* Attempts the dispatching of an "event" object
*
* @param topic topic
* @param event the event object to send
- *
* @return true if successful, false if a failure has occurred.
* @throws IllegalArgumentException when invalid or insufficient properties are provided
- * @throws IllegalStateException when the engine is in a state where this operation is not
- * permitted (ie. locked or stopped).
+ * @throws IllegalStateException when the engine is in a state where this operation is not
+ * permitted (ie. locked or stopped).
*/
- public boolean deliver(String topic, Object event);
+ boolean deliver(String topic, Object event);
/**
* Attempts the dispatching of an "event" object over communication infrastructure "busType"
*
* @param topic topic
* @param event the event object to send
- *
* @return true if successful, false if a failure has occurred.
- * @throws IllegalArgumentException when invalid or insufficient properties are provided
- * @throws IllegalStateException when the engine is in a state where this operation is not
- * permitted (ie. locked or stopped).
+ * @throws IllegalArgumentException when invalid or insufficient properties are provided
+ * @throws IllegalStateException when the engine is in a state where this operation is not
+ * permitted (ie. locked or stopped).
* @throws UnsupportedOperationException when the engine cannot deliver due to the functionality
- * missing (ie. communication infrastructure not supported.
+ * missing (ie. communication infrastructure not supported.
*/
- public boolean deliver(String busType, String topic, Object event);
+ boolean deliver(String busType, String topic, Object event);
/**
* Attempts the dispatching of an "event" object over communication infrastructure "busType"
*
* @param topic topic
* @param event the event object to send
- *
* @return true if successful, false if a failure has occurred.
- * @throws IllegalArgumentException when invalid or insufficient properties are provided
- * @throws IllegalStateException when the engine is in a state where this operation is not
- * permitted (ie. locked or stopped).
+ * @throws IllegalArgumentException when invalid or insufficient properties are provided
+ * @throws IllegalStateException when the engine is in a state where this operation is not
+ * permitted (ie. locked or stopped).
* @throws UnsupportedOperationException when the engine cannot deliver due to the functionality
- * missing (ie. communication infrastructure not supported.
+ * missing (ie. communication infrastructure not supported.
*/
- public boolean deliver(CommInfrastructure busType, String topic, Object event);
+ boolean deliver(CommInfrastructure busType, String topic, Object event);
/**
* Attempts delivering of an String over communication infrastructure "busType"
*
* @param topic topic
* @param event the event object to send
- *
* @return true if successful, false if a failure has occurred.
- * @throws IllegalArgumentException when invalid or insufficient properties are provided
- * @throws IllegalStateException when the engine is in a state where this operation is not
- * permitted (ie. locked or stopped).
+ * @throws IllegalArgumentException when invalid or insufficient properties are provided
+ * @throws IllegalStateException when the engine is in a state where this operation is not
+ * permitted (ie. locked or stopped).
* @throws UnsupportedOperationException when the engine cannot deliver due to the functionality
- * missing (ie. communication infrastructure not supported.
+ * missing (ie. communication infrastructure not supported.
*/
- public boolean deliver(CommInfrastructure busType, String topic, String event);
+ boolean deliver(CommInfrastructure busType, String topic, String event);
/**
* Invoked when the host goes into the active state.
*/
- public void activate();
+ void activate();
/**
* Invoked when the host goes into the standby state.
*/
- public void deactivate();
+ void deactivate();
/**
* produces a default telemetry configuration
*
* @return policy engine configuration
*/
- public Properties defaultTelemetryConfig();
+ Properties defaultTelemetryConfig();
}
@@ -357,42 +352,42 @@ class PolicyEngineManager implements PolicyEngine {
/**
* Is the Policy Engine running?
*/
- protected volatile boolean alive = false;
+ private volatile boolean alive = false;
/**
* Is the engine locked?
*/
- protected volatile boolean locked = false;
+ private volatile boolean locked = false;
/**
* Properties used to initialize the engine
*/
- protected Properties properties;
+ private Properties properties;
/**
* Environment Properties
*/
- protected final Properties environment = new Properties();
+ private final Properties environment = new Properties();
/**
* Policy Engine Sources
*/
- protected List<? extends TopicSource> sources = new ArrayList<>();
+ private List<? extends TopicSource> sources = new ArrayList<>();
/**
* Policy Engine Sinks
*/
- protected List<? extends TopicSink> sinks = new ArrayList<>();
+ private List<? extends TopicSink> sinks = new ArrayList<>();
/**
* Policy Engine HTTP Servers
*/
- protected List<HttpServletServer> httpServers = new ArrayList<>();
+ private List<HttpServletServer> httpServers = new ArrayList<>();
/**
* gson parser to decode configuration requests
*/
- protected final Gson decoder = new GsonBuilder().disableHtmlEscaping().create();
+ private final Gson decoder = new GsonBuilder().disableHtmlEscaping().create();
@Override
@@ -529,8 +524,6 @@ class PolicyEngineManager implements PolicyEngine {
e.getMessage(), e);
}
}
-
- return;
}
@Override
@@ -1473,7 +1466,7 @@ class PolicyEngineManager implements PolicyEngine {
}
}
- public boolean controllerConfig(PdpdConfiguration config) {
+ private boolean controllerConfig(PdpdConfiguration config) {
/* only this one supported for now */
final List<ControllerConfiguration> configControllers = config.getControllers();
if (configControllers == null || configControllers.isEmpty()) {
@@ -1482,26 +1475,18 @@ class PolicyEngineManager implements PolicyEngine {
}
final List<PolicyController> policyControllers = this.updatePolicyControllers(config.getControllers());
-
- boolean success;
-
- if (policyControllers == null || policyControllers.isEmpty()) {
- success = false;
- } else if (policyControllers.size() == configControllers.size()) {
+ boolean success = false;
+ if (!(policyControllers == null || policyControllers.isEmpty())
+ && (policyControllers.size() == configControllers.size())) {
success = true;
- } else {
- success = false;
}
-
return success;
}
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("PolicyEngineManager [alive=").append(this.alive).append(", locked=").append(this.locked)
- .append("]");
- return builder.toString();
+ return "PolicyEngineManager [alive=" + this.alive + ", locked=" + this.locked +
+ "]";
}
}
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java b/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java
index 5172fc3d..0b6643f8 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java
@@ -49,50 +49,50 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
/**
* Logger
*/
- private static Logger logger = LoggerFactory.getLogger(AggregatedPolicyController.class);
+ private static final Logger logger = LoggerFactory.getLogger(AggregatedPolicyController.class);
/**
* identifier for this policy controller
*/
- protected final String name;
+ private final String name;
/**
* Abstracted Event Sources List regardless communication technology
*/
- protected final List<? extends TopicSource> sources;
+ private final List<? extends TopicSource> sources;
/**
* Abstracted Event Sinks List regardless communication technology
*/
- protected final List<? extends TopicSink> sinks;
+ private final List<? extends TopicSink> sinks;
/**
* Mapping topics to sinks
*/
@JsonIgnore
- protected final HashMap<String, TopicSink> topic2Sinks = new HashMap<>();
+ private final HashMap<String, TopicSink> topic2Sinks = new HashMap<>();
/**
* Is this Policy Controller running (alive) ? reflects invocation of start()/stop() only
*/
- protected volatile boolean alive;
+ private volatile boolean alive;
/**
* Is this Policy Controller locked ? reflects if i/o controller related operations and start
* are permitted, more specifically: start(), deliver() and onTopicEvent(). It does not affect
* the ability to stop the underlying drools infrastructure
*/
- protected volatile boolean locked;
+ private volatile boolean locked;
/**
* Policy Drools Controller
*/
- protected volatile DroolsController droolsController;
+ private volatile DroolsController droolsController;
/**
* Properties used to initialize controller
*/
- protected final Properties properties;
+ private final Properties properties;
/**
* Constructor version mainly used for bootstrapping at initialization time a policy engine
@@ -131,7 +131,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
*
* @throws IllegalArgumentException if invalid parameters are passed in
*/
- protected void initDrools(Properties properties) {
+ private void initDrools(Properties properties) {
try {
// Register with drools infrastructure
this.droolsController = DroolsController.factory.build(properties, sources, sinks);
@@ -146,7 +146,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
*
* @throws IllegalArgumentException if invalid parameters are passed in
*/
- protected void initSinks() {
+ private void initSinks() {
this.topic2Sinks.clear();
for (TopicSink sink : sinks) {
this.topic2Sinks.put(sink.getTopic(), sink);
@@ -474,7 +474,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
if (!this.topic2Sinks.containsKey(topic)) {
logger.warn("{}: cannot deliver event because the sink {}:{} is not registered: {}", this, commType, topic,
event);
- throw new IllegalArgumentException("Unsuported topic " + topic + " for delivery");
+ throw new IllegalArgumentException("Unsupported topic " + topic + " for delivery");
}
boolean success = this.droolsController.deliver(this.topic2Sinks.get(topic), event);
@@ -633,10 +633,8 @@ public class AggregatedPolicyController implements PolicyController, TopicListen
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("AggregatedPolicyController [name=").append(name).append(", alive=").append(alive)
- .append(", locked=").append(locked).append(", droolsController=").append(droolsController).append("]");
- return builder.toString();
+ return "AggregatedPolicyController [name=" + name + ", alive=" + alive +
+ ", locked=" + locked + ", droolsController=" + droolsController + "]";
}
}