aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src/main/java/org/onap/policy/drools/controller
diff options
context:
space:
mode:
authorDaniel Cruz <dc443y@att.com>2019-02-14 00:42:45 -0600
committerDaniel Cruz <dc443y@att.com>2019-02-21 16:36:38 -0600
commitfa2a5a43c82cd35cca9e7d4b51f83ce70e1e3e59 (patch)
tree92b32081f70d2a7e3219e13836565cf81160ee3a /policy-management/src/main/java/org/onap/policy/drools/controller
parentbf69c619c8c5a660f6fde044dc9aa8304ba12982 (diff)
Add Nested JSON Filtering
The refactoring of the JsonProtocolFilter allows for complex filter queries for JSON events coming in on network topics. The underlying library used is json-path, which supports path based searching and ruby regex filtering at any level of the JSON document. The JsonProtocolFilter no longer requires a FilterRule class as one json-path filter can contain multiple constraints using "&&" or "||". This eliminates the need to identify the field name as a key with a regex associated with it in the controller properties file (see the original FilterRule implementation). It also simplifies the parsing needed in the DroolsControllerFactory when extracting the filter property and creating the JsonProtocolFilter. JUnit coverage is 100% and all sonar flags were addressed related to the JsonProtocolFilter class. Tested and verified working with the telemetry API in a locally deployed PDP-D. Change-Id: I8bd63db4e497c1ba0b5044b5449ccb7a9e4dbdbc Issue-ID: POLICY-1489 Signed-off-by: Daniel Cruz <dc443y@att.com>
Diffstat (limited to 'policy-management/src/main/java/org/onap/policy/drools/controller')
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java78
1 files changed, 18 insertions, 60 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java
index 24fc6de9..16daa947 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,7 +25,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
-
import org.onap.policy.common.endpoints.event.comm.Topic;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
@@ -38,7 +37,6 @@ import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomGsonCoder;
import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.PotentialCoderFilter;
-import org.onap.policy.drools.utils.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,11 +48,11 @@ public interface DroolsControllerFactory {
/**
* Constructs a Drools Controller based on properties.
- *
+ *
* @param properties properties containing initialization parameters
* @param eventSources list of event sources
* @param eventSinks list of event sinks
- *
+ *
* @return the instantiated Drools Controller
* @throws IllegalArgumentException with invalid parameters
* @throws LinkageError Failure to link rules and models in Drools Libraries
@@ -64,13 +62,13 @@ public interface DroolsControllerFactory {
/**
* Explicit construction of a Drools Controller.
- *
+ *
* @param groupId maven group id of drools artifact
* @param artifactId maven artifact id of drools artifact
* @param version maven version id of drools artifact
* @param decoderConfigurations list of decoder configurations
* @param encoderConfigurations list of encoder configurations
- *
+ *
* @return the instantiated Drools Controller
* @throws IllegalArgumentException with invalid parameters
* @throws LinkageError Failure to link rules and models in Drools Libraries
@@ -81,7 +79,7 @@ public interface DroolsControllerFactory {
/**
* Releases the Drools Controller from operation.
- *
+ *
* @param controller the Drools Controller to shut down
*/
public void shutdown(DroolsController controller);
@@ -93,7 +91,7 @@ public interface DroolsControllerFactory {
/**
* Destroys and releases resources for a Drools Controller.
- *
+ *
* @param controller the Drools Controller to destroy
*/
public void destroy(DroolsController controller);
@@ -105,11 +103,11 @@ public interface DroolsControllerFactory {
/**
* Gets the Drools Controller associated with the maven group and artifact id.
- *
+ *
* @param groupId maven group id of drools artifact
* @param artifactId maven artifact id of drools artifact
* @param version maven version id of drools artifact
- *
+ *
* @return the Drools Controller
* @throws IllegalArgumentException with invalid parameters
*/
@@ -117,7 +115,7 @@ public interface DroolsControllerFactory {
/**
* returns the current inventory of Drools Controllers.
- *
+ *
* @return a list of Drools Controllers
*/
public List<DroolsController> inventory();
@@ -208,7 +206,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
/*
* The Null Drools Controller for no maven coordinates is always here so when no
* coordinates present, this is the return point
- *
+ *
* assert (controllerCopy instanceof NullDroolsController)
*/
if (droolsControllers.containsKey(controllerId)) {
@@ -245,7 +243,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
/**
* find out decoder classes and filters.
- *
+ *
* @param properties properties with information about decoders
* @param topicEntities topic sources
* @return list of topics, each with associated decoder classes, each with a list of associated
@@ -313,7 +311,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
// 3. second the list of classes associated with each topic
String eventClasses = properties
- .getProperty(propertyTopicEntityPrefix + firstTopic
+ .getProperty(propertyTopicEntityPrefix + firstTopic
+ PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_SUFFIX);
if (eventClasses == null || eventClasses.isEmpty()) {
@@ -328,54 +326,14 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
for (String theClass : topicClasses) {
- // 4. third, for each coder class, get the list of field filters
+ // 4. third, for each coder class, get the filter expression
String filter = properties
- .getProperty(propertyTopicEntityPrefix + firstTopic
+ .getProperty(propertyTopicEntityPrefix + firstTopic
+ PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_SUFFIX
+ "." + theClass + PolicyEndPointProperties.PROPERTY_TOPIC_EVENTS_FILTER_SUFFIX);
- List<Pair<String, String>> filters = new ArrayList<>();
-
- if (filter == null || filter.isEmpty()) {
- // 4. topic -> class -> with no filters
-
- JsonProtocolFilter protocolFilter = JsonProtocolFilter.fromRawFilters(filters);
- PotentialCoderFilter class2Filters = new PotentialCoderFilter(theClass, protocolFilter);
- classes2Filters.add(class2Filters);
- continue;
- }
-
- // There are filters associated with the applicability of
- // this class for decoding.
- List<String> listOfFilters = new ArrayList<>(Arrays.asList(filter.split("\\s*,\\s*")));
-
- for (String nameValue : listOfFilters) {
- String fieldName;
- String regexValue;
-
- String[] nameValueSplit = nameValue.split("\\s*=\\s*");
- if (nameValueSplit.length <= 0 || nameValueSplit.length > 2) {
- // TODO warn
- // skip
- continue;
- }
-
- if (nameValueSplit.length == 2) {
- fieldName = nameValueSplit[0];
- regexValue = nameValueSplit[1];
- } else if (nameValueSplit.length == 1) {
- fieldName = nameValueSplit[0];
- regexValue = null;
- } else {
- // unreachable
- continue;
- }
-
- filters.add(new Pair<String, String>(fieldName, regexValue));
- }
-
- JsonProtocolFilter protocolFilter = JsonProtocolFilter.fromRawFilters(filters);
+ JsonProtocolFilter protocolFilter = new JsonProtocolFilter(filter);
PotentialCoderFilter class2Filters = new PotentialCoderFilter(theClass, protocolFilter);
classes2Filters.add(class2Filters);
}
@@ -408,7 +366,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
/**
* unmanage the drools controller.
- *
+ *
* @param controller the controller
*/
protected void unmanage(DroolsController controller) {