9
9
import argparse
10
10
import logging
11
11
import schema_salad .ref_resolver
12
+ import requests
12
13
from wes_service .util import visit
13
14
from bravado .client import SwaggerClient
14
15
from bravado .requests_client import RequestsClient
15
16
16
-
17
17
def main (argv = sys .argv [1 :]):
18
18
parser = argparse .ArgumentParser (description = 'Workflow Execution Service' )
19
19
parser .add_argument ("--host" , type = str , default = os .environ .get ("WES_API_HOST" ))
20
20
parser .add_argument ("--auth" , type = str , default = os .environ .get ("WES_API_AUTH" ))
21
21
parser .add_argument ("--proto" , type = str , default = os .environ .get ("WES_API_PROTO" , "https" ))
22
22
parser .add_argument ("--quiet" , action = "store_true" , default = False )
23
23
parser .add_argument ("--outdir" , type = str )
24
+ parser .add_argument ("--page" , type = str , default = None )
25
+ parser .add_argument ("--page-size" , type = int , default = None )
24
26
25
27
exgroup = parser .add_mutually_exclusive_group ()
26
28
exgroup .add_argument ("--run" , action = "store_true" , default = False )
@@ -54,7 +56,7 @@ def main(argv=sys.argv[1:]):
54
56
http_client = http_client , config = {'use_models' : False })
55
57
56
58
if args .list :
57
- response = client .WorkflowExecutionService .ListWorkflows ()
59
+ response = client .WorkflowExecutionService .ListWorkflows (page_token = args . page , page_size = args . page_size )
58
60
json .dump (response .result (), sys .stdout , indent = 4 )
59
61
return 0
60
62
@@ -98,10 +100,10 @@ def fixpaths(d):
98
100
if loc .startswith ("http:" ) or loc .startswith ("https:" ):
99
101
logging .error ("Directory inputs not supported with http references" )
100
102
exit (33 )
101
- if not (loc .startswith ("http:" ) or loc .startswith ("https:" )
102
- or args .job_order .startswith ("http:" ) or args .job_order .startswith ("https:" )):
103
- logging .error ("Upload local files not supported, must use http: or https: references." )
104
- exit (33 )
103
+ # if not (loc.startswith("http:") or loc.startswith("https:")
104
+ # or args.job_order.startswith("http:") or args.job_order.startswith("https:")):
105
+ # logging.error("Upload local files not supported, must use http: or https: references.")
106
+ # exit(33)
105
107
106
108
visit (input , fixpaths )
107
109
@@ -114,19 +116,37 @@ def fixpaths(d):
114
116
else :
115
117
logging .basicConfig (level = logging .INFO )
116
118
117
- body = {
118
- "workflow_params" : input ,
119
- "workflow_type" : "CWL" ,
120
- "workflow_type_version" : "v1.0"
121
- }
119
+ parts = [
120
+ ( "workflow_params" , json . dumps ( input )) ,
121
+ ( "workflow_type" , "CWL" ) ,
122
+ ( "workflow_type_version" , "v1.0" )
123
+ ]
122
124
123
125
if workflow_url .startswith ("file://" ):
124
- with open (workflow_url [7 :], "r" ) as f :
125
- body ["workflow_descriptor" ] = f .read ()
126
+ # with open(workflow_url[7:], "rb") as f:
127
+ # body["workflow_descriptor"] = f.read()
128
+ rootdir = os .path .dirname (workflow_url [7 :])
129
+ dirpath = rootdir
130
+ #for dirpath, dirnames, filenames in os.walk(rootdir):
131
+ for f in os .listdir (rootdir ):
132
+ if f .startswith ("." ):
133
+ continue
134
+ fn = os .path .join (dirpath , f )
135
+ if os .path .isfile (fn ):
136
+ parts .append (('workflow_descriptor' , (fn [len (rootdir )+ 1 :], open (fn , "rb" ))))
137
+ parts .append (("workflow_url" , os .path .basename (workflow_url [7 :])))
126
138
else :
127
- body ["workflow_url" ] = workflow_url
139
+ parts .append (("workflow_url" , workflow_url ))
140
+
141
+ postresult = http_client .session .post ("%s://%s/ga4gh/wes/v1/workflows" % (args .proto , args .host ),
142
+ files = parts ,
143
+ headers = {"Authorization" : args .auth })
144
+
145
+ r = json .loads (postresult .text )
128
146
129
- r = client .WorkflowExecutionService .RunWorkflow (body = body ).result ()
147
+ if postresult .status_code != 200 :
148
+ logging .error ("%s" , r )
149
+ exit (1 )
130
150
131
151
if args .wait :
132
152
logging .info ("Workflow id is %s" , r ["workflow_id" ])
@@ -137,15 +157,17 @@ def fixpaths(d):
137
157
r = client .WorkflowExecutionService .GetWorkflowStatus (
138
158
workflow_id = r ["workflow_id" ]).result ()
139
159
while r ["state" ] in ("QUEUED" , "INITIALIZING" , "RUNNING" ):
140
- time .sleep (1 )
160
+ time .sleep (8 )
141
161
r = client .WorkflowExecutionService .GetWorkflowStatus (
142
162
workflow_id = r ["workflow_id" ]).result ()
143
163
144
164
logging .info ("State is %s" , r ["state" ])
145
165
146
166
s = client .WorkflowExecutionService .GetWorkflowLog (
147
167
workflow_id = r ["workflow_id" ]).result ()
148
- logging .info ("Workflow log:\n " + s ["workflow_log" ]["stderr" ])
168
+ logging .info ("%s" , s ["workflow_log" ]["stderr" ])
169
+ logs = requests .get (s ["workflow_log" ]["stderr" ], headers = {"Authorization" : args .auth }).text
170
+ logging .info ("Workflow log:\n " + logs )
149
171
150
172
if "fields" in s ["outputs" ] and s ["outputs" ]["fields" ] is None :
151
173
del s ["outputs" ]["fields" ]
0 commit comments