def shutdown(signum = None, frame = None): with stopLock: global stopped if stopped: return else: stopped = True logging.getLogger().info("Shutting down probe") Scheduler.quit() if Params.COMMANDER and commander is not None: commander.quit() from calls.actions import Quit if Params.WATCHERS: WatcherManager.stopWatchers() from managers.probetests import TestManager, TestResponder TestManager.stopTests() TestResponder.stopTests() if actionMan is not None: ActionMan.addTask(Quit()) if server is not None: server.quit() if actionMan is not None: actionMan.quit() #everybody might need the client so stop it last if client is not None: client.quit()
def shutdown(signum=None, frame=None): with stopLock: global stopped if stopped: return else: stopped = True logging.getLogger().info("Shutting down probe") Scheduler.quit() if Params.COMMANDER and commander is not None: commander.quit() from calls.actions import Quit if Params.WATCHERS: WatcherManager.stopWatchers() from managers.probetests import TestManager, TestResponder TestManager.stopTests() TestResponder.stopTests() if actionMan is not None: ActionMan.addTask(Quit()) if server is not None: server.quit() if actionMan is not None: actionMan.quit() #everybody might need the client so stop it last if client is not None: client.quit()
def treatTestMessage(cls, message): """Treats a test message which can be Testee or Tester kind Testee are given to TesteeManager Tester are given to testResponder :param message: testMessage to treat """ cls.logger.ddebug("Handling Tester or Testee message") assert isinstance(message, TestMessage) # if probe is in test mode, give the message right to the TestManager! if isinstance(message, TesteeAnswer): cls.logger.ddebug("Handling TesteeAnswer") TestManager.handleMessage(message) elif isinstance(message, TesterMessage): cls.logger.ddebug("Handling TesterMessage") TestResponder.handleMessage(message) elif isinstance(message, TestMessage): #Prepare are test messages ActionMan.addTask(MTA.toAction(message))
def treatMessage(cls, message): """Handles the receptions of a Message (called by the listener) For regular Actions, addTask is called after translation of the message For TesterMessages and TesteeMessages, treatTestMessage is called :param message: The Message instance to treat """ cls.logger.debug("Treating message %s", message.__class__.__name__) assert isinstance(message, Message) # forwarding mechanism if message.targetId != Identification.PROBE_ID: if ProbeStorage.isKnownId(message.targetId): message.recipientId = message.targetId else: #if we already forwarded it before , stop here if message.hash in cls.forwardedMessages: cls.logger.warning( "Throwing message %s in forward because message was previously forwarded.", message.__class__.__name__) return Scheduler.forward() message.recipientId = ProbeStorage.getOtherRandomId() cls.logger.info("Forwarding message %s for %s to id %s", message.__class__.__name__, message.targetId, message.recipientId) cls.forwardedMessages.append(message.hash) Client.send(message) return # handle special class of messages separately if isinstance(message, TestMessage): cls.treatTestMessage(message) elif isinstance(message, WatcherMessage): cls.treatWatcherMessage(message) elif isinstance(message, BroadCast): # broadcast = do required action first and continue broadcast cls.logger.ddebug("Handling Broadcast") try: ActionMan.addTask(MTA.toAction(message.getMessage())) except ActionError: pass # be sure to propagate broadcast if a reasonable error occurs ActionMan.addTask(MTA.toAction(message)) # Client.broadcast(message) else: # handles everything else, including Do messages ActionMan.addTask(MTA.toAction(message))
def treatMessage(cls, message): """Handles the receptions of a Message (called by the listener) For regular Actions, addTask is called after translation of the message For TesterMessages and TesteeMessages, treatTestMessage is called :param message: The Message instance to treat """ cls.logger.debug("Treating message %s", message.__class__.__name__) assert isinstance(message, Message) # forwarding mechanism if message.targetId != Identification.PROBE_ID: if ProbeStorage.isKnownId(message.targetId): message.recipientId = message.targetId else: #if we already forwarded it before , stop here if message.hash in cls.forwardedMessages: cls.logger.warning("Throwing message %s in forward because message was previously forwarded.", message.__class__.__name__) return Scheduler.forward() message.recipientId = ProbeStorage.getOtherRandomId() cls.logger.info("Forwarding message %s for %s to id %s", message.__class__.__name__, message.targetId, message.recipientId) cls.forwardedMessages.append(message.hash) Client.send(message) return # handle special class of messages separately if isinstance(message, TestMessage): cls.treatTestMessage(message) elif isinstance(message, WatcherMessage): cls.treatWatcherMessage(message) elif isinstance(message, BroadCast): # broadcast = do required action first and continue broadcast cls.logger.ddebug("Handling Broadcast") try: ActionMan.addTask(MTA.toAction(message.getMessage())) except ActionError: pass # be sure to propagate broadcast if a reasonable error occurs ActionMan.addTask(MTA.toAction(message)) # Client.broadcast(message) else: # handles everything else, including Do messages ActionMan.addTask(MTA.toAction(message))
cParams.CODEC = cserialize addLogs() server = None actionMan = None client = None commander = None catchSignals() try: time.sleep(args.wait) logging.getLogger().info("Starting probe with id : %s, pid : %s", Identification.PROBE_ID, os.getpid()) server = Server() server.start() server.isUp.wait() actionMan = ActionMan() actionMan.start() if Params.COMMANDER: commander = CommanderServer() commander.start() if Params.WATCHERS: wd = os.path.join(DATA_DIR, WATCHERS_OUTPUT_DIR) if not os.path.exists(wd): os.mkdir(wd) WatcherManager.setOutputDir(wd) for watcher in args.watchers: parts = watcher.partition('=') try: WatcherManager.registerWatcher(parts[0], parts[2], wlogger)
addLogs() server = None actionMan = None client = None commander = None catchSignals() try: time.sleep(args.wait) logging.getLogger().info("Starting probe with id : %s, pid : %s", Identification.PROBE_ID, os.getpid()) server = Server() server.start() server.isUp.wait() actionMan = ActionMan() actionMan.start() if Params.COMMANDER: commander = CommanderServer() commander.start() if Params.WATCHERS: wd = os.path.join(DATA_DIR, WATCHERS_OUTPUT_DIR) if not os.path.exists(wd): os.mkdir(wd) WatcherManager.setOutputDir(wd) for watcher in args.watchers: parts = watcher.partition('=') try: WatcherManager.registerWatcher(parts[0], parts[2], wlogger)
def getStatus(self): """Return current probe status""" return ActionMan.getStatus()