5 import Alignment.MillePedeAlignmentAlgorithm.mpslib.Mpslibclass
as mpslib
10 """Fill timing info in the database for `mps_index`. 13 - `mps_index`: index in the MPS database 14 - `status`: job status 15 - `cpu_time`: extracted CPU timing information 18 cpu_time =
int(round(cpu_time))
19 if status
in (
"RUN",
"DONE"):
21 diff = cpu_time - lib.JOBRUNTIME[mps_index]
22 lib.JOBRUNTIME[mps_index] = cpu_time
23 lib.JOBHOST[mps_index] =
"+"+
str(diff)
24 lib.JOBINCR[mps_index] = diff
26 lib.JOBRUNTIME[mps_index] = 0
27 lib.JOBINCR[mps_index] = 0
33 htcondor_jobstatus = {
"1":
"PEND",
44 lib = mpslib.jobdatabase()
48 for i
in xrange(len(lib.JOBID)):
50 for status
in (
"SETUP",
"OK",
"DONE",
"FETCH",
"ABEND",
"WARN",
"FAIL"):
51 if status
in lib.JOBSTATUS[i]:
55 submitted_jobs[lib.JOBID[i]] = i
56 print "submitted jobs:", len(submitted_jobs)
61 if len(submitted_jobs) > 0:
63 if "htcondor" in lib.get_class(
"pede"):
64 condor_q = subprocess.check_output([
"condor_q",
"-af:j",
65 "JobStatus",
"RemoteSysCpu"],
66 stderr = subprocess.STDOUT)
67 for line
in condor_q.splitlines():
68 job_id, status, cpu_time = line.split()
69 job_status[job_id] = {
"status": htcondor_jobstatus[status],
70 "cpu":
float(cpu_time)}
72 bjobs = subprocess.check_output([
"bjobs",
"-l",
"-a"],
73 stderr = subprocess.STDOUT)
74 bjobs = bjobs.replace(
"\n",
"")
76 job_regex = re.compile(
r"Job<(\d+?)>,")
77 status_regex = re.compile(
r"Status<([A-Z]+?)>")
78 cputime_regex = re.compile(
r"TheCPUtimeusedis(\d+(\.\d+)?)seconds")
79 if bjobs !=
"No job found":
80 results = bjobs.replace(
" ",
"").
split(
"-----------------------")
82 if len(line.strip()) == 0:
continue 84 job_id = job_regex.search(line).
group(1)
86 status = status_regex.search(line).
group(1)
88 match = cputime_regex.search(line)
89 cpu_time =
float(match.group(1))
if match
else 0
90 print "out ", job_id,
" ", status,
" ", cpu_time
91 job_status[job_id] = {
"status": status,
94 for job_id, job_info
in six.iteritems(job_status):
95 mps_index = submitted_jobs.get(job_id, -1)
97 disabled =
"DISABLED" if "DISABLED" in lib.JOBSTATUS[mps_index]
else "" 101 print "mps_update.py - the job", job_id,
102 print "was not found in the JOBID array" 105 submitted_jobs.pop(job_id)
109 lib.JOBSTATUS[mps_index] = disabled+job_info[
"status"]
115 for job_id, mps_index
in submitted_jobs.items():
117 disabled =
"DISABLED" if "DISABLED" in lib.JOBSTATUS[mps_index]
else "" 118 print " DB job ", job_id, mps_index
122 theBatchDirectory =
"LSFJOB_"+job_id
123 if os.path.isdir(theBatchDirectory):
124 print "Directory ", theBatchDirectory,
"exists" 125 lib.JOBSTATUS[mps_index] = disabled +
"DONE" 126 submitted_jobs.pop(job_id)
130 elif "htcondor" in lib.get_class(
"pede"):
131 userlog = os.path.join(
"jobData", lib.JOBDIR[mps_index],
"HTCJOB")
132 condor_h = subprocess.check_output([
"condor_history", job_id,
"-limit",
"1",
134 "-af:j",
"JobStatus",
"RemoteSysCpu"],
135 stderr = subprocess.STDOUT)
136 if len(condor_h.strip()) > 0:
137 job_id, status, cpu_time = condor_h.split()
138 status = htcondor_jobstatus[status]
139 lib.JOBSTATUS[mps_index] = disabled + status
141 submitted_jobs.pop(job_id)
144 if "RUN" in lib.JOBSTATUS[mps_index]:
145 print "WARNING: Job ", mps_index,
146 print "in state RUN, neither found by htcondor, nor bjobs, nor find",
147 print "LSFJOB directory!" 152 for job_id, mps_index
in six.iteritems(submitted_jobs):
153 for status
in (
"SETUP",
"DONE",
"FETCH",
"TIMEL",
"SUBTD"):
154 if status
in lib.JOBSTATUS[mps_index]:
155 print "Funny entry index", mps_index,
" job", lib.JOBID[mps_index],
156 print " status", lib.JOBSTATUS[mps_index]
def fill_time_info(mps_index, status, cpu_time)