diff options
author | Jorge Hernandez <jh1730@att.com> | 2018-02-19 10:16:02 -0600 |
---|---|---|
committer | Jorge Hernandez <jh1730@att.com> | 2018-02-19 17:08:29 +0000 |
commit | 90cf04f2ac1066b2b6a012432ec42a467fe42392 (patch) | |
tree | d3f2c529ef39c750027622a4b71e444ec028482f /policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java | |
parent | 1708e9a45cb88571613c10b68d392811b2b3f0f4 (diff) |
interception of facts before injection
Added interceptor to drools controller, post-decoding and
pre/after injection into kie sessions. The decoded
object is passed as is. The set of hooks will be
expanded in the future.
This is added in the context of logging for POLICY-558
to track control loop transactions, per logging requirements.
The idea is that VirtualControlLoopNotifications on the
drools-applications area will use it to track control loop
transactions, times, etc .. to satisfy logging requirements.
This approach also reliefs the drools applications logic, (.drl)
for dealing with this. The logic therefore will be isolated into
a single feature.
Change-Id: Idf840c528e6175be4aaee3bf114091c203b37bc8
Issue-ID: POLICY-558
Signed-off-by: Jorge Hernandez <jh1730@att.com>
Diffstat (limited to 'policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java')
-rw-r--r-- | policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java index 8a0073c0..c8c73689 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java @@ -20,12 +20,13 @@ package org.onap.policy.drools.controller.internal; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; - import org.apache.commons.collections4.queue.CircularFifoQueue; import org.drools.core.ClassObjectFilter; import org.kie.api.definition.KiePackage; @@ -34,13 +35,12 @@ import org.kie.api.runtime.KieSession; import org.kie.api.runtime.rule.FactHandle; import org.kie.api.runtime.rule.QueryResults; import org.kie.api.runtime.rule.QueryResultsRow; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.core.PolicyContainer; import org.onap.policy.drools.core.PolicySession; import org.onap.policy.drools.core.jmx.PdpJmx; import org.onap.policy.drools.event.comm.TopicSink; +import org.onap.policy.drools.features.DroolsControllerFeatureAPI; import org.onap.policy.drools.protocol.coders.EventProtocolCoder; import org.onap.policy.drools.protocol.coders.JsonProtocolFilter; import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration; @@ -48,9 +48,8 @@ import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.Cust import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomJacksonCoder; import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.PotentialCoderFilter; import org.onap.policy.drools.utils.ReflectionUtil; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Maven-based Drools Controller that interacts with the @@ -118,8 +117,8 @@ public class MavenDroolsController implements DroolsController { * @param groupId maven group id * @param artifactId maven artifact id * @param version maven version - * @param decoderConfiguration list of topic -> decoders -> filters mapping - * @param encoderConfiguration list of topic -> encoders -> filters mapping + * @param decoderConfigurations list of topic -> decoders -> filters mapping + * @param encoderConfigurations list of topic -> encoders -> filters mapping * * @throws IllegalArgumentException invalid arguments passed in */ @@ -148,8 +147,8 @@ public class MavenDroolsController implements DroolsController { /** * init encoding/decoding configuration - * @param decoderConfiguration list of topic -> decoders -> filters mapping - * @param encoderConfiguration list of topic -> encoders -> filters mapping + * @param decoderConfigurations list of topic -> decoders -> filters mapping + * @param encoderConfigurations list of topic -> encoders -> filters mapping */ protected void init(List<TopicCoderFilterConfiguration> decoderConfigurations, List<TopicCoderFilterConfiguration> encoderConfigurations) { @@ -227,7 +226,7 @@ public class MavenDroolsController implements DroolsController { * Note this is critical to be done after the Policy Container is * instantiated to be able to fetch the corresponding classes. * - * @param decoderConfiguration list of topic -> decoders -> filters mapping + * @param coderConfigurations list of topic -> decoders -> filters mapping */ protected void initCoders(List<TopicCoderFilterConfiguration> coderConfigurations, boolean decoder) { @@ -512,11 +511,32 @@ public class MavenDroolsController implements DroolsController { // Broadcast if (logger.isInfoEnabled()) - logger.info(this + "BROADCAST-INJECT of " + event + " FROM " + topic + " INTO " + this.policyContainer.getName()); - - if (!this.policyContainer.insertAll(anEvent)) + logger.info(this + "BROADCAST-INJECT of " + event + " FROM " + topic + " INTO " + this.policyContainer.getName()); + + for (DroolsControllerFeatureAPI feature : DroolsControllerFeatureAPI.providers.getList()) { + try { + if (feature.beforeInsert(this, anEvent)) + return true; + } catch (Exception e) { + logger.error("{}: feature {} before-insert failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); + } + } + + boolean successInject = this.policyContainer.insertAll(anEvent); + if (!successInject) logger.warn(this + "Failed to inject into PolicyContainer " + this.getSessionNames()); - + + for (DroolsControllerFeatureAPI feature : DroolsControllerFeatureAPI.providers.getList()) { + try { + if (feature.afterInsert(this, anEvent, successInject)) + return true; + } catch (Exception e) { + logger.error("{}: feature {} after-insert failure because of {}", + this, feature.getClass().getName(), e.getMessage(), e); + } + } + return true; } |