From 7834c6e42a5fecc04d1d1496abcb01beae8fd9d3 Mon Sep 17 00:00:00 2001 From: Karim Ahmed <karim.ahmed@xfel.eu> Date: Tue, 8 Sep 2020 11:06:13 +0200 Subject: [PATCH] update mdc --- webservice/update_mdc.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/webservice/update_mdc.py b/webservice/update_mdc.py index 36eb34b93..56da834f6 100644 --- a/webservice/update_mdc.py +++ b/webservice/update_mdc.py @@ -1,17 +1,19 @@ -import yaml import argparse +import yaml + from metadata_client.metadata_client import MetadataClient parser = argparse.ArgumentParser( - description='Request dark characterization. Will wait on data transfers to complete first!') -parser.add_argument('--conf-file', type=str, help='Path to webcervice config', default='/home/xcal/calibration_webservice_deployed/webservice/webservice.yaml') -parser.add_argument('--flg', type=str, choices=["NA", "R", "A"], help='Status flag for MDC request') + description='Update run status at MDC for a given run id.') +parser.add_argument('--conf-file', type=str, help='Path to webservice config', + default='/home/xcal/calibration_webservice_deployed/webservice/webservice.yaml') # noqa +parser.add_argument('--flg', type=str, choices=["NA", "R", "A"], + help='Status flag for MDC request: NA - not available, R - running, A - available.') # noqa parser.add_argument('--rid', type=int, help='Run id from MDC') -parser.add_argument('--msg', type=str, help='Message string to MDC') - - +parser.add_argument('--msg', type=str, help='Message string to MDC', + default='Error while job submission') args = vars(parser.parse_args()) conf_file = args['conf_file'] @@ -19,23 +21,24 @@ rid = args['rid'] flg = args['flg'] msg = args['msg'] - with open(conf_file, "r") as f: config = yaml.load(f.read(), Loader=yaml.FullLoader) mdconf = config['metadata-client'] client_conn = MetadataClient(client_id=mdconf['user-id'], - client_secret=mdconf['user-secret'], - user_email=mdconf['user-email'], - token_url=mdconf['token-url'], - refresh_url=mdconf['refresh-url'], - auth_url=mdconf['auth-url'], - scope=mdconf['scope'], - base_api_url=mdconf['base-api-url']) - + client_secret=mdconf['user-secret'], + user_email=mdconf['user-email'], + token_url=mdconf['token-url'], + refresh_url=mdconf['refresh-url'], + auth_url=mdconf['auth-url'], + scope=mdconf['scope'], + base_api_url=mdconf['base-api-url']) response = client_conn.update_run_api(rid, {'flg_cal_data_status': flg, 'cal_pipeline_reply': msg}) -print(response, response.status_code) +if response.status_code == 200: + print('Run is updated') +else: + print(f'Update failed {response}') -- GitLab