Go to the documentation of this file.00001 from IMProv.IMProvQuery import IMProvQuery
00002 from IMProv.IMProvLoader import loadIMProvFile
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
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
00097
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