Exemplo n.º 1
0
def _initialise_github_alerter_manager() -> GithubAlerterManager:
    manager_display_name = GITHUB_ALERTER_MANAGER_NAME

    github_alerter_manager_logger = _initialise_logger(
        manager_display_name, GithubAlerterManager.__name__,
        env.MANAGERS_LOG_FILE_TEMPLATE)

    # Attempt to initialise the system alerters manager
    while True:
        try:
            rabbitmq = RabbitMQApi(
                logger=github_alerter_manager_logger.getChild(
                    RabbitMQApi.__name__),
                host=env.RABBIT_IP)
            github_alerter_manager = GithubAlerterManager(
                github_alerter_manager_logger, manager_display_name, rabbitmq)
            break
        except Exception as e:
            log_and_print(
                get_initialisation_error_message(manager_display_name, e),
                github_alerter_manager_logger)
            log_and_print(get_reattempting_message(manager_display_name),
                          github_alerter_manager_logger)
            # sleep before trying again
            time.sleep(RE_INITIALISE_SLEEPING_PERIOD)

    return github_alerter_manager
Exemplo n.º 2
0
def _initialise_data_store_manager() -> StoreManager:
    manager_display_name = DATA_STORE_MANAGER_NAME

    data_store_manager_logger = _initialise_logger(
        manager_display_name, StoreManager.__name__,
        env.MANAGERS_LOG_FILE_TEMPLATE)

    # Attempt to initialise the data store manager
    while True:
        try:
            rabbitmq = RabbitMQApi(logger=data_store_manager_logger.getChild(
                RabbitMQApi.__name__),
                                   host=env.RABBIT_IP)
            data_store_manager = StoreManager(data_store_manager_logger,
                                              manager_display_name, rabbitmq)
            break
        except Exception as e:
            log_and_print(
                get_initialisation_error_message(manager_display_name, e),
                data_store_manager_logger)
            log_and_print(get_reattempting_message(manager_display_name),
                          data_store_manager_logger)
            # sleep before trying again
            time.sleep(RE_INITIALISE_SLEEPING_PERIOD)

    return data_store_manager
Exemplo n.º 3
0
def _initialise_logger(component_display_name: str, component_module_name: str,
                       log_file_template: str) -> logging.Logger:
    # Try initialising the logger until successful. This had to be done
    # separately to avoid instances when the logger creation failed and we
    # attempt to use it.
    while True:
        try:
            new_logger = create_logger(
                log_file_template.format(component_display_name),
                component_module_name,
                env.LOGGING_LEVEL,
                rotating=True)
            break
        except Exception as e:
            # Use a dummy logger in this case because we cannot create the
            # manager's logger.
            dummy_logger = logging.getLogger('DUMMY_LOGGER')
            log_and_print(
                get_initialisation_error_message(component_display_name, e),
                dummy_logger)
            log_and_print(get_reattempting_message(component_display_name),
                          dummy_logger)
            # sleep before trying again
            time.sleep(RE_INITIALISE_SLEEPING_PERIOD)

    return new_logger
Exemplo n.º 4
0
def _initialise_channels_manager() -> ChannelsManager:
    manager_display_name = CHANNELS_MANAGER_NAME

    channels_manager_logger = _initialise_logger(
        manager_display_name, ChannelsManager.__name__,
        env.MANAGERS_LOG_FILE_TEMPLATE)

    # Attempt to initialise the data transformers manager
    while True:
        try:
            rabbitmq = RabbitMQApi(logger=channels_manager_logger.getChild(
                RabbitMQApi.__name__),
                                   host=env.RABBIT_IP)
            channels_manager = ChannelsManager(channels_manager_logger,
                                               manager_display_name, rabbitmq)
            break
        except Exception as e:
            log_and_print(
                get_initialisation_error_message(manager_display_name, e),
                channels_manager_logger)
            log_and_print(get_reattempting_message(manager_display_name),
                          channels_manager_logger)
            # sleep before trying again
            time.sleep(RE_INITIALISE_SLEEPING_PERIOD)

    return channels_manager
