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
10 class ArvadosCommandTool(CommandLineTool):
11 """Wrap cwltool CommandLineTool to override selected methods."""
13 def __init__(self, arvrunner, toolpath_object, **kwargs):
14 super(ArvadosCommandTool, self).__init__(toolpath_object, **kwargs)
15 self.arvrunner = arvrunner
16 self.work_api = kwargs["work_api"]
18 def makeJobRunner(self, **kwargs):
19 if self.work_api == "containers":
20 return ArvadosContainer(self.arvrunner)
21 elif self.work_api == "jobs":
22 return ArvadosJob(self.arvrunner)
24 def makePathMapper(self, reffiles, stagedir, **kwargs):
25 # type: (List[Any], unicode, **Any) -> PathMapper
26 if self.work_api == "containers":
27 return ArvPathMapper(self.arvrunner, reffiles+kwargs.get("extra_reffiles", []), kwargs["basedir"],
31 elif self.work_api == "jobs":
32 return ArvPathMapper(self.arvrunner, reffiles, kwargs["basedir"],
37 def job(self, joborder, output_callback, **kwargs):
39 # Workaround for #13365
40 builderargs = kwargs.copy()
41 builderargs["toplevel"] = True
42 builderargs["tmp_outdir_prefix"] = ""
43 builder = self._init_job(joborder, **builderargs)
44 joborder = builder.job
46 if self.work_api == "containers":
47 dockerReq, is_req = self.get_requirement("DockerRequirement")
48 if dockerReq and dockerReq.get("dockerOutputDirectory"):
49 kwargs["outdir"] = dockerReq.get("dockerOutputDirectory")
50 kwargs["docker_outdir"] = dockerReq.get("dockerOutputDirectory")
52 kwargs["outdir"] = "/var/spool/cwl"
53 kwargs["docker_outdir"] = "/var/spool/cwl"
54 elif self.work_api == "jobs":
55 kwargs["outdir"] = "$(task.outdir)"
56 kwargs["docker_outdir"] = "$(task.outdir)"
57 kwargs["tmpdir"] = "$(task.tmpdir)"
58 kwargs["docker_tmpdir"] = "$(task.tmpdir)"
59 return super(ArvadosCommandTool, self).job(joborder, output_callback, **kwargs)