问题描述
我在使用Apache NiFi执行脚本处理器时遇到问题。
执行executeScript烹饪书教程之后 https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-2/ta-p/249018,我能够编写一个写入输出流的常规脚本。
我正在将Json字符串写入输出流。
但是在Nifi上执行时,出现以下链接中所示的错误:
https://imgur.com/jYgH8EY.png
下面是代码
import groovy.json.JsonBuilder
import org.apache.commons.io.IoUtils
import java.nio.charset.StandardCharsets
import org.apache.nifi.processor.io.StreamCallback
flowFile = session.get()
if(flowFile == null){
return;
}
def incomingFlowFileName = flowFile.getAttribute('filename')
def pathToIngestionScript = pathtobashscript.value
def command = '''
docker ps | grep 'visallo/dev' | awk '{print $1}'
'''
def containerId = ['bash','-c',command].execute().in.text
if(containerId.replaceAll("\\s","").length() != 0){
/* "docker exec -i " + container_id + " bash < " + path_to_bash_script */
"docker exec -i ${containerId} bash < ${pathToIngestionScript}".execute()
}else {
/*ingest data like a savage*/
}
def result = ["fileId":incomingFlowFileName.tokenize('*')[1],"status":"2"]
flowFile = session.write(flowFile,{outputStream ->
outputStream.write(new JsonBuilder(result).toPrettyString().getBytes(StandardCharsets.UTF_8))
} as StreamCallBack)
session.transfer(flowFile,REL_SUCCESS)
脚本执行空间中不存在org.apache.nifi.processor.io.StreamCallback
吗?
我正在运行Nifi 1.9.2
解决方法
您有as StreamCallBack
,但它是StreamCallback(无大写字母B)