def init() -> None: if not os.environ.get(ENV_OPTIONS, None): raise ValueError('{} environment variable must be specified'.format(ENV_OPTIONS)) parser = argparse.ArgumentParser(description="Subscribe to changes in DSS-tracked Entity status") ResourceSet.add_arguments(parser) parser.add_argument('--base-url', help='Base URL at which this server may be reached externally') parser.add_argument('--monitor-rid', action='store_true', default=False, help='If specified, monitor ISA activity per the remote ID standard') parser.add_argument('--monitor-scd', action='store_true', default=False, help='If specified, monitor Operation and Constraint activity per the strategic deconfliction standard') args = parser.parse_args(shlex.split(os.environ[ENV_OPTIONS])) global resources resources = ResourceSet.from_arguments(args) config = vars(args) config['code_version'] = versioning.get_code_version() resources.logger.log_new('subscribe_start', config) try: _logger.info('Establishing Subscriptions from PID {} at {}...'.format(os.getpid(), datetime.datetime.utcnow())) _subscribe(resources, args.base_url, args.monitor_rid, args.monitor_scd) _logger.info('Subscriptions established.') except SubscriptionManagementError as e: msg = 'Failed to initialize: {}'.format(e) _logger.error(msg) sys.stderr.write(msg) sys.exit(-1) cleanup = { 'lock': threading.Lock(), 'complete': False, } def shutdown(signal_number, stack_frame) -> None: with cleanup['lock']: if cleanup['complete']: return _logger.info('Cleaning up Subscriptions from PID {} at {}...'.format(os.getpid(), datetime.datetime.utcnow())) _unsubscribe(resources, args.monitor_rid, args.monitor_scd) _logger.info('Subscription cleanup complete.') cleanup['complete'] = True resources.logger.log_new('subscribe_stop', { 'timestamp': datetime.datetime.utcnow(), 'signal_number': signal_number, }) atexit.register(shutdown, None, None) for sig in (signal.SIGABRT, signal.SIGINT, signal.SIGTERM): signal.signal(sig, shutdown) dt = (resources.end_time - datetime.datetime.utcnow()).total_seconds() def terminate_at_expiration(): time.sleep(dt) _logger.info('Terminating server at expiration of Subscription(s)') os.kill(os.getpid(), signal.SIGINT) threading.Thread(target=terminate_at_expiration, daemon=True).start()
def status(): return 'Ok {}'.format(versioning.get_code_version())
def status(): return 'Mock RID Display Provider ok {}'.format( versioning.get_code_version())
def status(): return 'Mock Host Service Provider ok {}'.format( versioning.get_code_version())
def main() -> int: args = parseArgs() # Required resources resources = ResourceSet.from_arguments(args) config = vars(args) config['code_version'] = versioning.get_code_version() resources.logger.log_new('poll_start', config) # Prepare pollers pollers: List[polling.Poller] = [] if args.rid_isa_poll_interval > 0: pollers.append( polling.Poller( name='poll_isas', object_diff_text=diff.isa_diff_text, interval=datetime.timedelta( seconds=args.rid_isa_poll_interval), poll=lambda: polling.poll_rid_isas(resources, resources.area))) if args.scd_operation_poll_interval > 0: pollers.append( polling.Poller( name='poll_ops', object_diff_text=diff.entity_diff_text, interval=datetime.timedelta( seconds=args.scd_operation_poll_interval), poll=lambda: polling.poll_scd_operations(resources))) if args.scd_constraint_poll_interval > 0: pollers.append( polling.Poller( name='poll_constraints', object_diff_text=diff.entity_diff_text, interval=datetime.timedelta( seconds=args.scd_constraint_poll_interval), poll=lambda: polling.poll_scd_constraints(resources))) if len(pollers) == 0: sys.stderr.write('Bad arguments: No data types had polling requests') return os.EX_USAGE # Execute the polling loop abort = False need_line_break = False while not abort: try: most_urgent_dt = datetime.timedelta(days=999999999) most_urgent_poller = None for poller in pollers: dt = poller.time_to_next_poll() if dt < most_urgent_dt: most_urgent_poller = poller most_urgent_dt = dt if most_urgent_dt.total_seconds() > 0: time.sleep(most_urgent_dt.total_seconds()) t0 = datetime.datetime.utcnow() result = most_urgent_poller.poll() t1 = datetime.datetime.utcnow() if result.has_different_content_than( most_urgent_poller.last_result): resources.logger.log_new(most_urgent_poller.name, result) if need_line_break: print() print(most_urgent_poller.diff_text(result)) need_line_break = False most_urgent_poller.last_result = result else: resources.logger.log_same(t0, t1, most_urgent_poller.name) print_no_newline('.') need_line_break = True except KeyboardInterrupt: abort = True resources.logger.log_new( 'poll_stop', { 'timestamp': datetime.datetime.utcnow().isoformat(), }) return os.EX_OK
def status(): return 'Mock USS ok {}; hosting {}'.format(versioning.get_code_version(), ', '.join(enabled_services))