Commit 4d733960 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Service component - L3NM NCE:

- Removed unused Settings Handler
- Added log messages
parent 6be8ffdc
Loading
Loading
Loading
Loading
+25 −45
Original line number Diff line number Diff line
@@ -20,11 +20,11 @@ from deepdiff import DeepDiff

from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method
from common.proto.context_pb2 import ConfigRule, DeviceId, Empty, Service, ServiceConfig
from common.tools.grpc.Tools import grpc_message_to_json_string
from common.tools.object_factory.Device import json_device_id
from common.type_checkers.Checkers import chk_type
from context.client.ContextClient import ContextClient
from service.service.service_handler_api._ServiceHandler import _ServiceHandler
from service.service.service_handler_api.SettingsHandler import SettingsHandler
from service.service.service_handler_api.Tools import (
    get_device_endpoint_uuids,
)
@@ -253,7 +253,6 @@ class L3NM_NCEFAN_ServiceHandler(_ServiceHandler):
    ) -> None:
        self.__service = service
        self.__task_executor = task_executor
        self.__settings_handler = SettingsHandler(service.service_config, **settings)

    @metered_subclass_method(METRICS_POOL)
    def SetEndpoint(
@@ -261,6 +260,10 @@ class L3NM_NCEFAN_ServiceHandler(_ServiceHandler):
        endpoints: List[Tuple[str, str, Optional[str]]],
        connection_uuid: Optional[str] = None,
    ) -> List[Union[bool, Exception]]:
        LOGGER.debug('[SetEndpoint] service={:s}'.format(grpc_message_to_json_string(self.__service)))
        LOGGER.debug('[SetEndpoint] endpoints={:s}'.format(str(endpoints)))
        LOGGER.debug('[SetEndpoint] connection_uuid={:s}'.format(str(connection_uuid)))

        chk_type('endpoints', endpoints, list)
        if len(endpoints) == 0: return []

@@ -268,7 +271,6 @@ class L3NM_NCEFAN_ServiceHandler(_ServiceHandler):
        try:
            context_client = ContextClient()
            service_config = self.__service.service_config
            settings = self.__settings_handler.get("/settings")

            src_device_uuid, src_endpoint_uuid = get_device_endpoint_uuids(endpoints[0])
            src_device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(src_device_uuid)))
@@ -500,60 +502,38 @@ class L3NM_NCEFAN_ServiceHandler(_ServiceHandler):
    def SetConstraint(
        self, constraints: List[Tuple[str, Any]]
    ) -> List[Union[bool, Exception]]:
        chk_type("constraints", constraints, list)
        if len(constraints) == 0:
            return []

        msg = "[SetConstraint] Method not implemented. Constraints({:s}) are being ignored."
        LOGGER.warning(msg.format(str(constraints)))
        return [True for _ in range(len(constraints))]
        chk_type('constraints', constraints, list)
        if len(constraints) == 0: return []
        MSG = '[SetConstraint] Method not implemented. Constraints({:s}) are being ignored.'
        LOGGER.warning(MSG.format(str(constraints)))
        return [True for _ in constraints]

    @metered_subclass_method(METRICS_POOL)
    def DeleteConstraint(
        self, constraints: List[Tuple[str, Any]]
    ) -> List[Union[bool, Exception]]:
        chk_type("constraints", constraints, list)
        if len(constraints) == 0:
            return []

        msg = "[DeleteConstraint] Method not implemented. Constraints({:s}) are being ignored."
        LOGGER.warning(msg.format(str(constraints)))
        return [True for _ in range(len(constraints))]
        chk_type('constraints', constraints, list)
        if len(constraints) == 0: return []
        MSG = '[DeleteConstraint] Method not implemented. Constraints({:s}) are being ignored.'
        LOGGER.warning(MSG.format(str(constraints)))
        return [True for _ in constraints]

    @metered_subclass_method(METRICS_POOL)
    def SetConfig(
        self, resources: List[Tuple[str, Any]]
    ) -> List[Union[bool, Exception]]:
        chk_type("resources", resources, list)
        if len(resources) == 0:
            return []

        results = []
        for resource in resources:
            try:
                resource_value = json.loads(resource[1])
                self.__settings_handler.set(resource[0], resource_value)
                results.append(True)
            except Exception as e:  # pylint: disable=broad-except
                LOGGER.exception("Unable to SetConfig({:s})".format(str(resource)))
                results.append(e)

        return results
        chk_type('resources', resources, list)
        if len(resources) == 0: return []
        MSG = '[SetConfig] Method not implemented. Resources({:s}) are being ignored.'
        LOGGER.warning(MSG.format(str(resources)))
        return [True for _ in resources]

    @metered_subclass_method(METRICS_POOL)
    def DeleteConfig(
        self, resources: List[Tuple[str, Any]]
    ) -> List[Union[bool, Exception]]:
        chk_type("resources", resources, list)
        if len(resources) == 0:
            return []

        results = []
        for resource in resources:
            try:
                self.__settings_handler.delete(resource[0])
            except Exception as e:  # pylint: disable=broad-except
                LOGGER.exception("Unable to DeleteConfig({:s})".format(str(resource)))
                results.append(e)

        return results
        chk_type('resources', resources, list)
        if len(resources) == 0: return []
        MSG = '[DeleteConfig] Method not implemented. Resources({:s}) are being ignored.'
        LOGGER.warning(MSG.format(str(resources)))
        return [True for _ in resources]