ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/StatusServer.py
Revision: 1.12
Committed: Thu Jun 28 16:35:01 2007 UTC (17 years, 10 months ago) by mcinquil
Content type: text/x-python
Branch: MAIN
Changes since 1.11: +9 -2 lines
Log Message:
Showing new client status: *retrieving*

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