nipyapi
nipyapi copied to clipboard
Support enabling all controller services when dependency exists in them
We use nipyapi to enable controller services instead of clicking them in the UI, and very often one controller service depends on the other controller service(s), which means some controller services must be enabled before the other controller services.
One function I implement
def enable_controller_services_recur(controller_services):
if not controller_services:
return
else:
invalid_services = []
for service in controller_services:
if service.component.validation_status == 'VALID':
nipyapi.canvas.schedule_controller(service, True)
else:
invalid_service = nipyapi.canvas.get_controller(identifier=service.id, identifier_type="id")
invalid_services.append(invalid_service)
enable_controller_services_recur(invalid_services)
and the input parameter I use is the processor group
controller_services = nipyapi.nifi.FlowApi().get_controller_services_from_group(pg.id,
include_descendant_groups=True)\
.controller_services
I could send a merge request with a more generic function as the following if the maintainer think it's useful.
Proposal
I would put this function in canvas.py closed to the function schedule_controller(controller, scheduled), and make it behave like
def schedule_controllers(controllers, scheduled):
"""
Start/Enable or Stop/Disable Controller Services with existing dependencies
Args:
controllers list(ControllerServiceEntity): Target Controllers to schedule
scheduled (bool): True to start, False to stop
Returns:
list(ControllerServiceEntity)
""
This sounds like an excellent contribution, could you also make an appropriate test for it? If you don't have the time for that I can take it in and wrap a test for it.
It may also make sense to upgrade the existing enable_controller method to have a recurse=False option which has this functionality, and then extend that test to cover this use case
sounds cool. I will open a pull request. However I think using descendants (bool) is more consistent with other functions?
and use descendants (bool) I think only schedule_controller is required. schedule_controllers should not be needed and use descendants instead, or?
there comes the other question. Should disabling controller also has to disable the independent controllers before the dependent controllers?