Github user dlukyanov commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1662#discussion_r124203242
  
    --- 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")
    --- End diff --
    
    with `require flow file = false` you can do any session.get(...) in code
    i agree it's not a big win to use `require flow file = true`. 
    i thought to add more values like `batch` and use `batch_size` custom 
property.
    
    a short entry about `require flow file` and `fail strategy`:
    we were migrating an 10years old j2ee project to nifi.  100k+ producers and 
100k consumers of the files with different formats (xml,csv,json,pdf,tiff,...). 
you can imagine a huge amount of specific code, libraries, ... to cover all 
specific things we used groovy script. and in 95% we used just `session.get(0)` 
(require flow file)
    
    and in 80%  `rollback` strategy  on exception is ok (btw it's a standard 
behavior of existing execute script processor). without try-catch the code just 
simpler. in case when using `rollback` you can do any custom try-catch in your 
code. and we used custom try-catch in 1% of cases.
    
    transfer to `failure` in code usually becomes a nightmare in script 
especially if you want to transfer the original file - and in our case it was 
always original. 
    
    so, both features are not removing customization ability. 
    
    about the `require flowfile` - i agree that it could be removed.
    
    but about `fail strategy` - i believe it's very useful. maybe the items in 
select should be renamed and more clarified... but i'd suggest to keep it.
    



---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to