ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/StatusServer.py
Revision: 1.6
Committed: Thu May 31 15:54:47 2007 UTC (17 years, 11 months ago) by mcinquil
Content type: text/x-python
Branch: MAIN
Changes since 1.5: +15 -7 lines
Log Message:
Support of kill functionalities (printout & jobDB)

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     self.countSubmit = 0
20     self.countSubmitting = 0
21     self.countDone = 0
22     self.countReady = 0
23     self.countSched = 0
24     self.countRun = 0
25     self.countAbort = 0
26     self.countCancel = 0
27 mcinquil 1.6 self.countKilled = 0
28 mcinquil 1.2 self.countCleared = 0
29     self.countToTjob = 0
30    
31 spiga 1.3 try:
32     self.server_name = self.cfg_params['CRAB.server_name'] # gsiftp://pcpg01.cern.ch/data/SEDir/
33     except KeyError:
34     msg = 'No server selected ...'
35     msg = msg + 'Please specify a server in the crab cfg file'
36     raise CrabException(msg)
37    
38 spiga 1.1 return
39 mcinquil 1.2
40     def translateStatus(self, status):
41     """
42     simmetric as server
43     """
44    
45 mcinquil 1.4 stateConverting = {'Running': 'R', 'Aborted': 'A', 'Done': 'D', 'Done (Failed)': 'D',\
46 mcinquil 1.2 'Cleared': 'D', 'Cancelled': 'K', 'Killed': 'K'}
47    
48     if status in stateConverting:
49     return stateConverting[status]
50     return None
51    
52    
53 spiga 1.1 def run(self):
54     """
55     The main method of the class: check the status of the task
56     """
57     common.logger.debug(5, "status server::run() called")
58     start = time.time()
59    
60     totalCreatedJobs = 0
61     flagSubmit = 1
62     for nj in range(common.jobDB.nJobs()):
63     if (common.jobDB.status(nj)!='S'):
64     totalCreatedJobs +=1
65 mcinquil 1.2 # flagSubmit = 0
66 spiga 1.1
67     if not flagSubmit:
68     common.logger.message("Not all jobs are submitted: before checking the status submit all the jobs.")
69     return
70    
71     common.scheduler.checkProxy()
72    
73     common.taskDB.load()
74     WorkDirName =os.path.basename(os.path.split(common.work_space.topDir())[0])
75     projectUniqName = 'crab_'+str(WorkDirName)+'_'+common.taskDB.dict('TasKUUID')
76     try:
77     common.logger.message ("Checking the status...\n")
78 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'
79 mcinquil 1.2 common.logger.debug(6, cmd)
80 spiga 1.1 os.system(cmd +' >& /dev/null')
81    
82     except:
83     msg = ("task status not yet available")
84     raise CrabException(msg)
85    
86     try:
87     file = open(common.work_space.resDir()+"xmlReportFile.xml", "r")
88     doc = xml.dom.minidom.parse(common.work_space.resDir()+ "xmlReportFile.xml" )
89    
90     except:
91     msg = ("problems reading report file")
92     raise CrabException(msg)
93    
94 mcinquil 1.2 ### <Job status='Submitted' job_exit='NULL' id='1' exe_exit='NULL'/>
95    
96 spiga 1.1 task = doc.childNodes[0].childNodes[1].getAttribute("taskName")
97 mcinquil 1.2 self.countToTjob = int(doc.childNodes[0].childNodes[1].getAttribute("totJob") )
98    
99     addTree = 3
100    
101     common.jobDB.load()
102    
103     if doc.childNodes[0].childNodes[3].getAttribute("id") == "all":
104     if doc.childNodes[0].childNodes[3].getAttribute("status") == "Submitted":
105     self.countSubmitting = common.jobDB.nJobs()
106     for nj in range(common.jobDB.nJobs()):
107     common.jobDB.setStatus(nj, 'S')
108 mcinquil 1.6 elif doc.childNodes[0].childNodes[3].getAttribute("status") == "Killed":
109     self.countKilled = common.jobDB.nJobs()
110     for nj in range(common.jobDB.nJobs()):
111     common.jobDB.setStatus(nj, 'K')
112 mcinquil 1.2 else:
113     self.countAbort = common.jobDB.nJobs()
114     for nj in range(common.jobDB.nJobs()):
115     common.jobDB.setStatus(nj, 'A')
116     self.countToTjob = common.jobDB.nJobs()
117 spiga 1.1 else:
118 mcinquil 1.2 printline = ''
119     printline+= "%-10s %-20s %-20s %-25s" % ('JOBID','STATUS','EXE_EXIT_CODE','JOB_EXIT_STATUS')
120     print printline
121     print '-------------------------------------------------------------------------------------'
122    
123     for job in range( self.countToTjob ):
124     idJob = doc.childNodes[0].childNodes[job+addTree].getAttribute("id")
125     stato = doc.childNodes[0].childNodes[job+addTree].getAttribute("status")
126     exe_exit_code = doc.childNodes[0].childNodes[job+addTree].getAttribute("job_exit")
127     job_exit_status = doc.childNodes[0].childNodes[job+addTree].getAttribute("exe_exit")
128 mcinquil 1.5 cleared = doc.childNodes[0].childNodes[job+addTree].getAttribute("cleared")
129 mcinquil 1.2 jobDbStatus = self.translateStatus(stato)
130 spiga 1.1
131 mcinquil 1.2 if jobDbStatus != None:
132     common.logger.debug(5, '*** Updating jobdb for job %s ***' %idJob)
133     if common.jobDB.status( str(int(idJob)-1) ) != "Y":
134 mcinquil 1.5 if jobDbStatus == 'D' and int(cleared) != 1:#exe_exit_code =='' and job_exit_status=='':
135     ## 'Done' but not yet cleared (server side) still showing 'Running'
136     stato = 'Running'
137     jobDbStatus = 'R'
138 mcinquil 1.2 common.jobDB.setStatus( str(int(idJob)-1), self.translateStatus(stato) )
139     else:
140     stato = "Cleared"
141     common.jobDB.setExitStatus( str(int(idJob)-1), job_exit_status )
142 mcinquil 1.4 if stato != "Done" and stato != "Cleared" and stato != "Aborted" and stato != "Done (Failed)":
143 mcinquil 1.2 print "%-10s %-20s" % (idJob,stato)
144     else:
145     print "%-10s %-20s %-20s %-25s" % (idJob,stato,exe_exit_code,job_exit_status)
146    
147     if stato == 'Running':
148     self.countRun += 1
149     elif stato == 'Aborted':
150     self.countAbort += 1
151     elif stato == 'Done':
152     self.countDone += 1
153     elif stato == 'Cancelled':
154     self.countCancel += 1
155     elif stato == 'Submitted':
156     self.countSubmit += 1
157     elif stato == 'Submitting':
158     self.countSubmitting += 1
159     elif stato == 'Ready':
160     self.countReady += 1
161     elif stato == 'Scheduled':
162     self.countSched += 1
163     elif stato == 'Cleared':
164     self.countCleared += 1
165    
166     addTree += 1
167     common.jobDB.save()
168    
169     self.PrintReport_()
170    
171    
172     def PrintReport_(self) :
173    
174     """ Report #jobs for each status """
175    
176    
177     print ''
178     print ">>>>>>>>> %i Total Jobs " % (self.countToTjob)
179     print ''
180    
181     if (self.countSubmitting != 0) :
182     print ">>>>>>>>> %i Jobs Submitting by the server" % (self.countSubmitting)
183     if (self.countSubmit != 0):
184     print ">>>>>>>>> %i Jobs Submitted" % (self.countSubmit)
185 mcinquil 1.6 if (self.countReady != 0):
186     print ">>>>>>>>> %i Jobs Ready" % (self.countReady)
187 mcinquil 1.2 if (self.countSched != 0):
188     print ">>>>>>>>> %i Jobs Scheduled" % (self.countSched)
189     if (self.countRun != 0):
190     print ">>>>>>>>> %i Jobs Running" % (self.countRun)
191 mcinquil 1.6 if (self.countDone != 0):
192     print ">>>>>>>>> %i Jobs Done" % (self.countDone)
193     print " Retrieve them with: crab -getoutput -continue"
194     if (self.countKilled != 0):
195     print ">>>>>>>>> %i Jobs Killed" % (self.countKilled)
196     print " Retrieve more information with: crab -postMortem -continue"
197     if (self.countAbort != 0):
198     print ">>>>>>>>> %i Jobs Aborted" % (self.countAbort)
199 mcinquil 1.2 if (self.countCleared != 0):
200     print ">>>>>>>>> %i Jobs Cleared" % (self.countRun)
201     print ''
202     pass
203 spiga 1.1