ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/StatusServer.py
Revision: 1.19
Committed: Tue Sep 25 15:18:37 2007 UTC (17 years, 7 months ago) by mcinquil
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_0_2_pre5, CRAB_2_0_2_pre4, CRAB_2_0_2_pre3, CRAB_2_0_2_pre2, CRAB_2_0_2_pre1, CRAB_2_0_1, CRAB_2_0_1_pre1, CRAB_2_0_0, CRAB_2_0_0_pre10, CRAB_2_0_0_pre9, CRAB_1_5_4
Changes since 1.18: +4 -1 lines
Log Message:
Not showing site if the jobs is resubmitting

File Contents

# User Rev Content
1 spiga 1.1 from Actor import *
2     from crab_util import *
3     import common
4     from ApmonIf import ApmonIf
5     import Statistic
6     import time
7     from ProgressBar import ProgressBar
8     from TerminalController import TerminalController
9    
10     import xml.dom.minidom
11     import xml.dom.ext
12     import TaskDB
13    
14     class StatusServer(Actor):
15    
16     def __init__(self, cfg_params,):
17     self.cfg_params = cfg_params
18 mcinquil 1.2
19 mcinquil 1.8 self.countNotSubmit = 0
20 mcinquil 1.2 self.countSubmit = 0
21     self.countSubmitting = 0
22 mcinquil 1.11 self.countWait = 0
23 mcinquil 1.2 self.countDone = 0
24     self.countReady = 0
25     self.countSched = 0
26     self.countRun = 0
27     self.countAbort = 0
28     self.countCancel = 0
29 mcinquil 1.12 self.countRet = 0
30 mcinquil 1.6 self.countKilled = 0
31 mcinquil 1.2 self.countCleared = 0
32     self.countToTjob = 0
33    
34 spiga 1.3 try:
35     self.server_name = self.cfg_params['CRAB.server_name'] # gsiftp://pcpg01.cern.ch/data/SEDir/
36     except KeyError:
37     msg = 'No server selected ...'
38     msg = msg + 'Please specify a server in the crab cfg file'
39     raise CrabException(msg)
40    
41 spiga 1.1 return
42 mcinquil 1.2
43     def translateStatus(self, status):
44     """
45     simmetric as server
46     """
47    
48 mcinquil 1.4 stateConverting = {'Running': 'R', 'Aborted': 'A', 'Done': 'D', 'Done (Failed)': 'D',\
49 mcinquil 1.12 'Cleared': 'D', 'Cancelled': 'K', 'Killed': 'K', 'NotSubmitted': 'C',\
50 spiga 1.13 'Retrieving by the server': 'R' }
51 mcinquil 1.2
52     if status in stateConverting:
53     return stateConverting[status]
54     return None
55    
56    
57 spiga 1.1 def run(self):
58     """
59     The main method of the class: check the status of the task
60     """
61     common.logger.debug(5, "status server::run() called")
62     start = time.time()
63    
64     totalCreatedJobs = 0
65 mcinquil 1.16 flagSubmit = 0
66 spiga 1.1 for nj in range(common.jobDB.nJobs()):
67 mcinquil 1.17 if (common.jobDB.status(nj) != 'C'):
68 spiga 1.1 totalCreatedJobs +=1
69 mcinquil 1.16 flagSubmit = 1
70 spiga 1.1
71     if not flagSubmit:
72 mcinquil 1.17 common.logger.message("Your jobs are not yet submitted!")
73 mcinquil 1.16 common.logger.message("Before checking the status submit your jobs with the command: crab -submit all -c\n")
74 spiga 1.1 return
75    
76     common.scheduler.checkProxy()
77    
78     common.taskDB.load()
79     WorkDirName =os.path.basename(os.path.split(common.work_space.topDir())[0])
80     projectUniqName = 'crab_'+str(WorkDirName)+'_'+common.taskDB.dict('TasKUUID')
81     try:
82     common.logger.message ("Checking the status...\n")
83 mcinquil 1.17 cmd = 'lcg-cp --vo cms gsiftp://' + str(self.server_name) + str(projectUniqName)+\
84     '/res/xmlReportFile.xml file://'+common.work_space.resDir()+'xmlReportFile.xml'
85 mcinquil 1.2 common.logger.debug(6, cmd)
86 spiga 1.1 os.system(cmd +' >& /dev/null')
87    
88     except:
89 mcinquil 1.10 #msg = ("task status not yet available")
90     msg = "The server is managing your task."
91     msg += "\n A detailed report will be ready soon.\n"
92 spiga 1.1 raise CrabException(msg)
93    
94     try:
95     file = open(common.work_space.resDir()+"xmlReportFile.xml", "r")
96     doc = xml.dom.minidom.parse(common.work_space.resDir()+ "xmlReportFile.xml" )
97    
98     except:
99 mcinquil 1.10 #msg = ("problems reading report file")
100     msg = "The server is managing your task."
101     msg += "\n A detailed report will be ready soon.\n"
102 spiga 1.1 raise CrabException(msg)
103    
104 mcinquil 1.2 ### <Job status='Submitted' job_exit='NULL' id='1' exe_exit='NULL'/>
105    
106 spiga 1.1 task = doc.childNodes[0].childNodes[1].getAttribute("taskName")
107 mcinquil 1.2 self.countToTjob = int(doc.childNodes[0].childNodes[1].getAttribute("totJob") )
108    
109     addTree = 3
110    
111     common.jobDB.load()
112    
113     if doc.childNodes[0].childNodes[3].getAttribute("id") == "all":
114     if doc.childNodes[0].childNodes[3].getAttribute("status") == "Submitted":
115     self.countSubmitting = common.jobDB.nJobs()
116     for nj in range(common.jobDB.nJobs()):
117     common.jobDB.setStatus(nj, 'S')
118 mcinquil 1.6 elif doc.childNodes[0].childNodes[3].getAttribute("status") == "Killed":
119     self.countKilled = common.jobDB.nJobs()
120     for nj in range(common.jobDB.nJobs()):
121     common.jobDB.setStatus(nj, 'K')
122 mcinquil 1.14 self.countKilled = common.jobDB.nJobs()
123 mcinquil 1.8 elif doc.childNodes[0].childNodes[3].getAttribute("status") == "NotSubmitted":
124     self.countNotSubmit = common.jobDB.nJobs()
125 mcinquil 1.2 for nj in range(common.jobDB.nJobs()):
126 mcinquil 1.8 common.jobDB.setStatus(nj, 'C')
127 mcinquil 1.2 self.countToTjob = common.jobDB.nJobs()
128 spiga 1.1 else:
129 mcinquil 1.2 printline = ''
130 mcinquil 1.18 printline+= "%-10s %-24s %-20s %-20s %-18s %-20s" % ('JOBID','STATUS','SITE','JOB_EXIT_STATUS','EXE_EXIT_CODE','RESUBMIT')
131 mcinquil 1.2 print printline
132 mcinquil 1.16 print '---------------------------------------------------------------------------------------------------------'
133 mcinquil 1.2
134     for job in range( self.countToTjob ):
135     idJob = doc.childNodes[0].childNodes[job+addTree].getAttribute("id")
136     stato = doc.childNodes[0].childNodes[job+addTree].getAttribute("status")
137     exe_exit_code = doc.childNodes[0].childNodes[job+addTree].getAttribute("job_exit")
138     job_exit_status = doc.childNodes[0].childNodes[job+addTree].getAttribute("exe_exit")
139 mcinquil 1.5 cleared = doc.childNodes[0].childNodes[job+addTree].getAttribute("cleared")
140 mcinquil 1.15
141     try:
142     site = doc.childNodes[0].childNodes[job+addTree].getAttribute("site")
143     resub = doc.childNodes[0].childNodes[job+addTree].getAttribute("resubmit")
144 mcinquil 1.17 if site == "NULL" or site=="None":
145 mcinquil 1.15 site=''
146 mcinquil 1.17 if resub == "NULL" or resub =="None" or resub == "0":
147 mcinquil 1.15 resub=''
148     if stato == "Killed":
149     resub=''
150     except Excpetion, ex:
151 mcinquil 1.17 common.logger.message ("Problem reading report file!")
152 mcinquil 1.15 common.logger.debug( 1 , str(ex) )
153    
154 mcinquil 1.2 jobDbStatus = self.translateStatus(stato)
155     if jobDbStatus != None:
156     common.logger.debug(5, '*** Updating jobdb for job %s ***' %idJob)
157     if common.jobDB.status( str(int(idJob)-1) ) != "Y":
158 mcinquil 1.5 if jobDbStatus == 'D' and int(cleared) != 1:#exe_exit_code =='' and job_exit_status=='':
159     ## 'Done' but not yet cleared (server side) still showing 'Running'
160 mcinquil 1.12 ##stato = 'Running'
161 spiga 1.13 stato = 'Retrieving by the server' ## changed - is this user friendly?
162 mcinquil 1.5 jobDbStatus = 'R'
163 mcinquil 1.2 common.jobDB.setStatus( str(int(idJob)-1), self.translateStatus(stato) )
164     else:
165     stato = "Cleared"
166     common.jobDB.setExitStatus( str(int(idJob)-1), job_exit_status )
167 mcinquil 1.4 if stato != "Done" and stato != "Cleared" and stato != "Aborted" and stato != "Done (Failed)":
168 mcinquil 1.19 sitotemp = site
169     if stato == "Resubmitting by the server":
170     sitotemp = ""
171     print "%-10s %-24s %-20s %-20s %-18s %-20s" % (idJob,stato,sitotemp,'','',resub)
172 mcinquil 1.2 else:
173 mcinquil 1.18 print "%-10s %-24s %-20s %-20s %-18s %-20s" % (idJob,stato,site,exe_exit_code,job_exit_status,resub)
174 mcinquil 1.2
175     if stato == 'Running':
176     self.countRun += 1
177     elif stato == 'Aborted':
178     self.countAbort += 1
179 mcinquil 1.11 elif stato == 'Done' or stato == 'Done (Failed)':
180 mcinquil 1.2 self.countDone += 1
181     elif stato == 'Cancelled':
182     self.countCancel += 1
183     elif stato == 'Submitted':
184     self.countSubmit += 1
185     elif stato == 'Submitting':
186     self.countSubmitting += 1
187     elif stato == 'Ready':
188     self.countReady += 1
189     elif stato == 'Scheduled':
190     self.countSched += 1
191     elif stato == 'Cleared':
192     self.countCleared += 1
193 mcinquil 1.8 elif stato == 'NotSubmitted':
194 mcinquil 1.18 self.countNotSubmit += 1
195 mcinquil 1.11 elif stato == 'Waiting':
196     self.countWait += 1
197 spiga 1.13 elif stato == 'Retrieving by the server':
198 mcinquil 1.12 self.countRet += 1
199 mcinquil 1.14 elif stato == 'Killed':
200     self.countKilled += 1
201 mcinquil 1.2
202     addTree += 1
203     common.jobDB.save()
204    
205     self.PrintReport_()
206    
207    
208     def PrintReport_(self) :
209    
210     """ Report #jobs for each status """
211    
212    
213     print ''
214     print ">>>>>>>>> %i Total Jobs " % (self.countToTjob)
215     print ''
216    
217     if (self.countSubmitting != 0) :
218     print ">>>>>>>>> %i Jobs Submitting by the server" % (self.countSubmitting)
219 mcinquil 1.8 if (self.countNotSubmit != 0):
220     print ">>>>>>>>> %i Jobs Not Submitted to the grid" % (self.countNotSubmit)
221 mcinquil 1.2 if (self.countSubmit != 0):
222     print ">>>>>>>>> %i Jobs Submitted" % (self.countSubmit)
223 mcinquil 1.11 if (self.countWait != 0):
224     print ">>>>>>>>> %i Jobs Waiting" % (self.countWait)
225 mcinquil 1.6 if (self.countReady != 0):
226     print ">>>>>>>>> %i Jobs Ready" % (self.countReady)
227 mcinquil 1.2 if (self.countSched != 0):
228     print ">>>>>>>>> %i Jobs Scheduled" % (self.countSched)
229 mcinquil 1.14 if (self.countRun != 0):
230     print ">>>>>>>>> %i Jobs Running" % (self.countRun)
231 mcinquil 1.12 if (self.countRet != 0):
232 spiga 1.13 print ">>>>>>>>> %i Jobs Retrieving by the server" % (self.countRet)
233 mcinquil 1.6 if (self.countDone != 0):
234     print ">>>>>>>>> %i Jobs Done" % (self.countDone)
235     print " Retrieve them with: crab -getoutput -continue"
236     if (self.countKilled != 0):
237     print ">>>>>>>>> %i Jobs Killed" % (self.countKilled)
238 mcinquil 1.14 # print " Retrieve more information with: crab -postMortem -continue"
239 mcinquil 1.6 if (self.countAbort != 0):
240     print ">>>>>>>>> %i Jobs Aborted" % (self.countAbort)
241 mcinquil 1.2 if (self.countCleared != 0):
242 farinafa 1.9 print ">>>>>>>>> %i Jobs Cleared" % (self.countCleared)
243    
244     countUnderMngmt = self.countToTjob - (self.countSubmitting+ self.countNotSubmit + self.countSubmit)
245 mcinquil 1.14 countUnderMngmt -= (self.countReady + self.countSched + self.countRun + self.countDone + self.countRet)
246 mcinquil 1.11 countUnderMngmt -= (self.countKilled + self.countAbort + self.countCleared + self.countWait)
247 farinafa 1.9 if (countUnderMngmt != 0):
248     print ">>>>>>>>> %i Jobs Waiting or Under Server Management" % (countUnderMngmt)
249    
250 mcinquil 1.2 print ''
251     pass
252 spiga 1.1