Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Building Custom NAR - How to add config sub directory into NAR?

avatar
Explorer

HI,

I have built a custom processor that uses another java library. This 3rd party JAR requires one sub directory ./data containing a file named config.ini.

I put the NAR into the ./extensions subfolder of NiFi. When NiFi starts up, it unpacks the NAR  into the folder 

nifi/work/nar/extensions/my-processor-nar-1.0.nar-unpacked/

This folder contains a subfolder NAR-INF.

And this NAR-INF is the location where my subfolder "data" needs to be copied. When I manually copy the folder with the containing config file into NAR-INF, the processor works fine.

But after the next restart of NiFi the subfolder is missing again.

I need the structure of the unpacked NAR to include this:

nifi/work/nar/extensions/my-processor-nar-1.0.nar-unpacked/data/config.ini

Does anyone have an example how I can build the NAR so that this subfolder and file are included?
Like an example pom.xml snippet?

Cheers,
Karsten

1 ACCEPTED SOLUTION

avatar
Master Collaborator

Hello @karsten, 

You should not include anything under the unpacked folder, after a restart it will always remove the content and the new unpack will put only the nar content. 

Now, you can use the resources path for this, for example: 

├── your-nifi-custom-processor
│   ├── pom.xml
│   └── src
│       └── main
│           ├── java
│           ├── resources
│               └── data
│           │       └── config.ini
│           └── webapp

This is based on the examples here: https://nifi.apache.org/docs/nifi-docs/html/developer-guide.html

You should include all the information on your pom.xml. The resources part should look like this: 

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*</include>
            </includes>
        </resource>
    </resources>

Also found this interesting blog with the same explanation: https://medium.com/@mr.sinchan.banerjee/nifi-custom-processor-series-part-1-writing-your-first-custo...
This is not Cloudera or NiFi official, but it could help you. 


Regards,
Andrés Fallas
--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs-up button.

View solution in original post

2 REPLIES 2

avatar
Master Collaborator

Hello @karsten, 

You should not include anything under the unpacked folder, after a restart it will always remove the content and the new unpack will put only the nar content. 

Now, you can use the resources path for this, for example: 

├── your-nifi-custom-processor
│   ├── pom.xml
│   └── src
│       └── main
│           ├── java
│           ├── resources
│               └── data
│           │       └── config.ini
│           └── webapp

This is based on the examples here: https://nifi.apache.org/docs/nifi-docs/html/developer-guide.html

You should include all the information on your pom.xml. The resources part should look like this: 

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*</include>
            </includes>
        </resource>
    </resources>

Also found this interesting blog with the same explanation: https://medium.com/@mr.sinchan.banerjee/nifi-custom-processor-series-part-1-writing-your-first-custo...
This is not Cloudera or NiFi official, but it could help you. 


Regards,
Andrés Fallas
--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs-up button.

avatar
Explorer

Thank you André,

This led to the right direction.
Since the configuration file is required by a third party JAR that I don't build, the way to solve it was to add a src/main/resources path to the myProcessor-nar directory instead of the myProcessor-processor directory. The nar directory doesn't include a src/main/java but you can nevertheless add a src/main/resources path and add subfolders/files to it, e.g. NAR-INF/data/config.ini.

Maven will copy automatically everything under src/main/resources to the target, hence it's not necessary to add the resources snippet to the pom.xml.

So, now NiFi's work/nar/extensions/myProcessor-nar-1.0.nar-unpacked/NAR-INF folder contains my subfolder/file data/config.ini every time NiFi unpacks the NAR.

I found this article helpful that explains the parts of a NAR and the three pom.xml files: https://www.javahotchocolate.com/notes/nifi-project.html

Thanks @vafs!