Nifi: how to convert multiple log file in one file?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Nifi: how to convert multiple log file in one file?

sally
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/
Reply | Threaded
Open this post in threaded view
|

Re: Nifi: how to convert multiple log file in one file?

Jeff
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 <[hidden email]>
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/
>