From 38c5838a8d8fdf349f90336adf12a36e2d4ba509 Mon Sep 17 00:00:00 2001 From: Matthias Tafelmeier Date: Fri, 17 Nov 2023 08:07:30 +0100 Subject: [PATCH] api - implement breeders list endpoint --- api/controller.py | 44 +++++++++++++++----------------------------- api/meta_data_db.py | 7 +++++++ 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/api/controller.py b/api/controller.py index 99bc4e4a..f0c790cf 100644 --- a/api/controller.py +++ b/api/controller.py @@ -136,38 +136,24 @@ def breeders_get(): # noqa: E501 Provides info on configured breeders # noqa: E501 """ + configured_breeders = dict() - api_response = None + ## fetch breeder meta data list + db_config = META_DB_CONFIG.copy() + db_config.update(dict(dbname='meta_data')) + db_table_name = 'breeder_meta_data' - with client.ApiClient(configuration) as api_client: - api_instance = dag_run_api.DAGRunApi(api_client) + __query = meta_data.queries.fetch_breeders_list(table_name=db_table_name, breeder_name=breeder_name) + breeder_meta_data_list = archive.archive_db.execute(db_info=db_config, query=__query, with_result=True) - list_dag_runs_form = ListDagRunsForm( - #order_by="order_by_example", - page_offset=0, - page_limit=10000, - dag_ids=[ - "linux_network_stack_breeder", # only one dag existing so far - ], - #states=[ - #], - execution_date_gte=dateutil_parser('1970-01-01T00:00:00.00Z'), - execution_date_lte=dateutil_parser('1970-01-01T00:00:00.00Z'), - start_date_gte=dateutil_parser('1970-01-01T00:00:00.00Z'), - start_date_lte=dateutil_parser('1970-01-01T00:00:00.00Z'), - end_date_gte=dateutil_parser('1970-01-01T00:00:00.00Z'), - end_date_lte=dateutil_parser('1970-01-01T00:00:00.00Z'), - ) # ListDagRunsForm | - - # example passing only required values which don't have defaults set - try: - # List DAG runs (batch) - api_response = api_instance.get_dag_runs_batch(list_dag_runs_form) - except client.ApiException as e: - pprint("Exception when calling DAGRunApi->get_dag_runs_batch: %s\n" % e) - raise e - - return api_response.to_dict() + # preformat timestamp to be stringifyable + breeder_meta_data_list = [(breeder_row[0].isoformat(),breeder_row[1]) for breeder_row in breeder_meta_data_list] + + logging.error(json.dumps(breeder_meta_data_list)) + + return Response(response=json.dumps(dict(breeders=configured_breeders)), + status=200, + mimetype='application/json') def breeders_name_get(breeder_name): # noqa: E501 diff --git a/api/meta_data_db.py b/api/meta_data_db.py index fd2f21d7..8394685c 100644 --- a/api/meta_data_db.py +++ b/api/meta_data_db.py @@ -40,3 +40,10 @@ def fetch_meta_data(table_name=None, breeder_name=None): """ return query + + def fetch_breeders_list(table_name=None, breeder_name=None): + query = f""" + SELECT definition->>'name',creation_tsz, FROM {table_name}; + """ + + return query