CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CalibMuon/DTCalibration/python/Workflow/crabStatusFromReport.py

Go to the documentation of this file.
00001 from IMProv.IMProvQuery import IMProvQuery
00002 from IMProv.IMProvLoader import loadIMProvFile
00003 
00004 # script to parse Crab XML report obtained with crab -status
00005 #
00006 # needs to be run in crab_..../share directory after
00007 # crab -status -USER.xml_report=RReport.xml
00008 #
00009 # status codes are explained in
00010 # CRAB_2_2_X/ProdCommon/ProdCommon/BossLite/Scheduler/GLiteLBQuery.py
00011 # i.e.
00012 #
00013 #    statusMap = {
00014 #        'Undefined':'UN',
00015 #        'Submitted':'SU',
00016 #        'Waiting':'SW',
00017 #        'Ready':'SR',
00018 #        'Scheduled':'SS',
00019 #        'Running':'R',
00020 #        'Done':'SD',
00021 #        'Cleared':'E',
00022 #        'Aborted':'A',
00023 #        'Cancelled':'K',
00024 #        'Unknown':'UN',
00025 #        'Done(failed)':'DA'
00026 #                }
00027 # more status code come from CrabServer and are here
00028 # https://twiki.cern.ch/twiki/bin/view/CMS/TaskTracking#Notes
00029 #
00030     
00031 # map from new (left) to old (right) code
00032 statusMap = {
00033     'Undefined':'U',
00034     'Created':'C',
00035     'Submitting':'B',
00036     'Submitted':'B',
00037     'Waiting':'S',
00038     'Ready':'S',
00039     'Scheduled':'S',
00040     'Running':'R',
00041     'Done':'D',
00042     'Done (Failed)':'D',
00043     'Cleared':'Y',
00044     'Retrieved':'Y',
00045     'Killing':'K',
00046     'Killed':'K',
00047     'CannotSubmit':'A',
00048     'Aborted':'A',
00049     'NotSubmitted':'A',
00050     'Cancelled':'K',
00051     'Cancelled by user':'K',
00052     'Unknown':'U',
00053     'Done(failed)':'D'   
00054     }
00055 
00056 def queryStatusXML(filename):
00057 
00058     try:
00059         report = loadIMProvFile(filename)
00060     except StandardError, ex:
00061         msg = "Error reading CRAB Status Report: %s\n" % filename
00062         msg += str(ex)
00063         raise RuntimeError, msg
00064 
00065     query = IMProvQuery("Task/TaskJobs/Job/RunningJob")
00066     Jobs = query(report)
00067 
00068     return Jobs
00069   
00070 def printCrabStatusFromReport(filename):
00071     Jobs = queryStatusXML(filename)
00072     print "Crab Id: StatusScheduler | Status | ProcessStatus | State | GridId |"
00073     for j in Jobs:
00074         crabId = int(j.attrs.get("jobId",None))
00075         statusScheduler = str(j.attrs.get("statusScheduler",None))
00076         status = str(j.attrs.get("status",None))
00077         processStatus = str(j.attrs.get("processStatus",None))
00078         state  = str(j.attrs.get("state",None))
00079         gridId = str(j.attrs.get("schedulerId",None))
00080 
00081         # print crabId, processStatus, statusScheduler, status, state, gridId
00082         print "%d : %s | %s | %s | %s | %s " % (crabId,statusScheduler,status,processStatus,state,gridId)
00083 
00084         """
00085         # remap into old status codes from BOSS for use in JobRobot
00086         if state == 'SubRequested' : status = 'Submitting'
00087         if state == 'Terminated' : status = 'Done'
00088         ost = statusMap[statusScheduler]
00089         # old bossId starts from 0
00090         bossId = crabId-1
00091         print ("%d|%1s||%s|%d|") % (bossId, ost, gridId, crabId)
00092         """
00093 
00094 def crabStatusFromReport(filename):
00095     Jobs = queryStatusXML(filename)
00096     #statusField = "statusScheduler"
00097     #statusField = "state"
00098     statusField = "status"
00099     summary = {}
00100     nJobs = 0
00101     for j in Jobs:
00102         jobStatus = str(j.attrs.get(statusField,None))
00103         if summary.has_key(jobStatus): summary[jobStatus] += 1
00104         else: summary[jobStatus] = 1
00105         nJobs += 1
00106 
00107     for item in summary: summary[item] = 100.*summary[item]/nJobs
00108 
00109     return summary
00110