Coverage for python/lsst/ctrl/bps/report.py: 13%
38 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-09 02:09 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-09 02:09 -0800
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 program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22"""Supporting functions for reporting on runs submitted to a WMS.
24Note: Expectations are that future reporting effort will revolve around LSST
25oriented database tables.
26"""
28import logging
30from lsst.utils import doImport
32from .bps_reports import DetailedRunReport, SummaryRunReport
33from .wms_service import WmsStates
35_LOG = logging.getLogger(__name__)
38def report(wms_service, run_id, user, hist_days, pass_thru, is_global=False):
39 """Print out summary of jobs submitted for execution.
41 Parameters
42 ----------
43 wms_service : `str`
44 Name of the class.
45 run_id : `str`
46 A run id the report will be restricted to.
47 user : `str`
48 A username the report will be restricted to.
49 hist_days : int
50 Number of days
51 pass_thru : `str`
52 A string to pass directly to the WMS service class.
53 is_global : `bool`, optional
54 If set, all available job queues will be queried for job information.
55 Defaults to False which means that only a local job queue will be
56 queried for information.
58 Only applicable in the context of a WMS using distributed job queues
59 (e.g., HTCondor).
60 """
61 wms_service_class = doImport(wms_service)
62 wms_service = wms_service_class({})
64 # If reporting on single run, increase history until better mechanism
65 # for handling completed jobs is available.
66 if run_id:
67 hist_days = max(hist_days, 2)
69 runs, message = wms_service.report(run_id, user, hist_days, pass_thru, is_global=is_global)
71 run_brief = SummaryRunReport(
72 [
73 ("X", "S"),
74 ("STATE", "S"),
75 ("%S", "S"),
76 ("ID", "S"),
77 ("OPERATOR", "S"),
78 ("PROJECT", "S"),
79 ("CAMPAIGN", "S"),
80 ("PAYLOAD", "S"),
81 ("RUN", "S"),
82 ]
83 )
84 if run_id:
85 fields = [(" ", "S")] + [(state.name, "i") for state in WmsStates] + [("EXPECTED", "i")]
86 run_report = DetailedRunReport(fields)
87 for run in runs:
88 run_brief.add(run, use_global_id=is_global)
89 run_report.add(run, use_global_id=is_global)
90 if run_report.message:
91 print(run_report.message)
93 print(run_brief)
94 print("\n")
95 print(f"Path: {run.path}")
96 print(f"Global job id: {run.global_wms_id}")
97 print("\n")
98 print(run_report)
100 run_brief.clear()
101 run_report.clear()
102 if not runs and not message:
103 print(
104 f"No records found for job id '{run_id}'. "
105 f"Hints: Double check id, retry with a larger --hist value (currently: {hist_days}), "
106 f"and/or use --global to search all job queues."
107 )
108 else:
109 for run in runs:
110 run_brief.add(run, use_global_id=is_global)
111 run_brief.sort("ID")
112 print(run_brief)
113 if message:
114 print(message)
115 print("\n")