ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/StatusServer.py
Revision: 1.2
Committed: Fri May 18 09:03:38 2007 UTC (17 years, 11 months ago) by mcinquil
Content type: text/x-python
Branch: MAIN
Changes since 1.1: +122 -26 lines
Log Message:
Suppport to the new xml; detailed job status; use of 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     self.countCleared = 0
28     self.countToTjob = 0
29    
30 spiga 1.1 return
31 mcinquil 1.2
32     def translateStatus(self, status):
33     """
34     simmetric as server
35     """
36    
37     stateConverting = {'Running': 'R', 'Aborted': 'A', 'Done': 'D',\
38     'Cleared': 'D', 'Cancelled': 'K', 'Killed': 'K'}
39    
40     if status in stateConverting:
41     return stateConverting[status]
42     return None
43    
44    
45 spiga 1.1 def run(self):
46     """
47     The main method of the class: check the status of the task
48     """
49     common.logger.debug(5, "status server::run() called")
50     start = time.time()
51    
52     totalCreatedJobs = 0
53     flagSubmit = 1
54     for nj in range(common.jobDB.nJobs()):
55     if (common.jobDB.status(nj)!='S'):
56     totalCreatedJobs +=1
57 mcinquil 1.2 # flagSubmit = 0
58 spiga 1.1
59     if not flagSubmit:
60     common.logger.message("Not all jobs are submitted: before checking the status submit all the jobs.")
61     return
62    
63     server_name = self.cfg_params['CRAB.server_name'] # gsiftp://pcpg01.cern.ch/data/SEDir/
64    
65     common.scheduler.checkProxy()
66    
67     common.taskDB.load()
68     WorkDirName =os.path.basename(os.path.split(common.work_space.topDir())[0])
69     projectUniqName = 'crab_'+str(WorkDirName)+'_'+common.taskDB.dict('TasKUUID')
70     try:
71     common.logger.message ("Checking the status...\n")
72     cmd = 'lcg-cp --vo cms gsiftp://' + str(server_name) + str(projectUniqName)+'/res/xmlReportFile.xml file://'+common.work_space.resDir()+'xmlReportFile.xml'
73 mcinquil 1.2 common.logger.debug(6, cmd)
74 spiga 1.1 os.system(cmd +' >& /dev/null')
75    
76     except:
77     msg = ("task status not yet available")
78     raise CrabException(msg)
79    
80     try:
81     file = open(common.work_space.resDir()+"xmlReportFile.xml", "r")
82     doc = xml.dom.minidom.parse(common.work_space.resDir()+ "xmlReportFile.xml" )
83    
84     except:
85     msg = ("problems reading report file")
86     raise CrabException(msg)
87    
88 mcinquil 1.2 ### <Job status='Submitted' job_exit='NULL' id='1' exe_exit='NULL'/>
89    
90 spiga 1.1 task = doc.childNodes[0].childNodes[1].getAttribute("taskName")
91 mcinquil 1.2 self.countToTjob = int(doc.childNodes[0].childNodes[1].getAttribute("totJob") )
92    
93     addTree = 3
94    
95     common.jobDB.load()
96    
97     if doc.childNodes[0].childNodes[3].getAttribute("id") == "all":
98     if doc.childNodes[0].childNodes[3].getAttribute("status") == "Submitted":
99     self.countSubmitting = common.jobDB.nJobs()
100     for nj in range(common.jobDB.nJobs()):
101     common.jobDB.setStatus(nj, 'S')
102     else:
103     self.countAbort = common.jobDB.nJobs()
104     for nj in range(common.jobDB.nJobs()):
105     common.jobDB.setStatus(nj, 'A')
106     self.countToTjob = common.jobDB.nJobs()
107 spiga 1.1 else:
108 mcinquil 1.2 printline = ''
109     printline+= "%-10s %-20s %-20s %-25s" % ('JOBID','STATUS','EXE_EXIT_CODE','JOB_EXIT_STATUS')
110     print printline
111     print '-------------------------------------------------------------------------------------'
112    
113     for job in range( self.countToTjob ):
114     idJob = doc.childNodes[0].childNodes[job+addTree].getAttribute("id")
115     stato = doc.childNodes[0].childNodes[job+addTree].getAttribute("status")
116     exe_exit_code = doc.childNodes[0].childNodes[job+addTree].getAttribute("job_exit")
117     job_exit_status = doc.childNodes[0].childNodes[job+addTree].getAttribute("exe_exit")
118     jobDbStatus = self.translateStatus(stato)
119 spiga 1.1
120 mcinquil 1.2 if jobDbStatus != None:
121     common.logger.debug(5, '*** Updating jobdb for job %s ***' %idJob)
122     if common.jobDB.status( str(int(idJob)-1) ) != "Y":
123     common.jobDB.setStatus( str(int(idJob)-1), self.translateStatus(stato) )
124     else:
125     stato = "Cleared"
126     common.jobDB.setExitStatus( str(int(idJob)-1), job_exit_status )
127     if stato != "Done" and stato != "Cleared" and stato != "Aborted":
128     print "%-10s %-20s" % (idJob,stato)
129     else:
130     print "%-10s %-20s %-20s %-25s" % (idJob,stato,exe_exit_code,job_exit_status)
131    
132     if stato == 'Running':
133     self.countRun += 1
134     elif stato == 'Aborted':
135     self.countAbort += 1
136     elif stato == 'Done':
137     self.countDone += 1
138     elif stato == 'Cancelled':
139     self.countCancel += 1
140     elif stato == 'Submitted':
141     self.countSubmit += 1
142     elif stato == 'Submitting':
143     self.countSubmitting += 1
144     elif stato == 'Ready':
145     self.countReady += 1
146     elif stato == 'Scheduled':
147     self.countSched += 1
148     elif stato == 'Cleared':
149     self.countCleared += 1
150    
151     addTree += 1
152     common.jobDB.save()
153    
154     self.PrintReport_()
155    
156    
157     def PrintReport_(self) :
158    
159     """ Report #jobs for each status """
160    
161    
162     print ''
163     print ">>>>>>>>> %i Total Jobs " % (self.countToTjob)
164     print ''
165    
166     if (self.countReady != 0):
167     print ">>>>>>>>> %i Jobs Ready" % (self.countReady)
168     if (self.countSubmitting != 0) :
169     print ">>>>>>>>> %i Jobs Submitting by the server" % (self.countSubmitting)
170     if (self.countSubmit != 0):
171     print ">>>>>>>>> %i Jobs Submitted" % (self.countSubmit)
172     if (self.countAbort != 0):
173     print ">>>>>>>>> %i Jobs Aborted" % (self.countAbort)
174     if (self.countSched != 0):
175     print ">>>>>>>>> %i Jobs Scheduled" % (self.countSched)
176     if (self.countRun != 0):
177     print ">>>>>>>>> %i Jobs Running" % (self.countRun)
178     if (self.countCleared != 0):
179     print ">>>>>>>>> %i Jobs Cleared" % (self.countRun)
180     if (self.countDone != 0):
181     print ">>>>>>>>> %i Jobs Done" % (self.countDone)
182     print " Retrieve them with: crab.py -getoutput -continue"
183     print ''
184     pass
185 spiga 1.1