ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/PostMortemServer.py
Revision: 1.7
Committed: Tue Apr 28 15:57:44 2009 UTC (16 years ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_6_0_pre2, CRAB_2_6_0_pre1
Changes since 1.6: +2 -1 lines
Log Message:
revert to direct loggingInfo if server has not a cached log available + cleanup

File Contents

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