Created 02-12-2018 02:26 PM
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
Created 02-12-2018 04:14 PM
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)
Created 02-12-2018 04:14 PM
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)
Created 05-15-2018 10:41 AM
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.
Created 05-15-2018 02:22 PM
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).
Created 06-22-2018 02:16 PM
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)