nipyapi icon indicating copy to clipboard operation
nipyapi copied to clipboard

Getting error Invalid value for `state` (RUN_ONCE), must be one of ['RUNNING', 'STOPPED', 'DISABLED']

Open poopae8055 opened this issue 1 year ago • 14 comments

  • Nipyapi version: 0.20.0
  • NiFi version: N/A
  • NiFi-Registry version: N/A
  • Python version: 3.12
  • Operating System: N/A

Description

because PUT/processors/{id}/run-statusUpdates the run state of a processor api of nifi allow the four value states: RUNNING, STOPPED, DISABLED, RUN_ONCE https://nifi.apache.org/docs/nifi-docs/rest-api/index.html#:~:text=about%20a%20processor-,PUT,Updates%20run%20status%20of%20a%20processor,-GET

Screenshot 2567-09-28 at 21 21 27

but after I use i got error Invalid value for state (RUN_ONCE), must be one of ['RUNNING', 'STOPPED', 'DISABLED'] nipyapi.nifi.apis.processors_api.ProcessorsApi( api_client=nipyapi.config.nifi_config.api_client).update_run_status( id=processor_id, body=data ) So pls help allow RUN_ONCE state for update_run_status function as well. Thank you in advance.

Urgency: Medium

poopae8055 avatar Sep 28 '24 14:09 poopae8055

The version of NIFI is important here, and missing. Please include the version of NIFI you are talking to.

ottobackwards avatar Sep 28 '24 21:09 ottobackwards

Check and see if it is this issue: https://github.com/Chaffelson/nipyapi/issues/309

ottobackwards avatar Sep 28 '24 21:09 ottobackwards

The version of NIFI is important here, and missing. Please include the version of NIFI you are talking to.

Oh sorry. i use NIfi version 1.27.0.

poopae8055 avatar Sep 29 '24 02:09 poopae8055

Check and see if it is this issue: #309

Yes. It's similar but I would like to use update_run_status_with_http_info this function to call this api>>> api_client.call_api('/processors/{id}/run-status', 'PUT', from this file https://github.com/Chaffelson/nipyapi/blob/main/nipyapi/nifi/apis/processors_api.py but still get the error not allow run_once or you have other ways pls help suggest.

poopae8055 avatar Sep 29 '24 02:09 poopae8055

I cannot see how this can be happening with the versions that you are reporting. The nipyapi model processor runtime status entity has RUN_ONECE, and the nifi processor runtime entity has it as well ( from my PR ). It looks like the generation is correct etc. Can you try to do it with curl and see if you get the same issues? @Chaffelson ?

ottobackwards avatar Sep 30 '24 01:09 ottobackwards

https://github.com/Chaffelson/nipyapi/blob/ca5cdc8a1f076557058b3773428520d938f2d7b7/nipyapi/nifi/models/processor_run_status_entity.py#L104

ottobackwards avatar Sep 30 '24 01:09 ottobackwards

update_run_status takes a ProcessorRunStatusEntity object not just the string "RUN_ONCE", are you passing that?

ottobackwards avatar Sep 30 '24 01:09 ottobackwards

I suspect you are right @ottobackwards - possibly we should add a check in the mustache templates that we are getting the expected object and not a plain String, as that comes up a lot.

If @poopae8055 can share their sample code of how they're making the call we could confirm if this is what is happening here.

Chaffelson avatar Sep 30 '24 08:09 Chaffelson

Maybe real type hints would help?

ottobackwards avatar Sep 30 '24 10:09 ottobackwards

First of all, thank you for your suggestion and your time. I'm just starting to learn to code, so I may make some mistakes. anyway the below is my some current code.

processor_id='9b78c4dc-cb4b-3f04-2bc3-6761487ee6ee'

