work in progress: agent application with commandline controllers
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2496 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
8f99753b1c
commit
771cf29cc2
7 changed files with 60 additions and 25 deletions
|
@ -106,7 +106,7 @@ the path to the configuration file.
|
||||||
>>> configFile.close()
|
>>> configFile.close()
|
||||||
|
|
||||||
>>> master.config
|
>>> master.config
|
||||||
controller.name = 'base.sample'
|
controller.names = ['base.sample']
|
||||||
logger.name = 'default'
|
logger.name = 'default'
|
||||||
logger.standard = 30
|
logger.standard = 30
|
||||||
scheduler.name = 'sample'
|
scheduler.name = 'sample'
|
||||||
|
@ -197,7 +197,7 @@ the core package so that now everything is running under the control of
|
||||||
the twisted reactor.
|
the twisted reactor.
|
||||||
|
|
||||||
>>> config = '''
|
>>> config = '''
|
||||||
... controller(name='core.sample')
|
... controller(names=['core.sample'])
|
||||||
... scheduler(name='core')
|
... scheduler(name='core')
|
||||||
... logger(name='default', standard=30)
|
... logger(name='default', standard=30)
|
||||||
... '''
|
... '''
|
||||||
|
|
10
agent/agent.cfg
Normal file
10
agent/agent.cfg
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#
|
||||||
|
# Standard configuration for agent application
|
||||||
|
#
|
||||||
|
# $Id$
|
||||||
|
#
|
||||||
|
|
||||||
|
controller(names=['cmdline', 'telnet'])
|
||||||
|
controller.telnet.port = 5001
|
||||||
|
scheduler(name='core')
|
||||||
|
logger(name='default', standard=30)
|
33
agent/app.py
33
agent/app.py
|
@ -23,21 +23,32 @@ Agent application.
|
||||||
$Id$
|
$Id$
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
|
|
||||||
from cybertools.agent.base.agent import Master
|
from cybertools.agent.base.agent import Master
|
||||||
|
|
||||||
config = '''
|
|
||||||
controller(name='telnet')
|
|
||||||
scheduler(name='core')
|
|
||||||
logger(name='default', standard=30)
|
|
||||||
'''
|
|
||||||
|
|
||||||
master = Master(config)
|
def getConfig():
|
||||||
master.setup()
|
agentHome = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
configName = 'agent.cfg'
|
||||||
|
configFile = open(os.path.join(agentHome, configName))
|
||||||
|
config = configFile.read()
|
||||||
|
configFile.close()
|
||||||
|
return config
|
||||||
|
|
||||||
print 'Starting agent application...'
|
|
||||||
print 'Using controller %s.' % master.config.controller.name
|
|
||||||
|
|
||||||
reactor.run()
|
def start():
|
||||||
|
master = Master(getConfig())
|
||||||
|
master.setup()
|
||||||
|
|
||||||
print 'Agent application has been stopped.'
|
print 'Starting agent application...'
|
||||||
|
print 'Using controllers %s.' % ', '.join(master.config.controller.names)
|
||||||
|
|
||||||
|
reactor.run()
|
||||||
|
|
||||||
|
print 'Agent application has been stopped.'
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
start()
|
||||||
|
|
|
@ -61,16 +61,19 @@ class Master(Agent):
|
||||||
name = 'master'
|
name = 'master'
|
||||||
scheduler = None
|
scheduler = None
|
||||||
|
|
||||||
def __init__(self, configuration=None):
|
def __init__(self, configuration):
|
||||||
config = self.config = Configurator()
|
if isinstance(configuration, Configurator):
|
||||||
|
config = configuration
|
||||||
|
else: # configuration is path to config file
|
||||||
|
config = self.config = Configurator()
|
||||||
|
config.load(configuration)
|
||||||
self.master = self
|
self.master = self
|
||||||
self.controllers = []
|
self.controllers = []
|
||||||
self.children = {}
|
self.children = {}
|
||||||
if configuration is not None:
|
self.logger = loggers(self, name=config.logger.name)
|
||||||
config.load(configuration)
|
for n in config.controller.names:
|
||||||
self.logger = loggers(self, name=config.logger.name)
|
self.controllers.append(controllers(self, n))
|
||||||
self.controllers.append(controllers(self, name=config.controller.name))
|
self.scheduler = schedulers(self, name=config.scheduler.name)
|
||||||
self.scheduler = schedulers(self, name=config.scheduler.name)
|
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
for cont in self.controllers:
|
for cont in self.controllers:
|
||||||
|
|
|
@ -4,6 +4,6 @@
|
||||||
# $Id$
|
# $Id$
|
||||||
#
|
#
|
||||||
|
|
||||||
controller(name='base.sample')
|
controller(names=['base.sample'])
|
||||||
scheduler(name='sample')
|
scheduler(name='sample')
|
||||||
logger(name='default', standard=30)
|
logger(name='default', standard=30)
|
||||||
|
|
|
@ -35,7 +35,9 @@ class CmdlineController(SampleController):
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
super(CmdlineController, self).setup()
|
super(CmdlineController, self).setup()
|
||||||
stdio.StandardIO(CmdlineProtocol())
|
prot = CmdlineProtocol()
|
||||||
|
prot.controller = self
|
||||||
|
stdio.StandardIO(prot)
|
||||||
|
|
||||||
controllers.register(CmdlineController, Master, name='cmdline')
|
controllers.register(CmdlineController, Master, name='cmdline')
|
||||||
|
|
||||||
|
@ -46,7 +48,8 @@ class TelnetController(CmdlineController):
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
super(CmdlineController, self).setup()
|
super(CmdlineController, self).setup()
|
||||||
reactor.listenTCP(5001, TelnetServerFactory())
|
port = self.agent.config.controller.telnet.port
|
||||||
|
reactor.listenTCP(port, TelnetServerFactory(self))
|
||||||
|
|
||||||
controllers.register(TelnetController, Master, name='telnet')
|
controllers.register(TelnetController, Master, name='telnet')
|
||||||
|
|
||||||
|
@ -54,6 +57,7 @@ controllers.register(TelnetController, Master, name='telnet')
|
||||||
class CmdlineProtocol(basic.LineReceiver):
|
class CmdlineProtocol(basic.LineReceiver):
|
||||||
|
|
||||||
delimiter = '\n'
|
delimiter = '\n'
|
||||||
|
controller = None
|
||||||
|
|
||||||
def connectionMade(self):
|
def connectionMade(self):
|
||||||
self.sendLine("Agent console. Type 'help' for help.")
|
self.sendLine("Agent console. Type 'help' for help.")
|
||||||
|
@ -97,4 +101,11 @@ class TelnetProtocol(CmdlineProtocol):
|
||||||
|
|
||||||
class TelnetServerFactory(protocol.ServerFactory):
|
class TelnetServerFactory(protocol.ServerFactory):
|
||||||
|
|
||||||
protocol = TelnetProtocol
|
def __init__(self, controller):
|
||||||
|
self.controller = controller
|
||||||
|
|
||||||
|
def protocol(self, *args, **kw):
|
||||||
|
prot = TelnetProtocol(*args, **kw)
|
||||||
|
prot.controller = self.controller
|
||||||
|
return prot
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ Agents for Job Execution and Communication Tasks
|
||||||
>>> from cybertools.agent.base.agent import Master
|
>>> from cybertools.agent.base.agent import Master
|
||||||
|
|
||||||
>>> config = '''
|
>>> config = '''
|
||||||
... controller(name='core.sample')
|
... controller(names=['core.sample'])
|
||||||
... scheduler(name='core')
|
... scheduler(name='core')
|
||||||
... logger(name='default', standard=30)
|
... logger(name='default', standard=30)
|
||||||
... '''
|
... '''
|
||||||
|
|
Loading…
Add table
Reference in a new issue