1 |
– |
from crab_logger import Logger |
1 |
|
from crab_exceptions import * |
2 |
|
from crab_util import * |
3 |
|
import common |
33 |
|
raise CrabException('Istantiate DB Session : '+str(e)) |
34 |
|
|
35 |
|
try: |
36 |
< |
common.bossSession.installDB('$CRABPRODCOMMONPYTHON/ProdCommon/BossLite/DbObjects/setupDatabase-sqlite.sql') |
36 |
> |
common.bossSession.bossLiteDB.installDB('$CRABPRODCOMMONPYTHON/ProdCommon/BossLite/DbObjects/setupDatabase-sqlite.sql') |
37 |
|
except Exception, e : |
38 |
|
raise CrabException('DB Installation error : '+str(e)) |
39 |
|
return |
55 |
|
Return task with all/list of jobs |
56 |
|
""" |
57 |
|
try: |
58 |
< |
task = common.bossSession.load(1,jobsList)[0] |
58 |
> |
task = common.bossSession.load(1,jobsList) |
59 |
|
except Exception, e : |
60 |
< |
common.logger.debug(3, "Error while getting task : " +str(traceback.format_exc())) |
60 |
> |
common.logger.debug( "Error while getting task : " +str(traceback.format_exc())) |
61 |
|
raise CrabException('Error while getting task '+str(e)) |
62 |
|
return task |
63 |
|
|
66 |
|
Return a task with a single job |
67 |
|
""" |
68 |
|
try: |
69 |
< |
task = common.bossSession.load(1,str(n))[0] |
69 |
> |
task = common.bossSession.load(1,str(n)) |
70 |
|
except Exception, e : |
71 |
< |
common.logger.debug(3, "Error while getting job : " +str(traceback.format_exc())) |
71 |
> |
common.logger.debug( "Error while getting job : " +str(traceback.format_exc())) |
72 |
|
raise CrabException('Error while getting job '+str(e)) |
73 |
|
return task |
74 |
|
|
80 |
|
""" |
81 |
|
opt={} |
82 |
|
if optsToSave.get('server_mode',0) == 1: opt['serverName']=optsToSave['server_name'] |
83 |
< |
opt['name']=common.work_space.taskName() |
83 |
> |
opt['name']= getUserName()+ '_' + string.split(common.work_space.topDir(),'/')[-2]+'_'+common.work_space.task_uuid() |
84 |
|
task = Task( opt ) |
85 |
|
try: |
86 |
|
common.bossSession.saveTask( task ) |
87 |
|
except Exception, e : |
89 |
– |
# common.logger.debug(3, "Error creating task : " +str(traceback.format_exc())) |
90 |
– |
# raise CrabException('Error creating task '+str(e)) |
88 |
|
raise CrabException('Error creating task '+str(traceback.format_exc())) |
89 |
|
|
90 |
|
return |
104 |
|
|
105 |
|
return |
106 |
|
|
107 |
< |
def createJobs_(self, jobsL): |
107 |
> |
def createJobs_(self, jobsL, isNew=True): |
108 |
|
""" |
109 |
|
Fill crab DB with the jobs filed |
110 |
|
""" |
113 |
|
jobs = [] |
114 |
|
for id in jobsL: |
115 |
|
parameters = {} |
116 |
< |
parameters['jobId'] = str(id) |
116 |
> |
parameters['jobId'] = int(id) |
117 |
> |
parameters['taskId'] = 1 |
118 |
|
parameters['name'] = task['name'] + '_' + 'job' + str(id) |
119 |
|
job = Job(parameters) |
120 |
|
jobs.append(job) |
121 |
|
common.bossSession.getRunningInstance(job) |
122 |
|
job.runningJob['status'] = 'C' |
123 |
< |
task.addJobs(jobs) |
123 |
> |
## added to support second step creation |
124 |
> |
## maybe it is not needed. TO CLARIFY |
125 |
> |
if isNew: |
126 |
> |
task.addJobs(jobs) |
127 |
> |
else: |
128 |
> |
task.appendJobs(jobs) |
129 |
|
try: |
130 |
|
common.bossSession.updateDB( task ) |
131 |
|
except Exception, e : |
180 |
|
""" |
181 |
|
task = self.getTask(jobs) |
182 |
|
|
180 |
– |
Jobs = task.getJobs() |
183 |
|
print "--------------------------" |
184 |
< |
for Job in Jobs: |
184 |
> |
for Job in task.jobs: |
185 |
|
print "Id: ",Job['jobId'] |
186 |
|
print "Dest: ", Job['dlsDestination'] |
187 |
|
print "Output: ", Job['outputFiles'] |
188 |
|
print "Args: ",Job['arguments'] |
189 |
+ |
print "Service: ",Job.runningJob['service'] |
190 |
|
print "--------------------------" |
191 |
|
return |
192 |
|
|
195 |
|
tmp_task = self.getTask() |
196 |
|
return common.bossSession.serialize(tmp_task) |
197 |
|
|
198 |
< |
def queryID(self,server_mode=0): |
198 |
> |
def queryID(self,server_mode=0, jid=False): |
199 |
|
''' |
200 |
|
Return the taskId if serevr_mode =1 |
201 |
|
Return the joblistId if serevr_mode =0 |
204 |
|
lines=[] |
205 |
|
task = self.getTask() |
206 |
|
if server_mode == 1: |
207 |
< |
header= "Task Id = %-40s " %(task['name']) |
208 |
< |
else: |
207 |
> |
# init client server params... |
208 |
> |
CliServerParams(self) |
209 |
> |
headerTask= "Task Id = %-40s " %(task['name']) |
210 |
> |
displayReport(self,headerTask,lines) |
211 |
> |
common.logger.info(showWebMon(self.server_name)) |
212 |
> |
if (jid ) or (server_mode == 0): |
213 |
|
for job in task.jobs: |
214 |
|
toPrint='' |
215 |
|
common.bossSession.getRunningInstance(job) |
216 |
|
toPrint = "%-5s %-50s " % (job['jobId'],job.runningJob['schedulerId']) |
217 |
|
lines.append(toPrint) |
218 |
|
header+= "%-5s %-50s " % ('Job:','ID' ) |
219 |
< |
displayReport(self,header,lines) |
219 |
> |
displayReport(self,header,lines) |
220 |
|
return |
221 |
|
|
222 |
|
def queryTask(self,attr): |
257 |
|
try: |
258 |
|
task = common.bossSession.loadJobDist( 1, attr ) |
259 |
|
except Exception, e : |
260 |
< |
common.logger.debug(3, "Error loading Jobs By distinct Attr : " +str(traceback.format_exc())) |
260 |
> |
common.logger.debug( "Error loading Jobs By distinct Attr : " +str(traceback.format_exc())) |
261 |
|
raise CrabException('Error loading Jobs By distinct Attr '+str(e)) |
262 |
|
|
263 |
|
for i in task: distAttr.append(i[attr]) |
271 |
|
try: |
272 |
|
task = common.bossSession.loadJobDistAttr( 1, attr_1, attr_2, list ) |
273 |
|
except Exception, e : |
274 |
< |
common.logger.debug(3, "Error loading Jobs By distinct Attr : " +str(traceback.format_exc())) |
274 |
> |
common.logger.debug( "Error loading Jobs By distinct Attr : " +str(traceback.format_exc())) |
275 |
|
raise CrabException('Error loading Jobs By distinct Attr '+str(e)) |
276 |
|
|
277 |
|
for i in task: distAttr.append(i[attr_1]) |
285 |
|
try: |
286 |
|
task = common.bossSession.loadJobsByAttr(attr ) |
287 |
|
except Exception, e : |
288 |
< |
common.logger.debug(3, "Error loading Jobs By Attr : " +str(traceback.format_exc())) |
288 |
> |
common.logger.debug( "Error loading Jobs By Attr : " +str(traceback.format_exc())) |
289 |
|
raise CrabException('Error loading Jobs By Attr '+str(e)) |
290 |
|
for i in task: |
291 |
|
matched.append(i[field]) |
300 |
|
try: |
301 |
|
task = common.bossSession.loadJobsByRunningAttr(attr) |
302 |
|
except Exception, e : |
303 |
< |
common.logger.debug(3, "Error loading Jobs By Running Attr : " +str(traceback.format_exc())) |
303 |
> |
common.logger.debug( "Error loading Jobs By Running Attr : " +str(traceback.format_exc())) |
304 |
|
raise CrabException('Error loading Jobs By Running Attr '+str(e)) |
305 |
|
for i in task: |
306 |
|
matched.append(i.runningJob[field]) |
316 |
|
common.bossSession.getNewRunningInstance(job) |
317 |
|
job.runningJob['status'] = 'C' |
318 |
|
job.runningJob['statusScheduler'] = 'Created' |
319 |
+ |
job.runningJob['state'] = 'Created' |
320 |
|
common.bossSession.updateDB(task) |
321 |
|
return |
322 |
|
|
323 |
|
def deserXmlStatus(self, reportList): |
324 |
|
|
325 |
|
task = self.getTask() |
318 |
– |
|
326 |
|
for job in task.jobs: |
327 |
|
if not job.runningJob: |
328 |
|
raise CrabException( "Missing running object for job %s"%str(job['jobId']) ) |
329 |
|
|
330 |
|
id = str(job.runningJob['jobId']) |
324 |
– |
# TODO linear search, probably it can be optized with binary search |
331 |
|
rForJ = None |
332 |
+ |
nj_list= [] |
333 |
|
for r in reportList: |
334 |
|
if r.getAttribute('id') in [ id, 'all']: |
335 |
|
rForJ = r |
336 |
|
break |
337 |
+ |
## Check the submission number and create new running jobs on the client side |
338 |
+ |
if rForJ.getAttribute('resubmit') != 'None' and (rForJ.getAttribute('status') not in ['Cleared','Killed','Done','Done (Failed)','Not Submitted', 'Cancelled by user']) : |
339 |
+ |
if int(job.runningJob['submission']) < int(rForJ.getAttribute('resubmit')) + 1: |
340 |
+ |
nj_list.append(id) |
341 |
+ |
if len(nj_list) > 0: self.newRunJobs(nj_list) |
342 |
+ |
|
343 |
+ |
task_new = self.getTask() |
344 |
|
|
345 |
+ |
for job in task_new.jobs: |
346 |
+ |
id = str(job.runningJob['jobId']) |
347 |
+ |
# TODO linear search, probably it can be optized with binary search |
348 |
+ |
rForJ = None |
349 |
+ |
for r in reportList: |
350 |
+ |
if r.getAttribute('id') in [ id, 'all']: |
351 |
+ |
rForJ = r |
352 |
+ |
break |
353 |
+ |
|
354 |
|
# Data alignment |
355 |
< |
jobStatus = str(job.runningJob['statusScheduler']) |
356 |
< |
if rForJ.getAttribute('status') not in ['Created', 'Submitting', 'Unknown'] and \ |
357 |
< |
job.runningJob['statusScheduler'] != 'Cleared': |
355 |
> |
if rForJ.getAttribute('status') not in ['Created', 'Unknown']: |
356 |
> |
# update the status |
357 |
> |
common.logger.debug("Updating DB status for job: " + str(id) + " @: " \ |
358 |
> |
+ str(rForJ.getAttribute('status')) ) |
359 |
|
job.runningJob['statusScheduler'] = str( rForJ.getAttribute('status') ) |
360 |
< |
jobStatus = str(job.runningJob['statusScheduler']) |
361 |
< |
job.runningJob['status'] = str( rForJ.getAttribute('sched_status') ) |
362 |
< |
|
363 |
< |
job.runningJob['destination'] = str( rForJ.getAttribute('site') ) |
364 |
< |
dest = str(job.runningJob['destination']).split(':')[0] |
365 |
< |
|
366 |
< |
job.runningJob['applicationReturnCode'] = str( rForJ.getAttribute('exe_exit') ) |
367 |
< |
exe_exit_code = str(job.runningJob['applicationReturnCode']) |
360 |
> |
if (rForJ.getAttribute('status') == 'Done' or rForJ.getAttribute('status') == 'Done (Failed)')\ |
361 |
> |
and rForJ.getAttribute('sched_status') == 'E' : |
362 |
> |
job.runningJob['status'] = 'SD' |
363 |
> |
else: |
364 |
> |
job.runningJob['status'] = str( rForJ.getAttribute('sched_status') ) |
365 |
> |
|
366 |
> |
job.runningJob['schedulerId'] = str( rForJ.getAttribute('sched_id') ) |
367 |
> |
|
368 |
> |
job.runningJob['destination'] = str( rForJ.getAttribute('site') ) |
369 |
> |
dest = str(job.runningJob['destination']).split(':')[0] |
370 |
> |
|
371 |
> |
job.runningJob['applicationReturnCode'] = str( rForJ.getAttribute('exe_exit') ) |
372 |
> |
exe_exit_code = str(job.runningJob['applicationReturnCode']) |
373 |
> |
|
374 |
> |
job.runningJob['wrapperReturnCode'] = str( rForJ.getAttribute('job_exit') ) |
375 |
> |
job_exit_code = str(job.runningJob['wrapperReturnCode']) |
376 |
|
|
377 |
< |
job.runningJob['wrapperReturnCode'] = str( rForJ.getAttribute('job_exit') ) |
378 |
< |
job_exit_code = str(job.runningJob['wrapperReturnCode']) |
377 |
> |
## unsing 'standardInput' field for 'ended' tag ['Y','N'] |
378 |
> |
job['standardInput'] = str( rForJ.getAttribute('ended') ) |
379 |
|
|
380 |
+ |
job.runningJob['state'] = str( rForJ.getAttribute('action') ) |
381 |
+ |
|
382 |
|
#if str( rForJ.getAttribute('resubmit') ).isdigit(): |
383 |
|
# job['submissionNumber'] = int(rForJ.getAttribute('resubmit')) |
384 |
|
# job.runningJob['submission'] = int(rForJ.getAttribute('resubmit')) |
385 |
< |
|
385 |
> |
|
386 |
|
# TODO cleared='0' field, how should it be handled/mapped in BL? #Fabio |
387 |
|
|
388 |
< |
common.bossSession.updateDB( task ) |
355 |
< |
|
388 |
> |
common.bossSession.updateDB( task_new ) |
389 |
|
return |
390 |
+ |
|
391 |
+ |
# FIXME temporary method to verify what kind of submission to perform towards the server |
392 |
+ |
def checkIfNeverSubmittedBefore(self): |
393 |
+ |
for j in self.getTask().jobs: |
394 |
+ |
if j.runningJob['submission'] > 1 or j.runningJob['state'] != 'Created': |
395 |
+ |
return False |
396 |
+ |
return True |
397 |
+ |
|
398 |
+ |
|