Coverage for python/lsst/ctrl/bps/cli/cmd/commands.py: 95%

64 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-03-29 03:04 -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/>. 

27"""Subcommand definitions. 

28""" 

29import click 

30from lsst.daf.butler.cli.utils import MWCommand 

31 

32from ...drivers import ( 

33 acquire_qgraph_driver, 

34 cancel_driver, 

35 cluster_qgraph_driver, 

36 ping_driver, 

37 prepare_driver, 

38 report_driver, 

39 restart_driver, 

40 submit_driver, 

41 transform_driver, 

42) 

43from .. import opt 

44 

45 

46class BpsCommand(MWCommand): 

47 """Command subclass with bps-command specific overrides.""" 

48 

49 extra_epilog = "See 'bps --help' for more options." 

50 

51 

52@click.command(cls=BpsCommand) 

53@opt.config_file_argument(required=True) 

54@opt.submission_options() 

55def acquire(*args, **kwargs): 

56 """Create a new quantum graph or read existing one from a file.""" 

57 acquire_qgraph_driver(*args, **kwargs) 

58 

59 

60@click.command(cls=BpsCommand) 

61@opt.config_file_argument(required=True) 

62@opt.submission_options() 

63def cluster(*args, **kwargs): 

64 """Create a clustered quantum graph.""" 

65 cluster_qgraph_driver(*args, **kwargs) 

66 

67 

68@click.command(cls=BpsCommand) 

69@opt.config_file_argument(required=True) 

70@opt.submission_options() 

71def transform(*args, **kwargs): 

72 """Transform a quantum graph to a generic workflow.""" 

73 transform_driver(*args, **kwargs) 

74 

75 

76@click.command(cls=BpsCommand) 

77@opt.config_file_argument(required=True) 

78@opt.wms_service_option() 

79@opt.submission_options() 

80def prepare(*args, **kwargs): 

81 """Prepare a workflow for submission.""" 

82 prepare_driver(*args, **kwargs) 

83 

84 

85@click.command(cls=BpsCommand) 

86@opt.config_file_argument(required=True) 

87@opt.wms_service_option() 

88@opt.compute_site_option() 

89@opt.submission_options() 

90def submit(*args, **kwargs): 

91 """Submit a workflow for execution.""" 

92 submit_driver(*args, **kwargs) 

93 

94 

95@click.command(cls=BpsCommand) 

96@opt.wms_service_option() 

97@click.option("--id", "run_id", help="Run id of workflow to restart.") 

98def restart(*args, **kwargs): 

99 """Restart a failed workflow.""" 

100 restart_driver(*args, **kwargs) 

101 

102 

103@click.command(cls=BpsCommand) 

104@opt.wms_service_option() 

105@click.option("--id", "run_id", help="Restrict report to specific WMS run id.") 

106@click.option("--user", help="Restrict report to specific user.") 

107@click.option("--hist", "hist_days", default=0.0, help="Search WMS history X days for completed info.") 

108@click.option("--pass-thru", help="Pass the given string to the WMS service class.") 

109@click.option( 

110 "--return-exit-codes", 

111 is_flag=True, 

112 show_default=True, 

113 default=False, 

114 help="Return exit codes from jobs with a non-success status.", 

115) 

116@click.option( 

117 "--global/--no-global", 

118 "is_global", 

119 default=False, 

120 help="Query all available job queues for job information.", 

121) 

122def report(*args, **kwargs): 

123 """Display execution status for submitted workflows.""" 

124 report_driver(*args, **kwargs) 

125 

126 

127@click.command(cls=BpsCommand) 

128@opt.wms_service_option() 

129@click.option("--id", "run_id", help="Run id of workflow to cancel.") 

130@click.option("--user", help="User for which to cancel all submitted workflows.") 

131@click.option( 

132 "--require-bps/--skip-require-bps", 

133 "require_bps", 

134 default=True, 

135 show_default=True, 

136 help="Only cancel jobs submitted via bps.", 

137) 

138@click.option("--pass-thru", "pass_thru", default="", help="Pass the given string to the WMS service.") 

139@click.option( 

140 "--global/--no-global", 

141 "is_global", 

142 default=False, 

143 help="Cancel jobs matching the search criteria from all job queues.", 

144) 

145def cancel(*args, **kwargs): 

146 """Cancel submitted workflow(s).""" 

147 cancel_driver(*args, **kwargs) 

148 

149 

150@click.command(cls=BpsCommand) 

151@opt.wms_service_option() 

152@click.option("--pass-thru", "pass_thru", default="", help="Pass the given string to the WMS service.") 

153def ping(*args, **kwargs): 

154 """Ping workflow services.""" 

155 # Note: Using return statement doesn't actually return the value 

156 # to the shell. Using click function instead. 

157 click.get_current_context().exit(ping_driver(*args, **kwargs))