ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/StatusServer.py
Revision: 1.11
Committed: Tue Jun 26 22:54:44 2007 UTC (17 years, 10 months ago) by mcinquil
Content type: text/x-python
Branch: MAIN
Changes since 1.10: +7 -2 lines
Log Message:
Counting also: waiting and done(failed) jobs

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