def run(): """ Top-level function for configuration controller """ config = get_config() scheduler = BackgroundScheduler() 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=db_engine) router = RequestRouter( sas_url=config.SAS_URL, rc_ingest_url=config.RC_INGEST_URL, cert_path=config.CC_CERT_PATH, ssl_key_path=config.CC_SSL_KEY_PATH, request_mapping=request_mapping, ssl_verify=config.SAS_CERT_PATH, ) fluentd_client = FluentdClient() for request_type in RequestTypes: req_type = request_type.value response_type = request_response[req_type] consumer = RequestDBConsumer( request_type=req_type, request_processing_limit=config.REQUEST_PROCESSING_LIMIT, ) processor = ResponseDBProcessor( response_type=response_type, process_responses_func=processor_strategies[req_type]["process_responses"], fluentd_client=fluentd_client, ) scheduler.add_job( process_requests, args=[consumer, processor, router, session_manager, fluentd_client], trigger=IntervalTrigger( seconds=config.REQUEST_PROCESSING_INTERVAL_SEC, ), max_instances=1, name=f"{req_type}_job", ) scheduler.start() while True: time.sleep(1)
import logging from json.decoder import JSONDecodeError from typing import Callable, List import requests from magma.configuration_controller.config import get_config from magma.configuration_controller.custom_types.custom_types import DBResponse from magma.db_service.models import DBGrantState, DBRequest from magma.db_service.session_manager import Session from magma.fluentd_client.client import FluentdClient, FluentdClientException from magma.fluentd_client.dp_logs import make_dp_log from magma.mappings.types import GrantStates logger = logging.getLogger(__name__) conf = get_config() class ResponseDBProcessor(object): """ Class responsible for processing Database requests """ def __init__( self, response_type: str, process_responses_func: Callable, fluentd_client: FluentdClient, ): self.response_type = response_type self.process_responses_func = process_responses_func