Skip to content

Commit 4b1afce

Browse files
author
Peter Amstutz
committed
More fixes for 0.3.0 WES
1 parent f85f805 commit 4b1afce

File tree

4 files changed

+45
-46
lines changed

4 files changed

+45
-46
lines changed

wes_client/wes_client_main.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ def main(argv=sys.argv[1:]):
8181
json.dump(response.result(), sys.stdout, indent=4)
8282
return 0
8383

84+
if not args.job_order:
85+
logging.error("Missing job order")
86+
return 1
87+
8488
loader = schema_salad.ref_resolver.Loader({
8589
"location": {"@type": "@id"},
8690
"path": {"@type": "@id"}
@@ -102,7 +106,7 @@ def fixpaths(d):
102106
visit(input_dict, fixpaths)
103107

104108
workflow_url = args.workflow_url
105-
if not workflow_url.startswith("/") and ":" not in workflow_url:
109+
if ":" not in workflow_url:
106110
workflow_url = "file://" + os.path.abspath(workflow_url)
107111

108112
if args.quiet:
@@ -131,7 +135,7 @@ def fixpaths(d):
131135
else:
132136
parts.append(("workflow_url", workflow_url))
133137

134-
postresult = http_client.session.post("%s://%s/ga4gh/wes/v1/workflows" % (args.proto, args.host),
138+
postresult = http_client.session.post("%s://%s/ga4gh/wes/v1/runs" % (args.proto, args.host),
135139
files=parts,
136140
headers={"Authorization": args.auth})
137141

@@ -142,19 +146,19 @@ def fixpaths(d):
142146
exit(1)
143147

144148
if args.wait:
145-
logging.info("Workflow id is %s", r["workflow_id"])
149+
logging.info("Workflow run id is %s", r["run_id"])
146150
else:
147-
sys.stdout.write(r["workflow_id"] + "\n")
151+
sys.stdout.write(r["run_id"] + "\n")
148152
exit(0)
149153

150-
r = client.WorkflowExecutionService.GetRunStatus(workflow_id=r["workflow_id"]).result()
154+
r = client.WorkflowExecutionService.GetRunStatus(run_id=r["run_id"]).result()
151155
while r["state"] in ("QUEUED", "INITIALIZING", "RUNNING"):
152156
time.sleep(8)
153-
r = client.WorkflowExecutionService.GetRunStatus(workflow_id=r["workflow_id"]).result()
157+
r = client.WorkflowExecutionService.GetRunStatus(run_id=r["run_id"]).result()
154158

155159
logging.info("State is %s", r["state"])
156160

157-
s = client.WorkflowExecutionService.GetRunLog(workflow_id=r["workflow_id"]).result()
161+
s = client.WorkflowExecutionService.GetRunLog(run_id=r["run_id"]).result()
158162

159163
try:
160164
# TODO: Only works with Arvados atm

wes_service/arvados_wes.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,10 @@ def invoke_cwl_runner(self, cr_uuid, workflow_url, workflow_params,
156156
workflow_descriptor_file.close()
157157

158158
@catch_exceptions
159-
def RunWorkflow(self, workflow_params, workflow_type, workflow_type_version,
160-
workflow_url, workflow_descriptor, workflow_engine_parameters=None, tags=None):
161-
tempdir = tempfile.mkdtemp()
162-
body = {}
163-
for k, ls in connexion.request.files.iterlists():
164-
for v in ls:
165-
if k == "workflow_descriptor":
166-
filename = secure_filename(v.filename)
167-
v.save(os.path.join(tempdir, filename))
168-
elif k in ("workflow_params", "tags", "workflow_engine_parameters"):
169-
body[k] = json.loads(v.read())
170-
else:
171-
body[k] = v.read()
172-
body["workflow_url"] = "file:///%s/%s" % (tempdir, body["workflow_url"])
173-
174-
if body["workflow_type"] != "CWL" or body["workflow_type_version"] != "v1.0": # NOQA
175-
return
159+
def RunWorkflow(self, **args):
160+
tempdir, body = self.collect_attachments()
161+
162+
print(body)
176163

177164
if not connexion.request.headers.get('Authorization'):
178165
raise MissingAuthorization()

wes_service/cwl_runner.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -182,27 +182,8 @@ def ListRuns(self, page_size=None, page_token=None, state_search=None):
182182
"next_page_token": ""
183183
}
184184

185-
def RunWorkflow(self):
186-
tempdir = tempfile.mkdtemp()
187-
body = {}
188-
for k, ls in connexion.request.files.iterlists():
189-
for v in ls:
190-
if k == "workflow_descriptor":
191-
filename = secure_filename(v.filename)
192-
v.save(os.path.join(tempdir, filename))
193-
elif k in ("workflow_params", "tags", "workflow_engine_parameters"):
194-
body[k] = json.loads(v.read())
195-
else:
196-
body[k] = v.read()
197-
198-
if body['workflow_type'] != "CWL" or \
199-
body['workflow_type_version'] != "v1.0":
200-
return
201-
202-
body["workflow_url"] = "file:///%s/%s" % (tempdir, body["workflow_url"])
203-
index = body["workflow_url"].find("http")
204-
if index > 0:
205-
body["workflow_url"] = body["workflow_url"][index:]
185+
def RunWorkflow(self, **args):
186+
tempdir, body = self.collect_attachments()
206187

207188
run_id = uuid.uuid4().hex
208189
job = Workflow(run_id)

wes_service/util.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
from six import itervalues
1+
import tempfile
2+
import json
3+
import os
24

5+
from six import itervalues
6+
import connexion
7+
from werkzeug.utils import secure_filename
38

49
def visit(d, op):
510
"""Recursively call op(d) for all list subelements and dictionary 'values' that d may have."""
@@ -35,3 +40,25 @@ def getoptlist(self, p):
3540
if k == p:
3641
optlist.append(v)
3742
return optlist
43+
44+
def collect_attachments(self):
45+
tempdir = tempfile.mkdtemp()
46+
body = {}
47+
for k, ls in connexion.request.files.iterlists():
48+
for v in ls:
49+
if k == "workflow_descriptor":
50+
filename = secure_filename(v.filename)
51+
v.save(os.path.join(tempdir, filename))
52+
elif k in ("workflow_params", "tags", "workflow_engine_parameters"):
53+
body[k] = json.loads(v.read())
54+
else:
55+
body[k] = v.read()
56+
57+
if body['workflow_type'] != "CWL" or \
58+
body['workflow_type_version'] != "v1.0":
59+
return
60+
61+
if ":" not in body["workflow_url"]:
62+
body["workflow_url"] = "file://%s" % os.path.join(tempdir, secure_filename(body["workflow_url"]))
63+
64+
return (tempdir, body)

0 commit comments

Comments
 (0)