Skip to content
Snippets Groups Projects
Commit 0997a144 authored by Carlos Natalino Da Silva's avatar Carlos Natalino Da Silva
Browse files

Finalizing the code. Making consistent parameter naming on the constructor of...

Finalizing the code. Making consistent parameter naming on the constructor of the clients. Improving tests to provide 100% coverage.
parent 485eb7da
No related branches found
No related tags found
1 merge request!54Release 2.0.0
......@@ -8,8 +8,8 @@ MAX_RETRIES = 15
DELAY_FUNCTION = delay_exponential(initial=0.01, increment=2.0, maximum=5.0)
class DbscanServingClient:
def __init__(self, host, port):
self.endpoint = '{:s}:{:s}'.format(str(host), str(port))
def __init__(self, address, port):
self.endpoint = '{:s}:{:s}'.format(str(address), str(port))
LOGGER.debug('Creating channel to {:s}...'.format(str(self.endpoint)))
self.channel = None
self.stub = None
......
......@@ -8,8 +8,8 @@ MAX_RETRIES = 15
DELAY_FUNCTION = delay_exponential(initial=0.01, increment=2.0, maximum=5.0)
class OpticalAttackMitigatorClient:
def __init__(self, host, port):
self.endpoint = '{:s}:{:s}'.format(str(host), str(port))
def __init__(self, address, port):
self.endpoint = '{:s}:{:s}'.format(str(address), str(port))
LOGGER.debug('Creating channel to {:s}...'.format(str(self.endpoint)))
self.channel = None
self.stub = None
......
......@@ -21,6 +21,6 @@ class OpticalAttackMitigatorServiceServicerImpl(AttackMitigatorServicer):
@safe_and_metered_rpc_method(METRICS, LOGGER)
def NotifyAttack(self, request : AttackDescription, context : grpc.ServicerContext) -> AttackResponse:
LOGGER.debug(f"NotifyAttack: {request}")
response: AttackResponse = AttackDescription()
response: AttackResponse = AttackResponse()
response.response_strategy_description = 'The AttackMitigator has received the attack description.'
return response
......@@ -45,8 +45,8 @@ class OpticalCentralizedAttackDetectorServiceServicerImpl(OpticalCentralizedAtta
self.monitoring_client: MonitoringClient = MonitoringClient(server=MONITORING_SERVICE_ADDRESS, port=MONITORING_GRPC_SERVICE_PORT)
self.service_client: ServiceClient = ServiceClient(SERVICE_SERVICE_ADDRESS, SERVICE_GRPC_SERVICE_PORT)
self.influxdb_client: InfluxDBClient = InfluxDBClient(host=MONITORING_SERVICE_ADDRESS, port=8086, username=INFLUXDB_USER, password=INFLUXDB_PASSWORD, database=INFLUXDB_DATABASE)
self.dbscanserving_client: DbscanServingClient = DbscanServingClient(host=INFERENCE_SERVICE_ADDRESS, port=DBSCANSERVING_GRPC_SERVICE_PORT)
self.attack_mitigator_client: OpticalAttackMitigatorClient = OpticalAttackMitigatorClient(host=ATTACK_MITIGATOR_SERVICE_ADDRESS, port=ATTACK_MITIGATOR_GRPC_SERVICE_PORT)
self.dbscanserving_client: DbscanServingClient = DbscanServingClient(address=INFERENCE_SERVICE_ADDRESS, port=DBSCANSERVING_GRPC_SERVICE_PORT)
self.attack_mitigator_client: OpticalAttackMitigatorClient = OpticalAttackMitigatorClient(address=ATTACK_MITIGATOR_SERVICE_ADDRESS, port=ATTACK_MITIGATOR_GRPC_SERVICE_PORT)
LOGGER.debug('Servicer Created')
@safe_and_metered_rpc_method(METRICS, LOGGER)
......@@ -70,7 +70,6 @@ class OpticalCentralizedAttackDetectorServiceServicerImpl(OpticalCentralizedAtta
# get monitoring data for each of the current services
results = self.influxdb_client.query('select * from samples;')
print(results.raw)
for service in services:
for endpoint in service.service_endpoint_ids:
......
......@@ -22,6 +22,7 @@ def signal_handler(signal, frame): # pylint: disable=redefined-outer-name
terminate.set()
def detect_attack(monitoring_interval):
time.sleep(10) # wait for the service to start
LOGGER.info("Starting the attack detection loop")
client = OpticalCentralizedAttackDetectorClient(address='localhost', port=GRPC_SERVICE_PORT)
client.connect()
......
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