13773: Don't intercept logger.info() calls for runtime status.
[arvados.git] / sdk / cwl / arvados_cwl / arvtool.py
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
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
10
11 class ArvadosCommandTool(CommandLineTool):
12     """Wrap cwltool CommandLineTool to override selected methods."""
13
14     def __init__(self, arvrunner, toolpath_object, loadingContext):
15         super(ArvadosCommandTool, self).__init__(toolpath_object, loadingContext)
16         self.arvrunner = arvrunner
17
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)
23         else:
24             raise Exception("Unsupported work_api %s", runtimeContext.work_api)
25
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,
29                                  "/keep/%s",
30                                  "/keep/%s/%s")
31         elif runtimeContext.work_api == "jobs":
32             return ArvPathMapper(self.arvrunner, reffiles, runtimeContext.basedir,
33                                  "$(task.keep)/%s",
34                                  "$(task.keep)/%s/%s")
35
36     def job(self, joborder, output_callback, runtimeContext):
37
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
44
45         runtimeContext = runtimeContext.copy()
46
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")
52             else:
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)