ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/EdgLoggingInfo.py
Revision: 1.6
Committed: Tue Apr 15 09:37:47 2008 UTC (17 years ago) by spiga
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_6_0_pre2, CRAB_2_6_0_pre1, CRAB_2_5_1, CRAB_2_5_1_pre4, CRAB_2_5_1_pre3, CRAB_2_5_1_pre2, CRAB_2_5_1_pre1, CRAB_2_5_0, CRAB_2_5_0_pre7, CRAB_2_5_0_pre6, CRAB_2_5_0_pre5, CRAB_2_5_0_pre4, CRAB_2_5_0_pre3, CRAB_2_5_0_pre2, CRAB_2_5_0_pre1, CRAB_2_4_4, CRAB_2_4_4_pre6, CRAB_2_4_4_pre5, CRAB_2_4_4_pre4, CRAB_2_4_4_pre3, CRAB_2_4_4_pre2, CRAB_2_4_4_pre1, CRAB_2_4_3, CRAB_2_4_3_pre8, CRAB_2_4_3_pre7, CRAB_2_4_3_pre6, CRAB_2_4_3_pre5, CRAB_2_4_3_pre3, CRAB_2_4_3_pre2, CRAB_2_4_3_pre1, CRAB_2_4_2, CRAB_2_4_2_pre3, CRAB_2_4_2_pre2, CRAB_2_4_2_pre1, 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, CRAB_2_2_2_pre4, CRAB_2_2_2_pre3, CRAB_2_2_2_pre2, CRAB_2_2_2_pre1, CRAB_2_2_1, CRAB_2_2_1_pre6, CRAB_2_2_1_pre5, CRAB_2_2_1_pre4, PRODCOMMON_0_10_7_testCS2, CRAB_2_2_1_pre3, CRAB_2_2_1_pre2, CRAB_2_2_1_pre1, CRAB_2_2_0, CRAB_2_2_0_pre21, CRAB_2_2_0_pre19, CRAB_2_2_0_pre18, CRAB_2_2_0_pre17, CRAB_2_2_0_pre16, CRAB_2_2_0_pre15, CRAB_2_2_0_pre13, CRAB_2_2_0_pre12, CRAB_2_2_0_pre11, CRAB_2_2_0_pre10, bp_osg_bdii, CRAB_2_2_0_pre9, CRAB_2_2_0_pre8, CRAB_2_2_0_pre7
Branch point for: AnaDataSet, CRAB_2_3_0_br, osg_bdii
Changes since 1.5: +11 -6 lines
Log Message:
PostMortem functionality restored. Many reorganization to allow inheritation from Server calss. Fix and improvement on Logging parsing

File Contents

