Support Questions

Find answers, ask questions, and share your expertise

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

6 REPLIES 6

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
New Member

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 Member

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)

avatar
New Contributor

Hello!

I'm newbe in NiFi and Groovy. I hope you can help me.

Related Topic: I found here – "Solved: Re: Get the processor-group name in NIFI flow - Cloudera Community - 213662" (2018) – very interestion solution! Thank to @mburges

I have related question: I want to build with Groovy dictionary/cache for every proceccor where key = Proccesor ID, value = "bread crumbs" (full path to processor from root canvas – the string like this: "PG1_Name" / "PG2_(Child_of_PG1)_Name" / "PG3_(Child_of_PG2)_Name" .

The quesions are:

  1. How to get list of Process Groups in the root and in Each PG?
  2. How to get list of Processors in Each PG?
  3. How to organize in Groovy cycles for scan PGs?
  4. How to save / read data in/from Groovy dictionary /  NiFi cache? 

Thanks in advance for any help! 

avatar
Master Mentor

@IgorSpryzhkov 

You have asked a new unrelated question in an older post which already has an accepted answer.   You would get better traction/visibility in the community of you were to start a new community question instead.  

Thank you,

Matt