From d1efda001540c6d369a0c5529017c562ee763384 Mon Sep 17 00:00:00 2001 From: Keith Suderman Date: Sun, 30 Apr 2023 21:33:57 -0400 Subject: [PATCH] Add invocation commands --- abm/__main__.py | 2 +- abm/lib/invocation.py | 38 ++++++++++++++++++++++++++++++++++++++ abm/lib/menu.yml | 11 +++++++++++ abm/lib/workflow.py | 11 +++++++++-- 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 abm/lib/invocation.py diff --git a/abm/__main__.py b/abm/__main__.py index a93a338..ee48e48 100644 --- a/abm/__main__.py +++ b/abm/__main__.py @@ -17,7 +17,7 @@ # These imports are required because we need Python to be load them to the # symbol table so the parse_menu method can find them in globals() -from lib import job, dataset, workflow, history, library, folder, benchmark, helm, kubectl, config, experiment, users, cloudlaunch +from lib import job, dataset, workflow, history, library, folder, benchmark, helm, kubectl, config, experiment, users, cloudlaunch, invocation log = logging.getLogger('abm') handler = logging.StreamHandler() diff --git a/abm/lib/invocation.py b/abm/lib/invocation.py new file mode 100644 index 0000000..09cf94b --- /dev/null +++ b/abm/lib/invocation.py @@ -0,0 +1,38 @@ +from common import Context, connect, summarize_metrics, print_json + +def doList(context: Context, args: list): + wid = None + hid = None + while len(args) > 0: + arg = args.pop(0) + if args in ['-h', '--history']: + hid = args.pop(0) + elif arg in ['-w', '--workflow']: + wid = args.pop(0) + else: + print(f'Invalid parameter: {arg}') + return + gi = connect(context) + invocations = gi.invocations.get_invocations(workflow_id=wid, history_id=hid) + print('ID\tState\tWorkflow\tHistory') + for invocation in invocations: + id = invocation['id'] + state = invocation['state'] + workflow = invocation['workflow_id'] + history = invocation['history_id'] + print(f'{id}\t{state}\t{workflow}\t{history}') + + +def summarize(context: Context, args: list): + if len(args) == 0: + print("ERROR: Provide one or more invocation ID values.") + return + gi = connect(context) + id = args[0] + all_jobs = [] + jobs = gi.jobs.get_jobs(invocation_id=id) + for job in jobs: + job['invocation_id'] = id + job['workflow_id'] = '' + all_jobs.append(job) + summarize_metrics(gi, all_jobs) diff --git a/abm/lib/menu.yml b/abm/lib/menu.yml index f8b0994..ecbfc54 100644 --- a/abm/lib/menu.yml +++ b/abm/lib/menu.yml @@ -243,6 +243,17 @@ help: playground code handler: experiment.test params: [VARIES] +- name: [invocation, inv, invocations] + help: get information about job and workflow invocations + menu: + - name: [list, ls] + help: list all invocations. + handler: invocation.doList + params: "[-w|--workflow ID] [-h|--history ID]" + - name: [summarize] + help: generate a CSV of job metrics for an invocation + params: ID + handler: invocation.summarize - name: [helm] help: execute a helm command menu: diff --git a/abm/lib/workflow.py b/abm/lib/workflow.py index 115422f..35a20f5 100644 --- a/abm/lib/workflow.py +++ b/abm/lib/workflow.py @@ -182,8 +182,15 @@ def invocation(context:Context, args:list): # return gi = connect(context) # result = gi.workflows.show_invocation(workflow_id, invocation_id) - result = gi.invocations.get_invocations(workflow_id=workflow_id, view='element', step_details=True) - print(json.dumps(result, indent=4)) + invocations = gi.invocations.get_invocations(workflow_id=workflow_id, view='element', step_details=True) + # print(json.dumps(result, indent=4)) + print('ID\tState\tWorkflow\tHistory') + for invocation in invocations: + id = invocation['id'] + state = invocation['state'] + workflow = invocation['workflow_id'] + history = invocation['history_id'] + print(f'{id}\t{state}\t{workflow}\t{history}') def find(context: Context, args: list):