5 import Alignment.MillePedeAlignmentAlgorithm.mpslib.Mpslibclass
as mpslib
9 """Fill timing info in the database for `mps_index`. 12 - `mps_index`: index in the MPS database 13 - `status`: job status 14 - `cpu_time`: extracted CPU timing information 17 cpu_time =
int(round(cpu_time))
18 if status
in (
"RUN",
"DONE"):
20 diff = cpu_time - lib.JOBRUNTIME[mps_index]
21 lib.JOBRUNTIME[mps_index] = cpu_time
22 lib.JOBHOST[mps_index] =
"+"+
str(diff)
23 lib.JOBINCR[mps_index] = diff
25 lib.JOBRUNTIME[mps_index] = 0
26 lib.JOBINCR[mps_index] = 0
32 htcondor_jobstatus = {
"1":
"PEND",
43 lib = mpslib.jobdatabase()
47 for i
in xrange(len(lib.JOBID)):
49 for status
in (
"SETUP",
"OK",
"DONE",
"FETCH",
"ABEND",
"WARN",
"FAIL"):
50 if status
in lib.JOBSTATUS[i]:
54 submitted_jobs[lib.JOBID[i]] = i
55 print "submitted jobs:", len(submitted_jobs)
60 if len(submitted_jobs) > 0:
62 if "htcondor" in lib.get_class(
"pede"):
63 condor_q = subprocess.check_output([
"condor_q",
"-af:j",
64 "JobStatus",
"RemoteSysCpu"],
65 stderr = subprocess.STDOUT)
66 for line
in condor_q.splitlines():
67 job_id, status, cpu_time = line.split()
68 job_status[job_id] = {
"status": htcondor_jobstatus[status],
69 "cpu":
float(cpu_time)}
71 bjobs = subprocess.check_output([
"bjobs",
"-l",
"-a"],
72 stderr = subprocess.STDOUT)
73 bjobs = bjobs.replace(
"\n",
"")
75 job_regex = re.compile(
r"Job<(\d+?)>,")
76 status_regex = re.compile(
r"Status<([A-Z]+?)>")
77 cputime_regex = re.compile(
r"TheCPUtimeusedis(\d+(\.\d+)?)seconds")
78 if bjobs !=
"No job found":
79 results = bjobs.replace(
" ",
"").
split(
"-----------------------")
81 if len(line.strip()) == 0:
continue 83 job_id = job_regex.search(line).
group(1)
85 status = status_regex.search(line).
group(1)
87 match = cputime_regex.search(line)
88 cpu_time =
float(match.group(1))
if match
else 0
89 print "out ", job_id,
" ", status,
" ", cpu_time
90 job_status[job_id] = {
"status": status,
93 for job_id, job_info
in job_status.iteritems():
94 mps_index = submitted_jobs.get(job_id, -1)
96 disabled =
"DISABLED" if "DISABLED" in lib.JOBSTATUS[mps_index]
else "" 100 print "mps_update.py - the job", job_id,
101 print "was not found in the JOBID array" 104 submitted_jobs.pop(job_id)
108 lib.JOBSTATUS[mps_index] = disabled+job_info[
"status"]
114 for job_id, mps_index
in submitted_jobs.items():
116 disabled =
"DISABLED" if "DISABLED" in lib.JOBSTATUS[mps_index]
else "" 117 print " DB job ", job_id, mps_index
121 theBatchDirectory =
"LSFJOB_"+job_id
122 if os.path.isdir(theBatchDirectory):
123 print "Directory ", theBatchDirectory,
"exists" 124 lib.JOBSTATUS[mps_index] = disabled +
"DONE" 125 submitted_jobs.pop(job_id)
129 elif "htcondor" in lib.get_class(
"pede"):
130 userlog = os.path.join(
"jobData", lib.JOBDIR[mps_index],
"HTCJOB")
131 condor_h = subprocess.check_output([
"condor_history", job_id,
"-limit",
"1",
133 "-af:j",
"JobStatus",
"RemoteSysCpu"],
134 stderr = subprocess.STDOUT)
135 if len(condor_h.strip()) > 0:
136 job_id, status, cpu_time = condor_h.split()
137 status = htcondor_jobstatus[status]
138 lib.JOBSTATUS[mps_index] = disabled + status
140 submitted_jobs.pop(job_id)
143 if "RUN" in lib.JOBSTATUS[mps_index]:
144 print "WARNING: Job ", mps_index,
145 print "in state RUN, neither found by htcondor, nor bjobs, nor find",
146 print "LSFJOB directory!" 151 for job_id, mps_index
in submitted_jobs.iteritems():
152 for status
in (
"SETUP",
"DONE",
"FETCH",
"TIMEL",
"SUBTD"):
153 if status
in lib.JOBSTATUS[mps_index]:
154 print "Funny entry index", mps_index,
" job", lib.JOBID[mps_index],
155 print " status", lib.JOBSTATUS[mps_index]
def fill_time_info(mps_index, status, cpu_time)