Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
poopae8055 opened this issue Sep 28, 2024 · 14 comments

Comments

@poopae8055
Copy link

  • 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

@ottobackwards
Copy link
Collaborator

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

@ottobackwards
Copy link
Collaborator

Check and see if it is this issue: #309

@poopae8055
Copy link
Author

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
Copy link
Author

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.

@ottobackwards
Copy link
Collaborator

ottobackwards commented Sep 30, 2024

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
Copy link
Collaborator

allowed_values = ["RUNNING", "STOPPED", "DISABLED", "RUN_ONCE"]

@ottobackwards
Copy link
Collaborator

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

@Chaffelson
Copy link
Owner

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.

@ottobackwards
Copy link
Collaborator

Maybe real type hints would help?

@poopae8055
Copy link
Author

poopae8055 commented Sep 30, 2024

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))```

@Chaffelson
Copy link
Owner

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.

@poopae8055
Copy link
Author

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
Copy link
Author

poopae8055 commented Oct 3, 2024

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']`

@j-tseng
Copy link

j-tseng commented Mar 6, 2025

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants