Coverage for python/lsst/ctrl/bps/cancel.py: 19%

18 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-08 03:00 -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 

28"""API for cancelling runs submitted to a WMS. 

29""" 

30 

31import logging 

32 

33from lsst.utils import doImport 

34 

35_LOG = logging.getLogger(__name__) 

36 

37 

38def cancel(wms_service, wms_id=None, user=None, require_bps=True, pass_thru=None, is_global=False): 

39 """Cancel submitted workflows. 

40 

41 Parameters 

42 ---------- 

43 wms_service : `str` or `lsst.ctrl.bps.BaseWmsService` 

44 Name of the Workload Management System service class. 

45 wms_id : `str`, optional 

46 ID or path of job that should be canceled. 

47 user : `str`, optional 

48 User whose submitted jobs should be canceled. 

49 require_bps : `bool`, optional 

50 Whether to require given run_id/user to be a bps submitted job. 

51 pass_thru : `str`, optional 

52 Information to pass through to WMS. 

53 is_global : `bool`, optional 

54 If set, all available job queues will be checked for jobs to cancel. 

55 Defaults to False which means that only a local job queue will be 

56 checked. 

57 

58 Only applicable in the context of a WMS using distributed job queues 

59 (e.g., HTCondor). 

60 """ 

61 _LOG.debug( 

62 "Cancel params: wms_id=%s, user=%s, require_bps=%s, pass_thru=%s, is_global=%s", 

63 wms_id, 

64 user, 

65 require_bps, 

66 pass_thru, 

67 is_global, 

68 ) 

69 

70 if isinstance(wms_service, str): 

71 wms_service_class = doImport(wms_service) 

72 service = wms_service_class({}) 

73 else: 

74 service = wms_service 

75 

76 jobs = service.list_submitted_jobs(wms_id, user, require_bps, pass_thru, is_global) 

77 if len(jobs) == 0: 

78 print( 

79 "No job matches the search criteria. " 

80 "Hints: Double check id, and/or use --global to search all job queues." 

81 ) 

82 else: 

83 for job_id in sorted(jobs): 

84 results = service.cancel(job_id, pass_thru) 

85 if results[0]: 

86 print(f"Successfully canceled job with id '{job_id}'") 

87 else: 

88 print(f"Couldn't cancel job with id '{job_id}' ({results[1]})")