Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Get the processor-group name in NIFI flow

avatar
Expert Contributor

Hi,

I need to get the processor-group name in my NIFI flow.

I could hardcode it in updateAttribute, but would prefere to get it dynamilly

Is that possible using expression langugage or executescript

1 ACCEPTED SOLUTION

avatar
Master Guru

It is possible with ExecuteScript and Groovy if you don't have a SecurityManager set on the JVM that would prevent Groovy from getting at the ProcessorNode which is a private member variable of the StandardProcessContext. The following script can be used in ExecuteScript to add the parent process group ID as an attribute to an incoming flow file:

def flowFile = session.get()
if(!flowFile) return
processGroupId = context.procNode?.processGroupIdentifier ?: 'unknown'
flowFile = session.putAttribute(flowFile, 'processGroupId', processGroupId)
session.transfer(flowFile, REL_SUCCESS)

View solution in original post

4 REPLIES 4

avatar
Master Guru

It is possible with ExecuteScript and Groovy if you don't have a SecurityManager set on the JVM that would prevent Groovy from getting at the ProcessorNode which is a private member variable of the StandardProcessContext. The following script can be used in ExecuteScript to add the parent process group ID as an attribute to an incoming flow file:

def flowFile = session.get()
if(!flowFile) return
processGroupId = context.procNode?.processGroupIdentifier ?: 'unknown'
flowFile = session.putAttribute(flowFile, 'processGroupId', processGroupId)
session.transfer(flowFile, REL_SUCCESS)

avatar
Explorer

Hi @Matt Burgess, your solution works really fine, thanks.

I was trying to see where procNode property was defined to see what else can be get from there but I am unable to find it.

Do you know where is this information?

Thanks.

avatar
Master Guru

It comes from knowing that the ProcessContext passed into the script is actually a StandardProcessContext which has some variables you can get at with Groovy (provided there is no SecurityManager as mentioned).

avatar
New Contributor

The process group name can actually be found with the attached groovy code:

def flowFile = session.get()
if(!flowFile) return
processGroupName = context.procNode?.getProcessGroup().getName()
flowFile = session.putAttribute(flowFile, 'processGroupName', processGroupName)
session.transfer(flowFile, REL_SUCCESS)