diff --git a/src/centralizedattackdetector/service/__main__.py b/src/centralizedattackdetector/service/__main__.py index da571acb4173fd376f0e5bdd716e587814caf525..5737402c0318fa58123c5fdf00296c237f09aeb8 100644 --- a/src/centralizedattackdetector/service/__main__.py +++ b/src/centralizedattackdetector/service/__main__.py @@ -1,51 +1,49 @@ -import logging, os, signal, sys, threading +import logging, signal, sys, threading from prometheus_client import start_http_server -from common.database.Factory import get_database +from common.Settings import get_setting +from centralizedattackdetector.Config import ( + GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD, LOG_LEVEL, METRICS_PORT) from centralizedattackdetector.service.CentralizedAttackDetectorService import CentralizedAttackDetectorService -from centralizedattackdetector.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD, LOG_LEVEL, METRICS_PORT terminate = threading.Event() -logger = None +LOGGER = None -def signal_handler(signal, frame): - global terminate, logger - logger.warning('Terminate signal received') +def signal_handler(signal, frame): # pylint: disable=redefined-outer-name + LOGGER.warning('Terminate signal received') terminate.set() def main(): - global terminate, logger + global LOGGER # pylint: disable=global-statement - service_port = os.environ.get('CENTRALIZEDATTACKDETECTORSERVICE_SERVICE_PORT_GRPC', GRPC_SERVICE_PORT) - max_workers = os.environ.get('MAX_WORKERS', GRPC_MAX_WORKERS ) - grace_period = os.environ.get('GRACE_PERIOD', GRPC_GRACE_PERIOD) - log_level = os.environ.get('LOG_LEVEL', LOG_LEVEL ) - metrics_port = os.environ.get('METRICS_PORT', METRICS_PORT ) + service_port = get_setting('CENTRALIZEDATTACKDETECTORSERVICE_SERVICE_PORT_GRPC', default=GRPC_SERVICE_PORT) + max_workers = get_setting('MAX_WORKERS', default=GRPC_MAX_WORKERS ) + grace_period = get_setting('GRACE_PERIOD', default=GRPC_GRACE_PERIOD) + log_level = get_setting('LOG_LEVEL', default=LOG_LEVEL ) + metrics_port = get_setting('METRICS_PORT', default=METRICS_PORT ) logging.basicConfig(level=log_level) - logger = logging.getLogger(__name__) + LOGGER = logging.getLogger(__name__) signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) - logger.info('Starting...') + LOGGER.info('Starting...') # Start metrics server start_http_server(metrics_port) - # Get database instance - database = get_database() - # Starting CentralizedCybersecurity service - grpc_service = CentralizedAttackDetectorService(database, port=service_port, max_workers=max_workers, grace_period=grace_period) + grpc_service = CentralizedAttackDetectorService( + port=service_port, max_workers=max_workers, grace_period=grace_period) grpc_service.start() # Wait for Ctrl+C or termination signal while not terminate.wait(timeout=0.1): pass - logger.info('Terminating...') + LOGGER.info('Terminating...') grpc_service.stop() - logger.info('Bye') + LOGGER.info('Bye') return 0 if __name__ == '__main__': diff --git a/src/compute/service/__main__.py b/src/compute/service/__main__.py index ec6902175fed23a2272d12e9d42cef05f1371e53..f45af374c471222bb4fdb089860418c5895d6321 100644 --- a/src/compute/service/__main__.py +++ b/src/compute/service/__main__.py @@ -1,22 +1,22 @@ import logging, signal, sys, threading from prometheus_client import start_http_server from common.Settings import get_setting -from compute.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD, LOG_LEVEL, RESTAPI_SERVICE_PORT, \ - RESTAPI_BASE_URL, METRICS_PORT +from compute.Config import ( + GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD, LOG_LEVEL, RESTAPI_SERVICE_PORT, RESTAPI_BASE_URL, + METRICS_PORT) from compute.service.ComputeService import ComputeService from compute.service.rest_server.Server import Server from compute.service.rest_server.resources.Compute import Compute terminate = threading.Event() -logger = None +LOGGER = None -def signal_handler(signal, frame): - global terminate, logger - logger.warning('Terminate signal received') +def signal_handler(signal, frame): # pylint: disable=redefined-outer-name + LOGGER.warning('Terminate signal received') terminate.set() def main(): - global terminate, logger + global LOGGER # pylint: disable=global-statement grpc_service_port = get_setting('COMPUTESERVICE_SERVICE_PORT_GRPC', default=GRPC_SERVICE_PORT ) max_workers = get_setting('MAX_WORKERS', default=GRPC_MAX_WORKERS ) @@ -27,12 +27,12 @@ def main(): metrics_port = get_setting('METRICS_PORT', default=METRICS_PORT ) logging.basicConfig(level=log_level) - logger = logging.getLogger(__name__) + LOGGER = logging.getLogger(__name__) signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) - logger.info('Starting...') + LOGGER.info('Starting...') # Start metrics server start_http_server(metrics_port) @@ -49,12 +49,12 @@ def main(): # Wait for Ctrl+C or termination signal while not terminate.wait(timeout=0.1): pass - logger.info('Terminating...') + LOGGER.info('Terminating...') grpc_service.stop() rest_server.shutdown() rest_server.join() - logger.info('Bye') + LOGGER.info('Bye') return 0 if __name__ == '__main__': diff --git a/src/context/service/__main__.py b/src/context/service/__main__.py index dbda296fa313abc8fe32f3b392a5d14ddbacc439..495c203c93ca7df2032cf54c44ba4cefa58d3324 100644 --- a/src/context/service/__main__.py +++ b/src/context/service/__main__.py @@ -16,7 +16,7 @@ from context.service.rest_server.Resources import RESOURCES terminate = threading.Event() LOGGER = None -def signal_handler(signal, frame): +def signal_handler(signal, frame): # pylint: disable=redefined-outer-name LOGGER.warning('Terminate signal received') terminate.set() diff --git a/src/service/service/__main__.py b/src/service/service/__main__.py index fdf602c394b4f93005c67021e7e7536f66bdb335..7de072b007d16fbd1c3274ee6a1ba04a5e0e56e5 100644 --- a/src/service/service/__main__.py +++ b/src/service/service/__main__.py @@ -7,7 +7,7 @@ from service.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIO terminate = threading.Event() LOGGER = None -def signal_handler(signal, frame): +def signal_handler(signal, frame): # pylint: disable=redefined-outer-name LOGGER.warning('Terminate signal received') terminate.set()