ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/EdgLoggingInfo.py
Revision: 1.3
Committed: Wed Jan 17 18:17:58 2007 UTC (18 years, 3 months ago) by slacapra
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_1_5_0, CRAB_1_5_0_pre9, CRAB_1_5_0_pre8, CRAB_1_5_0_pre7, CRAB_1_5_0_pre6, CRAB_1_5_0_pre5, CRAB_1_5_0_pre4
Changes since 1.2: +3 -10 lines
Log Message:
many minor fixes reported by pychecker, mostly unsude import and unused variables

File Contents

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