mattyb149 commented on a change in pull request #3886: NIFI-6855 - added action 
type enforcement option for handlers
URL: https://github.com/apache/nifi/pull/3886#discussion_r347481514
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/main/java/org/apache/nifi/rules/handlers/AbstractActionHandlerService.java
 ##########
 @@ -16,22 +16,54 @@
  */
 package org.apache.nifi.rules.handlers;
 
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nifi.annotation.lifecycle.OnEnabled;
+import org.apache.nifi.components.PropertyDescriptor;
 import org.apache.nifi.context.PropertyContext;
 import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.reporting.InitializationException;
 import org.apache.nifi.rules.Action;
 import org.apache.nifi.rules.PropertyContextActionHandler;
 
 import java.util.Map;
 
 public abstract class AbstractActionHandlerService extends 
AbstractControllerService implements PropertyContextActionHandler {
 
+    protected String enforceActionType;
+
     public static enum DebugLevels {
         trace, debug, info, warn, error
     }
-    public abstract void execute(Action action, Map<String, Object> facts);
+
+    public static final PropertyDescriptor ENFORCE_ACTION_TYPE = new 
PropertyDescriptor.Builder()
+            .name("action-handler-enforce-type")
+            .displayName("Enforce Action Type")
+            .required(false)
+            .description("The Action Type that should be supported by this 
handler.  If provided any other type an " +
+                    "exception will be thrown")
+            .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
+            .build();
+
+    public void execute(Action action, Map<String, Object> facts){
+        if(actionTypeNotSupported(action)){
+            throw new UnsupportedOperationException("This Action Handler does 
not support actions with the provided type: " + action.getType());
 
 Review comment:
   Should we just ignore the action if it is not supported? For example, using 
the test file `test_nifi_rules.yml` I have a LOG and ALERT actions. If I am not 
using a correctly-configured ActionHandlerLookup and instead using either a 
single LogHandler or AlertHandler, then when both rules fire, I will get an 
exception on the handler. I was picturing using this property to "suppress" or 
filter the fired rules based on the configured handler, so only the LOG rules 
would actually fire if I my action handler is a LogHandler with Enforce Types 
set to LOG. What do you think?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to