Thank you Mike for the thought on it, we'll consider that approach - in 
particular, it does look useful that the (compiled) code is reloaded without 
having to restart NiFi.

For many of our uses of scripted code, a theoretical advantage is avoiding 
having to install binaries or add things to the filesystem. It's unfortunate 
that any significant script will almost certainly need some extra library, such 
as those which make up NiFi itself, but the script cannot use that. I wonder 
how 'stateless' NiFi will be coping with this, as the target runtime operating 
system filesystems will need to have the script dependencies available. 

Regards,

 Nick

-----Original Message-----
From: Mike Thomsen <[email protected]> 
Sent: 17 November 2020 1:31 PM
To: [email protected]
Subject: Re: ScriptedReader - how to reuse Java libraries from 
nifi-standard-nar?

I would recommend creating a fat jar that has precisely what you need and 
referencing that. That's a pattern my team's been using for a while to get near 
custom NAR functionality through ExecuteScript.
Here's an overview of what it looks like:

https://mikethomsen.github.io/posts/2020/11/06/taking-executescript-to-the-next-level-with-fat-jars/

You should be able to copy and paste the Maven pom.xml and update it to match 
your needs pretty easily. Make sure to configure any NiFi api jars as 
"provided" scope.

On Tue, Nov 17, 2020 at 7:23 AM Piper, Nick <[email protected]> wrote:
>
> I've implemented a groovy ScriptedReader , and wish to reuse jar libraries 
> which are already part of NiFi from my script.
>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__nifi.apache.org_d
> ocs_nifi-2Ddocs_components_org.apache.nifi_nifi-2Dscripting-2Dnar_1.5.
> 0_org.apache.nifi.record.script.ScriptedReader_index.html&d=DwIFaQ&c=H
> 50I6Bh8SW87d_bXfZP_8g&r=qtiHf3oxfzao0QlKv0Pa4nnORYuepkcxMMbn7wBUyq0&m=
> 2bdrSUoix61CO2woFcsKtrz6Ajj4aH6ZlQqnZjJC2Io&s=X5wC0G47W5cF1RevN2DF9MkU
> AKmIuSa4r-5SOnqZno4&e=
>
> The script can be seen at 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__gist.github.com_p
> ipern_2d67fbc0a4225cf1b42d1fff832c2c54&d=DwIFaQ&c=H50I6Bh8SW87d_bXfZP_
> 8g&r=qtiHf3oxfzao0QlKv0Pa4nnORYuepkcxMMbn7wBUyq0&m=2bdrSUoix61CO2woFcs
> Ktrz6Ajj4aH6ZlQqnZjJC2Io&s=2KmU08qgvlzGeJbOFbGpHWXfrxcZTfyG8I6UdAxp9cs
> &e=
>
> My script needs some of the 'jar files' which are present in 
> nifi-standard-nar. Is there a way I can reuse those already inside that nar 
> file? Otherwise I'll have to unpack the nar, place the jar files in some 
> other folder, and refer to that folder in 'Module Directory' - on every 
> machine in the NiFi cluster. I'm looking for maybe some way to have my goovy 
> script use a different classloader (?) or somehow reuse the existing jar 
> files inside that nar file. Maybe it would be reliable to predict the 'work' 
> folder and look for unpacked nar files in there...
>
> Many thanks,
>
>  Nick

Reply via email to