Github user mattyb149 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1662#discussion_r124124963
--- Diff:
nifi-nar-bundles/nifi-groovyx-bundle/nifi-groovyx-processors/src/main/java/org/apache/nifi/processors/groovyx/ExecuteGroovyScript.java
---
@@ -0,0 +1,468 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.groovyx;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.nifi.annotation.behavior.Restricted;
+import org.apache.nifi.annotation.behavior.DynamicProperty;
+import org.apache.nifi.annotation.behavior.EventDriven;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.annotation.lifecycle.OnStopped;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.ControllerService;
+import org.apache.nifi.dbcp.DBCPService;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.AbstractProcessor;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.ProcessorInitializationContext;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.codehaus.groovy.control.CompilerConfiguration;
+import org.codehaus.groovy.runtime.ResourceGroovyMethods;
+import org.codehaus.groovy.runtime.StackTraceUtils;
+
+import org.apache.nifi.processors.groovyx.sql.OSql;
+import org.apache.nifi.processors.groovyx.util.Files;
+import org.apache.nifi.processors.groovyx.util.Validators;
+import org.apache.nifi.processors.groovyx.flow.GroovyProcessSessionWrap;
+
+import groovy.lang.GroovyShell;
+import groovy.lang.Script;
+
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.ValidationContext;
+
+@EventDriven
+@Tags({"script", "groovy", "groovyx"})
+@CapabilityDescription(
+ "Experimental Extended Groovy script processor. The script is
responsible for "
+ + "handling the incoming flow file (transfer to SUCCESS or remove,
e.g.) as well as any flow files created by "
+ + "the script. If the handling is incomplete or incorrect, the
session will be rolled back.")
+@Restricted("Provides operator the ability to execute arbitrary code
assuming all permissions that NiFi has.")
+@SeeAlso({})
+@DynamicProperty(name = "A script engine property to update",
+ value = "The value to set it to",
+ supportsExpressionLanguage = true,
+ description = "Updates a script engine property specified by the
Dynamic Property's key with the value "
+ + "specified by the Dynamic Property's value. Use `CTL.`
to access any controller services.")
+public class ExecuteGroovyScript extends AbstractProcessor {
+ public static final String GROOVY_CLASSPATH = "${groovy.classes.path}";
+
+ private static final String PRELOADS = "import
org.apache.nifi.components.*;" + "import org.apache.nifi.flowfile.FlowFile;" +
"import org.apache.nifi.processor.*;"
+ + "import
org.apache.nifi.processor.FlowFileFilter.FlowFileFilterResult;" + "import
org.apache.nifi.processor.exception.*;" + "import
org.apache.nifi.processor.io.*;"
+ + "import org.apache.nifi.processor.util.*;" + "import
org.apache.nifi.processors.script.*;" + "import
org.apache.nifi.logging.ComponentLog;";
+
+ public static final PropertyDescriptor SCRIPT_FILE = new
PropertyDescriptor.Builder().name("Script File").required(false)
+ .description("Path to script file to execute. Only one of
Script File or Script Body may be
used").addValidator(Validators.createFileExistsAndReadableValidator())
+ .expressionLanguageSupported(true).build();
+
+ public static final PropertyDescriptor SCRIPT_BODY = new
PropertyDescriptor.Builder().name("Script Body").required(false)
+ .description("Body of script to execute. Only one of Script
File or Script Body may be
used").addValidator(StandardValidators.NON_EMPTY_VALIDATOR).expressionLanguageSupported(false)
+ .build();
+
+ public static String[] VALID_BOOLEANS = {"true", "false"};
+ public static final PropertyDescriptor REQUIRE_FLOW = new
PropertyDescriptor.Builder().name("Requires flow file")
+ .description("If `true` then flowFile variable initialized and
validated. So developer don't need to do flowFile = session.get(). If `false`
the flowFile variable not initialized.")
+
.required(true).expressionLanguageSupported(false).allowableValues(VALID_BOOLEANS).defaultValue("false").build();
+
+ public static String[] VALID_FAIL_STRATEGY = {"rollback", "transfer to
failure"};
+ public static final PropertyDescriptor FAIL_STRATEGY = new
PropertyDescriptor.Builder()
--- End diff --
This also seems to try to automate "normal" handling of flow files, but
removes a little flexibility. Inside the script, the user has the ability to
roll back (via a thrown exception) or fail when desired. If the idea is to
allow the flow files to be transferred to failure in the event of an exception
in the script itself (rather than one caused by bad input, for example), then
it might be confusing for the user to know why the flow file was transferred to
failure (i.e. is the data bad or is the script bad). Maybe I'm just
misunderstanding the intent, could you clarify for me?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---