ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/StatusServer.py
Revision: 1.22
Committed: Tue Dec 11 09:09:05 2007 UTC (17 years, 4 months ago) by mcinquil
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_0_4, CRAB_2_0_4_pre2, CRAB_2_0_4_pre1
Changes since 1.21: +2 -0 lines
Log Message:
Added check and fix for server_name (path)

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