Commit c8d8f378 authored by Dmitry Duplyakin's avatar Dmitry Duplyakin

SLURM: start special-event file logging

parent ab71c903
......@@ -3,6 +3,7 @@ import logging
from elasticslice.managers.core import SimpleElasticSliceHelper, \
SimpleElasticSliceManager
from elasticslice.util.util import ShellCommand
from elasticslice.util.log import configure_file_logging
SECOND = 1
MINUTE = SECOND * 60
......@@ -24,13 +25,32 @@ LOG = logging.getLogger(__name__)
class SlurmDynamicManager(SimpleElasticSliceHelper,SimpleElasticSliceManager):
# Important: 'update_all' should precede 'update_available'
#DEF_ORDER = [ 'ensure_slice','ensure_sliver','update_sliver_status',
# 'renew','update_all','update_available','get_system_state',
# 'add_nodes','delete_nodes','set_system_state' ]
#DEF_INTERVALS = dict(ensure_slice=MINUTE,ensure_sliver=MINUTE,
# update_sliver_status=MINUTE,renew=HOUR,
# update_available=10 * MINUTE,update_all=DAY,
# add_nodes=5 * MINUTE,delete_nodes=5 * MINUTE)
DEF_ORDER = [ 'ensure_slice','ensure_sliver','update_sliver_status',
'renew','update_all','update_available','get_system_state',
'add_nodes','delete_nodes','set_system_state' ]
CM_METHODS = [ 'ensure_sliver','update_sliver_status',
'update_available','update_all','add_nodes','delete_nodes' ]
METHOD_RESET_TRIGGERS = \
dict(add_nodes=[ 'update_sliver_status','update_available',
'get_system_state','set_system_state' ],
delete_nodes=[ 'update_sliver_status','update_available',
'get_system_state','set_system_state' ])
DEF_INTERVALS = dict(ensure_slice=MINUTE,ensure_sliver=MINUTE,
update_sliver_status=MINUTE,renew=HOUR,
update_available=10 * MINUTE,update_all=DAY,
add_nodes=5 * MINUTE,delete_nodes=5 * MINUTE)
DEF_INTERVAL = MINUTE
DEF_MIN_THRESHOLD = 1
DEF_MAX_THRESHOLD = 10
def __init__(self,server,config=None):
SimpleElasticSliceHelper.__init__(self,server,config=config)
......@@ -44,7 +64,13 @@ class SlurmDynamicManager(SimpleElasticSliceHelper,SimpleElasticSliceManager):
# Add SLURM related capabilities
self.slurm = SlurmScheduler()
# File logger for special events
configure_file_logging('file_log', '/tmp/SlurmDynamicManager.log')
self.file_log = logging.getLogger('file_log')
self.file_log.debug("Created file logging for special events")
def get_add_args(self,count=1):
self.file_log.debug("Running get_add_args()")
from xml.sax.saxutils import escape
# If we didn't generate an rspec for a sliver creation,
......@@ -102,10 +128,39 @@ class SlurmDynamicManager(SimpleElasticSliceHelper,SimpleElasticSliceManager):
def get_system_state(self):
jc = self.slurm.get_job_count()
LOG.info("Number of SLURM jobs (running and pending): %d" % jc)
LOG.info("Number of SLURM jobs (running and pending): %d" % jc)
self.file_log.debug("Running get_system_state()")
pass
def set_system_state(self):
self.file_log.debug("Running set_system_state()")
pass
def handle_added_node(self,node,status):
"""
This method should be called by a manager when it sees that an
added node has become "ready" or "failed". @node is a dict like
{ 'client_id':'node-1','node_id':'pc100',...}
and @status is either 'ready', 'failed'. The return value is
not checked by the caller.
"""
self.file_log.debug("Handling added node: %s; Status: %s" % (node, status))
pass
def handle_deleted_node(self,node):
"""
This method should be called by a manager when it sees that an
added node has become "ready" or "failed". @node is a dict like
{ 'client_id':'node-1','node_id':'pc100',...}
The return value is not checked by the caller.
"""
self.file_log.debug("Handling deleted node: %s" % node)
pass
# Helper functions redefined:
......
......@@ -18,3 +18,18 @@ def configure_logging(debug=False):
else:
logging.getLogger('').setLevel(logging.WARN)
return
def configure_file_logging(logger_name, log_file, level=logging.DEBUG):
l = logging.getLogger(logger_name)
#formatter = logging.Formatter('%(asctime)s : %(message)s')
formatter = logging.Formatter('%(created)f - %(message)s')
fileHandler = logging.FileHandler(log_file, mode='a')
fileHandler.setFormatter(formatter)
streamHandler = logging.StreamHandler()
streamHandler.setFormatter(formatter)
l.setLevel(level)
l.addHandler(fileHandler)
# Add the following line if want to add console logging
#l.addHandler(streamHandler)
\ No newline at end of file
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