# User Rev Content
1 gutsche 1.1 #!/usr/bin/env python
2    
3 mcinquil 1.5 import sys , re #DS
4     EXIT_CODE_RE = re.compile('^\s*-\s*[Ee]xit.[Cc]ode\s*=\s*(.*?)\s*$')
5 gutsche 1.1
6     class EdgLoggingInfo:
7     def __init__(self) :
8     self._events = ['Running', 'Done', 'Abort']
9     self._errors = ['Maradona', 'Globus error',
10     'gridmanager error', 'CondorG',
11     'BrokerInfo', 'Cannot download',
12     'Cannot upload']
13     self._categories = ['Resource unavailable',
14     'Grid error before job started',
15     'Grid error after job started',
16     'Aborted by user',
17     'Application error',
18 spiga 1.6 'Success',
19     'Failure while executing job wrapper' ]
20 gutsche 1.1 self.category = ''
21     self.reason = ''
22    
23     def parse_reason(self,reason) :
24     error = reason
25     if reason.count('Cannot download') >= 1 :
26     error = 'Cannot download ... from ...'
27     if reason.count('cannot retrieve previous matches') >= 1 :
28     error = 'Harmless warning'
29     if reason.count('RetryCount') >= 1 :
30     error = 'Harmless warning'
31     if reason.count('There were some warnings') >= 1 :
32     error = 'Harmless warning'
33     return error;
34    
35     def parseFile(self,filename) :
36    
37     # open file
38     try:
39     file = open(filename)
40     except IOError:
41 slacapra 1.4 common.logger.message('Could not open file: '+filename)
42 gutsche 1.1 return ''
43    
44     return self.decodeReason(file.readlines())
45    
46     def decodeReason(self, input) :
47     """
48     extract meaningful message from edg-job-get-logging-info -v 2
49     """
50     # init final variables
51     final_done_code = 0
52     final_abort_msg = ''
53     final_done_msg = ''
54     final_category = ''
55     final_abort = 0
56     final_done = 0
57     final_running = 0
58    
59     # init variable used in loop
60     event = ''
61     reason = ''
62     exit_code = ''
63    
64     lines = input.split('\n')
65     for line in lines :
66     if line.count('Event:') >= 1 :
67     event = line.split(':')[1].strip()
68     if event == 'Abort' :
69     final_abort = 1
70     if event == 'Running' :
71     final_running = 1
72     if event == 'Done' :
73     final_done = 1
74 spiga 1.6 if line.count('Reason') >= 1 :
75 gutsche 1.1 reason = self.parse_reason(line.split('=')[1].strip())
76 mcinquil 1.5 match = EXIT_CODE_RE.match(line) #DS
77     if match: #DS
78     exit_code = match.groups()[0] #DS
79     #if line.count('exit_code') >= 1 :
80     # exit_code = line.split('=')[1].strip()
81 slacapra 1.3 # if line.count('time') >= 1 :
82     # time = line.split('=')[1].strip()
83 gutsche 1.1 if ( line.count('---') >= 1 or line.count('***') >= 1 ) and event != '' :
84     if event in self._events :
85     if event == 'Done' :
86     final_done_code = int(exit_code)
87     if final_done_msg == '' :
88     final_done_msg = reason
89     if final_done_msg != reason :
90     final_done_msg += '. '+reason
91     elif event == 'Abort' :
92     final_abort_msg = reason
93 spiga 1.6
94     if final_abort_msg.count('Failure while executing job wrapper') >= 1 and \
95     ( final_running == 1 ) :
96     final_category = self._categories[6]
97 gutsche 1.1
98     if final_abort_msg.count('no compatible resources') >= 1 :
99     final_category = self._categories[0]
100    
101     if ( final_running == 0 ) and \
102     ( final_abort == 1 ) and \
103     ( final_abort_msg.count('no compatible resources') >= 1 ) :
104     final_category = self._categories[1]
105    
106     if ( final_running == 0 ) :
107     for error in self._errors :
108     if final_done_msg.count(error) >= 1 :
109     final_category = self._categories[1]
110    
111     if ( final_running == 1 ) and \
112     ( final_done_code != 0 ) and \
113     ( final_done == 0 ) :
114     final_category = self._categories[2]
115    
116    
117     if ( final_running == 1 ) and \
118     ( final_done_code != 0 ) :
119     for error in self._errors :
120     if final_done_msg.count(error) >= 1 :
121     final_category = self._categories[2]
122    
123     if ( final_done == 1 ) and \
124     ( final_done_msg.count('Aborted by user') >= 1 ) :
125     final_category = self._categories[3]
126    
127     if ( final_running == 1 ) and \
128     ( final_abort == 0 ) and \
129     ( final_done == 1 ) and \
130     ( final_done_code != 0 ) :
131     check = 0
132     for error in self._errors :
133     if final_done_msg.count(error) >= 1 :
134     check = 1
135     if check == 0 :
136     final_category = self._categories[4]
137    
138     if ( final_running == 1 ) and \
139     ( final_abort == 0 ) and \
140     ( final_done_code == 0 ) and \
141     ( final_done_msg.count('Aborted by user') == 0 ) :
142     final_category = self._categories[5]
143    
144     msg = ''
145     if final_category == self._categories[0] :
146     msg = 'aborted because: "'+self._categories[0]+'". Abort msg: "'+final_abort_msg+'".'
147     self.reason = final_abort_msg
148     self.category = self._categories[0]
149     elif final_category == self._categories[1] :
150     if final_done == 1 :
151     msg = 'aborted with "'+self._categories[1]+'". Abort msg: "'+final_done_msg+'".'
152     self.reason = final_done_msg
153     self.category = self._categories[1]
154     else :
155     msg = 'aborted with "'+self._categories[1]+'". Abort msg: "'+final_abort_msg+'".'
156     self.reason = final_abort_msg
157     self.category = self._categories[1]
158     elif final_category == self._categories[2] :
159     msg = 'aborted with "'+self._categories[2]+'". Abort msg: "'+final_done_msg+'".'
160     self.reason = final_done_msg
161     self.category = self._categories[2]
162     elif final_category == self._categories[3] :
163     msg = 'was "'+self._categories[3]+'".'
164     self.reason = self._categories[3]
165     self.category = self._categories[3]
166     elif final_category == self._categories[4] :
167 corvo 1.2 msg = 'finished correctly but failed with error code: ', final_done_code
168 gutsche 1.1 self.reason = msg
169     self.category = self._categories[4]
170     elif final_category == self._categories[5] :
171     msg = 'succeeded'
172     self.reason = msg
173     self.category = self._categories[5]
174 spiga 1.6 elif final_category == self._categories[6] :
175     msg = 'aborted with msg "'+final_abort_msg+'".'
176     self.reason = msg
177     self.category = self._categories[5]
178 gutsche 1.1
179     return msg
180    
181     def getCategory(self) :
182     return self.category
183    
184     def getReason(self) :
185     return self.reason
186    
187    
188     if __name__ == '__main__' :
189    
190     info = EdgLoggingInfo()
191     print info.parseFile(sys.argv[1])