...
 
Commits (3)
......@@ -8,13 +8,11 @@ if sys.version_info.major > 2:
else:
import __builtin__ as builtins
from . import db
from . import cli
from . import const
from .log import get_logger
DAEMON_OP_INIT = ('PAUSE', 'EXEC')
DAEMON_MODE_INIT = ('AUTO', 'MANAGED', 'MANUAL')
############################################################
PROG = 'guardian'
......@@ -98,11 +96,11 @@ parser.add_argument('-s', '--state', metavar='<state>', dest='dstate',
parser.add_argument('-r', '--request', metavar='<state>', dest='drequest',
help="set initial request state for daemon")
parser.add_argument('-o', '--op', metavar='<op>', dest='dop',
choices=DAEMON_OP_INIT, default='EXEC',
help="set initial daemon OP ({}|{})".format(*DAEMON_OP_INIT))
choices=db.DAEMON_OP, default='EXEC',
help="set initial daemon OP ({}|{})".format(*db.DAEMON_OP))
parser.add_argument('-m', '--mode', metavar='<mode>', dest='dmode',
choices=DAEMON_MODE_INIT, default='AUTO',
help="set initial daemon MODE ({}|{}|{})".format(*DAEMON_MODE_INIT))
choices=db.DAEMON_MODE,
help="set initial daemon MODE ({}|{}|{})".format(*db.DAEMON_MODE))
cgroup = parser.add_mutually_exclusive_group()
cgroup.add_argument('-i', '--interactive', action='store_true',
......@@ -142,8 +140,7 @@ def main():
if system.ifo:
ifo = system.ifo
name = system.name
from db import guarddb
for chan in sorted(guarddb):
for chan in sorted(db.guarddb):
channel = const.CAS_PREFIX_FMT.format(IFO=ifo, SYSTEM=name) + chan
flag = ''
if guarddb[chan].get('archive'):
......
......@@ -93,7 +93,7 @@ class CADriver(pcaspy.Driver):
elif channel == 'MODE':
# value as string
mode = guarddb['MODE']['enums'][value]
# reject attempts to set MANAGED mode directrly without
# reject attempts to set MANAGED mode directly without
# specifying manager
if mode == 'MANAGED':
return False
......
......@@ -17,16 +17,10 @@ except ImportError:
############################################################
# used by db, so need to be defined first
DAEMON_OP_INIT = ('PAUSE', 'EXEC',)
DAEMON_MODE_INIT = ('AUTO', 'MANAGED', 'MANUAL')
############################################################
from ._version import __version__
from . import const
from . import db
from .system import GuardSystemError
from .db import guarddb, Database
from .worker import Worker
############################################################
......@@ -40,17 +34,17 @@ class Daemon(object):
"""
def __init__(self, system, logger,
initial_op='EXEC',
initial_mode='AUTO',
initial_mode=None,
initial_state=None,
initial_request=None,
single_shot=False,
archive=None,
):
# check arguments
if initial_op not in DAEMON_OP_INIT:
raise GuardDaemonError("Initial OP not in %s" % str(DAEMON_OP_INIT))
if initial_mode not in DAEMON_MODE_INIT:
raise GuardDaemonError("Initial MODE not in %s" % str(DAEMON_MODE_INIT))
if initial_op not in db.DAEMON_OP:
raise GuardDaemonError("Initial OP not in %s" % str(DAEMON_OP))
if initial_mode and initial_mode not in db.DAEMON_MODE:
raise GuardDaemonError("Initial MODE ({}) not in {}".format(initial_mode, str(DAEMON_MODE)))
# FIXME: check that system is initialized already
self.system = system
......@@ -90,7 +84,7 @@ class Daemon(object):
self.archive = None
# initialize internal db
self.db = Database(self.cas)
self.db = db.Database(self.cas)
# initialize state index and request enum
self.db.update_system(self.system, init=True)
......@@ -98,7 +92,13 @@ class Daemon(object):
# set initial values
self['TIME_INIT'] = int(time.time())
self['OP'] = initial_op
self['MODE'] = initial_mode
if initial_mode is not None:
self['MODE'] = initial_mode
elif self.system.manager:
self['MANAGER'] = self.system.manager
self['MODE'] = 'MANAGED'
else:
self['MODE'] = 'AUTO'
self['LOGLEVEL'] = self.default_loglevel
self['STATE'] = initial_state or 'INIT'
self['TARGET'] = self['STATE']
......@@ -123,6 +123,8 @@ class Daemon(object):
self.log.info("initial request: %s" % self['REQUEST'])
if not self.single_shot:
self.log.info("nominal state: %s" % self['NOMINAL'])
if self.system.manager:
self.log.info("initial manager: %s" % self['MANAGER'])
self.log.info("CA setpoint monitor: %s" % self['SPM_MONITOR'])
self.log.info("CA setpoint monitor notify: %s" % self['SPM_MONITOR_NOTIFY'])
......@@ -167,7 +169,7 @@ guardian version: {}
def __setitem__(self, channel, value):
if self.db[channel] != value \
and guarddb[channel].get('log_changes', True):
and db.guarddb[channel].get('log_changes', True):
self.log.debug('%s => %s' % (channel, value))
self.db[channel] = value
......
......@@ -2,6 +2,8 @@ from . import version
from ._version import __version__
from . import const
DAEMON_OP = ('STOPE', 'PAUSE', 'EXEC')
DAEMON_MODE = ('AUTO', 'MANAGED', 'MANUAL')
DAEMON_STATUS = ('ENTER', 'MAIN', 'RUN', 'DONE', 'JUMP', 'REDIRECT', 'EDGE', 'INIT')
WORKER_STATUS = ('INIT', 'COMMAND', 'CONTINUE', 'DONE', 'JUMP', 'CERROR', 'ERROR')
......@@ -46,14 +48,14 @@ guarddb = {
# op mode
'OP': {
'type': 'enum',
'enums': ('STOP', 'PAUSE', 'EXEC'),
'enums': DAEMON_OP,
'writable': True,
'archive': True,
},
# run mode
'MODE': {
'type': 'enum',
'enums': ('AUTO', 'MANAGED', 'MANUAL'),
'enums': DAEMON_MODE,
'writable': True,
'archive': True,
},
......
......@@ -128,6 +128,7 @@ class GuardSystem(object):
# reset parameters loaded from module
self._initial_request = None
self._nominal_state = None
self._manager = None
self._node_managers = {}
# don't recorgnize ca_prefix changes on reset
self._ca_monitor = False
......@@ -477,6 +478,12 @@ class GuardSystem(object):
else:
self._nominal_state = None
# set manager
if hasattr(module, 'GRD_MANAGER'):
self._manager = module.GRD_MANAGER
else:
self._manager = None
# add specified edges
if hasattr(module, 'edges'):
# verify states
......@@ -584,7 +591,7 @@ class GuardSystem(object):
@property
def related_displays(self):
"""MEDM related displays.
"""User code specified MEDM related displays.
List of (label, name, args) string tuples.
"""
......@@ -592,14 +599,19 @@ class GuardSystem(object):
@property
def request(self):
"""Initial REQUEST state."""
"""User code specified REQUEST state."""
return self._initial_request
@property
def nominal(self):
"""Initial NOMINAL state."""
"""User code specified NOMINAL state."""
return self._nominal_state
@property
def manager(self):
"""User code specified MANAGER."""
return self._manager
@property
def graph(self):
"""System state graph object."""
......