ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/PostMortemServer.py
Revision: 1.5
Committed: Fri Jun 6 13:04:15 2008 UTC (16 years, 10 months ago) by mcinquil
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_4_1, CRAB_2_4_1_pre4, CRAB_2_4_1_pre3, CRAB_2_4_1_pre2, CRAB_2_4_1_pre1, CRAB_2_4_0_Tutorial, CRAB_2_4_0_Tutorial_pre1, CRAB_2_4_0, CRAB_2_4_0_pre9, CRAB_2_4_0_pre8, CRAB_2_4_0_pre7, CRAB_2_4_0_pre6, CRAB_2_4_0_pre5, CRAB_2_4_0_pre4, CRAB_2_4_0_pre3, CRAB_2_4_0_pre2, CRAB_2_4_0_pre1, CRAB_DLS_PHED1, CRAB_DLS_PHED, CRAB_2_3_2_Fnal, CRAB_2_3_2, CRAB_2_3_2_pre7, CRAB_2_3_2_pre5, CRAB_2_3_2_pre4, CRAB_2_3_2_pre3, CRAB_2_3_2_pre2, CRAB_2_3_2_pre1, CRAB_2_4_0_test, CRAB_2_3_1, CRAB_2_3_1_pre6, CRAB_2_3_1_pre5, CRAB_2_3_1_pre4, CRAB_2_3_1_pre3, CRAB_2_3_1_pre2, CRAB_2_3_1_pre1, CRAB_2_3_0, CRAB_2_3_0_pre6, CRAB_2_3_0_pre1, CRAB_2_2_2_pre5
Branch point for: AnaDataSet, CRAB_2_3_0_br
Changes since 1.4: +110 -60 lines
Log Message:
First working post-mortem for server

File Contents

# User Rev Content
1 mcinquil 1.5 from PostMortem import PostMortem
2     from StatusServer import StatusServer
3    
4 spiga 1.1 from crab_util import *
5     import common
6 mcinquil 1.5 import string, os
7    
8     from ProdCommon.Storage.SEAPI.SElement import SElement
9     from ProdCommon.Storage.SEAPI.SBinterface import SBinterface
10    
11     class PostMortemServer(PostMortem, StatusServer):
12     def __init__(self, cfg_params, nj_list):
13    
14     PostMortem.__init__(self, cfg_params, nj_list)
15    
16     # init client server params...
17     CliServerParams(self)
18    
19     if self.storage_path[0]!='/':
20     self.storage_path = '/'+self.storage_path
21    
22 spiga 1.1 return
23    
24 mcinquil 1.5 def collectLogging(self):
25     # get updated status from server #inherited from StatusServer
26     self.resynchClientSide()
27    
28     #create once storage interaction object
29     seEl = None
30     loc = None
31     try:
32     seEl = SElement(self.storage_name, self.storage_proto, self.storage_port)
33     except Exception, ex:
34     common.logger.debug(1, str(ex))
35     msg = "ERROR: Unable to create SE source interface \n"
36     raise CrabException(msg)
37     try:
38     loc = SElement("localhost", "local")
39     except Exception, ex:
40     common.logger.debug(1, str(ex))
41     msg = "ERROR: Unable to create destination interface \n"
42     raise CrabException(msg)
43 spiga 1.1
44 mcinquil 1.5 ## coupling se interfaces
45     sbi = SBinterface( seEl, loc )
46 spiga 1.1
47 mcinquil 1.5 ## get the list of jobs to get logging.info skimmed by failed status
48     logginable = self.skimDeadList()
49    
50     ## iter over each asked job and print warning if not in skimmed list
51     for id in self.nj_list:
52     if id not in self.all_jobs:
53     common.logger.message('Warning: job # ' + str(id) + ' does not exist! Not possible to ask for postMortem ')
54     continue
55     elif id in logginable:
56     fname = self.fname_base + str(id) + '.LoggingInfo'
57     if os.path.exists(fname):
58     common.logger.message('Logging info for job ' + str(id) + ' already present in '+fname+'\nRemove it for update')
59     continue
60     ## retrieving & processing logging info
61     if self.retrieveFile( sbi, id, fname):
62     ## decode logging info
63     fl = open(fname, 'r')
64     out = "".join(fl.readlines())
65     fl.close()
66     reason = self.decodeLogging(out)
67     common.logger.message('Logging info for job '+ str(id) +': '+str(reason)+'\n written to '+str(fname)+' \n' )
68     else:
69     common.logger.message('Logging info for job '+ str(id) +' not retrieved')
70     else:
71     common.logger.message('Warning: job # ' + str(id) + ' not killed or aborted! Not possible to ask for postMortem ')
72     return
73 spiga 1.1
74    
75 mcinquil 1.5 def skimDeadList(self):
76     """
77     __skimDeadList__
78     return the list of jobs really failed: K, A
79     """
80     skimmedlist = []
81     self.up_task = common._db.getTask( self.nj_list )
82     for job in self.up_task.jobs:
83     if job.runningJob['status'] in ['K','A']:
84     skimmedlist.append(job['jobId'])
85     return skimmedlist
86    
87     def retrieveFile(self, sbi, jobid, destlog):
88     """
89     __retrieveFile__
90 spiga 1.1
91 mcinquil 1.5 retrieves logging.info file from the server storage area
92     """
93     self.taskuuid = str(common._db.queryTask('name'))
94     common.logger.debug(3, "Task name: " + self.taskuuid)
95 spiga 1.1
96 mcinquil 1.5 # full remote dir
97     remotedir = os.path.join(self.storage_path, self.taskuuid)
98     remotelog = remotedir + '/loggingInfo_'+str(jobid)+'.log'
99    
100     common.logger.message("Starting retrieving logging-info from server " \
101     + str(self.storage_name) + " for job " \
102     + str(jobid) + "...")
103 spiga 1.1
104 mcinquil 1.5 # retrieve logging info from storage
105     common.logger.debug(1, "retrieving "+ str(remotelog) +" to "+ str(destlog) )
106     try:
107     sbi.copy( remotelog, destlog)
108     except Exception, ex:
109     msg = "WARNING: Unable to retrieve logging-info file %s \n"%remotelog
110     msg += str(ex)
111     common.logger.debug(1,msg)
112     return False
113     # cleaning remote logging info file
114     try:
115     common.logger.debug(5, "Cleaning remote file [%s] " + str(remotelog) )
116     sbi.delete(remotelog)
117     except Exception, ex:
118     msg = "WARNING: Unable to clean remote logging-info file %s \n"%remotelog
119     msg += str(ex)
120     common.logger.debug(5,msg)
121     return True