class WatchDog: def __init__(self): jdir = cfg.journal.dir self.__impl = Impl(journal=Journal(jdir)) @remote def track(self, sn, replyto, any, timeout): return self.__impl.track(sn, replyto, any, timeout) @remote def hack(self, sn): return self.__impl.hack(sn) @remote @action(seconds=1) def process(self): self.__impl.process()
def __start(cls, url): cls.watchdog = WatchDog(url=url) cls.watchdog.start() cls.reply = ReplyManager(url) cls.reply.start(cls.watchdog) cls.heartbeat = HeartbeatManager(url) cls.heartbeat.start() cls.notify = NotifyManager() cls.notify.start()
def start(cls): url = config.get('messaging', 'url') log.info('Using URL: %s', url) # broker configuration broker = Broker(url) broker.cacert = config.get('messaging', 'cacert') broker.clientcert = config.get('messaging', 'clientcert') log.info('AMQP broker configured') # watchdog journal = Journal('/var/lib/pulp/journal/watchdog') cls.watchdog = WatchDog(url=url, journal=journal) cls.watchdog.start() log.info('AMQP watchdog started') # heartbeat cls.heartbeat_listener = HeartbeatListener(url) cls.heartbeat_listener.start() log.info('AMQP heartbeat listener started') # asynchronous reply cls.reply_handler = ReplyHandler(url) cls.reply_handler.start(cls.watchdog) log.info('AMQP reply handler started')
def testBasic(self): global ELAPSED # setup timeout = (5,30) watchdog = WatchDog(journal=Journal(self.jdir)) # tracking watchdog.track(SN, REPLYTO, ANY, timeout) path = os.path.join(self.jdir, '%s.jnl' % SN) self.assertTrue(os.path.exists(path)) envelope = json.load(open(path)) self.assertEquals(envelope['sn'], SN) self.assertEquals(envelope['idx'], 0) self.assertEquals(envelope['ts'][0], NOW+timeout[0]) self.assertEquals(envelope['ts'][1], NOW+timeout[1]) self.assertEquals(envelope['ts'][envelope['idx']], NOW+timeout[0]) self.assertEquals(envelope['replyto'], REPLYTO) self.assertEquals(envelope['any'], ANY) # started watchdog.started(SN) envelope = json.load(open(path)) self.assertEquals(envelope['sn'], SN) self.assertEquals(envelope['idx'], 1) self.assertEquals(envelope['ts'][0], NOW+timeout[0]) self.assertEquals(envelope['ts'][1], NOW+timeout[1]) self.assertEquals(envelope['ts'][envelope['idx']], NOW+timeout[1]) self.assertEquals(envelope['replyto'], REPLYTO) self.assertEquals(envelope['any'], ANY) # progress watchdog.progress(SN) envelope = json.load(open(path)) self.assertEquals(envelope['sn'], SN) self.assertEquals(envelope['idx'], 1) self.assertEquals(envelope['ts'][0], NOW+timeout[0]) self.assertEquals(envelope['ts'][1], NOW+timeout[1]) self.assertEquals(envelope['ts'][envelope['idx']], NOW+timeout[1]) self.assertEquals(envelope['replyto'], REPLYTO) self.assertEquals(envelope['any'], ANY) # progress (with 5 of timeout) ELAPSED = 28 watchdog.progress(SN) envelope = json.load(open(path)) self.assertEquals(envelope['sn'], SN) self.assertEquals(envelope['idx'], 1) self.assertEquals(envelope['ts'][0], NOW+timeout[0]) self.assertEquals(envelope['ts'][1], now()+5) self.assertEquals(envelope['ts'][envelope['idx']], now()+5) # completed watchdog.completed(SN) path = os.path.join(self.jdir, '%s.jnl' % SN) self.assertFalse(os.path.exists(path))
def __init__(self): jdir = cfg.journal.dir self.__impl = Impl(journal=Journal(jdir))
from gofer.rmi.async import ReplyConsumer, WatchDog, Journal from gofer.metrics import Timer from gofer.proxy import Agent from datetime import datetime as dt from datetime import timedelta as delta from logging import INFO, basicConfig, getLogger from threading import Thread from plugins import * basicConfig(filename="/opt/gofer/server.log", level=INFO) log = getLogger(__name__) # asynchronous RMI timeout watchdog jdir = "/opt/gofer/journal/watchdog" watchdog = WatchDog(journal=Journal(jdir)) watchdog.start() # watchdog = Agent('xyz').WatchDog() def onReply(reply): print "REPLY [%s]\n%s" % (dt.now(), reply) def isAsync(agent): options = agent._Container__options return options.async or options.ctag def demo(agent):