2 from __future__
import print_function
6 import Alignment.MillePedeAlignmentAlgorithm.mpslib.Mpslibclass
as mpslib
11 """Fill timing info in the database for `mps_index`. 14 - `mps_index`: index in the MPS database 15 - `status`: job status 16 - `cpu_time`: extracted CPU timing information 19 cpu_time =
int(round(cpu_time))
20 if status
in (
"RUN",
"DONE"):
22 diff = cpu_time - lib.JOBRUNTIME[mps_index]
23 lib.JOBRUNTIME[mps_index] = cpu_time
24 lib.JOBHOST[mps_index] =
"+"+
str(diff)
25 lib.JOBINCR[mps_index] = diff
27 lib.JOBRUNTIME[mps_index] = 0
28 lib.JOBINCR[mps_index] = 0
34 htcondor_jobstatus = {
"1":
"PEND",
45 lib = mpslib.jobdatabase()
49 for i
in xrange(len(lib.JOBID)):
51 for status
in (
"SETUP",
"OK",
"DONE",
"FETCH",
"ABEND",
"WARN",
"FAIL"):
52 if status
in lib.JOBSTATUS[i]:
56 submitted_jobs[lib.JOBID[i]] = i
57 print(
"submitted jobs:", len(submitted_jobs))
62 if len(submitted_jobs) > 0:
64 if "htcondor" in lib.get_class(
"pede"):
65 condor_q = subprocess.check_output([
"condor_q",
"-af:j",
66 "JobStatus",
"RemoteSysCpu"],
67 stderr = subprocess.STDOUT)
68 for line
in condor_q.splitlines():
69 job_id, status, cpu_time = line.split()
70 job_status[job_id] = {
"status": htcondor_jobstatus[status],
71 "cpu":
float(cpu_time)}
73 bjobs = subprocess.check_output([
"bjobs",
"-l",
"-a"],
74 stderr = subprocess.STDOUT)
75 bjobs = bjobs.replace(
"\n",
"")
77 job_regex = re.compile(
r"Job<(\d+?)>,")
78 status_regex = re.compile(
r"Status<([A-Z]+?)>")
79 cputime_regex = re.compile(
r"TheCPUtimeusedis(\d+(\.\d+)?)seconds")
80 if bjobs !=
"No job found":
81 results = bjobs.replace(
" ",
"").
split(
"-----------------------")
83 if len(line.strip()) == 0:
continue 85 job_id = job_regex.search(line).
group(1)
87 status = status_regex.search(line).
group(1)
89 match = cputime_regex.search(line)
90 cpu_time =
float(match.group(1))
if match
else 0
91 print(
"out ", job_id,
" ", status,
" ", cpu_time)
92 job_status[job_id] = {
"status": status,
95 for job_id, job_info
in six.iteritems(job_status):
96 mps_index = submitted_jobs.get(job_id, -1)
98 disabled =
"DISABLED" if "DISABLED" in lib.JOBSTATUS[mps_index]
else "" 102 print(
"mps_update.py - the job", job_id, end=
' ')
103 print(
"was not found in the JOBID array")
106 submitted_jobs.pop(job_id)
110 lib.JOBSTATUS[mps_index] = disabled+job_info[
"status"]
116 for job_id, mps_index
in submitted_jobs.items():
118 disabled =
"DISABLED" if "DISABLED" in lib.JOBSTATUS[mps_index]
else "" 119 print(
" DB job ", job_id, mps_index)
123 theBatchDirectory =
"LSFJOB_"+job_id
124 if os.path.isdir(theBatchDirectory):
125 print(
"Directory ", theBatchDirectory,
"exists")
126 lib.JOBSTATUS[mps_index] = disabled +
"DONE" 127 submitted_jobs.pop(job_id)
131 elif "htcondor" in lib.get_class(
"pede"):
132 userlog = os.path.join(
"jobData", lib.JOBDIR[mps_index],
"HTCJOB")
133 condor_h = subprocess.check_output([
"condor_history", job_id,
"-limit",
"1",
135 "-af:j",
"JobStatus",
"RemoteSysCpu"],
136 stderr = subprocess.STDOUT)
137 if len(condor_h.strip()) > 0:
138 job_id, status, cpu_time = condor_h.split()
139 status = htcondor_jobstatus[status]
140 lib.JOBSTATUS[mps_index] = disabled + status
142 submitted_jobs.pop(job_id)
145 if "RUN" in lib.JOBSTATUS[mps_index]:
146 print(
"WARNING: Job ", mps_index, end=
' ')
147 print(
"in state RUN, neither found by htcondor, nor bjobs, nor find", end=
' ')
148 print(
"LSFJOB directory!")
153 for job_id, mps_index
in six.iteritems(submitted_jobs):
154 for status
in (
"SETUP",
"DONE",
"FETCH",
"TIMEL",
"SUBTD"):
155 if status
in lib.JOBSTATUS[mps_index]:
156 print(
"Funny entry index", mps_index,
" job", lib.JOBID[mps_index], end=
' ')
157 print(
" status", lib.JOBSTATUS[mps_index])
S & print(S &os, JobReport::InputFile const &f)
def fill_time_info(mps_index, status, cpu_time)