I am having issues with Apache NiFi execute Script processor.
Following the executeScript cook book tutorial https://community.cloudera.com/t5/Community-Articles/ExecuteScript-Cookbook-part-2/ta-p/249018, I was able to write a groovy script that writes to the output stream.
I am writing a Json string to the the output stream.
However on execution on Nifi, I get an error as depicted on the following link:
https://imgur.com/jYgH8EY.png
Below is the code
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)
Doesn't org.apache.nifi.processor.io.StreamCallback exist in the Script execution space?
I am running Nifi 1.9.2