@@ -19,12 +19,13 @@ class MissingAuthorization(Exception):
19
19
pass
20
20
21
21
22
- def get_api ():
23
- if not connexion .request .headers .get ('Authorization' ):
24
- raise MissingAuthorization ()
25
- authtoken = connexion .request .headers ['Authorization' ]
26
- if authtoken .startswith ("Bearer " ) or authtoken .startswith ("OAuth2 " ):
27
- authtoken = authtoken [7 :]
22
+ def get_api (authtoken = None ):
23
+ if authtoken is None :
24
+ if not connexion .request .headers .get ('Authorization' ):
25
+ raise MissingAuthorization ()
26
+ authtoken = connexion .request .headers ['Authorization' ]
27
+ if authtoken .startswith ("Bearer " ) or authtoken .startswith ("OAuth2 " ):
28
+ authtoken = authtoken [7 :]
28
29
return arvados .api_from_config (version = "v1" , apiconfig = {
29
30
"ARVADOS_API_HOST" : os .environ ["ARVADOS_API_HOST" ],
30
31
"ARVADOS_API_TOKEN" : authtoken ,
@@ -55,6 +56,10 @@ def catch_exceptions_wrapper(self, *args, **kwargs):
55
56
return {"msg" : str (e ), "status_code" : 500 }, 500
56
57
except MissingAuthorization :
57
58
return {"msg" : "'Authorization' header is missing or empty, expecting Arvados API token" , "status_code" : 401 }, 401
59
+ except ValueError as e :
60
+ return {"msg" : str (e ), "status_code" : 400 }, 400
61
+ except Exception as e :
62
+ return {"msg" : str (e ), "status_code" : 500 }, 500
58
63
59
64
return catch_exceptions_wrapper
60
65
@@ -108,10 +113,10 @@ def ListRuns(self, page_size=None, page_token=None, state_search=None):
108
113
"next_page_token" : workflow_list [- 1 ]["run_id" ] if workflow_list else ""
109
114
}
110
115
111
- def log_for_run (self , run_id , message ):
112
- get_api ().logs ().create (body = {"log" : {"object_uuid" : run_id ,
116
+ def log_for_run (self , run_id , message , authtoken = None ):
117
+ get_api (authtoken ).logs ().create (body = {"log" : {"object_uuid" : run_id ,
113
118
"event_type" : "stderr" ,
114
- "properties" : {"text" : message }}}).execute ()
119
+ "properties" : {"text" : message + " \n " }}}).execute ()
115
120
116
121
def invoke_cwl_runner (self , cr_uuid , workflow_url , workflow_params ,
117
122
env , project_uuid ,
@@ -123,9 +128,18 @@ def invoke_cwl_runner(self, cr_uuid, workflow_url, workflow_params,
123
128
})
124
129
125
130
try :
126
- with tempfile .NamedTemporaryFile () as inputtemp :
131
+ with tempfile .NamedTemporaryFile (dir = tempdir , suffix = ".json" ) as inputtemp :
127
132
json .dump (workflow_params , inputtemp )
128
133
inputtemp .flush ()
134
+
135
+ msg = ""
136
+ for dirpath , dirs , files in os .walk (tempdir ):
137
+ for f in files :
138
+ msg += " " + dirpath + "/" + f + "\n "
139
+
140
+ self .log_for_run (cr_uuid , "Contents of %s:\n %s" % (tempdir , msg ),
141
+ env ['ARVADOS_API_TOKEN' ])
142
+
129
143
# TODO: run submission process in a container to prevent
130
144
# a-c-r submission processes from seeing each other.
131
145
@@ -138,6 +152,8 @@ def invoke_cwl_runner(self, cr_uuid, workflow_url, workflow_params,
138
152
cmd .append (workflow_url )
139
153
cmd .append (inputtemp .name )
140
154
155
+ self .log_for_run (cr_uuid , "Executing %s" % cmd , env ['ARVADOS_API_TOKEN' ])
156
+
141
157
proc = subprocess .Popen (cmd , env = env ,
142
158
cwd = tempdir ,
143
159
stdout = subprocess .PIPE ,
@@ -146,7 +162,7 @@ def invoke_cwl_runner(self, cr_uuid, workflow_url, workflow_params,
146
162
if proc .returncode != 0 :
147
163
api .container_requests ().update (uuid = cr_uuid , body = {"priority" : 0 }).execute ()
148
164
149
- self .log_for_run (cr_uuid , stderrdata )
165
+ self .log_for_run (cr_uuid , stderrdata , env [ 'ARVADOS_API_TOKEN' ] )
150
166
151
167
if tempdir :
152
168
shutil .rmtree (tempdir )
@@ -180,7 +196,15 @@ def RunWorkflow(self, **args):
180
196
"output_path" : "n/a" ,
181
197
"priority" : 500 }}).execute ()
182
198
183
- tempdir , body = self .collect_attachments (cr ["uuid" ])
199
+ try :
200
+ tempdir , body = self .collect_attachments (cr ["uuid" ])
201
+ except Exception as e :
202
+ self .log_for_run (cr ["uuid" ], str (e ))
203
+ cr = api .container_requests ().update (uuid = cr ["uuid" ],
204
+ body = {"container_request" :
205
+ {"priority" : 0 }}).execute ()
206
+
207
+ return {"run_id" : cr ["uuid" ]}
184
208
185
209
workflow_url = body .get ("workflow_url" )
186
210
0 commit comments