Support Questions

Find answers, ask questions, and share your expertise

Start/Stop a NiFi Processor via REST API: Desired State is not set

avatar

Hi everyone,

I'm trying to use NiFis Rest API to start and stop a Processor, but evertime I get the response 

The desired state is not set

Here is my curl-Command which I use:

curl -k --header "Authorization: Bearer $token" -i -H 'Content-Type: application/json' -XPUT -d'{ "revision": { "version": 18, "clientId": "01891026-da00-199f-9dc9-ae3a37dce067" }, "status": { "runStatus": "RUNNING" }, "component": { "id": "0189100e-1e29-115c-ec96-b857cd155f4a", "state": "RUNNING" }, "id": "0189100e-1e29-115c-ec96-b857cd155f4a" }' https://localhost:8443/nifi-api/processors/0189100e-1e29-115c-ec96-b857cd155f4a/run-status

Has anyone an idea what's the problem?

Best regards

Maik

1 ACCEPTED SOLUTION

avatar
Super Guru

Hi @CommanderLaus ,

 

Are you sure that your post data is correct? It needs to be in the following format:

 

{
    "revision": {
	    "clientId": "value",
	    "version": 0,
	    "lastModifier": "value"
	},
    "state": "value",
    "disconnectedNodeAcknowledged": true
}

yours looks like this:

 

{
	"revision": {
		"version": 18,
		"clientId": "01891026-da00-199f-9dc9-ae3a37dce067"
	},
	"status": {
		"runStatus": "RUNNING"
	},
	"component": {
		"id": "0189100e-1e29-115c-ec96-b857cd155f4a",
		"state": "RUNNING"
	},
	"id": "0189100e-1e29-115c-ec96-b857cd155f4a"
}

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

If that helps please accept solution.

Thanks

View solution in original post

4 REPLIES 4

avatar
Super Guru

Hi @CommanderLaus ,

 

Are you sure that your post data is correct? It needs to be in the following format:

 

{
    "revision": {
	    "clientId": "value",
	    "version": 0,
	    "lastModifier": "value"
	},
    "state": "value",
    "disconnectedNodeAcknowledged": true
}

yours looks like this:

 

{
	"revision": {
		"version": 18,
		"clientId": "01891026-da00-199f-9dc9-ae3a37dce067"
	},
	"status": {
		"runStatus": "RUNNING"
	},
	"component": {
		"id": "0189100e-1e29-115c-ec96-b857cd155f4a",
		"state": "RUNNING"
	},
	"id": "0189100e-1e29-115c-ec96-b857cd155f4a"
}

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

If that helps please accept solution.

Thanks

avatar

Hi @SAMSAL ,

thank you very much, you where absolutely right. I tried so many solutions from other members from other topics, that I completly messed up my own one.

Nice one, thank's again

Maik

avatar

Hello again,

if I start the processor via API, the "version" of the processor counts up. In my case above from version 18 to version 19. 

If I want to stop the processor now via API, I have to submit the new version 19.

 

Is it possible to start/stop the processoer without the up-to-date version? Or is it possible, that I get the current version only via API, save it as a variable (e.g. $version) and use this variable in my next API-Call?

 

Greetings

Maik

avatar
Super Guru

Hi @CommanderLaus ,

If you do anything manually with the processor you are trying to change its Running State through the API, then yes the revision will be updated. In my case what I do is basically the first API InvokeHttp is to get the latest revision using the following GET API:

 

https://localhost:8443/nifi-api/processors/${pipeline.start.processor.id}

 

This will give the following response where you can parse the latest "version" value using something like EvaluateJsonPath processor and store the value in an attribute:

 

{
    "revision": {
	    "clientId": "value",
	    "version": 0,
	    "lastModifier": "value"
	},
    "id": "value",
    "uri": "value",
    "position": {…},
    "permissions": {…},
    "bulletins": [{…}],
    "disconnectedNodeAcknowledged": true,
    "component": {…},
    "inputRequirement": "value",
    "status": {…},
    "operatePermissions": {…}
}

 

Then use extracted version attribute to build the next API post Body , for example in my case I use ReplaceText processor to generate the post body :

 

{
    "revision": {
	    "clientId": "${pipeline.start.processor.id}",
	    "version": ${processorVersion}
	   
	},
    "state": "...",
    "disconnectedNodeAcknowledged": true
	
}

 

Hope that helps.