nipyapi icon indicating copy to clipboard operation
nipyapi copied to clipboard

Timed Out waiting for nipyapi _schedule_controller_state to complete

Open Kingdom-Of-Heaven opened this issue 1 year ago • 5 comments

I just updated NIFI from version 1.11.4 to 1.16.3. I got one issue. Once my nifi's registry flow is taken and shown on workspace and when it comes to start installation of componenets i got error on that line below. Note that all is working on older nifi version. What might be the issue?

self.__nipyapi.canvas.schedule_controller(i, False)

Error:

Traceback (most recent call last):
  File "deploy01.py", line 134, in <module>
    main_handler.start_controllers()
  File "/code/nifi.py", line 1441, in start_controllers
    self.__start_controller_safe()
  File "/code/nifi.py", line 710, in __start_controller_safe
    self.__nipyapi.canvas.schedule_controller(i, True)
  File "/usr/local/lib/python3.8/site-packages/nipyapi/canvas.py", line 1249, in schedule_controller
    state_test = nipyapi.utils.wait_to_complete(
  File "/usr/local/lib/python3.8/site-packages/nipyapi/utils.py", line 243, in wait_to_complete
    raise ValueError("Timed Out waiting for {0} to complete".format(
ValueError: Timed Out waiting for _schedule_controller_state to complete
make: *** [Makefile:193: nifi-flow-deployment] Error 1

Code:

def __start_controller_safely(self) -> bool:
    for i in (
            self.__nipyapi.nifi.FlowApi()
        .get_controller_services_from_group(self.deployed_flow_id)
        .controller_services
    ):

        _ctrl_id = i.id
        print(i.component.name)
        if i.status.run_status == "DISABLED":
            print("Controller status is disabled... trying to start")
            self.__nipyapi.canvas.schedule_controller(i, True)
            while (
                    self.__nipyapi.canvas.get_controller(
                        _ctrl_id, identifier_type="id"
                    ).status.run_status
                    != "ENABLED"
            ):
                if (
                        self.__nipyapi.canvas.get_controller(
                            _ctrl_id, identifier_type="id"
                        ).status.run_status
                        != "ENABLED"
                ):
                    print("Controller status is enabled")
                    break
                else:
                    print("Waiting controller to start")
                    time.sleep(1)
        else:
            print("Controller already started")

    self.are_controllers_started: bool = True
    return True

Kingdom-Of-Heaven avatar Oct 15 '24 09:10 Kingdom-Of-Heaven

Hmm, there's a known variation when upgrading > NiFi 1.2.0, but I'm not aware of one for 1.11 to 1.16.

It calls nipyapi.nifi.ControllerServicesApi().get_controller_service(id) and checks if component.state is 'ENABLED'. It will timeout if that particular object parameter never changes to ENABLED, so perhaps if you run the command and check what is being returned in the object and share that we can find a discrepancy.

Chaffelson avatar Oct 16 '24 09:10 Chaffelson

@Chaffelson Can u help me out? U mean to do something like this?:

..
print("Controller status is disabled... trying to start")
obj = self.__nipyapi.canvas.schedule_controller(i, True)         # <---------------- ?
print(obj) # <--------------- ?
while ( ...

Kingdom-Of-Heaven avatar Oct 18 '24 06:10 Kingdom-Of-Heaven

@Chaffelson ?

Kingdom-Of-Heaven avatar Oct 21 '24 05:10 Kingdom-Of-Heaven

I would call the schedule_controller operation, and then run a loop fetching the component and printing it every second, specifically looking at the component.state. The state should be a string, and it should transition to 'ENABLED' or you should get an error message.

Or you could modify NiPy here to log the controller state during the wait loop to see what it is getting back.

Chaffelson avatar Oct 21 '24 08:10 Chaffelson

@Chaffelson if u look at my code posted i already have while loop. If that's not what u wrote. Can u help me out to add additional code to my posted code the way u mentioned? Would appreciate.

Kingdom-Of-Heaven avatar Oct 23 '24 15:10 Kingdom-Of-Heaven