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 if "cwlVersion" not in self.metadata:
16 raise Exception("missing")
17 self.arvrunner = arvrunner
18 self.work_api = kwargs["work_api"]
20 def makeJobRunner(self, **kwargs):
21 if self.work_api == "containers":
22 return ArvadosContainer(self.arvrunner)
23 elif self.work_api == "jobs":
24 return ArvadosJob(self.arvrunner)
26 def makePathMapper(self, reffiles, stagedir, **kwargs):
27 # type: (List[Any], unicode, **Any) -> PathMapper
28 if self.work_api == "containers":
29 return ArvPathMapper(self.arvrunner, reffiles+kwargs.get("extra_reffiles", []), kwargs["basedir"],
33 elif self.work_api == "jobs":
34 return ArvPathMapper(self.arvrunner, reffiles, kwargs["basedir"],
39 def job(self, joborder, output_callback, **kwargs):
41 # Workaround for #13365
42 builderargs = kwargs.copy()
43 builderargs["toplevel"] = True
44 builderargs["tmp_outdir_prefix"] = ""
45 builder = self._init_job(joborder, **builderargs)
46 joborder = builder.job
48 if self.work_api == "containers":
49 dockerReq, is_req = self.get_requirement("DockerRequirement")
50 if dockerReq and dockerReq.get("dockerOutputDirectory"):
51 kwargs["outdir"] = dockerReq.get("dockerOutputDirectory")
52 kwargs["docker_outdir"] = dockerReq.get("dockerOutputDirectory")
54 kwargs["outdir"] = "/var/spool/cwl"
55 kwargs["docker_outdir"] = "/var/spool/cwl"
56 elif self.work_api == "jobs":
57 kwargs["outdir"] = "$(task.outdir)"
58 kwargs["docker_outdir"] = "$(task.outdir)"
59 kwargs["tmpdir"] = "$(task.tmpdir)"
60 kwargs["docker_tmpdir"] = "$(task.tmpdir)"
61 return super(ArvadosCommandTool, self).job(joborder, output_callback, **kwargs)