test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
crabStatusFromReport.py
Go to the documentation of this file.
1 from IMProv.IMProvQuery import IMProvQuery
2 from IMProv.IMProvLoader import loadIMProvFile
3 
4 # script to parse Crab XML report obtained with crab -status
5 #
6 # needs to be run in crab_..../share directory after
7 # crab -status -USER.xml_report=RReport.xml
8 #
9 # status codes are explained in
10 # CRAB_2_2_X/ProdCommon/ProdCommon/BossLite/Scheduler/GLiteLBQuery.py
11 # i.e.
12 #
13 # statusMap = {
14 # 'Undefined':'UN',
15 # 'Submitted':'SU',
16 # 'Waiting':'SW',
17 # 'Ready':'SR',
18 # 'Scheduled':'SS',
19 # 'Running':'R',
20 # 'Done':'SD',
21 # 'Cleared':'E',
22 # 'Aborted':'A',
23 # 'Cancelled':'K',
24 # 'Unknown':'UN',
25 # 'Done(failed)':'DA'
26 # }
27 # more status code come from CrabServer and are here
28 # https://twiki.cern.ch/twiki/bin/view/CMS/TaskTracking#Notes
29 #
30 
31 # map from new (left) to old (right) code
32 statusMap = {
33  'Undefined':'U',
34  'Created':'C',
35  'Submitting':'B',
36  'Submitted':'B',
37  'Waiting':'S',
38  'Ready':'S',
39  'Scheduled':'S',
40  'Running':'R',
41  'Done':'D',
42  'Done (Failed)':'D',
43  'Cleared':'Y',
44  'Retrieved':'Y',
45  'Killing':'K',
46  'Killed':'K',
47  'CannotSubmit':'A',
48  'Aborted':'A',
49  'NotSubmitted':'A',
50  'Cancelled':'K',
51  'Cancelled by user':'K',
52  'Unknown':'U',
53  'Done(failed)':'D'
54  }
55 
56 def queryStatusXML(filename):
57 
58  try:
59  report = loadIMProvFile(filename)
60  except StandardError, ex:
61  msg = "Error reading CRAB Status Report: %s\n" % filename
62  msg += str(ex)
63  raise RuntimeError, msg
64 
65  query = IMProvQuery("Task/TaskJobs/Job/RunningJob")
66  Jobs = query(report)
67 
68  return Jobs
69 
71  Jobs = queryStatusXML(filename)
72  print "Crab Id: StatusScheduler | Status | ProcessStatus | State | GridId |"
73  for j in Jobs:
74  crabId = int(j.attrs.get("jobId",None))
75  statusScheduler = str(j.attrs.get("statusScheduler",None))
76  status = str(j.attrs.get("status",None))
77  processStatus = str(j.attrs.get("processStatus",None))
78  state = str(j.attrs.get("state",None))
79  gridId = str(j.attrs.get("schedulerId",None))
80 
81  # print crabId, processStatus, statusScheduler, status, state, gridId
82  print "%d : %s | %s | %s | %s | %s " % (crabId,statusScheduler,status,processStatus,state,gridId)
83 
84  """
85  # remap into old status codes from BOSS for use in JobRobot
86  if state == 'SubRequested' : status = 'Submitting'
87  if state == 'Terminated' : status = 'Done'
88  ost = statusMap[statusScheduler]
89  # old bossId starts from 0
90  bossId = crabId-1
91  print ("%d|%1s||%s|%d|") % (bossId, ost, gridId, crabId)
92  """
93 
94 def crabStatusFromReport(filename):
95  Jobs = queryStatusXML(filename)
96  #statusField = "statusScheduler"
97  #statusField = "state"
98  statusField = "status"
99  summary = {}
100  nJobs = 0
101  for j in Jobs:
102  jobStatus = str(j.attrs.get(statusField,None))
103  if summary.has_key(jobStatus): summary[jobStatus] += 1
104  else: summary[jobStatus] = 1
105  nJobs += 1
106 
107  for item in summary: summary[item] = 100.*summary[item]/nJobs
108 
109  return summary
110 
Definition: query.py:1