def main(): # Note: no logging must happen before this call. # Otherwise the log configuration will not apply. setup_logging() # [KN] The elements in the queue will appear if # 1. A callback is invoked from ha_link (this will happen in a motr # thread which must be free ASAP) # 2. A new HA notification has come form Consul via HTTP # [KN] The messages are consumed by Python thread created by # _run_qconsumer_thread function. # # [KN] Note: The server is launched in the main thread. q: Queue = Queue(maxsize=8) util: ConsulUtil = ConsulUtil() cfg: HL_Fids = _get_motr_fids(util) LOG.info('Welcome to HaX') LOG.info(f'Setting up ha_link interface with the options as follows: ' f'hax fid = {cfg.hax_fid}, hax endpoint = {cfg.hax_ep}, ' f'HA fid = {cfg.ha_fid}, RM fid = {cfg.rm_fid}') ffi = HaxFFI() herald = DeliveryHerald() motr = Motr(queue=q, rm_fid=cfg.rm_fid, ffi=ffi, herald=herald, consul_util=util) # Note that consumer thread must be started before we invoke motr.start(..) # Reason: hax process will send entrypoint request and somebody needs # to reply it. consumer = _run_qconsumer_thread(q, motr, herald, util) try: # [KN] We use just the first profile for Spiel API for now. motr.start(cfg.hax_ep, process=cfg.hax_fid, ha_service=cfg.ha_fid, rm_service=cfg.rm_fid, profile=cfg.profiles[0]) LOG.info('Motr API has been started') rconfc_starter = _run_rconfc_starter_thread(motr, consul_util=util) stats_updater = _run_stats_updater_thread(motr, consul_util=util) # [KN] This is a blocking call. It will work until the program is # terminated by signal run_server(q, herald, consul_util=util, threads_to_wait=[consumer, stats_updater, rconfc_starter]) except Exception: LOG.exception('Exiting due to an exception') finally: motr.close()
def main(): # Note: no logging must happen before this call. # Otherwise the log configuration will not apply. _setup_logging() # [KN] The elements in the queue will appear if # 1. A callback is invoked from ha_link (this will happen in a motr # thread which must be free ASAP) # 2. A new HA notification has come form Consul via HTTP # [KN] The messages are consumed by Python thread created by # _run_qconsumer_thread function. # # [KN] Note: The server is launched in the main thread. q = Queue(maxsize=8) util: ConsulUtil = ConsulUtil() cfg = _get_motr_fids(util) logging.info('Welcome to HaX') logging.info(f'Setting up ha_link interface with the options as follows: ' f'hax fid = {cfg.hax_fid}, hax endpoint = {cfg.hax_ep}, ' f'HA fid = {cfg.ha_fid}, RM fid = {cfg.rm_fid}') ffi = HaxFFI() herald = DeliveryHerald() motr = Motr(queue=q, rm_fid=cfg.rm_fid, ffi=ffi, herald=herald) consumer = _run_qconsumer_thread(q, motr) try: motr.start(cfg.hax_ep, process=cfg.hax_fid, ha_service=cfg.ha_fid, rm_service=cfg.rm_fid) logging.info('Motr API has been started') stats_updater = _run_stats_updater_thread(motr) # [KN] This is a blocking call. It will work until the program is # terminated by signal run_server(q, herald, threads_to_wait=[consumer, stats_updater]) except Exception: logging.exception('Exiting due to an exception') finally: motr.close()