Commit d538b17a authored by Dmitry Duplyakin's avatar Dmitry Duplyakin

Bug fixes and restore SLURM job reporting to working

parent b7675689
import logging
from manager import SimpleElasticSliceManager, SimpleElasticSliceHelper
from util import ShellCommand
SECOND = 1 SECOND = 1
MINUTE = SECOND * 60 MINUTE = SECOND * 60
HOUR = MINUTE * 60 HOUR = MINUTE * 60
...@@ -7,7 +11,7 @@ YEAR = DAY * 365 ...@@ -7,7 +11,7 @@ YEAR = DAY * 365
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class SlurmDynamicManager(manager.SimpleElasticSliceManager, manager.SimpleElasticSliceHelper): class SlurmDynamicManager(SimpleElasticSliceManager, SimpleElasticSliceHelper):
DEF_ORDER = [ 'ensure_slice','ensure_sliver','update_sliver_status', DEF_ORDER = [ 'ensure_slice','ensure_sliver','update_sliver_status',
'renew','update_available','update_all','get_system_state', 'renew','update_available','update_all','get_system_state',
...@@ -18,8 +22,10 @@ class SlurmDynamicManager(manager.SimpleElasticSliceManager, manager.SimpleElast ...@@ -18,8 +22,10 @@ class SlurmDynamicManager(manager.SimpleElasticSliceManager, manager.SimpleElast
add_nodes=5 * MINUTE,delete_nodes=5 * MINUTE) add_nodes=5 * MINUTE,delete_nodes=5 * MINUTE)
def __init__(self,server,config=None): def __init__(self,server,config=None):
manager.SimpleElasticSliceManager.__init__(self,server,config=config, manage_order=DEF_ORDER,manage_intervals=DEF_INTERVALS) SimpleElasticSliceManager.__init__(self,server,config=config,
manager.SimpleElasticSliceHelper.__init__(self,server,config=config) manage_order=SlurmDynamicManager.DEF_ORDER,
manage_intervals=SlurmDynamicManager.DEF_INTERVALS)
SimpleElasticSliceHelper.__init__(self,server,config=config)
self.slurm = SlurmScheduler() self.slurm = SlurmScheduler()
# Manager functions redefined: # Manager functions redefined:
...@@ -43,25 +49,28 @@ class SlurmDynamicManager(manager.SimpleElasticSliceManager, manager.SimpleElast ...@@ -43,25 +49,28 @@ class SlurmDynamicManager(manager.SimpleElasticSliceManager, manager.SimpleElast
class SlurmScheduler(object): class SlurmScheduler(object):
"""Define operations for interacting with the SLURM resource manager and scheduler""" """Define operations for interacting with the SLURM resource manager and scheduler"""
def __init__(self): def __init__(self):
LOG.info("Starting SlurmScheduler object") LOG.debug("Starting SlurmScheduler object")
# List of dislayed fields; all flags are documented at: http://slurm.schedmd.com/squeue.html # List of dislayed fields; all flags are documented at: http://slurm.schedmd.com/squeue.html
self.squeue_format = "%i,%P,%j,%u,%T,%M,%l,%D,%R,%p,%C,%D,%e" self.squeue_format = "%i,%P,%j,%u,%T,%M,%l,%D,%R,%p,%C,%D,%e"
def _get_queue_info(self, job_type): def _get_queue_info(self, job_type="RUNNING", show_header=True):
cmd = ShellCommand("squeue -o %s -t %s" % (self.squeue_format, job_type))
cmd = Command("squeue -o %s -t %s" % (self.squeue_format, job_type)) code,output = cmd.execute()
code = cmd.execute() job_list = filter(None, output.split('\n'))
if code: if show_header:
print "ERROR: Job queue check failed with the message: %s" % (cmd.stderr) return job_list
return None else:
else: return job_list[1:]
return cmd.stdout
def list_pending_jobs(self): def list_pending_jobs(self, show_header=True):
return self._get_queue_info("PENDING") return self._get_queue_info(job_type="PENDING", show_header=show_header)
def list_running_jobs(self): def list_running_jobs(self, show_header=True):
return self._get_queue_info("RUNNING") return self._get_queue_info(job_type="RUNNING", show_header=show_header)
def get_job_count(self, info): def get_job_count(self):
return len(self.list_pending_jobs()) + len(self.list_running_jobs()) pj = self.list_pending_jobs(show_header=False)
LOG.debug("Pending jobs: %s" % pj)
rj = self.list_running_jobs(show_header=False)
LOG.debug("Running jobs: %s" % rj)
return len(pj) + len(rj)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment