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