ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/StatusServer.py
Revision: 1.21
Committed: Mon Nov 19 18:01:32 2007 UTC (17 years, 5 months ago) by farinafa
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_0_3, CRAB_2_0_3_pre1
Changes since 1.20: +2 -3 lines
Log Message:
Replaced PyXML dependencies with standard xml.dom + fixed the traceback back-compatibility printout problem

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