ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Status.py
Revision: 1.16
Committed: Sat Dec 17 17:12:29 2005 UTC (19 years, 4 months ago) by corvo
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_0_6, CRAB_1_0_5, CRAB_1_0_4
Changes since 1.15: +11 -1 lines
Log Message:
Fixed ML bug

File Contents

# User Rev Content
1 slacapra 1.1 from Actor import *
2     import common, crab_util
3     import string, os
4 spiga 1.9 import Statistic
5 slacapra 1.1
6     class Status(Actor):
7 corvo 1.16 def __init__(self, cfg_params, nj_list=[]):
8 slacapra 1.15 if nj_list==[]:
9     self.nj_list = range(len(common.job_list))
10     else:
11     self.nj_list = nj_list
12 slacapra 1.1 self.countDone = 0
13     self.countReady = 0
14     self.countSched = 0
15     self.countRun = 0
16 slacapra 1.15 self.countAbort = 0
17     self.countCancel = 0
18 slacapra 1.1 self.countCleared = 0
19     self.countToTjob = 0
20 corvo 1.16 self.cfg_params = cfg_params
21 slacapra 1.1
22 spiga 1.9
23 slacapra 1.1 Status = crab_util.importName('edg_wl_userinterface_common_LbWrapper', 'Status')
24     # Bypass edg-job-status interfacing directly to C++ API
25     # Job attribute vector to retrieve status without edg-job-status
26     self.level = 0
27     # Instance of the Status class provided by LB API
28     self.jobStat = Status()
29    
30     self.states = [ "Acl", "cancelReason", "cancelling","ce_node","children", \
31     "children_hist","children_num","children_states","condorId","condor_jdl", \
32     "cpuTime","destination", "done_code","exit_code","expectFrom", \
33     "expectUpdate","globusId","jdl","jobId","jobtype", \
34     "lastUpdateTime","localId","location", "matched_jdl","network_server", \
35 slacapra 1.5 "owner","parent_job", "reason","resubmitted","rsl","seed",\
36     "stateEnterTime","stateEnterTimes","subjob_failed", \
37 slacapra 1.1 "user tags" , "status" , "status_code","hierarchy"]
38     self.hstates = {}
39 slacapra 1.6 for key in self.states:
40     self.hstates[key]=''
41 slacapra 1.1
42     return
43    
44     def run(self):
45     """
46     The main method of the class.
47     """
48     common.logger.debug(5, "Status::run() called")
49    
50 slacapra 1.15 self.compute()
51     self.PrintReport_()
52     pass
53    
54     def status(self) :
55     """ Return #jobs for each status as a tuple"""
56     return (self.countToTjob,self.countReady,self.countSched,self.countRun,self.countCleared,self.countAbort,self.countCancel,self.countDone)
57    
58     def compute(self):
59     """
60     Update the status to DB
61     """
62    
63 slacapra 1.1 common.jobDB.load()
64     for nj in self.nj_list:
65     st = common.jobDB.status(nj)
66     self.countToTjob = self.countToTjob + 1
67     jid = common.jobDB.jobId(nj)
68     if st == 'S':
69 slacapra 1.5 result = common.scheduler.queryStatus(jid)
70 slacapra 1.11 self.processResult_(nj, result, jid)
71 slacapra 1.10 exit = common.jobDB.exitStatus(nj)
72 slacapra 1.4 print 'Job %03d:'%(nj+1),jid,result,exit
73 corvo 1.16 dest = common.scheduler.getStatusAttribute_(jid, 'destination').split(":")[0]
74     if int(self.cfg_params['USER.activate_monalisa']) == 1:
75     self.cfg_params['apmon'].fillDict({'taskId': 'JobStatus', 'jobId': jid, \
76     'StatusValueReason': common.scheduler.getStatusAttribute_(jid, 'reason'), \
77     'StatusValue': st, 'StatusEnterTime': common.scheduler.getStatusAttribute_(jid, 'stateEnterTime'), 'StatusDestination': dest})
78     self.cfg_params['apmon'].sendToML()
79 slacapra 1.1 pass
80     else:
81 slacapra 1.10 exit = common.jobDB.exitStatus(nj)
82 fanzago 1.13 #print 'Job %03d:'%(nj+1),jid,crab_util.crabJobStatusToString(st),exit
83 slacapra 1.1 pass
84 corvo 1.16
85     if int(self.cfg_params['USER.activate_monalisa']) == 1:
86     self.cfg_params['apmon'].free()
87 slacapra 1.1 pass
88    
89 slacapra 1.2 common.jobDB.save()
90 slacapra 1.1 pass
91    
92 spiga 1.9 def processResult_(self, nj, result,jid):
93    
94     destination = common.scheduler.queryDest(jid).split(":")[0]
95     ID3 = jid.split("/")[3]
96     broker = jid.split("/")[2].split(":")[0]
97     resFlag = 0
98 slacapra 1.3 ### TODO: set relevant status also to DB
99    
100 slacapra 1.1 try:
101     if result == 'Done':
102     self.countDone = self.countDone + 1
103 spiga 1.9 exCode = common.scheduler.getExitStatus(jid)
104 slacapra 1.3 common.jobDB.setStatus(nj, 'D')
105 slacapra 1.10 jid = common.jobDB.jobId(nj)
106     exit = common.scheduler.getExitStatus(jid)
107     common.jobDB.setExitStatus(nj, exit)
108 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,exCode)
109 slacapra 1.1 elif result == 'Ready':
110     self.countReady = self.countReady + 1
111 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,'-----')
112 slacapra 1.1 elif result == 'Scheduled':
113     self.countSched = self.countSched + 1
114 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,'-----')
115 slacapra 1.1 elif result == 'Running':
116     self.countRun = self.countRun + 1
117 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,'-----')
118 slacapra 1.1 elif result == 'Aborted':
119 slacapra 1.2 common.jobDB.setStatus(nj, 'A')
120 slacapra 1.15 self.countAbort = self.countAbort + 1
121 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,'abort')
122 slacapra 1.1 pass
123     elif result == 'Cancelled':
124 slacapra 1.3 common.jobDB.setStatus(nj, 'K')
125 slacapra 1.15 self.countCancel = self.countCancel + 1
126 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,'cancel')
127 slacapra 1.1 pass
128     elif result == 'Cleared':
129 spiga 1.9 exCode = common.scheduler.getExitStatus(jid)
130 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,exCode)
131 slacapra 1.1 self.countCleared = self.countCleared + 1
132     except UnboundLocalError:
133     common.logger.message('ERROR: UnboundLocalError with ')
134    
135 slacapra 1.15 def PrintReport_(self) :
136 slacapra 1.1
137     """ Report #jobs for each status """
138    
139     #job_stat = common.job_list.loadStatus()
140    
141     print ''
142     print ">>>>>>>>> %i Total Jobs " % (self.countToTjob)
143    
144     if (self.countReady != 0):
145     print ''
146     print ">>>>>>>>> %i Jobs Ready" % (self.countReady)
147     if (self.countSched != 0):
148     print ''
149     print ">>>>>>>>> %i Jobs Scheduled" % (self.countSched)
150     if (self.countRun != 0):
151     print ''
152     print ">>>>>>>>> %i Jobs Running" % (self.countRun)
153     if (self.countCleared != 0):
154     print ''
155     print ">>>>>>>>> %i Jobs Retrieved (=Cleared)" % (self.countCleared)
156     print " You can resubmit them specifying JOB numbers: crab.py -resubmit JOB_number (or range of JOB) -continue"
157     print " (i.e -resubmit 1-3 => 1 and 2 and 3 or -resubmit 1,3 => 1 and 3)"
158     # if job_stat[6] or job_stat[7]:
159     # print ''
160     # print ">>>>>>>>> %i Jobs aborted or killed(=cancelled by user)" % (job_stat[6] + job_stat[7])
161     # print " Resubmit them with: crab.py -resubmit -continue to resubmit all"
162     # print " or specifying JOB numbers (i.e -resubmit 1-3 => 1 and 2 and 3 or -resubmit 1,3 => 1 and 3)"
163     # print " "
164     if (self.countDone != 0):
165     print ">>>>>>>>> %i Jobs Done" % (self.countDone)
166     print " Retrieve them with: crab.py -getoutput -continue to retrieve all"
167     print " or specifying JOB numbers (i.e -getoutput 1-3 => 1 and 2 and 3 or -getoutput 1,3 => 1 and 3)"
168     print('\n')
169     pass
170