1
1
import arvados
2
2
import arvados .util
3
3
import arvados .collection
4
+ import arvados .errors
4
5
import os
5
6
import connexion
6
7
import json
7
8
import subprocess
8
9
import tempfile
10
+ import functools
9
11
from wes_service .util import visit , WESBackend
10
12
11
13
@@ -26,6 +28,20 @@ def get_api():
26
28
}
27
29
28
30
31
+ def catch_exceptions (orig_func ):
32
+ """Catch uncaught exceptions and turn them into http errors"""
33
+
34
+ @functools .wraps (orig_func )
35
+ def catch_exceptions_wrapper (self , * args , ** kwargs ):
36
+ try :
37
+ return orig_func (self , * args , ** kwargs )
38
+ except arvados .errors .ApiError as e :
39
+ return {"msg" : e ._get_reason (), "status_code" : e .resp .status }, int (e .resp .status )
40
+ except subprocess .CalledProcessError as e :
41
+ return {"msg" : str (e ), "status_code" : 500 }, 500
42
+
43
+ return catch_exceptions_wrapper
44
+
29
45
class ArvadosBackend (WESBackend ):
30
46
def GetServiceInfo (self ):
31
47
return {
@@ -39,6 +55,7 @@ def GetServiceInfo(self):
39
55
"key_values" : {}
40
56
}
41
57
58
+ @catch_exceptions
42
59
def ListWorkflows (self ):
43
60
api = get_api ()
44
61
@@ -60,6 +77,7 @@ def ListWorkflows(self):
60
77
"next_page_token" : ""
61
78
}
62
79
80
+ @catch_exceptions
63
81
def RunWorkflow (self , body ):
64
82
if body ["workflow_type" ] != "CWL" or body ["workflow_type_version" ] != "v1.0" : # NOQA
65
83
return
@@ -77,6 +95,7 @@ def RunWorkflow(self, body):
77
95
body .get ("workflow_url" ), inputtemp .name ], env = env ).strip () # NOQA
78
96
return {"workflow_id" : workflow_id }
79
97
98
+ @catch_exceptions
80
99
def GetWorkflowLog (self , workflow_id ):
81
100
api = get_api ()
82
101
@@ -120,11 +139,13 @@ def keepref(d):
120
139
r ["workflow_log" ]["exit_code" ] = container ["exit_code" ]
121
140
return r
122
141
142
+ @catch_exceptions
123
143
def CancelJob (self , workflow_id ): # NOQA
124
144
api = get_api ()
125
145
request = api .container_requests ().update (body = {"priority" : 0 }).execute () # NOQA
126
146
return {"workflow_id" : request ["uuid" ]}
127
147
148
+ @catch_exceptions
128
149
def GetWorkflowStatus (self , workflow_id ):
129
150
api = get_api ()
130
151
request = api .container_requests ().get (uuid = workflow_id ).execute ()
0 commit comments