def test_list_all_controllers(regress_nifi, fix_pg, fix_cont): f_c1 = fix_cont(parent_pg=fix_pg.generate()) assert isinstance(f_c1, nifi.ControllerServiceEntity) r1 = canvas.list_all_controllers() assert f_c1.id in [x.id for x in r1] r2 = canvas.list_all_controllers(pg_id='root', descendants=False) r2 = [x for x in r2 if conftest.test_basename in x.component.name] assert not r2 with pytest.raises(AssertionError): _ = canvas.list_all_controllers(pg_id=['bob']) with pytest.raises(AssertionError): _ = canvas.list_all_controllers(descendants=['pie'])
def teardown(self): root_pg, _, flow_id = nf.set_environment() canvas.schedule_process_group(root_pg.id, False) while True: failed = False for controller in canvas.list_all_controllers(root_pg.id): try: canvas.schedule_controller(controller, False) LOG.debug('Controller %s stopped.', controller.component.name) except ApiException as exc: if exc.status == 409 and 'is referenced by' in exc.body: LOG.debug( 'Controller %s failed to stop. Will retry later.', controller.component.name) failed = True if not failed: break nf.delete_all(root_pg) efm.delete_all(flow_id) schreg.delete_all_schemas() reg_client = versioning.get_registry_client('NiFi Registry') if reg_client: versioning.delete_registry_client(reg_client) nifireg.delete_flows('SensorFlows') kudu.drop_table()
def test_list_all_controllers(regress_nifi, fix_pg, fix_cont): f_pg_1 = fix_pg.generate() f_pg_2 = fix_pg.generate(parent_pg=f_pg_1) f_c1 = fix_cont() f_c2 = fix_cont(parent_pg=f_pg_1) f_c3 = fix_cont(parent_pg=f_pg_2) assert isinstance(f_c1, nifi.ControllerServiceEntity) assert isinstance(f_c2, nifi.ControllerServiceEntity) assert isinstance(f_c3, nifi.ControllerServiceEntity) # Find all and l0 l1 and l2 r1 = canvas.list_all_controllers() assert all(y.id in [x.id for x in r1] for y in [f_c1, f_c2, f_c3]) # find just l0 r2 = canvas.list_all_controllers(pg_id='root', descendants=False) r2 = [x for x in r2 if conftest.test_basename in x.component.name] assert len(r2) == 1 assert f_c1.id in [x.id for x in r2] # find just l1 r3 = canvas.list_all_controllers(pg_id=f_pg_1.id, descendants=False) r3 = [x for x in r3 if conftest.test_basename in x.component.name] assert len(r3) == 2 assert all(y.id in [x.id for x in r3] for y in [f_c1, f_c2]) # Find l1 and l2 # This will fail if duplicates are introduced in the listing r4 = canvas.list_all_controllers(pg_id=f_pg_1.id, descendants=True) r4 = [x for x in r4 if conftest.test_basename in x.component.name] assert len(r4) == 3 assert all(y.id in [x.id for x in r4] for y in [f_c1, f_c2, f_c3]) # test errors with pytest.raises(AssertionError): _ = canvas.list_all_controllers(pg_id=['bob']) with pytest.raises(AssertionError): _ = canvas.list_all_controllers(descendants=['pie'])
def global_teardown(run_id=None, schema_text=None, cdsw_flag=True, target_lab=99): (run_id, root_pg, efm_pg_id, flow_id) = set_environment(run_id) canvas.schedule_process_group(root_pg.id, False) while True: failed = False for controller in canvas.list_all_controllers(root_pg.id): try: canvas.schedule_controller(controller, False) LOG.debug('Controller %s stopped.', controller.component.name) except ApiException as exc: if exc.status == 409 and 'is referenced by' in exc.body: LOG.debug( 'Controller %s failed to stop. Will retry later.', controller.component.name) failed = True if not failed: break nifi_delete_all(root_pg) class _Env(object): pass env = _Env() env.run_id, env.root_pg, env.efm_pg_id, env.flow_id = set_environment( run_id) env.schema_text = schema_text if schema_text is not None else read_in_schema( ) LOG.info("Using Schema: %s", schema_text) env.cdsw_flag = cdsw_flag LOG.info("Build just enough") lab2_edge_flow(env) lab3_register_schema(env) lab6_expand_edge_flow(env) create_kudu_table() LOG.info("Created edge, schema, kudu")
root_pg = canvas.get_process_group(root_pg_id, 'id') location_x = 2000 location_y = 2000 location = (location_x, location_y) template_entity = nipyapi.templates.upload_template(root_pg_id, 'jangowave_demo.xml') flow = nipyapi.templates.deploy_template(root_pg_id, template_entity.id, 2000, 2000) jd = canvas.get_process_group('jangowave_demo') for cs in canvas.list_all_processors(jd.id): if cs.status.run_status != "ENABLED" and cs.component.name == "RecordIngest": config_update = nifi.models.processor_config_dto.ProcessorConfigDTO( properties={ "Accumulo User": "******", "Instance Name": instance, "Accumulo Password": "******", "ZooKeeper Quorum": zookeeper_list }) canvas.update_processor(cs, config_update) for cs in canvas.list_all_controllers(jd.id): canvas.schedule_controller(cs, True) for cs in canvas.list_all_processors(jd.id): canvas.schedule_processor(cs, True) canvas.schedule_process_group(jd.id, True)
def __child_controller_services(self): controller_services = canvas.list_all_controllers(self.current_id(), False) return [cs for cs in controller_services if cs.parent_group_id == self.current_id()]