def heartbeat_timer(self): try: while True: self.cfg.heartbeatactive.wait() sleep(self.cfg.heartbeat_interval) self.heartbeat_event.set() self.heartbeat_event.clear() except Exception: log.critical("heartbeat_timer terminating due to exception", exc_info=True) raise
def _run(self): try: self.state = self.state_startup while True: self.state = self.state() except Exception: log.critical("PortAgent terminating due to exception", exc_info=True) raise finally: log.debug("Killing orbpkt src") try: self.orbpktsrc.kill() except: pass log.debug("Stopping dataserver") try: self.dataserver.stop() except: pass log.debug("Stopping cmdserver") try: self.cmdserver.stop() except: pass log.debug("PortAgent finally done")
def cmd_driver(self, msg): """ Process a command message against the driver. If the command exists as a driver attribute, call it passing supplied args and kwargs and returning the driver result. Special messages that are not forwarded to the driver are: 'stop_driver_process' - signal to close messaging and terminate. 'test_events' - populate event queue with test data. 'process_echo' - echos the message back. If the command is not found in the driver, an echo message is replied to the client. @param msg A driver command message. @retval The driver command result. """ cmd = msg.get('cmd', None) args = msg.get('args', None) kwargs = msg.get('kwargs', None) cmd_func = getattr(self.driver, cmd, None) log.debug("DriverProcess.cmd_driver(): cmd=%s, cmd_func=%s" % (cmd, cmd_func)) if cmd == 'stop_driver_process': self.stop_messaging() return 'stop_driver_process' elif cmd == 'test_events': events = kwargs['events'] self.events += events reply = 'test_events' elif cmd == 'process_echo': reply = 'ping from resource ppid:%s, resource:%s' % (str( self.ppid), str(self.driver)) #try: # msg = args[0] #except IndexError: # msg = 'no message to echo' # reply = 'process_echo: %s' % msg elif cmd_func: try: reply = cmd_func(*args, **kwargs) except Exception as e: reply = e # Command error events are better handled in the agent directly. #event = { # 'type' : DriverAsyncEvent.ERROR, # 'value' : str(e), # 'exception' : e, # 'time' : time.time() #} #self.send_event(event) if not isinstance(e, InstrumentException): trace = traceback.format_exc() log.critical("Python error, Trace follows: \n%s" % trace) else: reply = InstrumentCommandException('Unknown driver command.') # Command error events are better handled in the agent directly. #event = { # 'type' : DriverAsyncEvent.ERROR, # 'value' : str(reply), # 'exception' : reply, # 'time' : time.time() #} #self.send_event(event) return reply
def cmd_driver(self, msg): """ Process a command message against the driver. If the command exists as a driver attribute, call it passing supplied args and kwargs and returning the driver result. Special messages that are not forwarded to the driver are: 'stop_driver_process' - signal to close messaging and terminate. 'test_events' - populate event queue with test data. 'process_echo' - echos the message back. If the command is not found in the driver, an echo message is replied to the client. @param msg A driver command message. @retval The driver command result. """ cmd = msg.get('cmd', None) args = msg.get('args', None) kwargs = msg.get('kwargs', None) cmd_func = getattr(self.driver, cmd, None) log.debug("DriverProcess.cmd_driver(): cmd=%s, cmd_func=%s" %(cmd, cmd_func)) if cmd == 'stop_driver_process': self.stop_messaging() return'stop_driver_process' elif cmd == 'test_events': events = kwargs['events'] self.events += events reply = 'test_events' elif cmd == 'process_echo': reply = 'ping from resource ppid:%s, resource:%s' % (str(self.ppid), str(self.driver)) #try: # msg = args[0] #except IndexError: # msg = 'no message to echo' # reply = 'process_echo: %s' % msg elif cmd_func: try: reply = cmd_func(*args, **kwargs) except Exception as e: reply = e # Command error events are better handled in the agent directly. #event = { # 'type' : DriverAsyncEvent.ERROR, # 'value' : str(e), # 'exception' : e, # 'time' : time.time() #} #self.send_event(event) if not isinstance(e, InstrumentException): trace = traceback.format_exc() log.critical("Python error, Trace follows: \n%s" %trace) else: reply = InstrumentCommandException('Unknown driver command.') # Command error events are better handled in the agent directly. #event = { # 'type' : DriverAsyncEvent.ERROR, # 'value' : str(reply), # 'exception' : reply, # 'time' : time.time() #} #self.send_event(event) return reply