Chaffelson / nipyapi

A convenient Python wrapper for Apache NiFi
Other
245 stars 76 forks source link

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

Open poopae8055 opened 1 week ago

poopae8055 commented 1 week ago

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 commented 1 week ago

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

ottobackwards commented 1 week ago

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

poopae8055 commented 1 week ago

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 commented 1 week ago

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 commented 6 days ago

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 commented 6 days ago

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

ottobackwards commented 6 days ago

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

Chaffelson commented 5 days ago

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 commented 5 days ago

Maybe real type hints would help?

poopae8055 commented 5 days ago

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 commented 3 days ago
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 commented 2 days ago

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 commented 2 days ago
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']`