Skip to content
Snippets Groups Projects
Commit b0938294 authored by ldemarcosm's avatar ldemarcosm
Browse files

Removed database from Distributed component

parent 9a469631
No related branches found
No related tags found
1 merge request!54Release 2.0.0
import logging, signal, sys, threading, os
from prometheus_client import start_http_server
from common.Settings import get_setting
from common.orm.Factory import get_database_backend as get_database
from l3_distributedattackdetector.service.l3_distributedattackdetectorService import l3_distributedattackdetectorService
from l3_distributedattackdetector.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD, LOG_LEVEL, METRICS_PORT
......@@ -33,12 +32,9 @@ def main():
# Start metrics server
start_http_server(metrics_port)
# Get database instance
database = get_database()
# Starting l3_distributedattackdetector service
grpc_service = l3_distributedattackdetectorService(
database, port=service_port, max_workers=max_workers, grace_period=grace_period)
port=service_port, max_workers=max_workers, grace_period=grace_period)
grpc_service.start()
# Wait for Ctrl+C or termination signal
......
......@@ -23,13 +23,11 @@ LOGGER = logging.getLogger(__name__)
class l3_distributedattackdetectorService:
def __init__(
self,
database,
address=BIND_ADDRESS,
port=GRPC_SERVICE_PORT,
max_workers=GRPC_MAX_WORKERS,
grace_period=GRPC_GRACE_PERIOD,
):
self.database = database
self.address = address
self.port = port
self.endpoint = None
......@@ -52,7 +50,7 @@ class l3_distributedattackdetectorService:
self.server = grpc.server(self.pool) # , interceptors=(tracer_interceptor,))
self.l3_distributedattackdetector_servicer = (
l3_distributedattackdetectorServiceServicerImpl(self.database)
l3_distributedattackdetectorServiceServicerImpl()
)
add_L3CentralizedattackdetectorServicer_to_server(
self.l3_distributedattackdetector_servicer, self.server
......@@ -73,7 +71,7 @@ class l3_distributedattackdetectorService:
) # pylint: disable=maybe-no-member
LOGGER.debug("Service started")
self.l3_distributedattackdetector_servicer.setupl3_distributedattackdetector(self.database)
self.l3_distributedattackdetector_servicer.setupl3_distributedattackdetector()
LOGGER.debug("IMPL started")
def stop(self):
......
......@@ -6,8 +6,6 @@ import os
import multiprocessing
from subprocess import Popen, DEVNULL
from time import sleep
from l3_distributedattackdetector.proto.monitoring_pb2 import Kpi, KpiList
from common.orm.Factory import get_database_backend as get_database, BackendEnum as DatabaseEngineEnum
from l3_distributedattackdetector.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD
from l3_distributedattackdetector.client.l3_distributedattackdetectorClient import l3_distributedattackdetectorClient
from l3_distributedattackdetector.service.l3_distributedattackdetectorService import l3_distributedattackdetectorService
......@@ -19,15 +17,9 @@ LOGGER.setLevel(logging.DEBUG)
@pytest.fixture(scope='session')
def database():
_database = get_database(engine=DatabaseEngineEnum.INMEMORY)
return _database
@pytest.fixture(scope='session')
def l3_distributedattackdetector_service(database):
def l3_distributedattackdetector_service():
_service = l3_distributedattackdetectorService(
database, port=port, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD)
port=port, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD)
_service.start()
yield _service
_service.stop()
......@@ -44,10 +36,10 @@ def test_demo():
print('Demo Test')
pass
def test_tstat(database):
def test_tstat():
print('Starting DAD')
_service = l3_distributedattackdetectorService(
database, port=port, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD)
port=port, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD)
p1 = multiprocessing.Process(target=_service.start, args=())
p1.start()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment