Reputation: 313
I launched a container of apache/nifi, built, and configured a flow.
I'd like to somehow save that flow off somewhere, so that it can be loaded into a new docker image running Nifi.
Such that, a 'user' only has to do 'docker run....' and an instance of nifi will be launched, the flow loaded, and started.
It's not clear to me what files (nar, xml, etc...) need to be made available to the image a user is to run.
Upvotes: 1
Views: 2591
Reputation: 43
You could use the nifi-toolkit to deploy flows and process groups to your Apache NiFi instance without having to rely on the GUI.
https://nifi.apache.org/docs/nifi-docs/html/toolkit-guide.html
This setup required you having:
Here is a working example (provided that the hostname of your Apache NiFi-Registry container is nifi-registry and its port the default 18080) based on an empty Apache NiFi instance and Nifi-Registry. Tested on Apache NiFi 1.12.1.
Firstly you need to generate a JSON file for your flow through the Apache Registry.
/opt/nifi/nifi-toolkit-current/bin/cli.sh nifi create-reg-client -rcn registry -rcu http://nifi-registry:18080
Create a Process Group that will contain your flow. Right click on it and click on "Version" and "Start Version Control". This will save your flow inside the NiFi Registry. Work on your flow through the GUI and when you are ready, right click on your process group and commit your last changes. Now you will need to export the JSON of your flow from the registry.
/opt/nifi/nifi-toolkit-current/bin/cli.sh registry export-flow-version -u http://nifi-registry:18080 -f <flowid> -fv <flowversion> > <json_file>
Now that your JSON flow is ready, you are ready to deploy it on a fresh environment.
/opt/nifi/nifi-toolkit-current/bin/cli.sh registry create-bucket -u http://nifi-registry:18080 -bn <bucketname>
/opt/nifi/nifi-toolkit-current/bin/cli.sh registry create-flow -u http://nifi-registry:18080 -b <bucketid> -fn <flowname>
/opt/nifi/nifi-toolkit-current/bin/cli.sh registry import-flow-version -u http://nifi-registry:18080 -f <flowid> -i <json_file>
/opt/nifi/nifi-toolkit-current/bin/cli.sh nifi pg-import -b <bucketid> -f <flowid> -fv <flowversion>
/opt/nifi/nifi-toolkit-current/bin/cli.sh nifi pg-enable-services -pgid <processgroupid>
/opt/nifi/nifi-toolkit-current/bin/cli.sh nifi pg-start -pgid <processgroupid>
Please keep in mind that Apache NiFi should be up and running before executing these commands. If you are planning on embedding these instructions in the Dockerfile, some logic that waits for the service to be up should be implemented.
You might also take a look at this Python wrapper for the NiFi Toolkit:
https://github.com/Chaffelson/nipyapi
Lastly, Apache NiFi also provides some REST APIs that might help you:
https://nifi.apache.org/docs/nifi-docs/rest-api/index.html
Upvotes: 2
Reputation: 1771
if you have nothing custom you can save the flow.xml.gz
from the /conf
directory to save the flow.
if you also want to save the content flowfile or current flowfile, you should also save the flowfile repository
and content repository
if you have customs processors you should save the nar in lib
directory.
everything should be present in the nifi directory before starting it.
Upvotes: 2