ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/StatusServer.py
Revision: 1.15
Committed: Mon Jul 16 17:51:55 2007 UTC (17 years, 9 months ago) by mcinquil
Content type: text/x-python
Branch: MAIN
Changes since 1.14: +18 -5 lines
Log Message:
Added site and n.resubmit to the status output

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     flagSubmit = 1
66     for nj in range(common.jobDB.nJobs()):
67     if (common.jobDB.status(nj)!='S'):
68     totalCreatedJobs +=1
69 mcinquil 1.2 # flagSubmit = 0
70 spiga 1.1
71     if not flagSubmit:
72     common.logger.message("Not all jobs are submitted: before checking the status submit all the jobs.")
73     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 spiga 1.3 cmd = 'lcg-cp --vo cms gsiftp://' + str(self.server_name) + str(projectUniqName)+'/res/xmlReportFile.xml file://'+common.work_space.resDir()+'xmlReportFile.xml'
83 mcinquil 1.2 common.logger.debug(6, cmd)
84 spiga 1.1 os.system(cmd +' >& /dev/null')
85    
86     except:
87 mcinquil 1.10 #msg = ("task status not yet available")
88     msg = "The server is managing your task."
89     msg += "\n A detailed report will be ready soon.\n"
90 spiga 1.1 raise CrabException(msg)
91    
92     try:
93     file = open(common.work_space.resDir()+"xmlReportFile.xml", "r")
94     doc = xml.dom.minidom.parse(common.work_space.resDir()+ "xmlReportFile.xml" )
95    
96     except:
97 mcinquil 1.10 #msg = ("problems reading report file")
98     msg = "The server is managing your task."
99     msg += "\n A detailed report will be ready soon.\n"
100 spiga 1.1 raise CrabException(msg)
101    
102 mcinquil 1.2 ### <Job status='Submitted' job_exit='NULL' id='1' exe_exit='NULL'/>
103    
104 spiga 1.1 task = doc.childNodes[0].childNodes[1].getAttribute("taskName")
105 mcinquil 1.2 self.countToTjob = int(doc.childNodes[0].childNodes[1].getAttribute("totJob") )
106    
107     addTree = 3
108    
109     common.jobDB.load()
110    
111     if doc.childNodes[0].childNodes[3].getAttribute("id") == "all":
112     if doc.childNodes[0].childNodes[3].getAttribute("status") == "Submitted":
113     self.countSubmitting = common.jobDB.nJobs()
114     for nj in range(common.jobDB.nJobs()):
115     common.jobDB.setStatus(nj, 'S')
116 mcinquil 1.6 elif doc.childNodes[0].childNodes[3].getAttribute("status") == "Killed":
117     self.countKilled = common.jobDB.nJobs()
118     for nj in range(common.jobDB.nJobs()):
119     common.jobDB.setStatus(nj, 'K')
120 mcinquil 1.14 self.countKilled = common.jobDB.nJobs()
121 mcinquil 1.8 elif doc.childNodes[0].childNodes[3].getAttribute("status") == "NotSubmitted":
122     self.countNotSubmit = common.jobDB.nJobs()
123 mcinquil 1.2 for nj in range(common.jobDB.nJobs()):
124 mcinquil 1.8 common.jobDB.setStatus(nj, 'C')
125 mcinquil 1.2 self.countToTjob = common.jobDB.nJobs()
126 spiga 1.1 else:
127 mcinquil 1.2 printline = ''
128 mcinquil 1.15 printline+= "%-10s %-20s %-20s %-20s %-18s %-20s" % ('JOBID','STATUS','SITE','JOB_EXIT_STATUS','EXE_EXIT_CODE','RESUBMIT')
129 mcinquil 1.2 print printline
130 mcinquil 1.15 print '-------------------------------------------------------------------------------------------------------'
131 mcinquil 1.2
132     for job in range( self.countToTjob ):
133     idJob = doc.childNodes[0].childNodes[job+addTree].getAttribute("id")
134     stato = doc.childNodes[0].childNodes[job+addTree].getAttribute("status")
135     exe_exit_code = doc.childNodes[0].childNodes[job+addTree].getAttribute("job_exit")
136     job_exit_status = doc.childNodes[0].childNodes[job+addTree].getAttribute("exe_exit")
137 mcinquil 1.5 cleared = doc.childNodes[0].childNodes[job+addTree].getAttribute("cleared")
138 mcinquil 1.15
139     try:
140     site = doc.childNodes[0].childNodes[job+addTree].getAttribute("site")
141     resub = doc.childNodes[0].childNodes[job+addTree].getAttribute("resubmit")
142     if site == "none" or site == "NULL" or site=="None":
143     site=''
144     if resub == "none" or resub =="None" or resub == "0":
145     resub=''
146     if stato == "Killed":
147     resub=''
148     except Excpetion, ex:
149     common.logger.message ("Problem reading report file: are you using the latest crab version?")
150     common.logger.debug( 1 , str(ex) )
151    
152 mcinquil 1.2 jobDbStatus = self.translateStatus(stato)
153     if jobDbStatus != None:
154     common.logger.debug(5, '*** Updating jobdb for job %s ***' %idJob)
155     if common.jobDB.status( str(int(idJob)-1) ) != "Y":
156 mcinquil 1.5 if jobDbStatus == 'D' and int(cleared) != 1:#exe_exit_code =='' and job_exit_status=='':
157     ## 'Done' but not yet cleared (server side) still showing 'Running'
158 mcinquil 1.12 ##stato = 'Running'
159 spiga 1.13 stato = 'Retrieving by the server' ## changed - is this user friendly?
160 mcinquil 1.5 jobDbStatus = 'R'
161 mcinquil 1.2 common.jobDB.setStatus( str(int(idJob)-1), self.translateStatus(stato) )
162     else:
163     stato = "Cleared"
164     common.jobDB.setExitStatus( str(int(idJob)-1), job_exit_status )
165 mcinquil 1.4 if stato != "Done" and stato != "Cleared" and stato != "Aborted" and stato != "Done (Failed)":
166 mcinquil 1.15 print "%-10s %-20s %-20s %-20s %-18s %-20s" % (idJob,stato,site,'','',resub)
167 mcinquil 1.2 else:
168 mcinquil 1.15 print "%-10s %-20s %-20s %-20s %-18s %-20s" % (idJob,stato,site,exe_exit_code,job_exit_status,resub)
169 mcinquil 1.2
170     if stato == 'Running':
171     self.countRun += 1
172     elif stato == 'Aborted':
173     self.countAbort += 1
174 mcinquil 1.11 elif stato == 'Done' or stato == 'Done (Failed)':
175 mcinquil 1.2 self.countDone += 1
176     elif stato == 'Cancelled':
177     self.countCancel += 1
178     elif stato == 'Submitted':
179     self.countSubmit += 1
180     elif stato == 'Submitting':
181     self.countSubmitting += 1
182     elif stato == 'Ready':
183     self.countReady += 1
184     elif stato == 'Scheduled':
185     self.countSched += 1
186     elif stato == 'Cleared':
187     self.countCleared += 1
188 mcinquil 1.8 elif stato == 'NotSubmitted':
189     self.countSubmitting += 1
190 mcinquil 1.11 elif stato == 'Waiting':
191     self.countWait += 1
192 spiga 1.13 elif stato == 'Retrieving by the server':
193 mcinquil 1.12 self.countRet += 1
194 mcinquil 1.14 elif stato == 'Killed':
195     self.countKilled += 1
196 mcinquil 1.2
197     addTree += 1
198     common.jobDB.save()
199    
200     self.PrintReport_()
201    
202    
203     def PrintReport_(self) :
204    
205     """ Report #jobs for each status """
206    
207    
208     print ''
209     print ">>>>>>>>> %i Total Jobs " % (self.countToTjob)
210     print ''
211    
212     if (self.countSubmitting != 0) :
213     print ">>>>>>>>> %i Jobs Submitting by the server" % (self.countSubmitting)
214 mcinquil 1.8 if (self.countNotSubmit != 0):
215     print ">>>>>>>>> %i Jobs Not Submitted to the grid" % (self.countNotSubmit)
216 mcinquil 1.2 if (self.countSubmit != 0):
217     print ">>>>>>>>> %i Jobs Submitted" % (self.countSubmit)
218 mcinquil 1.11 if (self.countWait != 0):
219     print ">>>>>>>>> %i Jobs Waiting" % (self.countWait)
220 mcinquil 1.6 if (self.countReady != 0):
221     print ">>>>>>>>> %i Jobs Ready" % (self.countReady)
222 mcinquil 1.2 if (self.countSched != 0):
223     print ">>>>>>>>> %i Jobs Scheduled" % (self.countSched)
224 mcinquil 1.14 if (self.countRun != 0):
225     print ">>>>>>>>> %i Jobs Running" % (self.countRun)
226 mcinquil 1.12 if (self.countRet != 0):
227 spiga 1.13 print ">>>>>>>>> %i Jobs Retrieving by the server" % (self.countRet)
228 mcinquil 1.6 if (self.countDone != 0):
229     print ">>>>>>>>> %i Jobs Done" % (self.countDone)
230     print " Retrieve them with: crab -getoutput -continue"
231     if (self.countKilled != 0):
232     print ">>>>>>>>> %i Jobs Killed" % (self.countKilled)
233 mcinquil 1.14 # print " Retrieve more information with: crab -postMortem -continue"
234 mcinquil 1.6 if (self.countAbort != 0):
235     print ">>>>>>>>> %i Jobs Aborted" % (self.countAbort)
236 mcinquil 1.2 if (self.countCleared != 0):
237 farinafa 1.9 print ">>>>>>>>> %i Jobs Cleared" % (self.countCleared)
238    
239     countUnderMngmt = self.countToTjob - (self.countSubmitting+ self.countNotSubmit + self.countSubmit)
240 mcinquil 1.14 countUnderMngmt -= (self.countReady + self.countSched + self.countRun + self.countDone + self.countRet)
241 mcinquil 1.11 countUnderMngmt -= (self.countKilled + self.countAbort + self.countCleared + self.countWait)
242 farinafa 1.9 if (countUnderMngmt != 0):
243     print ">>>>>>>>> %i Jobs Waiting or Under Server Management" % (countUnderMngmt)
244    
245 mcinquil 1.2 print ''
246     pass
247 spiga 1.1