Yeskay
Yeskay

Reputation: 53

NiFi How to get the current processor Name and Processor group name through the custom processor using (Java)

I'm Creating the NiFi Custom processor using Java, one of the requirement is to get the previous processor name and processor group (like a breadcrumb) using java code.

Upvotes: 2

Views: 2542

Answers (2)

Mallik
Mallik

Reputation: 196

I faced this some time back. I used InvokeHTTP processor and used nifi-api/process-groups/${process_group_id} Web Service

This is how I implemented:

  1. Identify the process group where the error handling should be done. [Action Group]
  2. Create a new process group [Error Handling Group] next to the Action Group and add relationship to transfer files to Error Handling Group.
  3. Use the InvokeHTTP processor and set HTTP Method to GET
  4. Set Remote URL to http://{nifi-instance}:{port}/nifi-api/process-groups/${action_group_process_group_id}
  5. You will get response in JSON which you will have to customize according to your needs

Please let me know if you need the XML file that I am using. I can share that. It just works fine for me

Upvotes: 0

mattyb
mattyb

Reputation: 12103

The previous processor name and process group name is not immediately (nor meant to be) available to processors, can you explain more about your use case? You can perhaps use a SiteToSiteProvenanceReportingTask to send provenance information back to your own NiFi instance (an Input Port, e.g.) and find the events that correspond to FlowFiles entering your custom processor, the events should have the source (previous) processor and destination (your custom) processor.

If instead you code your custom processor using InvokeScriptedProcessor with Groovy for example, then you can "bend the rules" and get at the previous processor name and such, as Groovy allows access to private members and you can assume the implementation of the ProcessContext in onTrigger is an instance of StandardProcessContext, so you can get at its members which include upstream connections and thus the previous processor. For a particular FlowFile though, I'm not sure you can use this approach to know which upstream processor it came from.

Alternatively, you could add an UpdateAttribute after each "previous processor" to set attribute(s) with the information about that processor, but that has to be hardcoded and applied to every corresponding part of the flow.

Upvotes: 1

Related Questions