Commit 8cf37415 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Automation component:

- Resolved import issue
- Minor code formatting
parent 4393820c
Loading
Loading
Loading
Loading
+22 −13
Original line number Original line Diff line number Diff line
@@ -12,20 +12,21 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.


import grpc, json, logging
import grpc, logging
from uuid import uuid4
from uuid import uuid4
from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.proto.automation_pb2_grpc import AutomationServiceServicer
from common.proto.automation_pb2_grpc import AutomationServiceServicer
from common.method_wrappers.ServiceExceptions import InvalidArgumentException
from common.method_wrappers.ServiceExceptions import NotFoundException
from common.proto.automation_pb2 import ZSMCreateRequest, ZSMService, ZSMServiceID, ZSMServiceState, ZSMCreateUpdate
from common.proto.automation_pb2 import ZSMCreateRequest, ZSMService, ZSMServiceID, ZSMServiceState
from common.proto.context_pb2 import Service, ServiceId
from common.proto.context_pb2 import ServiceId
from automation.service.zsm_handlers import ZSM_SERVICE_HANDLERS
from automation.service.zsm_handler_api.ZSMFilterFields import ZSMFilterFieldEnum , TELEMETRY_SERVICE_TYPE_VALUES, TARGET_SERVICE_TYPE_VALUES , ZSM_FILTER_FIELD_ALLOWED_VALUES
from common.proto.context_pb2 import ServiceTypeEnum , DeviceDriverEnum
from context.client.ContextClient import ContextClient
from automation.service.database.AutomationDB import AutomationDB
from automation.service.database.AutomationDB import AutomationDB
from automation.service.database.AutomationModel import AutomationModel
from automation.service.database.AutomationModel import AutomationModel
from common.method_wrappers.ServiceExceptions import NotFoundException
from automation.service.zsm_handlers import ZSM_SERVICE_HANDLERS
from automation.service.zsm_handler_api.ZSMFilterFields import (
    ZSMFilterFieldEnum, #TELEMETRY_SERVICE_TYPE_VALUES, TARGET_SERVICE_TYPE_VALUES,
    ZSM_FILTER_FIELD_ALLOWED_VALUES
)
from context.client.ContextClient import ContextClient


LOGGER = logging.getLogger(__name__)
LOGGER = logging.getLogger(__name__)
METRICS_POOL = MetricsPool('Automation', 'RPC')
METRICS_POOL = MetricsPool('Automation', 'RPC')
@@ -43,7 +44,9 @@ class AutomationServiceServicerImpl(AutomationServiceServicer):
        targetService = context_client.GetService(request.target_service_id)
        targetService = context_client.GetService(request.target_service_id)
        telemetryService = context_client.GetService(request.telemetry_service_id)
        telemetryService = context_client.GetService(request.telemetry_service_id)


        handler_cls = self.get_service_handler_based_on_service_types(targetService.service_type, telemetryService.service_type, ZSM_SERVICE_HANDLERS)
        handler_cls = self.get_service_handler_based_on_service_types(
            targetService.service_type, telemetryService.service_type, ZSM_SERVICE_HANDLERS
        )


        if handler_cls:
        if handler_cls:
            handler_obj = handler_cls()  # instantiate it
            handler_obj = handler_cls()  # instantiate it
@@ -93,16 +96,22 @@ class AutomationServiceServicerImpl(AutomationServiceServicer):
        LOGGER.info('NOT IMPLEMENTED ZSMGetByService')
        LOGGER.info('NOT IMPLEMENTED ZSMGetByService')
        return ZSMService()
        return ZSMService()


    def get_service_handler_based_on_service_types(self, targetServiceType ,telemetryServiceType , ZSM_SERVICE_HANDLERS):
    def get_service_handler_based_on_service_types(
        self, targetServiceType ,telemetryServiceType , ZSM_SERVICE_HANDLERS
    ):
        flag = True
        flag = True
        for handler_cls, filters in ZSM_SERVICE_HANDLERS:
        for handler_cls, filters in ZSM_SERVICE_HANDLERS:
            for filter in filters:
            for filter in filters:
                flag = self.check_if_requested_services_pass_filter_criteria(filter , targetServiceType, telemetryServiceType)
                flag = self.check_if_requested_services_pass_filter_criteria(
                    filter, targetServiceType, telemetryServiceType
                )
            if flag:
            if flag:
                return handler_cls
                return handler_cls
        return None
        return None


    def check_if_requested_services_pass_filter_criteria(self ,filter , targetServiceType , telemetryServiceType):
    def check_if_requested_services_pass_filter_criteria(
        self ,filter , targetServiceType , telemetryServiceType
    ):
        flag = True
        flag = True
        for filter_key, filter_value in filter.items():
        for filter_key, filter_value in filter.items():
            if filter_value in ZSM_FILTER_FIELD_ALLOWED_VALUES[filter_key.value]:
            if filter_value in ZSM_FILTER_FIELD_ALLOWED_VALUES[filter_key.value]: