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

63 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-19 10:53 +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/>. 

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 "--global/--no-global", 

111 "is_global", 

112 default=False, 

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

114) 

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

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

117 report_driver(*args, **kwargs) 

118 

119 

120@click.command(cls=BpsCommand) 

121@opt.wms_service_option() 

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

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

124@click.option( 

125 "--require-bps/--skip-require-bps", 

126 "require_bps", 

127 default=True, 

128 show_default=True, 

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

130) 

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

132@click.option( 

133 "--global/--no-global", 

134 "is_global", 

135 default=False, 

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

137) 

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

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

140 cancel_driver(*args, **kwargs) 

141 

142 

143@click.command(cls=BpsCommand) 

144@opt.wms_service_option() 

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

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

147 """Ping workflow services.""" 

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

149 # to the shell. Using click function instead. 

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