CMS 3D CMS Logo

mps_update.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from __future__ import print_function
3 from builtins import range
4 import os
5 import re
6 import subprocess
7 import Alignment.MillePedeAlignmentAlgorithm.mpslib.Mpslibclass as mpslib
8 
9 import six
10 
11 def fill_time_info(mps_index, status, cpu_time):
12  """Fill timing info in the database for `mps_index`.
13 
14  Arguments:
15  - `mps_index`: index in the MPS database
16  - `status`: job status
17  - `cpu_time`: extracted CPU timing information
18  """
19 
20  cpu_time = int(round(cpu_time)) # care only about seconds for now
21  if status in ("RUN", "DONE"):
22  if cpu_time > 0:
23  diff = cpu_time - lib.JOBRUNTIME[mps_index]
24  lib.JOBRUNTIME[mps_index] = cpu_time
25  lib.JOBHOST[mps_index] = "+"+str(diff)
26  lib.JOBINCR[mps_index] = diff
27  else:
28  lib.JOBRUNTIME[mps_index] = 0
29  lib.JOBINCR[mps_index] = 0
30 
31 
32 
33 
35 htcondor_jobstatus = {"1": "PEND", # Idle
36  "2": "RUN", # Running
37  "3": "EXIT", # Removed
38  "4": "DONE", # Completed
39  "5": "PEND", # Held
40  "6": "RUN", # Transferring output
41  "7": "PEND"} # Suspended
42 
43 
44 
46 lib = mpslib.jobdatabase()
47 lib.read_db()
48 
49 submitted_jobs = {}
50 for i in range(len(lib.JOBID)):
51  submitted = True
52  for status in ("SETUP", "OK", "DONE", "FETCH", "ABEND", "WARN", "FAIL"):
53  if status in lib.JOBSTATUS[i]:
54  submitted = False
55  break
56  if submitted:
57  submitted_jobs[lib.JOBID[i]] = i
58 print("submitted jobs:", len(submitted_jobs))
59 
60 
61 
63 if len(submitted_jobs) > 0:
64  job_status = {}
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)}
72 
73  for job_id, job_info in six.iteritems(job_status):
74  mps_index = submitted_jobs.get(job_id, -1)
75  # check for disabled Jobs
76  disabled = "DISABLED" if "DISABLED" in lib.JOBSTATUS[mps_index] else ""
77 
78  # continue with next batch job if not found or not interesting
79  if mps_index == -1:
80  print("mps_update.py - the job", job_id, end=' ')
81  print("was not found in the JOBID array")
82  continue
83  else: # pop entry from submitted jobs
84  submitted_jobs.pop(job_id)
85 
86 
87  # if found update Joblists for mps.db
88  lib.JOBSTATUS[mps_index] = disabled+job_info["status"]
89  fill_time_info(mps_index, job_info["status"], job_info["cpu"])
90 
91 
92 
94 for job_id, mps_index in submitted_jobs.items(): # IMPORTANT to copy here (no iterator!)
95  # check if current job is disabled. Print stuff.
96  disabled = "DISABLED" if "DISABLED" in lib.JOBSTATUS[mps_index] else ""
97  print(" DB job ", job_id, mps_index)
98 
99  # check if it is a HTCondor job already moved to "history"
100  userlog = os.path.join("jobData", lib.JOBDIR[mps_index], "HTCJOB")
101  condor_h = subprocess.check_output(["condor_history", job_id, "-limit", "1",
102  "-userlog", userlog,
103  "-af:j", "JobStatus", "RemoteSysCpu"],
104  stderr = subprocess.STDOUT)
105  if len(condor_h.strip()) > 0:
106  job_id, status, cpu_time = condor_h.split()
107  status = htcondor_jobstatus[status]
108  lib.JOBSTATUS[mps_index] = disabled + status
109  fill_time_info(mps_index, status, float(cpu_time))
110  submitted_jobs.pop(job_id)
111  continue
112 
113  if "RUN" in lib.JOBSTATUS[mps_index]:
114  print("WARNING: Job ", mps_index, end=' ')
115  print("in state RUN, neither found by htcondor, nor bjobs, nor find", end=' ')
116  print("LSFJOB directory!")
117 
118 
119 
121 for job_id, mps_index in six.iteritems(submitted_jobs):
122  for status in ("SETUP", "DONE", "FETCH", "TIMEL", "SUBTD"):
123  if status in lib.JOBSTATUS[mps_index]:
124  print("Funny entry index", mps_index, " job", lib.JOBID[mps_index], end=' ')
125  print(" status", lib.JOBSTATUS[mps_index])
126 
127 
128 lib.write_db()
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
str
#define str(s)
Definition: TestProcessor.cc:51
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
mps_update.fill_time_info
def fill_time_info(mps_index, status, cpu_time)
Definition: mps_update.py:11
createfilelist.int
int
Definition: createfilelist.py:10