Loading src/opticalcentralizedattackdetector/service/OpticalCentralizedAttackDetectorService.py +7 −7 Original line number Diff line number Diff line Loading @@ -4,16 +4,16 @@ from concurrent import futures from grpc_health.v1.health import HealthServicer, OVERALL_HEALTH from grpc_health.v1.health_pb2 import HealthCheckResponse from grpc_health.v1.health_pb2_grpc import add_HealthServicer_to_server from opticalcentralizedattackdetector.proto.centralized_attack_detector_pb2_grpc import ( add_CentralizedAttackDetectorServiceServicer_to_server) from opticalcentralizedattackdetector.service.CentralizedAttackDetectorServiceServicerImpl import ( CentralizedAttackDetectorServiceServicerImpl) from opticalcentralizedattackdetector.proto.optical_centralized_attack_detector_pb2_grpc import ( add_OpticalCentralizedAttackDetectorServiceServicer_to_server) from opticalcentralizedattackdetector.service.OpticalCentralizedAttackDetectorServiceServicerImpl import ( OpticalCentralizedAttackDetectorServiceServicerImpl) from opticalcentralizedattackdetector.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD BIND_ADDRESS = '0.0.0.0' LOGGER = logging.getLogger(__name__) class CentralizedAttackDetectorService: class OpticalCentralizedAttackDetectorService: def __init__( self, address=BIND_ADDRESS, port=GRPC_SERVICE_PORT, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD): Loading @@ -36,8 +36,8 @@ class CentralizedAttackDetectorService: self.pool = futures.ThreadPoolExecutor(max_workers=self.max_workers) self.server = grpc.server(self.pool) # , interceptors=(tracer_interceptor,)) self.centralized_attack_detector_servicer = CentralizedAttackDetectorServiceServicerImpl() add_CentralizedAttackDetectorServiceServicer_to_server(self.centralized_attack_detector_servicer, self.server) self.centralized_attack_detector_servicer = OpticalCentralizedAttackDetectorServiceServicerImpl() add_OpticalCentralizedAttackDetectorServiceServicer_to_server(self.centralized_attack_detector_servicer, self.server) self.health_servicer = HealthServicer( experimental_non_blocking=True, experimental_thread_pool=futures.ThreadPoolExecutor(max_workers=1)) Loading src/opticalcentralizedattackdetector/service/OpticalCentralizedAttackDetectorServiceServicerImpl.py +4 −4 Original line number Diff line number Diff line Loading @@ -2,16 +2,16 @@ import grpc, logging from common.rpc_method_wrapper.Decorator import create_metrics, safe_and_metered_rpc_method from opticalcentralizedattackdetector.proto.context_pb2 import Empty, Service from opticalcentralizedattackdetector.proto.monitoring_pb2 import KpiList from opticalcentralizedattackdetector.proto.centralized_attack_detector_pb2_grpc import ( CentralizedAttackDetectorServiceServicer) from opticalcentralizedattackdetector.proto.optical_centralized_attack_detector_pb2_grpc import ( OpticalCentralizedAttackDetectorServiceServicer) LOGGER = logging.getLogger(__name__) SERVICE_NAME = 'CentralizedAttackDetector' SERVICE_NAME = 'OpticalCentralizedAttackDetector' METHOD_NAMES = ['NotifyServiceUpdate', 'DetectAttack', 'ReportSummarizedKpi', 'ReportKpi'] METRICS = create_metrics(SERVICE_NAME, METHOD_NAMES) class CentralizedAttackDetectorServiceServicerImpl(CentralizedAttackDetectorServiceServicer): class OpticalCentralizedAttackDetectorServiceServicerImpl(OpticalCentralizedAttackDetectorServiceServicer): def __init__(self): LOGGER.debug('Creating Servicer...') Loading src/opticalcentralizedattackdetector/service/__main__.py +8 −8 Original line number Diff line number Diff line import logging, signal, sys, threading from prometheus_client import start_http_server from common.Settings import get_setting from centralizedattackdetector.Config import ( from opticalcentralizedattackdetector.Config import ( GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD, LOG_LEVEL, METRICS_PORT) from centralizedattackdetector.service.CentralizedAttackDetectorService import CentralizedAttackDetectorService from opticalcentralizedattackdetector.service.OpticalCentralizedAttackDetectorService import OpticalCentralizedAttackDetectorService terminate = threading.Event() LOGGER = None Loading @@ -15,7 +15,7 @@ def signal_handler(signal, frame): # pylint: disable=redefined-outer-name def main(): global LOGGER # pylint: disable=global-statement service_port = get_setting('CENTRALIZEDATTACKDETECTORSERVICE_SERVICE_PORT_GRPC', default=GRPC_SERVICE_PORT) service_port = get_setting('OPTICALCENTRALIZEDATTACKDETECTORSERVICE_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 ) Loading @@ -33,7 +33,7 @@ def main(): start_http_server(metrics_port) # Starting CentralizedCybersecurity service grpc_service = CentralizedAttackDetectorService( grpc_service = OpticalCentralizedAttackDetectorService( port=service_port, max_workers=max_workers, grace_period=grace_period) grpc_service.start() Loading src/opticalcentralizedattackdetector/tests/test_unitary.py +14 −14 Original line number Diff line number Diff line import logging, pytest from opticalcentralizedattackdetector.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD from opticalcentralizedattackdetector.client.CentralizedAttackDetectorClient import CentralizedAttackDetectorClient from opticalcentralizedattackdetector.client.OpticalCentralizedAttackDetectorClient import OpticalCentralizedAttackDetectorClient from opticalcentralizedattackdetector.proto.context_pb2 import Empty, Service from opticalcentralizedattackdetector.proto.monitoring_pb2 import Kpi, KpiList from opticalcentralizedattackdetector.service.CentralizedAttackDetectorService import CentralizedAttackDetectorService from opticalcentralizedattackdetector.service.OpticalCentralizedAttackDetectorService import OpticalCentralizedAttackDetectorService port = 10000 + GRPC_SERVICE_PORT # avoid privileged ports Loading @@ -11,31 +11,31 @@ LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @pytest.fixture(scope='session') def centralized_attack_detector_service(): _service = CentralizedAttackDetectorService( def optical_centralized_attack_detector_service(): _service = OpticalCentralizedAttackDetectorService( port=port, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD) _service.start() yield _service _service.stop() @pytest.fixture(scope='session') def centralized_attack_detector_client(centralized_attack_detector_service): _client = CentralizedAttackDetectorClient(address='127.0.0.1', port=port) def optical_centralized_attack_detector_client(optical_centralized_attack_detector_service): _client = OpticalCentralizedAttackDetectorClient(address='127.0.0.1', port=port) yield _client _client.close() def test_notify_service_update(centralized_attack_detector_client: CentralizedAttackDetectorClient): def test_notify_service_update(optical_centralized_attack_detector_client: OpticalCentralizedAttackDetectorClient): service = Service() centralized_attack_detector_client.NotifyServiceUpdate(service) optical_centralized_attack_detector_client.NotifyServiceUpdate(service) def test_detect_attack(centralized_attack_detector_client: CentralizedAttackDetectorClient): def test_detect_attack(optical_centralized_attack_detector_client: OpticalCentralizedAttackDetectorClient): request = Empty() centralized_attack_detector_client.DetectAttack(request) optical_centralized_attack_detector_client.DetectAttack(request) def test_report_summarized_kpi(centralized_attack_detector_client: CentralizedAttackDetectorClient): def test_report_summarized_kpi(optical_centralized_attack_detector_client: OpticalCentralizedAttackDetectorClient): kpi_list = KpiList() centralized_attack_detector_client.ReportSummarizedKpi(kpi_list) optical_centralized_attack_detector_client.ReportSummarizedKpi(kpi_list) def test_report_kpi(centralized_attack_detector_client: CentralizedAttackDetectorClient): def test_report_kpi(optical_centralized_attack_detector_client: OpticalCentralizedAttackDetectorClient): kpi_list = KpiList() centralized_attack_detector_client.ReportKpi(kpi_list) optical_centralized_attack_detector_client.ReportKpi(kpi_list) Loading
src/opticalcentralizedattackdetector/service/OpticalCentralizedAttackDetectorService.py +7 −7 Original line number Diff line number Diff line Loading @@ -4,16 +4,16 @@ from concurrent import futures from grpc_health.v1.health import HealthServicer, OVERALL_HEALTH from grpc_health.v1.health_pb2 import HealthCheckResponse from grpc_health.v1.health_pb2_grpc import add_HealthServicer_to_server from opticalcentralizedattackdetector.proto.centralized_attack_detector_pb2_grpc import ( add_CentralizedAttackDetectorServiceServicer_to_server) from opticalcentralizedattackdetector.service.CentralizedAttackDetectorServiceServicerImpl import ( CentralizedAttackDetectorServiceServicerImpl) from opticalcentralizedattackdetector.proto.optical_centralized_attack_detector_pb2_grpc import ( add_OpticalCentralizedAttackDetectorServiceServicer_to_server) from opticalcentralizedattackdetector.service.OpticalCentralizedAttackDetectorServiceServicerImpl import ( OpticalCentralizedAttackDetectorServiceServicerImpl) from opticalcentralizedattackdetector.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD BIND_ADDRESS = '0.0.0.0' LOGGER = logging.getLogger(__name__) class CentralizedAttackDetectorService: class OpticalCentralizedAttackDetectorService: def __init__( self, address=BIND_ADDRESS, port=GRPC_SERVICE_PORT, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD): Loading @@ -36,8 +36,8 @@ class CentralizedAttackDetectorService: self.pool = futures.ThreadPoolExecutor(max_workers=self.max_workers) self.server = grpc.server(self.pool) # , interceptors=(tracer_interceptor,)) self.centralized_attack_detector_servicer = CentralizedAttackDetectorServiceServicerImpl() add_CentralizedAttackDetectorServiceServicer_to_server(self.centralized_attack_detector_servicer, self.server) self.centralized_attack_detector_servicer = OpticalCentralizedAttackDetectorServiceServicerImpl() add_OpticalCentralizedAttackDetectorServiceServicer_to_server(self.centralized_attack_detector_servicer, self.server) self.health_servicer = HealthServicer( experimental_non_blocking=True, experimental_thread_pool=futures.ThreadPoolExecutor(max_workers=1)) Loading
src/opticalcentralizedattackdetector/service/OpticalCentralizedAttackDetectorServiceServicerImpl.py +4 −4 Original line number Diff line number Diff line Loading @@ -2,16 +2,16 @@ import grpc, logging from common.rpc_method_wrapper.Decorator import create_metrics, safe_and_metered_rpc_method from opticalcentralizedattackdetector.proto.context_pb2 import Empty, Service from opticalcentralizedattackdetector.proto.monitoring_pb2 import KpiList from opticalcentralizedattackdetector.proto.centralized_attack_detector_pb2_grpc import ( CentralizedAttackDetectorServiceServicer) from opticalcentralizedattackdetector.proto.optical_centralized_attack_detector_pb2_grpc import ( OpticalCentralizedAttackDetectorServiceServicer) LOGGER = logging.getLogger(__name__) SERVICE_NAME = 'CentralizedAttackDetector' SERVICE_NAME = 'OpticalCentralizedAttackDetector' METHOD_NAMES = ['NotifyServiceUpdate', 'DetectAttack', 'ReportSummarizedKpi', 'ReportKpi'] METRICS = create_metrics(SERVICE_NAME, METHOD_NAMES) class CentralizedAttackDetectorServiceServicerImpl(CentralizedAttackDetectorServiceServicer): class OpticalCentralizedAttackDetectorServiceServicerImpl(OpticalCentralizedAttackDetectorServiceServicer): def __init__(self): LOGGER.debug('Creating Servicer...') Loading
src/opticalcentralizedattackdetector/service/__main__.py +8 −8 Original line number Diff line number Diff line import logging, signal, sys, threading from prometheus_client import start_http_server from common.Settings import get_setting from centralizedattackdetector.Config import ( from opticalcentralizedattackdetector.Config import ( GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD, LOG_LEVEL, METRICS_PORT) from centralizedattackdetector.service.CentralizedAttackDetectorService import CentralizedAttackDetectorService from opticalcentralizedattackdetector.service.OpticalCentralizedAttackDetectorService import OpticalCentralizedAttackDetectorService terminate = threading.Event() LOGGER = None Loading @@ -15,7 +15,7 @@ def signal_handler(signal, frame): # pylint: disable=redefined-outer-name def main(): global LOGGER # pylint: disable=global-statement service_port = get_setting('CENTRALIZEDATTACKDETECTORSERVICE_SERVICE_PORT_GRPC', default=GRPC_SERVICE_PORT) service_port = get_setting('OPTICALCENTRALIZEDATTACKDETECTORSERVICE_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 ) Loading @@ -33,7 +33,7 @@ def main(): start_http_server(metrics_port) # Starting CentralizedCybersecurity service grpc_service = CentralizedAttackDetectorService( grpc_service = OpticalCentralizedAttackDetectorService( port=service_port, max_workers=max_workers, grace_period=grace_period) grpc_service.start() Loading
src/opticalcentralizedattackdetector/tests/test_unitary.py +14 −14 Original line number Diff line number Diff line import logging, pytest from opticalcentralizedattackdetector.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD from opticalcentralizedattackdetector.client.CentralizedAttackDetectorClient import CentralizedAttackDetectorClient from opticalcentralizedattackdetector.client.OpticalCentralizedAttackDetectorClient import OpticalCentralizedAttackDetectorClient from opticalcentralizedattackdetector.proto.context_pb2 import Empty, Service from opticalcentralizedattackdetector.proto.monitoring_pb2 import Kpi, KpiList from opticalcentralizedattackdetector.service.CentralizedAttackDetectorService import CentralizedAttackDetectorService from opticalcentralizedattackdetector.service.OpticalCentralizedAttackDetectorService import OpticalCentralizedAttackDetectorService port = 10000 + GRPC_SERVICE_PORT # avoid privileged ports Loading @@ -11,31 +11,31 @@ LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @pytest.fixture(scope='session') def centralized_attack_detector_service(): _service = CentralizedAttackDetectorService( def optical_centralized_attack_detector_service(): _service = OpticalCentralizedAttackDetectorService( port=port, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD) _service.start() yield _service _service.stop() @pytest.fixture(scope='session') def centralized_attack_detector_client(centralized_attack_detector_service): _client = CentralizedAttackDetectorClient(address='127.0.0.1', port=port) def optical_centralized_attack_detector_client(optical_centralized_attack_detector_service): _client = OpticalCentralizedAttackDetectorClient(address='127.0.0.1', port=port) yield _client _client.close() def test_notify_service_update(centralized_attack_detector_client: CentralizedAttackDetectorClient): def test_notify_service_update(optical_centralized_attack_detector_client: OpticalCentralizedAttackDetectorClient): service = Service() centralized_attack_detector_client.NotifyServiceUpdate(service) optical_centralized_attack_detector_client.NotifyServiceUpdate(service) def test_detect_attack(centralized_attack_detector_client: CentralizedAttackDetectorClient): def test_detect_attack(optical_centralized_attack_detector_client: OpticalCentralizedAttackDetectorClient): request = Empty() centralized_attack_detector_client.DetectAttack(request) optical_centralized_attack_detector_client.DetectAttack(request) def test_report_summarized_kpi(centralized_attack_detector_client: CentralizedAttackDetectorClient): def test_report_summarized_kpi(optical_centralized_attack_detector_client: OpticalCentralizedAttackDetectorClient): kpi_list = KpiList() centralized_attack_detector_client.ReportSummarizedKpi(kpi_list) optical_centralized_attack_detector_client.ReportSummarizedKpi(kpi_list) def test_report_kpi(centralized_attack_detector_client: CentralizedAttackDetectorClient): def test_report_kpi(optical_centralized_attack_detector_client: OpticalCentralizedAttackDetectorClient): kpi_list = KpiList() centralized_attack_detector_client.ReportKpi(kpi_list) optical_centralized_attack_detector_client.ReportKpi(kpi_list)