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
MINUTE = SECOND * 60
HOUR = MINUTE * 60
......@@ -7,7 +11,7 @@ YEAR = DAY * 365
LOG = logging.getLogger(__name__)
class SlurmDynamicManager(manager.SimpleElasticSliceManager, manager.SimpleElasticSliceHelper):
class SlurmDynamicManager(SimpleElasticSliceManager, SimpleElasticSliceHelper):
DEF_ORDER = [ 'ensure_slice','ensure_sliver','update_sliver_status',
'renew','update_available','update_all','get_system_state',
......@@ -18,8 +22,10 @@ class SlurmDynamicManager(manager.SimpleElasticSliceManager, manager.SimpleElast
add_nodes=5 * MINUTE,delete_nodes=5 * MINUTE)
def __init__(self,server,config=None):
manager.SimpleElasticSliceManager.__init__(self,server,config=config, manage_order=DEF_ORDER,manage_intervals=DEF_INTERVALS)
manager.SimpleElasticSliceHelper.__init__(self,server,config=config)
SimpleElasticSliceManager.__init__(self,server,config=config,
manage_order=SlurmDynamicManager.DEF_ORDER,
manage_intervals=SlurmDynamicManager.DEF_INTERVALS)
SimpleElasticSliceHelper.__init__(self,server,config=config)
self.slurm = SlurmScheduler()
# Manager functions redefined:
......@@ -43,25 +49,28 @@ class SlurmDynamicManager(manager.SimpleElasticSliceManager, manager.SimpleElast
class SlurmScheduler(object):
"""Define operations for interacting with the SLURM resource manager and scheduler"""
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
self.squeue_format = "%i,%P,%j,%u,%T,%M,%l,%D,%R,%p,%C,%D,%e"
def _get_queue_info(self, job_type):
cmd = Command("squeue -o %s -t %s" % (self.squeue_format, job_type))
code = cmd.execute()
if code:
print "ERROR: Job queue check failed with the message: %s" % (cmd.stderr)
return None
else:
return cmd.stdout
def _get_queue_info(self, job_type="RUNNING", show_header=True):
cmd = ShellCommand("squeue -o %s -t %s" % (self.squeue_format, job_type))
code,output = cmd.execute()
job_list = filter(None, output.split('\n'))
if show_header:
return job_list
else:
return job_list[1:]
def list_pending_jobs(self):
return self._get_queue_info("PENDING")
def list_pending_jobs(self, show_header=True):
return self._get_queue_info(job_type="PENDING", show_header=show_header)
def list_running_jobs(self):
return self._get_queue_info("RUNNING")
def list_running_jobs(self, show_header=True):
return self._get_queue_info(job_type="RUNNING", show_header=show_header)
def get_job_count(self, info):
return len(self.list_pending_jobs()) + len(self.list_running_jobs())
def get_job_count(self):
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