Coverage for python/lsst/ctrl/bps/report.py: 13%
38 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-06 11:04 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-06 11:04 +0000
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, 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):
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 """
67 wms_service_class = doImport(wms_service)
68 wms_service = wms_service_class({})
70 # If reporting on single run, increase history until better mechanism
71 # for handling completed jobs is available.
72 if run_id:
73 hist_days = max(hist_days, 2)
75 runs, message = wms_service.report(run_id, user, hist_days, pass_thru, is_global=is_global)
77 run_brief = SummaryRunReport(
78 [
79 ("X", "S"),
80 ("STATE", "S"),
81 ("%S", "S"),
82 ("ID", "S"),
83 ("OPERATOR", "S"),
84 ("PROJECT", "S"),
85 ("CAMPAIGN", "S"),
86 ("PAYLOAD", "S"),
87 ("RUN", "S"),
88 ]
89 )
90 if run_id:
91 fields = [(" ", "S")] + [(state.name, "i") for state in WmsStates] + [("EXPECTED", "i")]
92 run_report = DetailedRunReport(fields)
93 for run in runs:
94 run_brief.add(run, use_global_id=is_global)
95 run_report.add(run, use_global_id=is_global)
96 if run_report.message:
97 print(run_report.message)
99 print(run_brief)
100 print("\n")
101 print(f"Path: {run.path}")
102 print(f"Global job id: {run.global_wms_id}")
103 print("\n")
104 print(run_report)
106 run_brief.clear()
107 run_report.clear()
108 if not runs and not message:
109 print(
110 f"No records found for job id '{run_id}'. "
111 f"Hints: Double check id, retry with a larger --hist value (currently: {hist_days}), "
112 "and/or use --global to search all job queues."
113 )
114 else:
115 for run in runs:
116 run_brief.add(run, use_global_id=is_global)
117 run_brief.sort("ID")
118 print(run_brief)
119 if message:
120 print(message)
121 print("\n")