NiFi Dynamic Script Executors
Work-in-Progress
The goal of this project is to enable processing NiFi FlowFiles using scripting languages.
- ExecuteJavaScript Execute supplied javaScript with arguments configured. Use case: JSON -> Mapping -> JSON
- ExecuteGroovy: Execute supplied groovy script with arguments configured.
- ExecuteGroovyLdap: Provide configured LDAP object to the script. Execute supplied groovy script with arguments configured. See Groovy LDAP
- ExecuteRemoteProcess: Similar to NiFi built-in ExecuteProcess but run on remote host. See Groovy SSH
- Manual: Download Apache NiFi binaries and unpack to a folder.
- On Mac: brew install nifi
# Assume you unpacked nifi-0.4.1-bin.zip to /Developer/Applications/nifi
./gradlew clean deploy -Pnifi_home=/Developer/Applications/nifi
On Mac
gradle clean deploy -Pnifi_home=/usr/local/Cellar/nifi/0.4.1/libexec
cd /Developer/Applications/nifi
./bin/nifi.sh start
./bin/nifi.sh stop
On Mac
# nifi start|stop|run|restart|status|dump|install
nifi start
nifi status
nifi stop
# Working Directory: /usr/local/Cellar/nifi/0.4.1/libexec
Upload the sample flow into NiFi and use test data and below javascript for testing:
function convert(val) {
var g = JSON.parse(val);
var d = {
widget: g.widget.window.title,
imageURI: g.widget.image.src
};
return JSON.stringify(d);
}
print("Hello from inside scripting!");
var fs = util.flowFileToString(flowFile, session);
log.error(fs);
var flowString = convert(fs);
log.error(flowString);
//flowFile = session.importFrom(buff, true, flowFile);
session.remove(flowFile);
flowFile = util.stringToFlowFile(flowString, session);
flowFile = session.putAttribute(flowFile, "JS", 2222 );
SSH Config DSL
remotes {
web01 {
role 'masterNode'
host = '192.168.1.5'
user = 'sumo'
password = 'demo'
knownHosts = allowAnyHosts
}
web02 {
host = '192.168.1.5'
user = 'sumo'
knownHosts = allowAnyHosts
}
}
Run DSL
ssh.run {
session(ssh.remotes.web01) {
result = execute 'uname -a'
}
}
gradle nifi-scripting:nifi-lang-groovy install
gradle nar
-
Follow steps NiFi Hadoop Library for MapR
-
Set auth login config in $NIFI_HOME/conf/bootstrap.conf
java.arg.15=-Djava.security.auth.login.config=/opt/mapr/conf/mapr.login.conf
- Support adding popular javaScript libraries (lodash.js, moment.js etc.,) via processor configuration.
- ExecuteRemoteProcess: add expression language support for RUN_DSL.
- Groovy Script
- java8-nashorn-tutorial
- Mapping Complex JSON Structures With JDK8 Nashorn
- Groovy SSH
- See document of Gradle SSH Plugin for details of DSL.
- Groovy Goodness: Store Closures in Script Binding