This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
ErrorDiagnosis.py
211 lines (164 loc) · 8.05 KB
/
ErrorDiagnosis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# Class definition:
# ErrorDiagnosis
#
import os
import re
from Diagnosis import Diagnosis
from PilotErrors import PilotErrors
from pUtil import tolog, getExperiment
class ErrorDiagnosis(Diagnosis):
# private data members
__instance = None # Boolean used by subclasses to become a Singleton
__error = PilotErrors() # PilotErrors object
def __init__(self):
""" Default initialization """
# e.g. self.__errorLabel = errorLabel
pass
def __new__(cls, *args, **kwargs):
""" Override the __new__ method to make the class a singleton """
if not cls.__instance:
cls.__instance = super(ErrorDiagnosis, cls).__new__(cls, *args, **kwargs)
return cls.__instance
def interpretPayload(self, job, res, getstatusoutput_was_interrupted, current_job_number, runCommandList, failureCode):
""" Interpret the payload, look for specific errors in the stdout """
# get the experiment object
thisExperiment = getExperiment(job.experiment)
if not thisExperiment:
job.pilotErrorDiag = "ErrorDiagnosis did not get an experiment object from the factory"
job.result[2] = self.__error.ERR_GENERALERROR # change to better/new error code
tolog("!!WARNING!!3234!! %s" % (job.pilotErrorDiag))
return job
### WARNING: EXPERIMENT SPECIFIC, MOVE LATER
try:
ec, pilotErrorDiag = self.processJobReport(job.workdir)
except Exception, e:
tolog("!!WARNING!!1114!! Caught exception: %s" % (e))
else:
if ec != 0:
job.pilotErrorDiag = pilotErrorDiag
job.result[2] = ec
return job
# handle special errors from the trf
if res[0] == 146:
# try to extract the tarball url from res[1] (should have been added in executePayload())
tarball_url = self.extractTarballURL(res[1])
job.pilotErrorDiag = "User tarball %s cannot be downloaded from PanDA server" % tarball_url
job.result[2] = self.__error.ERR_NOUSERTARBALL
# no need to continue, as the job report will not exist
return job
# Extract job information (e.g. number of events)
job = self.extractJobInformation(job, runCommandList) # add more arguments as needed
# interpret the stdout (the stdout is experiment specific so use the corresponding method)
job = thisExperiment.interpretPayloadStdout(job, res, getstatusoutput_was_interrupted, current_job_number, runCommandList, failureCode)
return job
def extractTarballURL(self, tail):
""" Extract the tarball URL for missing user code if possible from stdout tail """
tarball_url = "(source unknown)"
if "https://" in tail or "http://" in tail:
pattern = r"(https?\:\/\/.+)"
found = re.findall(pattern, tail)
if len(found) > 0:
tarball_url = found[0]
return tarball_url
### WARNING: EXPERIMENT SPECIFIC, MOVE LATER
def getJobReport(self, workDir):
""" Get the jobReport.json dictionary """
fileName = os.path.join(workDir, "jobReport.json")
if os.path.exists(fileName):
# the jobReport file exists, read it back
try:
f = open(fileName, "r")
except Exception, e:
tolog("!!WARNING!!1001!! Could not open file: %s, %s" % (fileName, e))
jobReport_dictionary = {}
else:
from json import load
try:
# load the dictionary
jobReport_dictionary = load(f)
except Exception, e:
tolog("!!WARNING!!1001!! Could not read back jobReport dictionary: %s" % (e))
jobReport_dictionary = {}
# done with the file
f.close()
else:
tolog("WARNING: File %s does not exist" % (fileName))
jobReport_dictionary = {}
return jobReport_dictionary
### WARNING: EXPERIMENT SPECIFIC, MOVE LATER
def getJobReportErrors(self, jobReport_dictionary):
""" Extract the error list from the jobReport.json dictionary """
# WARNING: Currently compatible with version <= 0.9.4
jobReportErrors = []
if jobReport_dictionary.has_key('reportVersion'):
tolog("Scanning jobReport (v %s) for error info" % jobReport_dictionary['reportVersion'])
else:
tolog("WARNING: jobReport does not have the reportVersion key")
if jobReport_dictionary.has_key('executor'):
try:
error_details = jobReport_dictionary['executor'][0]['logfileReport']['details']['ERROR']
except Exception, e:
tolog("WARNING: Aborting jobReport scan: %s"% (e))
else:
try:
for m in error_details:
jobReportErrors.append(m['message'])
except Exception, e:
tolog("!!WARNING!!1113!! Did not get a list object: %s" % (e))
else:
tolog("WARNING: jobReport does not have the executor key (aborting)")
return jobReportErrors
### WARNING: EXPERIMENT SPECIFIC, MOVE LATER
def isBadAlloc(self, jobReportErrors):
""" Check for bad_alloc errors """
bad_alloc = False
pilotErrorDiag = ""
for m in jobReportErrors:
if "bad_alloc" in m:
tolog("!!WARNING!!1112!! Encountered a bad_alloc error: %s" % (m))
bad_alloc = True
pilotErrorDiag = m
break
return bad_alloc, pilotErrorDiag
### WARNING: EXPERIMENT SPECIFIC, MOVE LATER
def processJobReport(self, workDir):
""" Scan the jobReport.json for specific errors """
# Specific errors
ec = 0
pilotErrorDiag = ""
bad_alloc = False
jobReport_dictionary = self.getJobReport(workDir)
if jobReport_dictionary != {}:
jobReportErrors = self.getJobReportErrors(jobReport_dictionary)
# Check for specific errors
if jobReportErrors != []:
bad_alloc, pilotErrorDiag = self.isBadAlloc(jobReportErrors)
if bad_alloc:
ec = self.__error.ERR_BADALLOC # get the corresponding error code
return ec, pilotErrorDiag
def extractJobInformation(self, job, runCommandList):
""" Extract relevant job information, e.g. number of events """
# get the experiment object
thisExperiment = getExperiment(job.experiment)
if not thisExperiment:
job.pilotErrorDiag = "ErrorDiagnosis did not get an experiment object from the factory"
job.result[2] = self.__error.ERR_GENERALERROR # change to better/new error code
tolog("!!WARNING!!3234!! %s" % (job.pilotErrorDiag))
return job
# note that this class should not be experiment specific, so move anything related to ATLAS to ATLASExperiment.py
# and use thisExperiment.whatever() to retrieve it here
# grab the number of events
try:
# nEvents_str can be a string of the form N|N|..|N with the number of jobs in the trf(s) [currently not used]
# Add to Job class if necessary
job.nEvents, job.nEventsW, nEvents_str = thisExperiment.getNumberOfEvents(job=job, number_of_jobs=len(runCommandList))
except Exception, e:
tolog("!!WARNING!!2999!! Failed to get number of events: %s (ignore)" % str(e))
# get the DB info from the jobReport (experiment specific)
from FileHandling import getDBInfo
job.dbTime, job.dbData = getDBInfo(job.workdir)
return job
if __name__ == "__main__":
print "Implement test cases here"
ed = ErrorDiagnosis()
# ed.hello()