def run(): """ Top-level function for radio controller """ logger.info("Starting grpc server") config = get_config() scheduler = BackgroundScheduler() metricsd_client = get_metricsd_client() scheduler.add_job( process_metrics, args=[metricsd_client, config.SERVICE_HOSTNAME, "radio_controller"], trigger=IntervalTrigger( seconds=config.METRICS_PROCESSING_INTERVAL_SEC, ), max_instances=1, name="metrics_processing_job", ) scheduler.start() logger.info(f"grpc port is: {config.GRPC_PORT}") db_engine = create_engine( url=config.SQLALCHEMY_DB_URI, encoding=config.SQLALCHEMY_DB_ENCODING, echo=config.SQLALCHEMY_ECHO, future=config.SQLALCHEMY_FUTURE, pool_size=config.SQLALCHEMY_ENGINE_POOL_SIZE, max_overflow=config.SQLALCHEMY_ENGINE_MAX_OVERFLOW, ) session_manager = SessionManager(db_engine) server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) add_RadioControllerServicer_to_server( RadioControllerService(session_manager=session_manager), server, ) add_ActiveModeControllerServicer_to_server( ActiveModeControllerService(session_manager=session_manager), server, ) add_DPServiceServicer_to_server( DPService( session_manager=session_manager, now_func=datetime.now, fluentd_client=FluentdClient(), ), server, ) server.add_insecure_port(f"[::]:{config.GRPC_PORT}") server.start() logger.info(f"GRPC Server started on port {config.GRPC_PORT}") def handle_sigterm(*_): logger.info("Received shutdown signal") all_rpcs_done_event = server.stop(30) all_rpcs_done_event.wait(30) logger.info("Shut down gracefully") signal(SIGTERM, handle_sigterm) server.wait_for_termination()
def run(): """ Top-level function for radio controller """ logger.info("Starting grpc server") config = get_config() logger.info(f"grpc port is: {config.GRPC_PORT}") db_engine = create_engine( url=config.SQLALCHEMY_DB_URI, encoding=config.SQLALCHEMY_DB_ENCODING, echo=config.SQLALCHEMY_ECHO, future=config.SQLALCHEMY_FUTURE, pool_size=config.SQLALCHEMY_ENGINE_POOL_SIZE, max_overflow=config.SQLALCHEMY_ENGINE_MAX_OVERFLOW, ) session_manager = SessionManager(db_engine) server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) add_RadioControllerServicer_to_server( RadioControllerService(session_manager=session_manager), server, ) add_ActiveModeControllerServicer_to_server( ActiveModeControllerService(session_manager=session_manager), server, ) add_DPServiceServicer_to_server( DPService( session_manager=session_manager, now_func=datetime.now, fluentd_client=FluentdClient(), ), server, ) server.add_insecure_port(f"[::]:{config.GRPC_PORT}") server.start() logger.info(f"GRPC Server started on port {config.GRPC_PORT}") def handle_sigterm(*_): logger.info("Received shutdown signal") all_rpcs_done_event = server.stop(30) all_rpcs_done_event.wait(30) logger.info("Shut down gracefully") signal(SIGTERM, handle_sigterm) server.wait_for_termination()
DBGrant, DBGrantState, DBRequest, DBRequestType, ) from magma.db_service.session_manager import Session, SessionManager from magma.fluentd_client.client import FluentdClient, FluentdClientException from magma.fluentd_client.dp_logs import make_dp_log from magma.mappings.types import CbsdStates, GrantStates, RequestTypes from magma.radio_controller.config import get_config from magma.radio_controller.metrics import GET_CBSD_STATE_PROCESSING_TIME from sqlalchemy.sql.functions import now logger = logging.getLogger(__name__) config = get_config() class DPService(DPServiceServicer): """ DP gRPC service class """ def __init__( self, session_manager: SessionManager, now_func: Callable[..., datetime], fluentd_client: FluentdClient, ): self.session_manager = session_manager self.now = now_func self.fluentd_client = fluentd_client