Coverage for python/lsst/ctrl/bps/report.py: 11%
45 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 03:02 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 03:02 -0700
1# This file is part of ctrl_bps.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <https://www.gnu.org/licenses/>.
28"""Supporting functions for reporting on runs submitted to a WMS.
30Note: Expectations are that future reporting effort will revolve around LSST
31oriented database tables.
32"""
34import logging
36from lsst.utils import doImport
38from .bps_reports import DetailedRunReport, ExitCodesReport, SummaryRunReport
39from .wms_service import WmsStates
41_LOG = logging.getLogger(__name__)
44def report(wms_service, run_id, user, hist_days, pass_thru, is_global=False, return_exit_codes=False):
45 """Print out summary of jobs submitted for execution.
47 Parameters
48 ----------
49 wms_service : `str`
50 Name of the class.
51 run_id : `str`
52 A run id the report will be restricted to.
53 user : `str`
54 A username the report will be restricted to.
55 hist_days : int
56 Number of days.
57 pass_thru : `str`
58 A string to pass directly to the WMS service class.
59 is_global : `bool`, optional
60 If set, all available job queues will be queried for job information.
61 Defaults to False which means that only a local job queue will be
62 queried for information.
64 Only applicable in the context of a WMS using distributed job queues
65 (e.g., HTCondor).
66 return_exit_codes : `bool`, optional
67 If set, return exit codes related to jobs with a
68 non-success status. Defaults to False, which means that only
69 the summary state is returned.
71 Only applicable in the context of a WMS with associated
72 handlers to return exit codes from jobs.
73 """
74 wms_service_class = doImport(wms_service)
75 wms_service = wms_service_class({})
77 # If reporting on single run, increase history until better mechanism
78 # for handling completed jobs is available.
79 if run_id:
80 hist_days = max(hist_days, 2)
82 runs, message = wms_service.report(run_id, user, hist_days, pass_thru, is_global=is_global)
84 run_brief = SummaryRunReport(
85 [
86 ("X", "S"),
87 ("STATE", "S"),
88 ("%S", "S"),
89 ("ID", "S"),
90 ("OPERATOR", "S"),
91 ("PROJECT", "S"),
92 ("CAMPAIGN", "S"),
93 ("PAYLOAD", "S"),
94 ("RUN", "S"),
95 ]
96 )
98 if run_id:
99 fields = [(" ", "S")] + [(state.name, "i") for state in WmsStates] + [("EXPECTED", "i")]
100 run_report = DetailedRunReport(fields)
101 for run in runs:
102 run_brief.add(run, use_global_id=is_global)
103 run_report.add(run, use_global_id=is_global)
104 if run_report.message:
105 print(run_report.message)
107 print(run_brief)
108 print("\n")
109 print(f"Path: {run.path}")
110 print(f"Global job id: {run.global_wms_id}")
111 print("\n")
112 print(run_report)
114 if return_exit_codes:
115 fields = [
116 (" ", "S"),
117 ("PAYLOAD ERROR COUNT", "i"),
118 ("PAYLOAD ERROR CODES", "S"),
119 ("INFRASTRUCTURE ERROR COUNT", "i"),
120 ("INFRASTRUCTURE ERROR CODES", "S"),
121 ]
122 run_exits_report = ExitCodesReport(fields)
123 run_exits_report.add(run, use_global_id=is_global)
124 print("\n")
125 print(run_exits_report)
126 run_exits_report.clear()
128 run_brief.clear()
129 run_report.clear()
130 if not runs and not message:
131 print(
132 f"No records found for job id '{run_id}'. "
133 f"Hints: Double check id, retry with a larger --hist value (currently: {hist_days}), "
134 "and/or use --global to search all job queues."
135 )
136 else:
137 for run in runs:
138 run_brief.add(run, use_global_id=is_global)
139 run_brief.sort("ID")
140 print(run_brief)
141 if message:
142 print(message)
143 print("\n")