Search code examples
pythonrestapache-nifi

Processors without client_id in revision allows no PUT-updates via the REST-API


I want to update the state of a processor. I can successfully retrieve the current state of a processor with a GET request on /nifi-api/processors/proc_id.

I get the following JSON back:

{"revision":{"version":1},"id":"cd55-processor-id-03ab4","uri":" ..." ....

The problem occurs during the PUT on /processors/{id}/run-status when I try to write a new state back to Nifi - I receive the following error:

b'Node [....] is unable to fulfill this request due to: [3, cd55-processor-id-03ab4] 
    is not the most up-to-date revision. This component appears to have been modified'

My code:

# Get node for current version
response = requests.get(url_nifi_api + f'processors/{processor_id}'
                        , headers=header
                        , verify=False)
processor = json.loads(response.content)
# increment for new state
proc_version_inc = processor['revision']['version'] + 1 
put_dict = {"revision": {"version": proc_version_inc}, "state": new_state, "disconnectedNodeAcknowledged": True}  

payload = json.dumps(put_dict).encode('utf8')
response = requests.put(url_nifi_api + 'processors/' + processor_id + '/run-status', headers=header, data=payload)

So I figured the problem is that I need to pass clientId in the revision (despite the docs saying it is an optional attribute) - but the processor doesn't have a client-ID.

Here is my code with a client ID - this works for processors where a client-ID exists in the GET JSON.

processor= json.loads(requests.get(url_nifi_api + f'processors/{processor_id}'
                        , headers=header
                        , verify=False).content)
# get result for instance:  {"revision":{"clientId":"60b-00d0-client-id-37c","version":4}, ....

client_id = processor['revision']['clientId']
proc_version_inc = processor['revision']['version'] + 1  # in this example: 4+1
put_dict = {"revision": {"clientId": client_id, "version": proc_version_inc}, 
            "state": new_state, "disconnectedNodeAcknowledged": True}

The only difference between this and the other processor is, that the other processors has no clientId in the processor's GET JSON. But even if I explictely set clientId to an empty String (or copy it from a processor with an existing clientId), it just gives me the same error.

The only solution I found so far is to manually change the processor in the Web-UI, after which the processor has a client-id and the code works by . I really don't want to do this every time the error occurs. Does anyone have any ideas?


Solution

  • So, @yaprak was right in the comments - sending the un-incremented version number back worked. The behavior is a bit weird though, so I guess the easiest way is to never change the revision of a processor manually.

    1. If there exists a clientId and a version-number, then you can increment the version manually as much as you want.

    2. If there exists no clientId and only a version-number, then Nifi does not allow any incrementation of the versions.