CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions
WorkFlowRunner Namespace Reference

Classes

class  WorkFlowRunner
 

Functions

def esReportWorkflow
 

Function Documentation

def WorkFlowRunner.esReportWorkflow (   kwds)

Definition at line 18 of file WorkFlowRunner.py.

References mergeVDriftHistosByStation.file, SiPixelLorentzAngle_cfi.read, python.rootplot.root2matplotlib.replace(), and split.

18 
19 def esReportWorkflow(**kwds):
20  # Silently exit if we cannot contact elasticsearch
21  es_hostname = getenv("ES_HOSTNAME")
22  es_auth = getenv("ES_AUTH")
23  if not es_hostname and not es_auth:
24  return
25  payload = kwds
26  sha1_id = sha1(kwds["release"] + kwds["architecture"] + kwds["workflow"] + str(kwds["step"])).hexdigest()
27  d = datetime.now()
28  if "_201" in kwds["release"]:
29  datepart = "201" + kwds["release"].split("_201")[1]
30  d = datetime.strptime(datepart, "%Y-%m-%d-%H00")
31  payload["release_queue"] = kwds["release"].split("_201")[0]
32  payload["release_date"] = d.strftime("%Y-%m-%d-%H00")
33  # Parse log file to look for exceptions, errors and warnings.
34  logFile = payload.pop("log_file", "")
35  exception = ""
36  error = ""
37  errors = []
38  inException = False
39  inError = False
40  if exists(logFile):
41  lines = file(logFile).read()
42  payload["message"] = lines
43  for l in lines.split("\n"):
44  if l.startswith("----- Begin Fatal Exception"):
45  inException = True
46  continue
47  if l.startswith("----- End Fatal Exception"):
48  inException = False
49  continue
50  if l.startswith("%MSG-e"):
51  inError = True
52  error = l
53  error_kind = re.split(" [0-9a-zA-Z-]* [0-9:]{8} CET", error)[0].replace("%MSG-e ", "")
54  continue
55  if inError == True and l.startswith("%MSG"):
56  inError = False
57  errors.append({"error": error, "kind": error_kind})
58  error = ""
59  error_kind = ""
60  continue
61  if inException:
62  exception += l + "\n"
63  if inError:
64  error += l + "\n"
65 
66  if exception:
67  payload["exception"] = exception
68  if errors:
69  payload["errors"] = errors
70 
71  payload["hostname"] = gethostname()
72  url = "https://%s/ib-matrix.%s/runTheMatrix-data/%s" % (es_hostname,
73  d.strftime("%Y-%W-1"),
74  sha1_id)
75  request = urllib2.Request(url)
76  if es_auth:
77  base64string = base64.encodestring(es_auth).replace('\n', '')
78  request.add_header("Authorization", "Basic %s" % base64string)
79  request.get_method = lambda: 'PUT'
80  data = json.dumps(payload)
81  try:
82  result = urllib2.urlopen(request, data=data)
83  except urllib2.HTTPError as e:
84  print e
85  try:
86  print result.read()
87  except:
88  pass
double split
Definition: MVATrainer.cc:139