ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/Status.py
Revision: 1.17
Committed: Tue Mar 21 16:08:04 2006 UTC (19 years, 1 month ago) by corvo
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_0_7, CRAB_1_0_7_pre1
Changes since 1.16: +0 -4 lines
Log Message:
Removed the call to free() for apmon

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