ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Status.py
Revision: 1.18
Committed: Mon Mar 27 17:36:35 2006 UTC (19 years, 1 month ago) by gutsche
Content type: text/x-python
Branch: MAIN
Changes since 1.17: +17 -7 lines
Log Message:
commented out call to edg_wl_userinterface_common_LbWrapper because it would break condor_g scheduler execution on OSG-client only machines and secure parsing of jid and destination, in case of condor, no https grid id is available

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