Nifi:如何在一个文件中转换多个日志文件?

时间:2017-12-18 13:19:11

标签: groovy apache-nifi

我有很多内部日志,我在nifi环境中编写自己的内容,我想在一个日志flowFile中输入所有这些数据,但这段代码拖曳Null指针异常我该怎么办?

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);
}

0 个答案:

没有答案