response = self.update_process_state(processor_id, "RUN_ONCE")

     processor_res = nipyapi.nifi.apis.processors_api.ProcessorsApi(
         api_client=nipyapi.config.nifi_config.api_client).get_processor(
         id=processor_id)
     processor_version = processor_res.revision.version
     processor_id = processor_res.id
     print(processor_id)
     # comment because add run_status_entity 
     # data = {"revision": {"clientId": processor_id,
     #                      "version": processor_version},
     #         "state": state}
     # Create ProcessorRunStatusEntity object
     run_status_entity = nipyapi.nifi.models.ProcessorRunStatusEntity(
         revision=nipyapi.nifi.models.RevisionDTO(
             version=processor_version
         ),
         state=state
     )
     #  example run_status_entity response
     # {'disconnected_node_acknowledged': None,
     #  'revision': {'client_id': None, 'last_modifier': None, 'version': 71},
     #  'state': 'RUN_ONCE'}

     try:
         response = nipyapi.nifi.apis.processors_api.ProcessorsApi(
             api_client=nipyapi.config.nifi_config.api_client).update_run_status(
             id=processor_id,
             body=run_status_entity
         )
         print(response)
         return response
     except Exception as ex:
         logger.error(str(ex))
         raise Exception(str(ex))```

poopae8055 avatar Sep 30 '24 10:09 poopae8055

nipyapi.nifi.apis.processors_api.ProcessorsApi(
   api_client=nipyapi.config.nifi_config.api_client).update_run_status(
       id=processor_id,
       body=nipyapi.nifi.models.ProcessorRunStatusEntity(
           revision=nipyapi.nifi.models.RevisionDTO(
               version=processor_version
           ),
           state='RUN_ONCE'
       )
    )
)

I would expect this to work. You are correct that update_run_status is a separate call to update_processor which doesn't have a convenience method in canvas.py at this time.

Chaffelson avatar Oct 02 '24 21:10 Chaffelson

nipyapi.nifi.apis.processors_api.ProcessorsApi( api_client=nipyapi.config.nifi_config.api_client).update_run_status( id=processor_id, body=nipyapi.nifi.models.ProcessorRunStatusEntity( revision=nipyapi.nifi.models.RevisionDTO( version=processor_version ), state='RUN_ONCE' ) ) )

ok i gonna try. and will update the result. thank you so much.

poopae8055 avatar Oct 03 '24 08:10 poopae8055

nipyapi.nifi.apis.processors_api.ProcessorsApi(
   api_client=nipyapi.config.nifi_config.api_client).update_run_status(
       id=processor_id,
       body=nipyapi.nifi.models.ProcessorRunStatusEntity(
           revision=nipyapi.nifi.models.RevisionDTO(
               version=processor_version
           ),
           state='RUN_ONCE'
       )
    )
)

I would expect this to work. You are correct that update_run_status is a separate call to update_processor which doesn't have a convenience method in canvas.py at this time.

after i update to

            api_client=nipyapi.config.nifi_config.api_client).get_processor(
            id=processor_id)
        processor_version = processor_res.revision.version
        processor_id = processor_res.id

        try:
            response =   nipyapi.nifi.apis.processors_api.ProcessorsApi(
                api_client=nipyapi.config.nifi_config.api_client).update_run_status(
                id=processor_id,
                body=nipyapi.nifi.models.ProcessorRunStatusEntity(
                    revision=nipyapi.nifi.models.RevisionDTO(
                        version=processor_version
                    ),
                state='RUN_ONCE'
            )
        )
            print(response)
            return response
        except Exception as ex:
            logger.error(str(ex))
            raise Exception(str(ex))```



It still gets the error
`Exception: Invalid value for `state` (RUN_ONCE), must be one of ['RUNNING', 'STOPPED', 'DISABLED']`

poopae8055 avatar Oct 03 '24 10:10 poopae8055

Hey @poopae8055 - maybe give this a try:

proc_id = "your_nifi_processor_id"
out = nipyapi.nifi.ProcessorsApi().get_processor(proc_id) # return the ProcessorEntity object

# create the ProcessorRunStatusEntity object, grabbing the disconnected_node_acknowledged and revision details from the returned ProcessorEntity object
update_status = nipyapi.nifi.models.ProcessorRunStatusEntity(disconnected_node_acknowledged = out.disconnected_node_acknowledged,
                                                             state = 'RUN_ONCE', # set state to RUN_ONCE
                                                             revision = out.revision)

# execute update_run_status
out = nipyapi.nifi.ProcessorsApi().update_run_status(proc_id, update_status)

This works for me! Originally, I tried to modify the ProcessorEntity status field directly so I could reuse the output in the update call, and that's when I also got the error that RUN_ONCE was not an option. It's because the ProcessorEntity object status routes to ProcessorStatusDTO, which does not allow RUN_ONCE as an option (see line 198 here in processor_status_dto.py).

j-tseng avatar Mar 06 '25 16:03 j-tseng

Running into this issue as well, except what I've noticed is that once the state (RUN_ONCE) has been set, if I immediately get the processor again, sometimes it will throw an error saying the state can't be set to RUN_ONCE. It looks like the state can sometimes stay as RUN_ONCE before switching to stopped if you immediately retrieve it from nifi, and nipyapi throws an error when it attempts to deseralise the object into a ProcessorEntity which doesn't allow RUN_ONCE as a state (as mentioned by @j-tseng).

I'm on nifi version 1.28.1

delibrete avatar Jul 08 '25 07:07 delibrete

Hmm, that is interesting. So if you PUT a RUN_ONCE in an update_run_status, and then immediately GET the processor again it can error because of the validation? I should be able to generate a test for that and improve the validator.

Chaffelson avatar Jul 09 '25 20:07 Chaffelson