ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/StatusServer.py
Revision: 1.9
Committed: Mon Jun 11 15:25:37 2007 UTC (17 years, 10 months ago) by farinafa
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_5_3_pre1, CRAB_2_0_0_pre3
Changes since 1.8: +8 -1 lines
Log Message:
Small fix to the cleared jobs printout.
Additiona print for the jobs in waiting and "Managed by server" status.

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