1 |
|
from Actor import * |
2 |
+ |
from crab_util import * |
3 |
|
import common |
4 |
|
import string, os |
5 |
|
|
6 |
|
class PostMortem(Actor): |
7 |
< |
def __init__(self, cfg_params, nj_list, use_boss): |
7 |
> |
def __init__(self, cfg_params, nj_list): |
8 |
|
self.cfg_params = cfg_params |
9 |
|
self.nj_list = nj_list |
10 |
< |
self.flag_useboss = use_boss |
10 |
> |
self.all_jobs=common._db.nJobs('list') |
11 |
> |
|
12 |
> |
self.fname_base = common.work_space.jobDir() + self.cfg_params['CRAB.jobtype'].upper() + '_' |
13 |
> |
|
14 |
|
return |
15 |
|
|
16 |
|
def run(self): |
17 |
|
""" |
18 |
|
The main method of the class. |
19 |
|
""" |
20 |
< |
common.logger.debug(5, "PostMortem::run() called") |
20 |
> |
common.logger.debug( "PostMortem::run() called") |
21 |
|
|
22 |
< |
if len(self.nj_list)==0: |
19 |
< |
common.logger.debug(5, "No jobs to check") |
20 |
< |
return |
22 |
> |
self.collectLogging() |
23 |
|
|
24 |
< |
# run a list-match on first job |
25 |
< |
for nj in self.nj_list: |
26 |
< |
#nj parte da 1 --> nj = internal_id di boss |
27 |
< |
if self.flag_useboss == 1 : |
28 |
< |
id = common.scheduler.boss_SID(nj) |
29 |
< |
#print "id = ", id |
30 |
< |
#else: |
31 |
< |
# id = common.jobDB.jobId(nj) |
32 |
< |
out = common.scheduler.loggingInfo(id) |
33 |
< |
# job_list inizia a contare da zero |
34 |
< |
job = common.job_list[nj-1] |
35 |
< |
#print "job.jdlFilename()", job.jdlFilename() |
36 |
< |
jdl_fname = string.replace(job.jdlFilename(),'jdl','loggingInfo') |
37 |
< |
#print "jdl_fname = ", jdl_fname |
38 |
< |
if os.path.exists(jdl_fname): |
39 |
< |
common.logger.message('Logging info for job '+str(nj)+' already present in '+jdl_fname+' Remove it for update') |
40 |
< |
continue |
41 |
< |
jdl = open(jdl_fname, 'w') |
42 |
< |
for line in out: jdl.write(line) |
43 |
< |
jdl.close() |
42 |
< |
common.logger.message('Logging info for job '+str(nj)+' written to '+jdl_fname) |
43 |
< |
|
44 |
< |
pass |
24 |
> |
def collectOneLogging(self, id): |
25 |
> |
job=self.up_task.getJob(id) |
26 |
> |
if not job: #id not in self.all_jobs: |
27 |
> |
common.logger.info('Warning: job # ' + str(id) + ' does not exist! Not possible to ask for postMortem ') |
28 |
> |
return |
29 |
> |
elif job.runningJob['state'] == 'Created': |
30 |
> |
common.logger.info('Warning: job # ' + str(id) + ' just Created ! Not possible to ask for postMortem ') |
31 |
> |
else: |
32 |
> |
fname = self.fname_base + str(id) + '.LoggingInfo' |
33 |
> |
if os.path.exists(fname): |
34 |
> |
common.logger.info('Logging info for job ' + str(id) + ' already present in '+fname+'\nRemove it for update') |
35 |
> |
return |
36 |
> |
common.scheduler.loggingInfo(id,fname) |
37 |
> |
fl = open(fname, 'r') |
38 |
> |
out = "".join(fl.readlines()) |
39 |
> |
fl.close() |
40 |
> |
reason = self.decodeLogging(out) |
41 |
> |
common.logger.info('Logging info for job '+ str(id) +': '+str(reason)+'\n written to '+str(fname)+' \n' ) |
42 |
> |
return |
43 |
> |
|
44 |
|
|
45 |
+ |
def collectLogging(self): |
46 |
+ |
self.up_task = common._db.getTask( self.nj_list ) |
47 |
+ |
for id in self.nj_list: |
48 |
+ |
self.collectOneLogging(id) |
49 |
|
return |
50 |
+ |
|
51 |
+ |
def decodeLogging(self, out): |
52 |
+ |
""" |
53 |
+ |
""" |
54 |
+ |
return common.scheduler.decodeLogInfo(out) |
55 |
|
|