ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Status.py
Revision: 1.1
Committed: Mon Jul 25 14:31:24 2005 UTC (19 years, 9 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
Log Message:
too many changes to be listed...

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