Example #1
0
File: lsf.py Project: ewiger/plato
 def list_jobs(self, mask=["all"]):
     result = dict()
     stderr = StringIO()
     if "*" in mask or "all" in mask:
         output = bjobs("-a", _err=stderr)
     else:
         output = bjobs(_err=stderr)
     error_message = stderr.getvalue().strip()
     logger.debug(error_message)
     if re.search(r"No (?:\w* )job found", error_message):
         return result
     # Parse job info, pack it into dictionary
     job_lines = output.split("\n")[1:]  # skip column headers
     for job_line in job_lines:
         job_line = job_line.strip()
         if not job_line:
             continue
         match = job_expr.search(job_line)
         if not match:
             logger.warn("Failed to parse job line: %s" % job_line)
             continue
         lsf_info = dict()
         lsf_info["lsf_id"] = match.group(1)
         lsf_info["lsf_user"] = match.group(2)
         lsf_info["lsf_status"] = match.group(3)
         lsf_info["lsf_queue"] = match.group(4)
         lsf_info["lsf_from_host"] = match.group(5)
         lsf_info["lsf_exec_host"] = match.group(6)
         lsf_info["lsf_job_name"] = match.group(7)
         lsf_info["lsf_submitted_time"] = match.group(8)
         result[lsf_info["lsf_id"]] = lsf_info
     return result
Example #2
0
 def get_lsf_running_jobs(self, depth=0):
     """Query LSF for status of all jobs. Returns Set of job IDs"""
     try:
         status_str = bjobs().stdout
     except ErrorReturnCode, e:
         if depth < 4:
             logger.warn("bjobs failed with message {0}".format(str(e)))
             return self.get_lsf_running_jobs(depth+1)
         else:
             raise