@@ -87,7 +87,7 @@ def ListWorkflows(self):
87
87
"next_page_token" : ""
88
88
}
89
89
90
- def invoke_cwl_runner (self , cr_uuid , workflow_url , workflow_params , env ):
90
+ def invoke_cwl_runner (self , cr_uuid , workflow_url , workflow_params , env , workflow_descriptor_file ):
91
91
api = arvados .api_from_config (version = "v1" , apiconfig = {
92
92
"ARVADOS_API_HOST" : env ["ARVADOS_API_HOST" ],
93
93
"ARVADOS_API_TOKEN" : env ['ARVADOS_API_TOKEN' ],
@@ -98,10 +98,12 @@ def invoke_cwl_runner(self, cr_uuid, workflow_url, workflow_params, env):
98
98
with tempfile .NamedTemporaryFile () as inputtemp :
99
99
json .dump (workflow_params , inputtemp )
100
100
inputtemp .flush ()
101
+ # TODO: run submission process in a container to prevent
102
+ # a-c-r submission processes from seeing each other.
101
103
proc = subprocess .Popen (["arvados-cwl-runner" , "--submit-request-uuid=" + cr_uuid , # NOQA
102
- "--submit" , "--no-wait" , "--api=containers" , # NOQA
103
- workflow_url , inputtemp .name ], env = env ,
104
- stdout = subprocess .PIPE , stderr = subprocess .PIPE ) # NOQA
104
+ "--submit" , "--no-wait" , "--api=containers" , # NOQA
105
+ workflow_url , inputtemp .name ], env = env ,
106
+ stdout = subprocess .PIPE , stderr = subprocess .PIPE ) # NOQA
105
107
(stdoutdata , stderrdata ) = proc .communicate ()
106
108
if proc .returncode != 0 :
107
109
api .container_requests ().update (uuid = cr_uuid , body = {"priority" : 0 ,
@@ -111,6 +113,9 @@ def invoke_cwl_runner(self, cr_uuid, workflow_url, workflow_params, env):
111
113
except subprocess .CalledProcessError as e :
112
114
api .container_requests ().update (uuid = cr_uuid , body = {"priority" : 0 ,
113
115
"properties" : {"arvados-cwl-runner-log" : str (e )}}).execute ()
116
+ finally :
117
+ if workflow_descriptor_file is not None :
118
+ workflow_descriptor_file .close ()
114
119
115
120
@catch_exceptions
116
121
def RunWorkflow (self , body ):
@@ -136,7 +141,19 @@ def RunWorkflow(self, body):
136
141
"output_path" : "n/a" ,
137
142
"priority" : 500 }}).execute ()
138
143
139
- threading .Thread (target = self .invoke_cwl_runner , args = (cr ["uuid" ], body .get ("workflow_url" ), body ["workflow_params" ], env )).start ()
144
+ workflow_url = body .get ("workflow_url" )
145
+ workflow_descriptor_file = None
146
+ if body .get ("workflow_descriptor" ):
147
+ workflow_descriptor_file = tempfile .NamedTemporaryFile ()
148
+ workflow_descriptor_file .write (body .get ('workflow_descriptor' ))
149
+ workflow_descriptor_file .flush ()
150
+ workflow_url = workflow_descriptor_file .name
151
+
152
+ threading .Thread (target = self .invoke_cwl_runner , args = (cr ["uuid" ],
153
+ workflow_url ,
154
+ body ["workflow_params" ],
155
+ env ,
156
+ workflow_descriptor_file )).start ()
140
157
141
158
return {"workflow_id" : cr ["uuid" ]}
142
159
0 commit comments