1 |
gutsche |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
|
3 |
|
|
import sys, os, string
|
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_event = ''
|
52 |
|
|
final_reason = ''
|
53 |
|
|
final_exit_code = ''
|
54 |
|
|
final_time = ''
|
55 |
|
|
final_done_code = 0
|
56 |
|
|
final_abort_msg = ''
|
57 |
|
|
final_done_msg = ''
|
58 |
|
|
final_category = ''
|
59 |
|
|
final_abort = 0
|
60 |
|
|
final_done = 0
|
61 |
|
|
final_running = 0
|
62 |
|
|
|
63 |
|
|
# init variable used in loop
|
64 |
|
|
event = ''
|
65 |
|
|
reason = ''
|
66 |
|
|
exit_code = ''
|
67 |
|
|
time = ''
|
68 |
|
|
|
69 |
|
|
lines = input.split('\n')
|
70 |
|
|
|
71 |
|
|
for line in lines :
|
72 |
|
|
if line.count('Event:') >= 1 :
|
73 |
|
|
event = line.split(':')[1].strip()
|
74 |
|
|
if event == 'Abort' :
|
75 |
|
|
final_abort = 1
|
76 |
|
|
if event == 'Running' :
|
77 |
|
|
final_running = 1
|
78 |
|
|
if event == 'Done' :
|
79 |
|
|
final_done = 1
|
80 |
|
|
if line.count('reason') >= 1 :
|
81 |
|
|
reason = self.parse_reason(line.split('=')[1].strip())
|
82 |
|
|
if line.count('exit_code') >= 1 :
|
83 |
|
|
exit_code = line.split('=')[1].strip()
|
84 |
|
|
if line.count('time') >= 1 :
|
85 |
|
|
time = line.split('=')[1].strip()
|
86 |
|
|
|
87 |
|
|
if ( line.count('---') >= 1 or line.count('***') >= 1 ) and event != '' :
|
88 |
|
|
if event in self._events :
|
89 |
|
|
if event == 'Done' :
|
90 |
|
|
final_done_code = int(exit_code)
|
91 |
|
|
if final_done_msg == '' :
|
92 |
|
|
final_done_msg = reason
|
93 |
|
|
if final_done_msg != reason :
|
94 |
|
|
final_done_msg += '. '+reason
|
95 |
|
|
elif event == 'Abort' :
|
96 |
|
|
final_abort_msg = reason
|
97 |
|
|
final_exit_code = exit_code
|
98 |
|
|
final_time = time
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
if final_abort_msg.count('no compatible resources') >= 1 :
|
102 |
|
|
final_category = self._categories[0]
|
103 |
|
|
|
104 |
|
|
if ( final_running == 0 ) and \
|
105 |
|
|
( final_abort == 1 ) and \
|
106 |
|
|
( final_abort_msg.count('no compatible resources') >= 1 ) :
|
107 |
|
|
final_category = self._categories[1]
|
108 |
|
|
|
109 |
|
|
if ( final_running == 0 ) :
|
110 |
|
|
for error in self._errors :
|
111 |
|
|
if final_done_msg.count(error) >= 1 :
|
112 |
|
|
final_category = self._categories[1]
|
113 |
|
|
|
114 |
|
|
if ( final_running == 1 ) and \
|
115 |
|
|
( final_done_code != 0 ) and \
|
116 |
|
|
( final_done == 0 ) :
|
117 |
|
|
final_category = self._categories[2]
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
if ( final_running == 1 ) and \
|
121 |
|
|
( final_done_code != 0 ) :
|
122 |
|
|
for error in self._errors :
|
123 |
|
|
if final_done_msg.count(error) >= 1 :
|
124 |
|
|
final_category = self._categories[2]
|
125 |
|
|
|
126 |
|
|
if ( final_done == 1 ) and \
|
127 |
|
|
( final_done_msg.count('Aborted by user') >= 1 ) :
|
128 |
|
|
final_category = self._categories[3]
|
129 |
|
|
|
130 |
|
|
if ( final_running == 1 ) and \
|
131 |
|
|
( final_abort == 0 ) and \
|
132 |
|
|
( final_done == 1 ) and \
|
133 |
|
|
( final_done_code != 0 ) :
|
134 |
|
|
check = 0
|
135 |
|
|
for error in self._errors :
|
136 |
|
|
if final_done_msg.count(error) >= 1 :
|
137 |
|
|
check = 1
|
138 |
|
|
if check == 0 :
|
139 |
|
|
final_category = self._categories[4]
|
140 |
|
|
|
141 |
|
|
if ( final_running == 1 ) and \
|
142 |
|
|
( final_abort == 0 ) and \
|
143 |
|
|
( final_done_code == 0 ) and \
|
144 |
|
|
( final_done_msg.count('Aborted by user') == 0 ) :
|
145 |
|
|
final_category = self._categories[5]
|
146 |
|
|
|
147 |
|
|
msg = ''
|
148 |
|
|
if final_category == self._categories[0] :
|
149 |
|
|
msg = 'aborted because: "'+self._categories[0]+'". Abort msg: "'+final_abort_msg+'".'
|
150 |
|
|
self.reason = final_abort_msg
|
151 |
|
|
self.category = self._categories[0]
|
152 |
|
|
elif final_category == self._categories[1] :
|
153 |
|
|
if final_done == 1 :
|
154 |
|
|
msg = 'aborted with "'+self._categories[1]+'". Abort msg: "'+final_done_msg+'".'
|
155 |
|
|
self.reason = final_done_msg
|
156 |
|
|
self.category = self._categories[1]
|
157 |
|
|
else :
|
158 |
|
|
msg = 'aborted with "'+self._categories[1]+'". Abort msg: "'+final_abort_msg+'".'
|
159 |
|
|
self.reason = final_abort_msg
|
160 |
|
|
self.category = self._categories[1]
|
161 |
|
|
elif final_category == self._categories[2] :
|
162 |
|
|
msg = 'aborted with "'+self._categories[2]+'". Abort msg: "'+final_done_msg+'".'
|
163 |
|
|
self.reason = final_done_msg
|
164 |
|
|
self.category = self._categories[2]
|
165 |
|
|
elif final_category == self._categories[3] :
|
166 |
|
|
msg = 'was "'+self._categories[3]+'".'
|
167 |
|
|
self.reason = self._categories[3]
|
168 |
|
|
self.category = self._categories[3]
|
169 |
|
|
elif final_category == self._categories[4] :
|
170 |
|
|
msg = 'finished correctly but failed with error code: '+final_done_code
|
171 |
|
|
self.reason = msg
|
172 |
|
|
self.category = self._categories[4]
|
173 |
|
|
elif final_category == self._categories[5] :
|
174 |
|
|
msg = 'succeeded'
|
175 |
|
|
self.reason = msg
|
176 |
|
|
self.category = self._categories[5]
|
177 |
|
|
|
178 |
|
|
return msg
|
179 |
|
|
|
180 |
|
|
def getCategory(self) :
|
181 |
|
|
return self.category
|
182 |
|
|
|
183 |
|
|
def getReason(self) :
|
184 |
|
|
return self.reason
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
if __name__ == '__main__' :
|
188 |
|
|
|
189 |
|
|
info = EdgLoggingInfo()
|
190 |
|
|
print info.parseFile(sys.argv[1])
|