nifi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff <jtsw...@gmail.com>
Subject Re: Nifi: how to convert multiple log file in one file?
Date Wed, 03 Jan 2018 19:00:38 GMT
Hello Sally,

There's a utility [1] written by Matt Burgess that might help you debug
your scripts more quickly, without having to run them in NiFi.  I haven't
tested your code, but please make sure your usage of whitespace isn't
causing any issues. The following code looks like there might be a newline
after the return:
        if( size == ff.getAttribute('fileSize') ){ n++; return
FlowFileFilterResult.ACCEPT_AND_CONTINUE;
        }

Groovy does not require semicolons to terminate statements, and I am no
groovy expert, but I believe newlines do terminate statements.

Also, verify that the "fileSize" attribute exists on the flowfiles you're
processing.  One of the ways you can do that is through the Provenance UI.

[1] https://github.com/mattyb149/nifi-script-tester

On Wed, Jan 3, 2018 at 10:45 AM sally <salome.tkhilaishvili@gmail.com>
wrote:

> I have many internal log , which i write myself inside nifi environment, i
> want to input all this data inside one log flowFile, but this code trows
> Null pointer exception what should i cahnge?
>
> import java.nio.charset.StandardCharsets;
> import org.apache.commons.io.IOUtils;
> import org.apache.nifi.processor.FlowFileFilter;
> import groovy.json.JsonSlurper;
> import groovy.json.JsonBuilder;
>
> def flowFile = session.get();
> def  n=0;
>
> if(!flowFile)return
> def size = flowFile.getAttribute('fileSize');
> int value = size as Integer;
> log.error("g");
> if((value/338)>1){
> def ffList = session.get(new FlowFileFilter(){
>     public FlowFileFilterResult filter(FlowFile ff) {
>
>         if( size == ff.getAttribute('fileSize') ){ n++; return
> FlowFileFilterResult.ACCEPT_AND_CONTINUE;
>         }
>         else{
>         return FlowFileFilterResult.REJECT_AND_CONTINUE
>         }
>     }
>
> })
>
> session.transfer(ffList[n-1],REL_SUCCESS);
> session.remove( ffList[0..-2] )
> session.remove(flowFile);
>
> }
> else{
>
> session.transfer(flowFile,REL_SUCCESS);
> }
>
>
>
> --
> Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message