ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Status.py
Revision: 1.20
Committed: Wed Oct 25 16:21:36 2006 UTC (18 years, 6 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_5_0_pre3, CRAB_1_5_0_pre2, CRAB_1_4_2, CRAB_1_5_0_pre1, CRAB_1_4_1, CRAB_1_4_1_pre2, CRAB_1_4_1_pre1
Branch point for: branch_1_4_1
Changes since 1.19: +4 -1 lines
Log Message:
modify the logic of status so that first the status of all jobs is retrieved from Boss DB, and then is used: previously the status of each jobs was retrieved separately

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 gutsche 1.18 #Status = crab_util.importName('edg_wl_userinterface_common_LbWrapper', 'Status')
24 slacapra 1.1 # 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 gutsche 1.18 #self.jobStat = Status()
29 slacapra 1.1
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 slacapra 1.20 bossTaskId = common.taskDB.dict('BossTaskId')
63     statusList = common.scheduler.queryStatusList(bossTaskId, int_id)
64 slacapra 1.15
65 slacapra 1.1 common.jobDB.load()
66     for nj in self.nj_list:
67     st = common.jobDB.status(nj)
68     self.countToTjob = self.countToTjob + 1
69     jid = common.jobDB.jobId(nj)
70 gutsche 1.18 if st == 'S' or st == 'A' or st == 'D' or st == 'K':
71 slacapra 1.20 #result = common.scheduler.queryStatus(jid)
72     result = statusList[jid]
73 slacapra 1.11 self.processResult_(nj, result, jid)
74 slacapra 1.10 exit = common.jobDB.exitStatus(nj)
75 slacapra 1.4 print 'Job %03d:'%(nj+1),jid,result,exit
76 gutsche 1.18 dest = common.scheduler.queryDest(jid)
77     if ( dest.find(":") != -1 ) :
78     dest = destination.split(":")[0]
79 corvo 1.16 if int(self.cfg_params['USER.activate_monalisa']) == 1:
80 corvo 1.19 params = {'taskId': 'JobStatus', 'jobId': jid, 'StatusValueReason': common.scheduler.getStatusAttribute_(jid, 'reason'), \
81     'StatusValue': st, 'StatusEnterTime': common.scheduler.getStatusAttribute_(jid, 'stateEnterTime'), 'StatusDestination': dest}
82     # self.cfg_params['apmon'].fillDict({'taskId': 'JobStatus', 'jobId': jid, \
83     # 'StatusValueReason': common.scheduler.getStatusAttribute_(jid, 'reason'), \
84     # 'StatusValue': st, 'StatusEnterTime': common.scheduler.getStatusAttribute_(jid, 'stateEnterTime'), 'StatusDestination': dest})
85     self.cfg_params['apmon'].sendToML(params)
86 slacapra 1.1 pass
87     else:
88 slacapra 1.10 exit = common.jobDB.exitStatus(nj)
89 fanzago 1.13 #print 'Job %03d:'%(nj+1),jid,crab_util.crabJobStatusToString(st),exit
90 slacapra 1.1 pass
91 corvo 1.16
92 slacapra 1.2 common.jobDB.save()
93 slacapra 1.1 pass
94    
95 spiga 1.9 def processResult_(self, nj, result,jid):
96    
97 gutsche 1.18 destination = common.scheduler.queryDest(jid)
98     if ( destination.find(":") != -1 ) :
99     destination = destination.split(":")[0]
100    
101     if ( jid.find(":") != -1 ) :
102     ID3 = jid.split("/")[3]
103     broker = jid.split("/")[2].split(":")[0]
104     else :
105     ID3 = jid
106     broker = 'OSG'
107    
108 spiga 1.9 resFlag = 0
109 slacapra 1.3 ### TODO: set relevant status also to DB
110    
111 slacapra 1.1 try:
112     if result == 'Done':
113     self.countDone = self.countDone + 1
114 spiga 1.9 exCode = common.scheduler.getExitStatus(jid)
115 slacapra 1.3 common.jobDB.setStatus(nj, 'D')
116 slacapra 1.10 jid = common.jobDB.jobId(nj)
117     exit = common.scheduler.getExitStatus(jid)
118     common.jobDB.setExitStatus(nj, exit)
119 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,exCode)
120 slacapra 1.1 elif result == 'Ready':
121     self.countReady = self.countReady + 1
122 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,'-----')
123 slacapra 1.1 elif result == 'Scheduled':
124     self.countSched = self.countSched + 1
125 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,'-----')
126 slacapra 1.1 elif result == 'Running':
127     self.countRun = self.countRun + 1
128 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,'-----')
129 slacapra 1.1 elif result == 'Aborted':
130 slacapra 1.2 common.jobDB.setStatus(nj, 'A')
131 slacapra 1.15 self.countAbort = self.countAbort + 1
132 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,'abort')
133 slacapra 1.1 pass
134     elif result == 'Cancelled':
135 slacapra 1.3 common.jobDB.setStatus(nj, 'K')
136 slacapra 1.15 self.countCancel = self.countCancel + 1
137 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,'cancel')
138 slacapra 1.1 pass
139     elif result == 'Cleared':
140 spiga 1.9 exCode = common.scheduler.getExitStatus(jid)
141 spiga 1.14 Statistic.Monitor('checkstatus',resFlag,jid,exCode)
142 slacapra 1.1 self.countCleared = self.countCleared + 1
143     except UnboundLocalError:
144     common.logger.message('ERROR: UnboundLocalError with ')
145    
146 slacapra 1.15 def PrintReport_(self) :
147 slacapra 1.1
148     """ Report #jobs for each status """
149    
150     #job_stat = common.job_list.loadStatus()
151    
152     print ''
153     print ">>>>>>>>> %i Total Jobs " % (self.countToTjob)
154    
155     if (self.countReady != 0):
156     print ''
157     print ">>>>>>>>> %i Jobs Ready" % (self.countReady)
158     if (self.countSched != 0):
159     print ''
160     print ">>>>>>>>> %i Jobs Scheduled" % (self.countSched)
161     if (self.countRun != 0):
162     print ''
163     print ">>>>>>>>> %i Jobs Running" % (self.countRun)
164     if (self.countCleared != 0):
165     print ''
166     print ">>>>>>>>> %i Jobs Retrieved (=Cleared)" % (self.countCleared)
167     print " You can resubmit them specifying JOB numbers: crab.py -resubmit JOB_number (or range of JOB) -continue"
168     print " (i.e -resubmit 1-3 => 1 and 2 and 3 or -resubmit 1,3 => 1 and 3)"
169     # if job_stat[6] or job_stat[7]:
170     # print ''
171     # print ">>>>>>>>> %i Jobs aborted or killed(=cancelled by user)" % (job_stat[6] + job_stat[7])
172     # print " Resubmit them with: crab.py -resubmit -continue to resubmit all"
173     # print " or specifying JOB numbers (i.e -resubmit 1-3 => 1 and 2 and 3 or -resubmit 1,3 => 1 and 3)"
174     # print " "
175     if (self.countDone != 0):
176     print ">>>>>>>>> %i Jobs Done" % (self.countDone)
177     print " Retrieve them with: crab.py -getoutput -continue to retrieve all"
178     print " or specifying JOB numbers (i.e -getoutput 1-3 => 1 and 2 and 3 or -getoutput 1,3 => 1 and 3)"
179     print('\n')
180     pass
181