Debian Codegraph @

cylc/flow/job_runner_handlers/pbs_multi_cluster.py

raw
1 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
2 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 """PBS job submission and manipulation: multi-cluster variant.
17
18 Support PBS clients that front heterogeneous clusters where the Job ID returned
19 by qsub is <id>.<server>. PBS 13 qstat and qdel need <id>.<server>@<server>.
20 From PBS 14, the standard cylc PBS module works ("@<server>" is not needed).
21
22 So this PBS handler writes "job_id@server" to the job status file, and appends
23 "@server" to Job IDs returned by qstat, to matched the stored IDs.
24 """
25
26 import re
27 from cylc.flow.job_runner_handlers.pbs import PBSHandler
28
29
30 # Match and extract PBS Job ID of the form "<job>.<host>"
31 REC_JOB = re.compile(r'^ *(?P<job>[^ ]+?)\.(?P<host>[^ ]+) *$')
32 # Replace with "<job>.<host>@<host>"
33 REP_JOB = r'\g<job>.\g<host>@\g<host>'
34
35
36 class PBSMulticlusterHandler(PBSHandler):
37
38 @classmethod
39 def filter_poll_many_output(cls, out):
40 """Extract and return Job IDs from qstat output.
41
42 Ignore first two lines of qstat output (header lines).
43 Manipulate Job IDs as described above, if matched, else leave as-is.
44 """
45 job_ids = []
46 for line in out.splitlines()[2:]:
47 job_ids.append(cls.manip_job_id(line))
48 return job_ids
49
50 @classmethod
51 def manip_job_id(cls, job_id):
52 """For job_id of the form "id.server", return job_id@server."""
53 return re.sub(REC_JOB, REP_JOB, job_id.strip())
54
55
56 JOB_RUNNER_HANDLER = PBSMulticlusterHandler()