|
6 | 6 | import time
|
7 | 7 | import pprint
|
8 | 8 | import sys
|
| 9 | +import os |
| 10 | +import argparse |
| 11 | +import logging |
9 | 12 |
|
10 |
| -f = open("swagger/proto/workflow_execution.swagger.json") |
11 |
| -client = SwaggerClient.from_spec(json.load(f), origin_url="http://localhost:8080") |
| 13 | +def main(argv=sys.argv[1:]): |
12 | 14 |
|
13 |
| -with open(sys.argv[2]) as f: |
14 |
| - input = json.load(f) |
| 15 | + parser = argparse.ArgumentParser(description='Workflow Execution Service') |
| 16 | + parser.add_argument("--host", type=str, default=os.environ.get("WES_API_HOST")) |
| 17 | + parser.add_argument("--auth", type=str, default=os.environ.get("WES_API_TOKEN")) |
| 18 | + parser.add_argument("--proto", type=str, default="https") |
| 19 | + parser.add_argument("--quiet", action="store_true", default=False) |
| 20 | + parser.add_argument("workflow_url", type=str) |
| 21 | + parser.add_argument("job_order", type=str) |
| 22 | + args = parser.parse_args(argv) |
15 | 23 |
|
16 |
| -r = client.WorkflowExecutionService.RunWorkflow(body={ |
17 |
| - "workflow_url": sys.argv[1], |
18 |
| - "workflow_params": input, |
19 |
| - "workflow_type": "CWL", |
20 |
| - "workflow_type_version": "v1.0"}).result() |
| 24 | + http_client = RequestsClient() |
| 25 | + http_client.set_api_key( |
| 26 | + args.host, args.auth, |
| 27 | + param_name='Authorization', param_in='header') |
| 28 | + client = SwaggerClient.from_url("%s://%s/swagger.json" % (args.proto, args.host), http_client=http_client) |
21 | 29 |
|
22 |
| -sys.stderr.write(r.workflow_id+"\n") |
| 30 | + with open(args.job_order) as f: |
| 31 | + input = json.load(f) |
| 32 | + |
| 33 | + workflow_url = args.workflow_url |
| 34 | + if not workflow_url.startswith("/") or ":" in workflow_url: |
| 35 | + workflow_url = os.path.abspath(workflow_url) |
| 36 | + |
| 37 | + if args.quiet: |
| 38 | + logging.basicConfig(level=logging.WARNING) |
| 39 | + else: |
| 40 | + logging.basicConfig(level=logging.INFO) |
| 41 | + |
| 42 | + r = client.WorkflowExecutionService.RunWorkflow(body={ |
| 43 | + "workflow_url": workflow_url, |
| 44 | + "workflow_params": input, |
| 45 | + "workflow_type": "CWL", |
| 46 | + "workflow_type_version": "v1.0"}).result() |
| 47 | + |
| 48 | + logging.info("Workflow id is %s", r.workflow_id) |
23 | 49 |
|
24 |
| -r = client.WorkflowExecutionService.GetWorkflowStatus(workflow_id=r.workflow_id).result() |
25 |
| -while r.state == "Running": |
26 |
| - time.sleep(1) |
27 | 50 | r = client.WorkflowExecutionService.GetWorkflowStatus(workflow_id=r.workflow_id).result()
|
| 51 | + while r.state == "Running": |
| 52 | + time.sleep(1) |
| 53 | + r = client.WorkflowExecutionService.GetWorkflowStatus(workflow_id=r.workflow_id).result() |
| 54 | + |
| 55 | + logging.info("State is %s", r.state) |
| 56 | + |
| 57 | + s = client.WorkflowExecutionService.GetWorkflowLog(workflow_id=r.workflow_id).result() |
| 58 | + logging.info(s.workflow_log.stderr) |
| 59 | + |
| 60 | + d = {k: s.outputs[k] for k in s.outputs if k != "fields"} |
| 61 | + json.dump(d, sys.stdout, indent=4) |
28 | 62 |
|
29 |
| -s = client.WorkflowExecutionService.GetWorkflowLog(workflow_id=r.workflow_id).result() |
30 |
| -sys.stderr.write(s.workflow_log.stderr+"\n") |
| 63 | + if r.state == "Complete": |
| 64 | + return 0 |
| 65 | + else: |
| 66 | + return 1 |
31 | 67 |
|
32 |
| -d = {k: s.outputs[k] for k in s.outputs if k != "fields"} |
33 |
| -json.dump(d, sys.stdout, indent=4) |
| 68 | +if __name__ == "__main__": |
| 69 | + sys.exit(main(sys.argv[1:])) |
0 commit comments