From 2a78350806368ae9dd4f5e43f4652251adbb52e6 Mon Sep 17 00:00:00 2001 From: Jorge Hernandez Date: Thu, 1 Jun 2017 22:51:59 -0500 Subject: [POLICY-9,POLICY-18] warnings + Controller hooks 1. clean up policy-utils warnings. drools-pdp project has no warnings now. 2. add new Policy Controller hooks for feature programmability. Change-Id: Ie991320e23e73118b235018d15ea66340a841a89 Signed-off-by: Jorge Hernandez --- .../drools/healthcheck/HealthCheckFeature.java | 129 +-------------- .../features/PolicyControllerFeatureAPI.java | 165 +++++++++++++++++- .../drools/features/PolicyEngineFeatureAPI.java | 32 ++-- .../internal/AggregatedPolicyController.java | 184 +++++++++++++++++++-- .../drools/persistence/PersistenceFeature.java | 84 ---------- .../policy/drools/utils/OrderedServiceImpl.java | 4 +- .../policy/drools/utils/PropertyUtilTest.java | 13 +- 7 files changed, 364 insertions(+), 247 deletions(-) diff --git a/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java index b2f29392..63216f6d 100644 --- a/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java +++ b/policy-healthcheck/src/main/java/org/openecomp/policy/drools/healthcheck/HealthCheckFeature.java @@ -20,34 +20,24 @@ package org.openecomp.policy.drools.healthcheck; -import java.util.Properties; - import org.openecomp.policy.drools.features.PolicyEngineFeatureAPI; import org.openecomp.policy.drools.system.PolicyEngine; +/** + * This feature provides healthcheck verification of remotely associated RESTful components + */ public class HealthCheckFeature implements PolicyEngineFeatureAPI { - public static final String CONFIGURATION_PROPERTIES_NAME = "policy-healthcheck"; - /** - * {@inheritDoc} + * Properties Configuration Name */ + public static final String CONFIGURATION_PROPERTIES_NAME = "policy-healthcheck"; + @Override public int getSequenceNumber() { return 1000; } - /** - * {@inheritDoc} - */ - @Override - public boolean beforeStart(PolicyEngine engine) throws IllegalStateException { - return false; - } - - /** - * {@inheritDoc} - */ @Override public boolean afterStart(PolicyEngine engine) { try { @@ -59,17 +49,6 @@ public class HealthCheckFeature implements PolicyEngineFeatureAPI { return false; } - /** - * {@inheritDoc} - */ - @Override - public boolean beforeShutdown(PolicyEngine engine) { - return false; - } - - /** - * {@inheritDoc} - */ @Override public boolean afterShutdown(PolicyEngine engine) { try { @@ -80,102 +59,6 @@ public class HealthCheckFeature implements PolicyEngineFeatureAPI { return false; } - - /** - * {@inheritDoc} - */ - @Override - public boolean beforeConfigure(PolicyEngine engine, Properties properties) { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean afterConfigure(PolicyEngine engine) { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean beforeActivate(PolicyEngine engine) { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean afterActivate(PolicyEngine engine) { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean beforeDeactivate(PolicyEngine engine) { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean afterDeactivate(PolicyEngine engine) { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean beforeStop(PolicyEngine engine) { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean afterStop(PolicyEngine engine) { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean beforeLock(PolicyEngine engine) { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean afterLock(PolicyEngine engine) { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean beforeUnlock(PolicyEngine engine) { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean afterUnlock(PolicyEngine engine) { - return false; - } /** * gets the monitor diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyControllerFeatureAPI.java b/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyControllerFeatureAPI.java index a52ada3d..66f64a82 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyControllerFeatureAPI.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyControllerFeatureAPI.java @@ -22,6 +22,7 @@ package org.openecomp.policy.drools.features; import java.util.Properties; +import org.openecomp.policy.drools.event.comm.Topic.CommInfrastructure; import org.openecomp.policy.drools.system.PolicyController; import org.openecomp.policy.drools.utils.OrderedService; import org.openecomp.policy.drools.utils.OrderedServiceImpl; @@ -40,7 +41,7 @@ public interface PolicyControllerFeatureAPI extends OrderedService { * 'null' indicates that no take over has taken place, and processing should * continue to the next feature provider. */ - public PolicyController beforeCreate(String name, Properties properties); + public default PolicyController beforeCreate(String name, Properties properties) {return null;} /** * called after creating a controller with name 'name' @@ -51,7 +52,167 @@ public interface PolicyControllerFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public boolean afterCreate(PolicyController controller); + public default boolean afterCreate(PolicyController controller) {return false;} + + /** + * intercept before the Policy Controller is started. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public default boolean beforeStart(PolicyController controller) {return false;} + + /** + * intercept after the Policy Controller is started. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public default boolean afterStart(PolicyController controller) {return false;} + + /** + * intercept before the Policy Controller is stopped. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise.. + */ + public default boolean beforeStop(PolicyController controller) {return false;} + + /** + * intercept after the Policy Controller is stopped + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise.d. + */ + public default boolean afterStop(PolicyController controller) {return false;} + + /** + * intercept before the Policy Controller is locked + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public default boolean beforeLock(PolicyController controller) {return false;} + + /** + * intercept after the Policy Controller is locked + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise.. + */ + public default boolean afterLock(PolicyController controller) {return false;} + + /** + * intercept before the Policy Controller is locked + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public default boolean beforeUnlock(PolicyController controller) {return false;} + + /** + * intercept after the Policy Controller is locked + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public default boolean afterUnlock(PolicyController controller) {return false;} + + /** + * intercept before the Policy Controller is shut down + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise.. + */ + public default boolean beforeShutdown(PolicyController controller) {return false;} + + /** + * called after the Policy Controller is shut down + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public default boolean afterShutdown(PolicyController controller) {return false;} + + /** + * intercept before the Policy Controller is halted + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise.. + */ + public default boolean beforeHalt(PolicyController controller) {return false;} + + /** + * called after the Policy Controller is halted + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public default boolean afterHalt(PolicyController controller) {return false;} + + + /** + * intercept before the Policy Controller is offered an event + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public default boolean beforeOffer(PolicyController controller, + CommInfrastructure protocol, + String topic, + String event) {return false;} + + /** + * called after the Policy Controller processes an event offer + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public default boolean afterOffer(PolicyController controller, + CommInfrastructure protocol, + String topic, + String event, + boolean success) {return false;} + + /** + * intercept before the Policy Controller delivers (posts) an event + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public default boolean beforeDeliver(PolicyController controller, + CommInfrastructure protocol, + String topic, + Object event) {return false;} + + /** + * called after the Policy Controller delivers (posts) an event + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public default boolean afterDeliver(PolicyController controller, + CommInfrastructure protocol, + String topic, + Object event, + boolean success) {return false;} + /** * Feature providers implementing this interface diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyEngineFeatureAPI.java b/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyEngineFeatureAPI.java index 8615ed3c..30e3a14c 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyEngineFeatureAPI.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyEngineFeatureAPI.java @@ -39,7 +39,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public boolean beforeConfigure(PolicyEngine engine, Properties properties); + public default boolean beforeConfigure(PolicyEngine engine, Properties properties) {return false;}; /** * intercept after the Policy Engine is configured. @@ -48,7 +48,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public boolean afterConfigure(PolicyEngine engine); + public default boolean afterConfigure(PolicyEngine engine) {return false;}; /** * intercept before the Policy Engine goes active. @@ -57,7 +57,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public boolean beforeActivate(PolicyEngine engine); + public default boolean beforeActivate(PolicyEngine engine) {return false;}; /** * intercept after the Policy Engine goes active. @@ -66,7 +66,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public boolean afterActivate(PolicyEngine engine); + public default boolean afterActivate(PolicyEngine engine) {return false;}; /** * intercept before the Policy Engine goes standby. @@ -75,7 +75,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public boolean beforeDeactivate(PolicyEngine engine); + public default boolean beforeDeactivate(PolicyEngine engine) {return false;}; /** * intercept after the Policy Engine goes standby. @@ -84,7 +84,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public boolean afterDeactivate(PolicyEngine engine); + public default boolean afterDeactivate(PolicyEngine engine) {return false;}; /** * intercept before the Policy Engine is started. @@ -93,7 +93,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public boolean beforeStart(PolicyEngine engine); + public default boolean beforeStart(PolicyEngine engine) {return false;}; /** * intercept after the Policy Engine is started. @@ -102,7 +102,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public boolean afterStart(PolicyEngine engine); + public default boolean afterStart(PolicyEngine engine) {return false;}; /** * intercept before the Policy Engine is stopped. @@ -111,7 +111,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise.. */ - public boolean beforeStop(PolicyEngine engine); + public default boolean beforeStop(PolicyEngine engine) {return false;}; /** * intercept after the Policy Engine is stopped @@ -120,7 +120,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise.d. */ - public boolean afterStop(PolicyEngine engine); + public default boolean afterStop(PolicyEngine engine) {return false;}; /** * intercept before the Policy Engine is locked @@ -129,7 +129,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public boolean beforeLock(PolicyEngine engine); + public default boolean beforeLock(PolicyEngine engine) {return false;}; /** * intercept after the Policy Engine is locked @@ -138,7 +138,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise.. */ - public boolean afterLock(PolicyEngine engine); + public default boolean afterLock(PolicyEngine engine) {return false;}; /** * intercept before the Policy Engine is locked @@ -147,7 +147,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public boolean beforeUnlock(PolicyEngine engine); + public default boolean beforeUnlock(PolicyEngine engine) {return false;}; /** * intercept after the Policy Engine is locked @@ -156,7 +156,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public boolean afterUnlock(PolicyEngine engine); + public default boolean afterUnlock(PolicyEngine engine) {return false;}; /** * intercept the Policy Engine is shut down @@ -165,7 +165,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise.. */ - public boolean beforeShutdown(PolicyEngine engine); + public default boolean beforeShutdown(PolicyEngine engine){return false;}; /** * called after the Policy Engine is shut down @@ -174,7 +174,7 @@ public interface PolicyEngineFeatureAPI extends OrderedService { * of the operation preventing the invocation of * lower priority features. False, otherwise. */ - public boolean afterShutdown(PolicyEngine engine); + public default boolean afterShutdown(PolicyEngine engine) {return false;}; /** * Feature providers implementing this interface diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/system/internal/AggregatedPolicyController.java b/policy-management/src/main/java/org/openecomp/policy/drools/system/internal/AggregatedPolicyController.java index e41a8898..36a58512 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/system/internal/AggregatedPolicyController.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/system/internal/AggregatedPolicyController.java @@ -32,6 +32,7 @@ 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.drools.features.PolicyControllerFeatureAPI; import org.openecomp.policy.drools.persistence.SystemPersistence; import org.openecomp.policy.drools.properties.PolicyProperties; import org.openecomp.policy.drools.protocol.configuration.DroolsConfiguration; @@ -228,8 +229,18 @@ public class AggregatedPolicyController implements PolicyController, */ @Override public boolean start() throws IllegalStateException { + if (logger.isInfoEnabled()) - logger.info("START: " + this); + logger.info("START: " + this); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.beforeStart(this)) + return true; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } if (this.isLocked()) throw new IllegalStateException("Policy Controller " + name + " is locked"); @@ -258,6 +269,15 @@ public class AggregatedPolicyController implements PolicyController, } } + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.afterStart(this)) + return true; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } + return success; } @@ -267,7 +287,17 @@ public class AggregatedPolicyController implements PolicyController, @Override public boolean stop() { - logger.info("STOP: " + this); + if (logger.isInfoEnabled()) + logger.info("STOP: " + this); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.beforeStop(this)) + return true; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } /* stop regardless locked state */ @@ -285,6 +315,16 @@ public class AggregatedPolicyController implements PolicyController, } boolean success = this.droolsController.stop(); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.afterStop(this)) + return true; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } + return success; } @@ -294,11 +334,29 @@ public class AggregatedPolicyController implements PolicyController, @Override public void shutdown() throws IllegalStateException { if (logger.isInfoEnabled()) - logger.info(this + "SHUTDOWN"); + logger.info("SHUTDOWN: " + this); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.beforeShutdown(this)) + return; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } this.stop(); DroolsController.factory.shutdown(this.droolsController); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.afterShutdown(this)) + return; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } } /** @@ -307,11 +365,29 @@ public class AggregatedPolicyController implements PolicyController, @Override public void halt() throws IllegalStateException { if (logger.isInfoEnabled()) - logger.info(this + "HALT"); + logger.info("HALT: " + this); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.beforeHalt(this)) + return; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } this.stop(); DroolsController.factory.destroy(this.droolsController); SystemPersistence.manager.deleteController(this.name); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.afterHalt(this)) + return; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } } /** @@ -321,7 +397,17 @@ public class AggregatedPolicyController implements PolicyController, public void onTopicEvent(Topic.CommInfrastructure commType, String topic, String event) { - logger.info("EVENT NOTIFICATION: " + commType + ":" + topic + ":" + event + " INTO " + this); + if (logger.isDebugEnabled()) + logger.debug("EVENT NOTIFICATION: " + commType + ":" + topic + ":" + event + " INTO " + this); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.beforeOffer(this, commType, topic, event)) + return; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } if (this.locked) return; @@ -329,7 +415,16 @@ public class AggregatedPolicyController implements PolicyController, if (!this.alive) return; - this.droolsController.offer(topic, event); + boolean success = this.droolsController.offer(topic, event); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.afterOffer(this, commType, topic, event, success)) + return; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } } /** @@ -341,7 +436,17 @@ public class AggregatedPolicyController implements PolicyController, throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { - logger.info("DELIVER: " + commType + ":" + topic + ":" + event + " FROM " + this); + if (logger.isDebugEnabled()) + logger.debug("DELIVER: " + commType + ":" + topic + ":" + event + " FROM " + this); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.beforeDeliver(this, commType, topic, event)) + return true; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } if (topic == null || topic.isEmpty()) throw new IllegalArgumentException("Invalid Topic"); @@ -361,8 +466,18 @@ public class AggregatedPolicyController implements PolicyController, ("Unsuported topic " + topic + " for delivery"); } - return this.droolsController.deliver - (this.topic2Sinks.get(topic), event); + boolean success = this.droolsController.deliver(this.topic2Sinks.get(topic), event); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.afterDeliver(this, commType, topic, event, success)) + return success; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } + + return success; } /** @@ -378,7 +493,17 @@ public class AggregatedPolicyController implements PolicyController, */ @Override public boolean lock() { - logger.info("LOCK: " + this); + if (logger.isInfoEnabled()) + logger.info("LOCK: " + this); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.beforeLock(this)) + return true; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } synchronized(this) { if (this.locked) @@ -390,7 +515,18 @@ public class AggregatedPolicyController implements PolicyController, // it does not affect associated sources/sinks, they are // autonomous entities - return this.droolsController.lock(); + boolean success = this.droolsController.lock(); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.afterLock(this)) + return true; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } + + return success; } /** @@ -398,7 +534,18 @@ public class AggregatedPolicyController implements PolicyController, */ @Override public boolean unlock() { - logger.info("UNLOCK: " + this); + + if (logger.isInfoEnabled()) + logger.info("UNLOCK: " + this); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.beforeUnlock(this)) + return true; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } synchronized(this) { if (!this.locked) @@ -407,7 +554,18 @@ public class AggregatedPolicyController implements PolicyController, this.locked = false; } - return this.droolsController.unlock(); + boolean success = this.droolsController.unlock(); + + for (PolicyControllerFeatureAPI feature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (feature.afterUnlock(this)) + return true; + } catch (Exception e) { + logger.warn("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage(), e); + } + } + + return success; } /** diff --git a/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/PersistenceFeature.java b/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/PersistenceFeature.java index b7695ab4..3883acab 100644 --- a/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/PersistenceFeature.java +++ b/policy-persistence/src/main/java/org/openecomp/policy/drools/persistence/PersistenceFeature.java @@ -224,36 +224,6 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine PolicyEngine.manager.lock(); return false; } - - /** - * {@inheritDoc} - */ - @Override - public boolean beforeStart(PolicyEngine engine) {return false;} - - /** - * {@inheritDoc} - */ - @Override - public boolean beforeShutdown(PolicyEngine engine) {return false;} - - /** - * {@inheritDoc} - */ - @Override - public boolean afterShutdown(PolicyEngine engine) {return false;} - - /** - * {@inheritDoc} - */ - @Override - public boolean beforeConfigure(PolicyEngine engine, Properties properties) {return false;} - - /** - * {@inheritDoc} - */ - @Override - public boolean afterConfigure(PolicyEngine engine) {return false;} /** * {@inheritDoc} @@ -363,60 +333,6 @@ public class PersistenceFeature implements PolicySessionFeatureAPI, PolicyEngine return(false); } - /** - * {@inheritDoc} - */ - @Override - public boolean afterActivate(PolicyEngine engine) {return false;} - - /** - * {@inheritDoc} - */ - @Override - public boolean beforeDeactivate(PolicyEngine engine) {return false;} - - /** - * {@inheritDoc} - */ - @Override - public boolean afterDeactivate(PolicyEngine engine) {return false;} - - /** - * {@inheritDoc} - */ - @Override - public boolean beforeStop(PolicyEngine engine) {return false;} - - /** - * {@inheritDoc} - */ - @Override - public boolean afterStop(PolicyEngine engine) {return false;} - - /** - * {@inheritDoc} - */ - @Override - public boolean beforeLock(PolicyEngine engine) {return false;} - - /** - * {@inheritDoc} - */ - @Override - public boolean afterLock(PolicyEngine engine) {return false;} - - /** - * {@inheritDoc} - */ - @Override - public boolean beforeUnlock(PolicyEngine engine) {return false;} - - /** - * {@inheritDoc} - */ - @Override - public boolean afterUnlock(PolicyEngine engine) {return false;} - /**************************/ /** diff --git a/policy-utils/src/main/java/org/openecomp/policy/drools/utils/OrderedServiceImpl.java b/policy-utils/src/main/java/org/openecomp/policy/drools/utils/OrderedServiceImpl.java index 809d3679..c5f9a343 100644 --- a/policy-utils/src/main/java/org/openecomp/policy/drools/utils/OrderedServiceImpl.java +++ b/policy-utils/src/main/java/org/openecomp/policy/drools/utils/OrderedServiceImpl.java @@ -45,7 +45,7 @@ public class OrderedServiceImpl * @param clazz the class object associated with 'T' (I supposed it could * be a subclass, but I'm not sure this is useful) */ - public OrderedServiceImpl(Class clazz) + public OrderedServiceImpl(Class clazz) { // This constructor wouldn't be needed if 'T.class' was legal serviceLoader = ServiceLoader.load(clazz); @@ -75,6 +75,7 @@ public class OrderedServiceImpl * @return the sorted list of services implementing interface 'T' discovered * by 'ServiceLoader'. */ + @SuppressWarnings("unchecked") public synchronized List rebuildList() { // build a list of all of the current implementors @@ -117,6 +118,7 @@ public class OrderedServiceImpl } // use this to ensure that we only use one unique instance of each class + @SuppressWarnings("rawtypes") static private HashMap classToSingleton = new HashMap<>(); diff --git a/policy-utils/src/test/java/org/openecomp/policy/drools/utils/PropertyUtilTest.java b/policy-utils/src/test/java/org/openecomp/policy/drools/utils/PropertyUtilTest.java index 55091718..32386725 100644 --- a/policy-utils/src/test/java/org/openecomp/policy/drools/utils/PropertyUtilTest.java +++ b/policy-utils/src/test/java/org/openecomp/policy/drools/utils/PropertyUtilTest.java @@ -20,11 +20,7 @@ package org.openecomp.policy.drools.utils; -import static org.junit.Assert.*; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import static org.junit.Assert.assertEquals; import java.io.File; import java.io.FileOutputStream; @@ -35,8 +31,9 @@ import java.util.Set; import java.util.TreeSet; import java.util.UUID; -import org.apache.log4j.Logger; - +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; import org.openecomp.policy.common.logging.eelf.PolicyLogger; public class PropertyUtilTest @@ -198,7 +195,7 @@ public class PropertyUtilTest assertEquals(prop2, returns[0]); // verify that we have the expected set of keys - assertEquals(new TreeSet(Arrays.asList(new String[]{"p1", "p2", "p4"})), + assertEquals(new TreeSet(Arrays.asList(new String[]{"p1", "p2", "p4"})), returns[1]); } } -- cgit 1.2.3-korg