diff options
author | Ralph Straubs <rs8887@att.com> | 2017-04-21 04:23:55 -0500 |
---|---|---|
committer | Ralph Straubs <rs8887@att.com> | 2017-04-21 05:55:16 -0500 |
commit | 5bd9ff4130799247be3be88fc02f3ce0efd014c0 (patch) | |
tree | 327ed17fae044265b08c419913290e2f9bcddcec /policy-management/src/main/java/org | |
parent | 8f7e5de17521836a96fa1c771a1651f63216675c (diff) |
Batch submit -- force rebuild
[ECOMPD2TD-1126 1707] Delay the start of the election handler by one
more update interval to allow updatedDate to be set and recoginized by
other nodes.
[ECOMPD2TD-1073 1707] Remove pessimistic locks from DB access to prevent
DB deadlock
[US867397-policy-management-feature-api] Split original FeatureAPI into
three service interfaces.
These are:
- the original FeatureAPI for core
- PolicyControllerFeatureAPI (additional interface methods yet to
come ..)
- PolicyEngineFeatureAPI (additional interface methods yet to come ..)
Additional extensions will be done in the future.
This is to have equivalent functionality with what it is already there.
[US867397-policy-management-feature-api] Split original FeatureAPI into
three service interfaces.
These are:
- the original FeatureAPI for core
- PolicyControllerFeatureAPI (additional interface methods yet to
come ..)
- PolicyEngineFeatureAPI (additional interface methods yet to come ..)
Additional extensions will be done in the future.
This is to have equivalent functionality with what it is already there.
[ECOMPD2TD-1167] Avoid redundant dependencies and remove obsolete sql
scripts
[ECOMPD2TD-848] Fix copied from ATT droolspdp repo -- add timestamp to
metric and audit logs
[ECOMPD2TD-1167] update jetty version to 9.3.14
[ECOMPD2TD-1167] pull in policy-core jar as a dependency of
policy-management, instead of zip file
[ECOMPD2TD-1159] Add property to ignore repository audit errors
The property is called 'repository.audit.ignore.errors' -- it resides in
'IntegrityMonitor.properties', and it defaults to 'true'. When true, any
errors that occur in the repository audit are logged, but not reported
to integrity monitor.
[US867397] additional hooks for policy engine, and support operation
take over by feature bypassing further feature processing
[US867397] additional hooks for policy engine, and support operation
take over by feature bypassing further feature processing
[US867397] fix reverse return javadoc comment
[ECOMPD2TD-1192] Select correct persistent session information
This is a modification to 'DroolsPdpsElectionHandler.DesignatedWaiter'.
When going active, the list of persistent sessions needs to come from
the most recent active DroolsPDP. The most recent active DroolsPDP is
tracked in a local variable 'mostRecentPrimary', and the associated
list of sessions needs to be extracted just prior to going active.
The problem was that the list of sessions was extracted after the
current DroolsPDP was set to 'mostRecentPrimary'.
[ECOMPD2TD-1073 1707] Remove pessimistic locks from DB access to
prevent DB deadlock
[US860546] Add workaround for missing logger in message router
[US860546] add DME2 properties to PolicyProperties
[US860546] add DME2 support, pending unit testing
[US860546] updated unit tests for dmaap/DME2
[US860546] removed System.out.println lines from BusConsumer and
BusPublisher
[US860546] modifications and additions to TopicEndpoint tests
[US860546] remove block to append /events to serviceName in
BusConsumer, BusPublisher
[US860546] removing dmaap unit tests with ATT references
[ECOMPD2TD-1167] Audit release repository by default
[ECOMPD2TD-000] Cherry-pick versioning fixes from 1707.39.1 release
branch
[ECOMPD2TD-000] Fix policy-endpoints cambriaClient version
[US865296] ECOMP Policy Logging Compliance, remove redundant timestamp
from metric and audit log for logging compliance
[US865296] ECOMP Policy Logging Compliance, remove TargetVirtualEntity
from audit log, provide name to un-used column
[US865296] ECOMP Policy Logging Compliance, remove Unused from
AuditLogPattern, leave the column blank means un-used.
[US000000] Cleanup and performance improvements
1) Changed 'OrderedServiceImpl' to ensure that the same service instance
is used in every queue. This gets around the 'ServiceLoader' behavior
that generates a new instance for each interface the service
implements.
2) In 'PolicySession': add adaptive poll times within Drools sessions.
Instead of always polling every 5 seconds, poll frequency increases
when rules fire, and decreases when they don't. At present, the
poll delay ranges from 100 milliseconds to 5 seconds, but at some
point, it would be nice to make this configurable.
3) In 'PolicySession': add tests for 'logger.isDebugEnabled()' in
session listener methods -- this results in a significant amount of
real-time savings under load.
[ECOMPD2TD-1126 1707] Changes to the election handler to deal with
situations (race conditions) which can affect the site choice
[ECOMPD2TD-1126 1707] Clean up of site afinity logic. Minor changes
and a fix of the case where all pdpd are designated or all are
hot standby.
[ECOMPD2TD-1126 1707] Fixed issue with election handler and got all
StandbyStateManagmentTest JUnits working.
[ECOMPD2TD-1126 1707] Hopefully final changes to
DroolsPdpsElectionHandler and StateManagementTest. Also removed the
ResiliencyTestCases since they were redundant.
[ECOMPD2TD-1126 1707] Found a minor bug in the computeMostRecentPrimary
algorithm which I corrected and added a JUnit to confirm.
[ECOMPD2TD-1126 1707] Removed code that was commented out of election
handler to improve reability. Added an explanatory note to
StandbyStateManagementTest.
[US869183] Convert integrity monitor test endpoint to use
HttpServletServer
[US869183] add swagger-maven-plugin, update swagger annotation for
IM test interface
[US860371] Modified existing Dmaap and Ueb code to allow for https
connectivity. HTTP/HTTPS is configurable via controller.properties file
[US860520] Removed extra useHttps() method call from BusConsumer class
where the consumer should be using http. Also, restored pom.xml to
version at time feature branch was created.
[US860520] Removed TopicEndpointTest.java.
Added the ability to configure use of self-signed certificates for
consumer topics. Functionality cannot be added for publisher at
this time.
Removed useHttps parameter field from multiple .builder methods to
allow for greater ability to build source/sink objects without
specifying http vs https connectivity.
Other code cleanup and comments
[US860520] -Deleted sys.out statements used in testing from
BusConsumer/BusPublisher
-Moved setProps method outside of if/else stub in BusConsumer
-Could not add useHttps or selfSignedCerts to toString methods in
BusConsumer
-Move setProperty(contenttype, app/json) call outside of if/else
branch in BusPublisher
-Renamed doesAllowSelfSignedCerts method to is isAllowSelfSignedCerts
and moved to BusTopicBase
-Moved allowSelfSignedCerts member variable to BusTopicBase class.
BusTopicBase is ancestor of
SingleThreadedDmapp*/SingleThreadedUeb*/SingleThreadedBus* classes
therefore, it will be inherited.
-This changed resulted in cascading changes to the subclasses of
BusTopicbase
-Default is now set to disallow self-signed certs
-Added several javadoc param annotations
[US869183 1707] Changes to satisfy dependencies and correct pom syntax
[ECOMPD2TD-1280] move DroolsPDPIntegrityMonitor.RestManager to its
own class
[ECOMPD2TD-1278] Resolve duplicate dependency issues
(cherry-pick from 1707.40.1)
[ECOMPD2TD-1278] revert cambriaClient back to 0.0.1
[ECOMPD2TD-1278] put dmaap version back to 0.2.12
[ECOMPD2TD-1280 1707] Fix Commons-lang3 version and
common-modules version
Conflicts:
policy-endpoints/pom.xml
policy-healthcheck/pom.xml
policy-persistence/pom.xml
pom.xml
Change-Id: I803554bc64c55d2e82a3d6ad9120757f287144fb
Signed-off-by: Ralph Straubs <rs8887@att.com>
Diffstat (limited to 'policy-management/src/main/java/org')
5 files changed, 447 insertions, 79 deletions
diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java index 2c5708d3..76bc5151 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/controller/internal/MavenDroolsController.java @@ -519,11 +519,13 @@ public class MavenDroolsController implements DroolsController { this.getArtifactId(), topic, event); + } catch (UnsupportedOperationException uoe) { + if (logger.isInfoEnabled()) + logger.info("DECODE:"+ this + ":" + topic + ":" + event); + return true; } catch (Exception e) { - logger.error(MessageCodes.EXCEPTION_ERROR, e, - "DECODE:"+ this.getGroupId() + ":" + - this.getArtifactId() + ":" + topic + ":" + event, - this.toString()); + e.printStackTrace(); + logger.error("DECODE:"+ this + ":" + topic + ":" + event); return true; } @@ -709,8 +711,7 @@ public class MavenDroolsController implements DroolsController { builder.append("MavenDroolsController [policyContainer=") .append((policyContainer != null) ? policyContainer.getName() : "NULL").append(":") .append(", alive=") - .append(alive).append(", locked=").append(locked).append(", decoderConfigurations=") - .append(decoderConfigurations).append(", encoderConfigurations=").append(encoderConfigurations) + .append(alive).append(", locked=") .append(", modelClassLoaderHash=").append(modelClassLoaderHash).append("]"); return builder.toString(); } 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 new file mode 100644 index 00000000..3418d067 --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyControllerFeatureAPI.java @@ -0,0 +1,41 @@ +package org.openecomp.policy.drools.features; + +import java.util.Properties; + +import org.openecomp.policy.drools.system.PolicyController; +import org.openecomp.policy.drools.utils.OrderedService; +import org.openecomp.policy.drools.utils.OrderedServiceImpl; + +public interface PolicyControllerFeatureAPI extends OrderedService { + + /** + * called before creating a controller with name 'name' and + * properties 'properties' + * + * @param name name of the the controller + * @param properties configuration properties + * + * @return a policy controller. A take over of the creation operation + * is performed by returning a non-null policy controller. + * '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); + + /** + * called after creating a controller with name 'name' + * + * @param controller controller + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public boolean afterCreate(PolicyController controller); + + /** + * Feature providers implementing this interface + */ + public static final OrderedServiceImpl<PolicyControllerFeatureAPI> providers = + new OrderedServiceImpl<PolicyControllerFeatureAPI>(PolicyControllerFeatureAPI.class); +} 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 new file mode 100644 index 00000000..c8298dde --- /dev/null +++ b/policy-management/src/main/java/org/openecomp/policy/drools/features/PolicyEngineFeatureAPI.java @@ -0,0 +1,164 @@ +package org.openecomp.policy.drools.features; + +import java.util.Properties; + +import org.openecomp.policy.drools.system.PolicyEngine; +import org.openecomp.policy.drools.utils.OrderedService; +import org.openecomp.policy.drools.utils.OrderedServiceImpl; + +/** + * Policy Engine Feature API. + * Provides Interception Points during the Policy Engine lifecycle. + */ +public interface PolicyEngineFeatureAPI extends OrderedService { + + /** + * intercept before the Policy Engine is configured. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public boolean beforeConfigure(PolicyEngine engine, Properties properties); + + /** + * intercept after the Policy Engine is configured. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public boolean afterConfigure(PolicyEngine engine); + + /** + * intercept before the Policy Engine goes active. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public boolean beforeActivate(PolicyEngine engine); + + /** + * intercept after the Policy Engine goes active. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public boolean afterActivate(PolicyEngine engine); + + /** + * intercept before the Policy Engine goes standby. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public boolean beforeDeactivate(PolicyEngine engine); + + /** + * intercept after the Policy Engine goes standby. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public boolean afterDeactivate(PolicyEngine engine); + + /** + * intercept before the Policy Engine is started. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public boolean beforeStart(PolicyEngine engine); + + /** + * intercept after the Policy Engine is started. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public boolean afterStart(PolicyEngine engine); + + /** + * intercept before the Policy Engine is stopped. + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise.. + */ + public boolean beforeStop(PolicyEngine engine); + + /** + * intercept after the Policy Engine 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 boolean afterStop(PolicyEngine engine); + + /** + * intercept before the Policy Engine is locked + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public boolean beforeLock(PolicyEngine engine); + + /** + * intercept after the Policy Engine is locked + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise.. + */ + public boolean afterLock(PolicyEngine engine); + + /** + * intercept before the Policy Engine is locked + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public boolean beforeUnlock(PolicyEngine engine); + + /** + * intercept after the Policy Engine is locked + * + * @return true if this feature intercepts and takes ownership + * of the operation preventing the invocation of + * lower priority features. False, otherwise. + */ + public boolean afterUnlock(PolicyEngine engine); + + /** + * intercept the Policy Engine 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 boolean beforeShutdown(PolicyEngine engine); + + /** + * called after the Policy Engine 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 boolean afterShutdown(PolicyEngine engine); + + /** + * Feature providers implementing this interface + */ + public static final OrderedServiceImpl<PolicyEngineFeatureAPI> providers = + new OrderedServiceImpl<PolicyEngineFeatureAPI>(PolicyEngineFeatureAPI.class); +} diff --git a/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java index 33f2a098..6933003e 100644 --- a/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java +++ b/policy-management/src/main/java/org/openecomp/policy/drools/system/PolicyEngine.java @@ -28,7 +28,6 @@ import org.openecomp.policy.common.logging.eelf.MessageCodes; import org.openecomp.policy.common.logging.flexlogger.FlexLogger; import org.openecomp.policy.common.logging.flexlogger.Logger; import org.openecomp.policy.drools.controller.DroolsController; -import org.openecomp.policy.drools.core.FeatureAPI; import org.openecomp.policy.drools.core.jmx.PdpJmxListener; import org.openecomp.policy.drools.event.comm.Topic; import org.openecomp.policy.drools.event.comm.Topic.CommInfrastructure; @@ -36,6 +35,8 @@ 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.features.PolicyEngineFeatureAPI; import org.openecomp.policy.drools.http.server.HttpServletServer; import org.openecomp.policy.drools.persistence.SystemPersistence; import org.openecomp.policy.drools.properties.Lockable; @@ -329,19 +330,33 @@ class PolicyEngineManager implements PolicyEngine { */ protected List<HttpServletServer> httpServers = new ArrayList<HttpServletServer>(); + /** + * gson parser to decode configuration requests + */ protected Gson decoder = new GsonBuilder().disableHtmlEscaping().create(); - + /** * {@inheritDoc} */ @Override - public void configure(Properties properties) throws IllegalArgumentException { + public synchronized void configure(Properties properties) throws IllegalArgumentException { if (properties == null) { logger.warn("No properties provided"); throw new IllegalArgumentException("No properties provided"); } + /* policy-engine dispatch pre configure hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.beforeConfigure(this, properties)) + return; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } + } + this.properties = properties; try { @@ -365,6 +380,17 @@ class PolicyEngineManager implements PolicyEngine { logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine", "configure"); } + /* policy-engine dispatch post configure hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.afterConfigure(this)) + return; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } + } + return; } @@ -372,7 +398,7 @@ class PolicyEngineManager implements PolicyEngine { * {@inheritDoc} */ @Override - public PolicyController createPolicyController(String name, Properties properties) + public synchronized PolicyController createPolicyController(String name, Properties properties) throws IllegalArgumentException, IllegalStateException { // check if a PROPERTY_CONTROLLER_NAME property is present @@ -388,19 +414,31 @@ class PolicyEngineManager implements PolicyEngine { name = propertyControllerName; } - // feature hook - for (FeatureAPI feature : FeatureAPI.impl.getList()) { - feature.beforeCreateController(name, properties); + PolicyController controller; + for (PolicyControllerFeatureAPI controllerFeature : PolicyControllerFeatureAPI.providers.getList()) { + try { + controller = controllerFeature.beforeCreate(name, properties); + if (controller != null) + return controller; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + controllerFeature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } } - PolicyController controller = PolicyController.factory.build(name, properties); + controller = PolicyController.factory.build(name, properties); if (this.isLocked()) controller.lock(); // feature hook - for (FeatureAPI feature : FeatureAPI.impl.getList()) { - // NOTE: this should change to the actual controller object - feature.afterCreateController(name); + for (PolicyControllerFeatureAPI controllerFeature : PolicyControllerFeatureAPI.providers.getList()) { + try { + if (controllerFeature.afterCreate(controller)) + return controller; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + controllerFeature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } } return controller; @@ -573,22 +611,24 @@ class PolicyEngineManager implements PolicyEngine { * {@inheritDoc} */ @Override - public boolean start() throws IllegalStateException { - - if (this.locked) { - throw new IllegalStateException("Engine is locked"); - } - - // Features hook - for (FeatureAPI feature : FeatureAPI.impl.getList()) { - feature.beforeStartEngine(); - } + public synchronized boolean start() throws IllegalStateException { - synchronized(this) { - this.alive = true; + /* policy-engine dispatch pre start hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.beforeStart(this)) + return true; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } } - + boolean success = true; + if (this.locked) + throw new IllegalStateException("Engine is locked"); + + this.alive = true; /* Start Policy Engine exclusively-owned (unmanaged) http servers */ @@ -600,6 +640,7 @@ class PolicyEngineManager implements PolicyEngine { logger.error(MessageCodes.EXCEPTION_ERROR, e, httpServer.toString(), this.toString()); } } + /* Start Policy Engine exclusively-owned (unmanaged) sources */ for (TopicSource source: this.sources) { @@ -650,9 +691,15 @@ class PolicyEngineManager implements PolicyEngine { PdpJmxListener.start(); - // Features hook - for (FeatureAPI feature : FeatureAPI.impl.getList()) { - feature.afterStartEngine(); + /* policy-engine dispatch after start hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.afterStart(this)) + return success; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } } return success; @@ -662,18 +709,27 @@ class PolicyEngineManager implements PolicyEngine { * {@inheritDoc} */ @Override - public boolean stop() { - - /* stop regardless of the lock state */ + public synchronized boolean stop() { - synchronized(this) { - if (!this.alive) - return true; - - this.alive = false; + /* policy-engine dispatch pre stop hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.beforeStop(this)) + return true; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } } + /* stop regardless of the lock state */ + boolean success = true; + if (!this.alive) + return true; + + this.alive = false; + List<PolicyController> controllers = PolicyController.factory.inventory(); for (PolicyController controller : controllers) { try { @@ -719,6 +775,17 @@ class PolicyEngineManager implements PolicyEngine { } } + /* policy-engine dispatch pre stop hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.afterStop(this)) + return success; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } + } + return success; } @@ -726,17 +793,21 @@ class PolicyEngineManager implements PolicyEngine { * {@inheritDoc} */ @Override - public void shutdown() throws IllegalStateException { - - synchronized(this) { - this.alive = false; - } + public synchronized void shutdown() throws IllegalStateException { - // feature hook reporting that the Policy Engine is being shut down - for (FeatureAPI feature : FeatureAPI.impl.getList()) { - feature.beforeShutdownEngine(); + /* policy-engine dispatch pre shutdown hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.beforeShutdown(this)) + return; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } } - + + this.alive = false; + /* Shutdown Policy Engine owned (unmanaged) sources */ for (TopicSource source: this.sources) { try { @@ -764,10 +835,17 @@ class PolicyEngineManager implements PolicyEngine { PdpJmxListener.stop(); - // feature hook reporting that the Policy Engine has being shut down - for (FeatureAPI feature : FeatureAPI.impl.getList()) { - feature.afterShutdownEngine(); + /* policy-engine dispatch post shutdown hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.afterShutdown(this)) + return; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } } + new Thread(new Runnable() { @Override @@ -802,7 +880,7 @@ class PolicyEngineManager implements PolicyEngine { * {@inheritDoc} */ @Override - public boolean isAlive() { + public synchronized boolean isAlive() { return this.alive; } @@ -810,15 +888,24 @@ class PolicyEngineManager implements PolicyEngine { * {@inheritDoc} */ @Override - public boolean lock() { + public synchronized boolean lock() { - synchronized(this) { - if (this.locked) - return true; - - this.locked = true; + /* policy-engine dispatch pre lock hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.beforeLock(this)) + return true; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } } + if (this.locked) + return true; + + this.locked = true; + boolean success = true; List<PolicyController> controllers = PolicyController.factory.inventory(); for (PolicyController controller : controllers) { @@ -830,7 +917,19 @@ class PolicyEngineManager implements PolicyEngine { } } - success = TopicEndpoint.manager.lock(); + success = TopicEndpoint.manager.lock() && success; + + /* policy-engine dispatch post lock hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.afterLock(this)) + return success; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } + } + return success; } @@ -838,14 +937,24 @@ class PolicyEngineManager implements PolicyEngine { * {@inheritDoc} */ @Override - public boolean unlock() { - synchronized(this) { - if (!this.locked) - return true; - - this.locked = false; + public synchronized boolean unlock() { + + /* policy-engine dispatch pre unlock hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.beforeUnlock(this)) + return true; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } } + if (!this.locked) + return true; + + this.locked = false; + boolean success = true; List<PolicyController> controllers = PolicyController.factory.inventory(); for (PolicyController controller : controllers) { @@ -857,7 +966,19 @@ class PolicyEngineManager implements PolicyEngine { } } - success = TopicEndpoint.manager.unlock(); + success = TopicEndpoint.manager.unlock() && success; + + /* policy-engine dispatch after unlock hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.afterUnlock(this)) + return success; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } + } + return success; } @@ -865,7 +986,7 @@ class PolicyEngineManager implements PolicyEngine { * {@inheritDoc} */ @Override - public boolean isLocked() { + public synchronized boolean isLocked() { return this.locked; } @@ -945,7 +1066,7 @@ class PolicyEngineManager implements PolicyEngine { * {@inheritDoc} */ @Override - public boolean onTopicEvent(CommInfrastructure commType, String topic, String event) { + public void onTopicEvent(CommInfrastructure commType, String topic, String event) { /* configuration request */ try { PdpdConfiguration configuration = this.decoder.fromJson(event, PdpdConfiguration.class); @@ -953,8 +1074,6 @@ class PolicyEngineManager implements PolicyEngine { } catch (Exception e) { logger.error(MessageCodes.EXCEPTION_ERROR, e, "CONFIGURATION ERROR IN PDP-D POLICY ENGINE: "+ event + ":" + e.getMessage() + ":" + this); } - - return true; } /** @@ -1131,6 +1250,17 @@ class PolicyEngineManager implements PolicyEngine { */ @Override public synchronized void activate() { + + /* policy-engine dispatch pre activate hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.beforeActivate(this)) + return; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } + } // activate 'policy-management' for (PolicyController policyController : getPolicyControllers()) { @@ -1147,6 +1277,17 @@ class PolicyEngineManager implements PolicyEngine { } this.unlock(); + + /* policy-engine dispatch post activate hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.afterActivate(this)) + return; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } + } } /** @@ -1155,6 +1296,17 @@ class PolicyEngineManager implements PolicyEngine { @Override public synchronized void deactivate() { + /* policy-engine dispatch pre deactivate hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.beforeDeactivate(this)) + return; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } + } + this.lock(); for (PolicyController policyController : getPolicyControllers()) { @@ -1167,7 +1319,18 @@ class PolicyEngineManager implements PolicyEngine { logger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyEngine.deactivate: cannot start " + policyController + " because of " + e.getMessage()); } - } + } + + /* policy-engine dispatch post deactivate hook */ + for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { + try { + if (feature.afterDeactivate(this)) + return; + } catch (Exception e) { + System.out.println("ERROR: Feature API: " + feature.getClass().getName() + e.getMessage()); + e.printStackTrace(); + } + } } @Override 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 96f9e5bf..3badbd08 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 @@ -317,18 +317,18 @@ public class AggregatedPolicyController implements PolicyController, * {@inheritDoc} */ @Override - public boolean onTopicEvent(Topic.CommInfrastructure commType, + public void onTopicEvent(Topic.CommInfrastructure commType, String topic, String event) { logger.info("EVENT NOTIFICATION: " + commType + ":" + topic + ":" + event + " INTO " + this); if (this.locked) - return false; + return; if (!this.alive) - return true; + return; - return this.droolsController.offer(topic, event); + this.droolsController.offer(topic, event); } /** @@ -444,8 +444,7 @@ public class AggregatedPolicyController implements PolicyController, @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("AggregatedPolicyController [name=").append(name).append(", sources=").append(sources) - .append(", sinks=").append(sinks).append(", alive=").append(alive).append(", locked=").append(locked) + builder.append("AggregatedPolicyController [name=").append(name).append(", alive=").append(alive).append(", locked=").append(locked) .append(", droolsController=").append(droolsController).append("]"); return builder.toString(); } |