ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Status.py
Revision: 1.2
Committed: Tue Jul 26 16:49:11 2005 UTC (19 years, 9 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_0_0_pre1
Changes since 1.1: +3 -7 lines
Log Message:
more changes

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     print 'Job %03d:'%(nj+1),jid,crabJobStatusToString(st)
53     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     try:
75     if result == 'Done':
76     self.countDone = self.countDone + 1
77     exCode = self.hstates['exit_code']
78     #statistic.notify('checkstatus',resFlag,exCode,dataset,owner,destination,broker,ID3,ID1,NJC)
79     elif result == 'Ready':
80     self.countReady = self.countReady + 1
81     #statistic.notify('checkstatus',resFlag,'-----',dataset,owner,destination,broker,ID3,ID1,NJC)
82     elif result == 'Scheduled':
83     self.countSched = self.countSched + 1
84     #statistic.notify('checkstatus',resFlag,'-----',dataset,owner,destination,broker,ID3,ID1,NJC)
85     elif result == 'Running':
86     self.countRun = self.countRun + 1
87     #statistic.notify('checkstatus',resFlag,'-----',dataset,owner,destination,broker,ID3,ID1,NJC)
88     elif result == 'Aborted':
89 slacapra 1.2 common.jobDB.setStatus(nj, 'A')
90 slacapra 1.1 #job.saveJobStatus()
91     #statistic.notify('checkstatus',resFlag,'abort',dataset,owner,destination,broker,ID3,ID1,NJC)
92     pass
93     elif result == 'Cancelled':
94     #job.setStatus('K')
95     #job.saveJobStatus()
96     #statistic.notify('checkstatus',resFlag,'cancel',dataset,owner,destination,broker,ID3,ID1,NJC)
97     pass
98     elif result == 'Cleared':
99     #job.setStatus('P')
100     exCode = self.hstates['exit_code']
101     #statistic.notify('checkstatus',resFlag,exCode,dataset,owner,destination,broker,ID3,ID1,NJC)
102     #job.saveJobStatus()
103     self.countCleared = self.countCleared + 1
104     except UnboundLocalError:
105     common.logger.message('ERROR: UnboundLocalError with ')
106    
107     def Report_(self) :
108    
109     """ Report #jobs for each status """
110    
111     #job_stat = common.job_list.loadStatus()
112    
113     print ''
114     print ">>>>>>>>> %i Total Jobs " % (self.countToTjob)
115    
116     if (self.countReady != 0):
117     print ''
118     print ">>>>>>>>> %i Jobs Ready" % (self.countReady)
119     if (self.countSched != 0):
120     print ''
121     print ">>>>>>>>> %i Jobs Scheduled" % (self.countSched)
122     if (self.countRun != 0):
123     print ''
124     print ">>>>>>>>> %i Jobs Running" % (self.countRun)
125     if (self.countCleared != 0):
126     print ''
127     print ">>>>>>>>> %i Jobs Retrieved (=Cleared)" % (self.countCleared)
128     print " You can resubmit them specifying JOB numbers: crab.py -resubmit JOB_number (or range of JOB) -continue"
129     print " (i.e -resubmit 1-3 => 1 and 2 and 3 or -resubmit 1,3 => 1 and 3)"
130     # if job_stat[6] or job_stat[7]:
131     # print ''
132     # print ">>>>>>>>> %i Jobs aborted or killed(=cancelled by user)" % (job_stat[6] + job_stat[7])
133     # print " Resubmit them with: crab.py -resubmit -continue to resubmit all"
134     # print " or specifying JOB numbers (i.e -resubmit 1-3 => 1 and 2 and 3 or -resubmit 1,3 => 1 and 3)"
135     # print " "
136     if (self.countDone != 0):
137     print ">>>>>>>>> %i Jobs Done" % (self.countDone)
138     print " Retrieve them with: crab.py -getoutput -continue to retrieve all"
139     print " or specifying JOB numbers (i.e -getoutput 1-3 => 1 and 2 and 3 or -getoutput 1,3 => 1 and 3)"
140     print('\n')
141     pass
142    
143    
144     def getJobStatus_(self, sid, attr):
145     result = ''
146     st = 0
147     self.jobStat.getStatus(sid, self.level)
148     (err, apiMsg) = self.jobStat.get_error()
149     if err:
150     common.logger.message(apiMsg)
151     return None
152     else:
153     for i in range(len(self.states)):
154     #print "states = ", self.states
155     # Fill an hash table with all information retrieved from LB API
156     self.hstates[ self.states[i] ] = self.jobStat.loadStatus(st)[i]
157     result = self.jobStat.loadStatus(st)[ self.states.index(attr) ]
158     return result