Exemplo n.º 5
0
def _initialise_system_monitors_manager() -> SystemMonitorsManager:
    manager_display_name = SYSTEM_MONITORS_MANAGER_NAME

    system_monitors_manager_logger = _initialise_logger(
        manager_display_name, SystemMonitorsManager.__name__,
        env.MANAGERS_LOG_FILE_TEMPLATE)

    # Attempt to initialise the system monitors manager
    while True:
        try:
            rabbit_ip = env.RABBIT_IP
            rabbitmq = RabbitMQApi(
                logger=system_monitors_manager_logger.getChild(
                    RabbitMQApi.__name__),
                host=rabbit_ip)
            system_monitors_manager = SystemMonitorsManager(
                system_monitors_manager_logger, manager_display_name, rabbitmq)
            break
        except Exception as e:
            log_and_print(
                get_initialisation_error_message(manager_display_name, e),
                system_monitors_manager_logger)
            log_and_print(get_reattempting_message(manager_display_name),
                          system_monitors_manager_logger)
            # sleep before trying again
            time.sleep(RE_INITIALISE_SLEEPING_PERIOD)

    return system_monitors_manager
Exemplo n.º 6
0
def _initialise_alert_router() -> Tuple[AlertRouter, logging.Logger]:
    display_name = ALERT_ROUTER_NAME

    # Try initialising the logger until successful. This had to be done
    # separately to avoid instances when the logger creation failed and we
    # attempt to use it.
    while True:
        try:
            alert_router_logger = create_logger(env.ALERT_ROUTER_LOG_FILE,
                                                AlertRouter.__name__,
                                                env.LOGGING_LEVEL,
                                                rotating=True)
            break
        except Exception as e:
            # Use a dummy logger in this case because we cannot create the
            # manager's logger.
            dummy_logger = logging.getLogger('DUMMY_LOGGER')
            log_and_print(get_initialisation_error_message(display_name, e),
                          dummy_logger)
            log_and_print(get_reattempting_message(display_name), dummy_logger)
            # sleep before trying again
            time.sleep(RE_INITIALISE_SLEEPING_PERIOD)

    rabbit_ip = env.RABBIT_IP
    redis_ip = env.REDIS_IP
    redis_db = env.REDIS_DB
    redis_port = env.REDIS_PORT
    unique_alerter_identifier = env.UNIQUE_ALERTER_IDENTIFIER

    while True:
        try:
            alert_router = AlertRouter(display_name, alert_router_logger,
                                       rabbit_ip, redis_ip, redis_db,
                                       redis_port, unique_alerter_identifier,
                                       env.ENABLE_CONSOLE_ALERTS,
                                       env.ENABLE_LOG_ALERTS)
            return alert_router, alert_router_logger
        except Exception as e:
            log_and_print(get_initialisation_error_message(display_name, e),
                          alert_router_logger)
            log_and_print(get_reattempting_message(display_name),
                          alert_router_logger)
            # sleep before trying again
            time.sleep(RE_INITIALISE_SLEEPING_PERIOD)
Exemplo n.º 7
0
def _initialise_health_checker_manager() -> HealthCheckerManager:
    manager_display_name = HEALTH_CHECKER_MANAGER_NAME

    health_checker_manager_logger = _initialise_logger(
        manager_display_name, HealthCheckerManager.__name__,
        env.MANAGERS_LOG_FILE_TEMPLATE)

    # Attempt to initialise the health checker manager
    while True:
        try:
            health_checker_manager = HealthCheckerManager(
                health_checker_manager_logger, manager_display_name)
            break
        except Exception as e:
            msg = get_initialisation_error_message(manager_display_name, e)
            log_and_print(msg, health_checker_manager_logger)
            log_and_print(get_reattempting_message(manager_display_name),
                          health_checker_manager_logger)
            # sleep before trying again
            time.sleep(RE_INITIALISE_SLEEPING_PERIOD)

    return health_checker_manager
Exemplo n.º 8
0
def _initialise_config_manager() -> Tuple[ConfigsManager, logging.Logger]:
    display_name = CONFIGS_MANAGER_NAME
    config_manager_logger = _initialise_logger(display_name,
                                               ConfigsManager.__name__,
                                               env.CONFIG_MANAGER_LOG_FILE)

    rabbit_ip = env.RABBIT_IP
    while True:
        try:
            config_manager = ConfigsManager(display_name,
                                            config_manager_logger, '../config',
                                            rabbit_ip)
            return config_manager, config_manager_logger
        except Exception as e:
            # This is already logged, we need to try again. This exception
            # should not happen, but if it does the program can't fully start
            # up
            log_and_print(get_initialisation_error_message(display_name, e),
                          config_manager_logger)
            log_and_print(get_reattempting_message(display_name),
                          config_manager_logger)
            # sleep before trying again
            time.sleep(RE_INITIALISE_SLEEPING_PERIOD)