diff options
Diffstat (limited to 'policy-management/src/main/java/org')
3 files changed, 350 insertions, 31 deletions
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; } /** |