Exploring Nifi Rest API with Stopping and Starting a processor and Process-group

Shubham Kanungo
4 min readJun 28, 2020

In this blog, I will try to explain one of Nifi Funcationlity (Rest API) which is used for purposes like stopping a processor, starting a processor changing state of the processor, service, processor group, input ports, etc.

Definition according to Documentation

The Rest API provides programmatic access to command and controls a NiFi instance in real-time. Start and stop processors, monitor queues, query provenance data, and more.

Prerequisite -Nifi is installed. In my case, I have installed nifi on port 8081 but by default, it will be installed on port 8080.

Scenario 1- We need to start a processor with API

In the First basic flow, we have generateFlowFile processor and we need to start this processor.

Solution

First, we try to get the present condition of our processor

we will hit flowing get API.

http://localhost:8081/nifi-api/processors/f66a3da2-0172-1000-c4a5-4d04f80924c3

In which f66a3da2–0172–1000-c4a5–4d04f80924c3 is our processor id

When we hit the above API following is the response.

{
“revision”: {
“version”: 13
},
“id”: “f66a3da2–0172–1000-c4a5–4d04f80924c3”,
“uri”: “http://localhost:8081/nifi-api/processors/f66a3da2-0172-1000-c4a5-4d04f80924c3",
“bulletins”: [],
“name”: “GenerateFlowFile”,
“type”: “org.apache.nifi.processors.standard.GenerateFlowFile”,
“bundle”: {
“group”: “org.apache.nifi”,
“artifact”: “nifi-standard-nar”,
“version”: “1.11.3”
},
“state”: “STOPPED”,
“style”: {},
“relationships”: [{
“name”: “success”,
“description”: “”,
“autoTerminate”: false
}],
“validationStatus”: “VALID”,
“extensionMissing”: false,

“operatePermissions”: {
“canRead”: true,
“canWrite”: true
}
}

There are a lot of properties I have discarded because they are not relevant.

In the above JSON message, we need to pay attention to two properties.

  1. Version- Whenever we change some properties of processors, nifi will update the processor’s version.
  2. State- By name it is clear that it shows us the current state of the processor. For example stopped, running.

Now we have a version as well as the state of the processor. Now we will put a request to start the processor. For this case, we will use run-status PUT API.

http://localhost:8081/nifi-api/processors/f66a3da2-0172-1000-c4a5-4d04f80924c3/run-status

Body- { “revision”: {“version”:13}, “state”: “RUNNING”}

Now our version would be changed.

As we know how to stop a processor with Normal API, Now we try to stop a processor-group with Nifi flow only.

Scenario 2-Stopping a process-group with Nifi flow

Since we are hitting API, We need to use invokeHttp processor.

Algorithm of the flow we are going to use

  1. Get the current version of the processor.
  2. Create a JSON body for PUT request with state=” stopped”.
  3. Hit the nifi PUT API with the JSON body.
  4. Enjoy!!!
Flow for stopping a processor

Flow Properties

  1. GenerateFlowfile — This processor is used to create a flow file for creating an API request.

2. Get_Processor_Details(InvokeHttp)

This processor is used for getting details of the flow.

Attributes(hidden in Screen Shot):

HTTP Method- GET

Remote URL-http://localhost:8081/nifi-api/process-groups/${processor_group_id}

3. Extract_status_from_processor_group(EvaluateJsonPath)

This processor is used for creating JSON PUT request to stop to processor group.

4. create_JSON_message_for_PUT_request(ReplaceText)

This processor is used to update the id of the processor and state of the processor group.

5. Invoke_http_put_request(InvokeHTTP)

Now we just need to hit the Below API.

http://localhost:8081/nifi-api/flow/process-groups/${processor_group_id}

That’s it Now our process group will be stopped.

There are much more use case and Apache have provided many API. But Documentation is not available in abundance.

I have used below link for all POC’s

https://nifi.apache.org/docs/nifi-docs/rest-api/index.html

I hope this blog will help you with Nifi API. I have worked on Nifi API. If you need any help you can let me know I will create another blog for related topics.

--

--