def __init__(self, name, empty_mconfig, loop=None): self._name = name self._port = 0 self._get_status_callback = None self._get_operational_states_cb = None self._log_count_handler = MsgCounterHandler() # Init logging before doing anything logging.basicConfig( level=logging.INFO, format='[%(asctime)s %(levelname)s %(name)s] %(message)s') # Add a handler to count errors logging.root.addHandler(self._log_count_handler) # Set gRPC polling strategy self._set_grpc_poll_strategy() # Load the managed config if present self._mconfig = empty_mconfig self._mconfig_metadata = None self._mconfig_manager = get_mconfig_manager() self.reload_mconfig() self._state = ServiceInfo.STARTING self._health = ServiceInfo.APP_UNHEALTHY if loop is None: loop = asyncio.get_event_loop() self._loop = loop self._start_time = int(time.time()) self._register_signal_handlers() # Load the service config if present self._config = None self.reload_config() # Count errors self.log_counter = ServiceLogErrorReporter( loop=self._loop, service_config=self._config, handler=self._log_count_handler, ) self.log_counter.start() # Operational States self._operational_states = [] self._version = '0.0.0' # Load the service version if available try: self._version = pkg_resources.get_distribution('orc8r').version except pkg_resources.ResolutionError as e: logging.info(e) self._server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) add_Service303Servicer_to_server(self, self._server)
def __init__(self, name, loop=None): self._name = name self._port = 0 self._get_status_callback = None self._reload_config_callback = None # Init logging before doing anything logging.basicConfig( level=logging.INFO, format='[%(asctime)s %(levelname)s %(name)s] %(message)s') # Set gRPC polling strategy self._set_grpc_poll_strategy() # Load the managed config if present self._mconfig = None self._mconfig_manager = get_mconfig_manager() self.reload_mconfig() self._state = ServiceInfo.STARTING self._health = ServiceInfo.APP_UNHEALTHY if loop is None: loop = asyncio.get_event_loop() self._loop = loop self._start_time = int(time.time()) self._register_signal_handlers() # Load the service config if present self._config = None try: self._config = load_service_config(name) except LoadConfigError as e: logging.warning(e) self._setup_logging() self._version = '0.0.0' # Load the service version if available try: self._version = pkg_resources.get_distribution('orc8r').version except pkg_resources.ResolutionError as e: logging.info(e) self._server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) add_Service303Servicer_to_server(self, self._server)
def __init__(self, name, empty_mconfig, loop=None): self._name = name self._port = 0 self._get_status_callback = None self._get_operational_states_cb = None self._log_count_handler = MsgCounterHandler() # Init logging before doing anything logging.basicConfig( level=logging.INFO, format='[%(asctime)s %(levelname)s %(name)s] %(message)s') # Add a handler to count errors logging.root.addHandler(self._log_count_handler) # Set gRPC polling strategy self._set_grpc_poll_strategy() # Load the managed config if present self._mconfig = empty_mconfig self._mconfig_metadata = None self._mconfig_manager = get_mconfig_manager() self.reload_mconfig() self._state = ServiceInfo.STARTING self._health = ServiceInfo.APP_UNHEALTHY if loop is None: loop = asyncio.get_event_loop() self._loop = loop self._start_time = int(time.time()) self._register_signal_handlers() # Load the service config if present self._config = None self.reload_config() # Count errors self.log_counter = ServiceLogErrorReporter( loop=self._loop, service_config=self._config, handler=self._log_count_handler, ) self.log_counter.start() # Operational States self._operational_states = [] self._version = '0.0.0' # Load the service version if available try: # Check if service on docker if self._config and 'init_system' in self._config \ and self._config['init_system'] == 'docker': # image comes in form of "feg_gateway_python:<IMAGE_TAG>\n" # Skip the "feg_gateway_python:" part image = os.popen( 'docker ps --filter name=magmad --format "{{.Image}}" | ' 'cut -d ":" -f 2') image_tag = image.read().strip('\n') self._version = image_tag else: self._version = pkg_resources.get_distribution('orc8r').version except pkg_resources.ResolutionError as e: logging.info(e) self._server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) add_Service303Servicer_to_server(self, self._server)