1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 from cwltool.command_line_tool import CommandLineTool
6 from .arvjob import ArvadosJob
7 from .arvcontainer import ArvadosContainer
8 from .pathmapper import ArvPathMapper
9 from functools import partial
11 class ArvadosCommandTool(CommandLineTool):
12 """Wrap cwltool CommandLineTool to override selected methods."""
14 def __init__(self, arvrunner, toolpath_object, loadingContext):
15 super(ArvadosCommandTool, self).__init__(toolpath_object, loadingContext)
16 self.arvrunner = arvrunner
18 def make_job_runner(self, runtimeContext):
19 if runtimeContext.work_api == "containers":
20 return partial(ArvadosContainer, self.arvrunner)
21 elif runtimeContext.work_api == "jobs":
22 return partial(ArvadosJob, self.arvrunner)
24 raise Exception("Unsupported work_api %s", runtimeContext.work_api)
26 def make_path_mapper(self, reffiles, stagedir, runtimeContext, separateDirs):
27 if runtimeContext.work_api == "containers":
28 return ArvPathMapper(self.arvrunner, reffiles+runtimeContext.extra_reffiles, runtimeContext.basedir,
31 elif runtimeContext.work_api == "jobs":
32 return ArvPathMapper(self.arvrunner, reffiles, runtimeContext.basedir,
36 def job(self, joborder, output_callback, runtimeContext):
38 # Workaround for #13365
39 builderargs = runtimeContext.copy()
40 builderargs.toplevel = True
41 builderargs.tmp_outdir_prefix = ""
42 builder = self._init_job(joborder, builderargs)
43 joborder = builder.job
45 runtimeContext = runtimeContext.copy()
47 if runtimeContext.work_api == "containers":
48 dockerReq, is_req = self.get_requirement("DockerRequirement")
49 if dockerReq and dockerReq.get("dockerOutputDirectory"):
50 runtimeContext.outdir = dockerReq.get("dockerOutputDirectory")
51 runtimeContext.docker_outdir = dockerReq.get("dockerOutputDirectory")
53 runtimeContext.outdir = "/var/spool/cwl"
54 runtimeContext.docker_outdir = "/var/spool/cwl"
55 elif runtimeContext.work_api == "jobs":
56 runtimeContext.outdir = "$(task.outdir)"
57 runtimeContext.docker_outdir = "$(task.outdir)"
58 runtimeContext.tmpdir = "$(task.tmpdir)"
59 runtimeContext.docker_tmpdir = "$(task.tmpdir)"
60 return super(ArvadosCommandTool, self).job(joborder, output_callback, runtimeContext)