ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/StatusServer.py
Revision: 1.10
Committed: Thu Jun 21 09:10:51 2007 UTC (17 years, 10 months ago) by mcinquil
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_5_3_pre2
Changes since 1.9: +6 -2 lines
Log Message:
*printout*

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 mcinquil 1.10 #msg = ("task status not yet available")
85     msg = "The server is managing your task."
86     msg += "\n A detailed report will be ready soon.\n"
87 spiga 1.1 raise CrabException(msg)
88    
89     try:
90     file = open(common.work_space.resDir()+"xmlReportFile.xml", "r")
91     doc = xml.dom.minidom.parse(common.work_space.resDir()+ "xmlReportFile.xml" )
92    
93     except:
94 mcinquil 1.10 #msg = ("problems reading report file")
95     msg = "The server is managing your task."
96     msg += "\n A detailed report will be ready soon.\n"
97 spiga 1.1 raise CrabException(msg)
98    
99 mcinquil 1.2 ### <Job status='Submitted' job_exit='NULL' id='1' exe_exit='NULL'/>
100    
101 spiga 1.1 task = doc.childNodes[0].childNodes[1].getAttribute("taskName")
102 mcinquil 1.2 self.countToTjob = int(doc.childNodes[0].childNodes[1].getAttribute("totJob") )
103    
104     addTree = 3
105    
106     common.jobDB.load()
107    
108     if doc.childNodes[0].childNodes[3].getAttribute("id") == "all":
109     if doc.childNodes[0].childNodes[3].getAttribute("status") == "Submitted":
110     self.countSubmitting = common.jobDB.nJobs()
111     for nj in range(common.jobDB.nJobs()):
112     common.jobDB.setStatus(nj, 'S')
113 mcinquil 1.6 elif doc.childNodes[0].childNodes[3].getAttribute("status") == "Killed":
114     self.countKilled = common.jobDB.nJobs()
115     for nj in range(common.jobDB.nJobs()):
116     common.jobDB.setStatus(nj, 'K')
117 mcinquil 1.8 elif doc.childNodes[0].childNodes[3].getAttribute("status") == "NotSubmitted":
118     self.countNotSubmit = common.jobDB.nJobs()
119 mcinquil 1.2 for nj in range(common.jobDB.nJobs()):
120 mcinquil 1.8 common.jobDB.setStatus(nj, 'C')
121 mcinquil 1.2 self.countToTjob = common.jobDB.nJobs()
122 spiga 1.1 else:
123 mcinquil 1.2 printline = ''
124     printline+= "%-10s %-20s %-20s %-25s" % ('JOBID','STATUS','EXE_EXIT_CODE','JOB_EXIT_STATUS')
125     print printline
126     print '-------------------------------------------------------------------------------------'
127    
128     for job in range( self.countToTjob ):
129     idJob = doc.childNodes[0].childNodes[job+addTree].getAttribute("id")
130     stato = doc.childNodes[0].childNodes[job+addTree].getAttribute("status")
131     exe_exit_code = doc.childNodes[0].childNodes[job+addTree].getAttribute("job_exit")
132     job_exit_status = doc.childNodes[0].childNodes[job+addTree].getAttribute("exe_exit")
133 mcinquil 1.5 cleared = doc.childNodes[0].childNodes[job+addTree].getAttribute("cleared")
134 mcinquil 1.2 jobDbStatus = self.translateStatus(stato)
135 spiga 1.1
136 mcinquil 1.2 if jobDbStatus != None:
137     common.logger.debug(5, '*** Updating jobdb for job %s ***' %idJob)
138     if common.jobDB.status( str(int(idJob)-1) ) != "Y":
139 mcinquil 1.5 if jobDbStatus == 'D' and int(cleared) != 1:#exe_exit_code =='' and job_exit_status=='':
140     ## 'Done' but not yet cleared (server side) still showing 'Running'
141     stato = 'Running'
142     jobDbStatus = 'R'
143 mcinquil 1.2 common.jobDB.setStatus( str(int(idJob)-1), self.translateStatus(stato) )
144     else:
145     stato = "Cleared"
146     common.jobDB.setExitStatus( str(int(idJob)-1), job_exit_status )
147 mcinquil 1.4 if stato != "Done" and stato != "Cleared" and stato != "Aborted" and stato != "Done (Failed)":
148 mcinquil 1.2 print "%-10s %-20s" % (idJob,stato)
149     else:
150     print "%-10s %-20s %-20s %-25s" % (idJob,stato,exe_exit_code,job_exit_status)
151    
152     if stato == 'Running':
153     self.countRun += 1
154     elif stato == 'Aborted':
155     self.countAbort += 1
156     elif stato == 'Done':
157     self.countDone += 1
158     elif stato == 'Cancelled':
159     self.countCancel += 1
160     elif stato == 'Submitted':
161     self.countSubmit += 1
162     elif stato == 'Submitting':
163     self.countSubmitting += 1
164     elif stato == 'Ready':
165     self.countReady += 1
166     elif stato == 'Scheduled':
167     self.countSched += 1
168     elif stato == 'Cleared':
169     self.countCleared += 1
170 mcinquil 1.8 elif stato == 'NotSubmitted':
171     self.countSubmitting += 1
172 mcinquil 1.2
173     addTree += 1
174     common.jobDB.save()
175    
176     self.PrintReport_()
177    
178    
179     def PrintReport_(self) :
180    
181     """ Report #jobs for each status """
182    
183    
184     print ''
185     print ">>>>>>>>> %i Total Jobs " % (self.countToTjob)
186     print ''
187    
188     if (self.countSubmitting != 0) :
189     print ">>>>>>>>> %i Jobs Submitting by the server" % (self.countSubmitting)
190 mcinquil 1.8 if (self.countNotSubmit != 0):
191     print ">>>>>>>>> %i Jobs Not Submitted to the grid" % (self.countNotSubmit)
192 mcinquil 1.2 if (self.countSubmit != 0):
193     print ">>>>>>>>> %i Jobs Submitted" % (self.countSubmit)
194 mcinquil 1.6 if (self.countReady != 0):
195     print ">>>>>>>>> %i Jobs Ready" % (self.countReady)
196 mcinquil 1.2 if (self.countSched != 0):
197     print ">>>>>>>>> %i Jobs Scheduled" % (self.countSched)
198     if (self.countRun != 0):
199     print ">>>>>>>>> %i Jobs Running" % (self.countRun)
200 mcinquil 1.6 if (self.countDone != 0):
201     print ">>>>>>>>> %i Jobs Done" % (self.countDone)
202     print " Retrieve them with: crab -getoutput -continue"
203     if (self.countKilled != 0):
204     print ">>>>>>>>> %i Jobs Killed" % (self.countKilled)
205 mcinquil 1.7 print " Retrieve more information with: crab -postMortem -continue"
206 mcinquil 1.6 if (self.countAbort != 0):
207     print ">>>>>>>>> %i Jobs Aborted" % (self.countAbort)
208 mcinquil 1.2 if (self.countCleared != 0):
209 farinafa 1.9 print ">>>>>>>>> %i Jobs Cleared" % (self.countCleared)
210    
211     countUnderMngmt = self.countToTjob - (self.countSubmitting+ self.countNotSubmit + self.countSubmit)
212     countUnderMngmt -= (self.countReady + self.countSched + self.countRun + self.countDone)
213     countUnderMngmt -= (self.countKilled + self.countAbort + self.countCleared)
214     if (countUnderMngmt != 0):
215     print ">>>>>>>>> %i Jobs Waiting or Under Server Management" % (countUnderMngmt)
216    
217 mcinquil 1.2 print ''
218     pass
219 spiga 1.1