ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Status.py
Revision: 1.3
Committed: Wed Aug 10 16:52:51 2005 UTC (19 years, 8 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
Changes since 1.2: +6 -1 lines
Log Message:
more check on DB plus other

File Contents

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