From 534ad49c336e26cd350fb38721978bf9519dd2ae Mon Sep 17 00:00:00 2001 From: jjdiaz <jjdiaz@cttc.es> Date: Mon, 16 Sep 2024 12:28:32 +0200 Subject: [PATCH] Code Cleanup --- manifests/dltservice.yaml | 10 +++++----- .../service/DltConnectorServiceServicerImpl.py | 2 +- src/dlt/connector/service/__main__.py | 8 ++++---- src/dlt/connector/service/tools/Checkers.py | 2 +- src/interdomain/service/__main__.py | 4 ++-- .../service/topology_abstractor/DltRecordSender.py | 3 +-- .../service/topology_abstractor/DltRecorder.py | 12 ++---------- 7 files changed, 16 insertions(+), 25 deletions(-) diff --git a/manifests/dltservice.yaml b/manifests/dltservice.yaml index e96896489..35ab9919d 100644 --- a/manifests/dltservice.yaml +++ b/manifests/dltservice.yaml @@ -51,11 +51,11 @@ spec: env: - name: LOG_LEVEL value: "INFO" - ## for debug purposes - #- name: DLT_GATEWAY_HOST - # value: "mock-blockchain.tfs-bchain.svc.cluster.local" - #- name: DLT_GATEWAY_PORT - # value: "50051" + ## for debug purposes + #- name: DLT_GATEWAY_HOST + # value: "mock-blockchain.tfs-bchain.svc.cluster.local" + #- name: DLT_GATEWAY_PORT + # value: "50051" readinessProbe: exec: command: ["/bin/grpc_health_probe", "-addr=:8080"] diff --git a/src/dlt/connector/service/DltConnectorServiceServicerImpl.py b/src/dlt/connector/service/DltConnectorServiceServicerImpl.py index 1d4066fc9..edba01fac 100644 --- a/src/dlt/connector/service/DltConnectorServiceServicerImpl.py +++ b/src/dlt/connector/service/DltConnectorServiceServicerImpl.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import grpc, asyncio, logging +import logging from grpc.aio import ServicerContext from typing import Optional from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method_async diff --git a/src/dlt/connector/service/__main__.py b/src/dlt/connector/service/__main__.py index f8296660e..e368f6302 100644 --- a/src/dlt/connector/service/__main__.py +++ b/src/dlt/connector/service/__main__.py @@ -13,7 +13,7 @@ # limitations under the License. -import logging, signal, sys, threading, asyncio +import logging, signal, threading, asyncio from prometheus_client import start_http_server from common.Constants import ServiceNameEnum from common.Settings import ( @@ -25,12 +25,12 @@ from .DltConnectorService import DltConnectorService terminate = threading.Event() LOGGER: logging.Logger = None -def signal_handler(signal, frame): +def signal_handler(signal, frame): # pylint: disable=redefined-outer-name LOGGER.warning('Terminate signal received') terminate.set() async def main(): - global LOGGER + global LOGGER # pylint: disable=global-statement log_level = get_log_level() logging.basicConfig(level=log_level, format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s") @@ -59,7 +59,7 @@ async def main(): await grpc_service.start() # Wait for Ctrl+C or termination signal - while not terminate.wait(timeout=1.0): + while not terminate.is_set(): await asyncio.sleep(1.0) LOGGER.info('Terminating...') diff --git a/src/dlt/connector/service/tools/Checkers.py b/src/dlt/connector/service/tools/Checkers.py index 94a10d409..9afb0da07 100644 --- a/src/dlt/connector/service/tools/Checkers.py +++ b/src/dlt/connector/service/tools/Checkers.py @@ -20,5 +20,5 @@ def record_exists(record : DltRecord) -> bool: exists = exists and (record.record_id.type != DLTRECORDTYPE_UNDEFINED) exists = exists and (len(record.record_id.record_uuid.uuid) > 0) #exists = exists and (record.operation != DLTRECORDOPERATION_UNDEFINED) - #exists = exists and (len(record.data_json) > 0) + #exists = exists and (len(record.data_json) > 0) #It conflicts as sometimes records do not have a data_json. return exists diff --git a/src/interdomain/service/__main__.py b/src/interdomain/service/__main__.py index 8c392821e..4181fa73a 100644 --- a/src/interdomain/service/__main__.py +++ b/src/interdomain/service/__main__.py @@ -50,7 +50,7 @@ def main(): signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGTERM, signal_handler) - LOGGER.info('Starting Interdomain Service...') + LOGGER.info('Starting...') # Start metrics server metrics_port = get_metrics_port() @@ -71,7 +71,7 @@ def main(): # topology_abstractor.start() # Subscribe to Context Events - #dlt_enabled = is_dlt_enabled() + #dlt_enabled = is_dlt_enabled() #How to change the config? dlt_enabled = True if dlt_enabled: LOGGER.info('Starting DLT functionality...') diff --git a/src/interdomain/service/topology_abstractor/DltRecordSender.py b/src/interdomain/service/topology_abstractor/DltRecordSender.py index 2dd899be2..5605ae412 100644 --- a/src/interdomain/service/topology_abstractor/DltRecordSender.py +++ b/src/interdomain/service/topology_abstractor/DltRecordSender.py @@ -16,10 +16,9 @@ import logging import asyncio -from typing import Dict, List, Optional, Tuple +from typing import Dict, List, Tuple from common.proto.context_pb2 import Device, Link, Service, Slice, TopologyId from common.proto.dlt_connector_pb2 import DltDeviceId, DltLinkId, DltServiceId, DltSliceId -from common.tools.grpc.Tools import grpc_message_to_json_string from context.client.ContextClient import ContextClient from dlt.connector.client.DltConnectorClientAsync import DltConnectorClientAsync diff --git a/src/interdomain/service/topology_abstractor/DltRecorder.py b/src/interdomain/service/topology_abstractor/DltRecorder.py index 97b48628a..79067072c 100644 --- a/src/interdomain/service/topology_abstractor/DltRecorder.py +++ b/src/interdomain/service/topology_abstractor/DltRecorder.py @@ -12,21 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging -import threading -import asyncio -import time +import logging, threading, asyncio, time from typing import Dict, Optional - from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME, INTERDOMAIN_TOPOLOGY_NAME, ServiceNameEnum -from common.Settings import ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC, find_environment_variables, get_env_var_name -from common.proto.context_pb2 import ContextEvent, ContextId, Device, DeviceEvent, DeviceId, EndPointId, Link, LinkId, LinkEvent, TopologyId, TopologyEvent +from common.proto.context_pb2 import ContextEvent, ContextId, Device, DeviceEvent, DeviceId, LinkId, LinkEvent, TopologyId, TopologyEvent from common.tools.context_queries.Context import create_context -from common.tools.context_queries.Device import get_uuids_of_devices_in_topology -from common.tools.context_queries.Topology import create_missing_topologies from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.object_factory.Context import json_context_id -from common.tools.object_factory.Device import json_device_id from common.tools.object_factory.Topology import json_topology_id from context.client.ContextClient import ContextClient from context.client.EventsCollector import EventsCollector -- GitLab