Commit ce156189 authored by Konstantinos Poulakakis's avatar Konstantinos Poulakakis
Browse files

temp: commit refactored automation code

parent 8dfe9a79
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -40,13 +40,12 @@ enum ZSMServiceStateEnum {

enum ZSMTypeEnum {
  ZSMTYPE_UNKNOWN = 0;
  ZSMTYPE_P4 = 1;
  ZSMTYPE_L2NM = 2;
  ZSMTYPE = 1;
}

message ZSMCreateRequest {
  context.ServiceId targetServiceId = 1;
  context.ServiceId telemetryServiceId = 2;
  context.ServiceId target_service_id = 1;
  context.ServiceId telemetry_service_id = 2;
  analytics_frontend.Analyzer analyzer = 3;
  policy.PolicyRuleService policy = 4;
}
+3 −4
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,8 +17,7 @@ from common.proto.context_pb2 import ServiceTypeEnum

class ZSMFilterFieldEnum(Enum):
    TARGET_SERVICE_TYPE  = 'target_service_type'
    TELEMETRY_SERVICE_TYPE = 'telemetry_service_driver'

    TELEMETRY_SERVICE_TYPE = 'telemetry_service_type'

TARGET_SERVICE_TYPE_VALUES = {
    ServiceTypeEnum.SERVICETYPE_L2NM
@@ -28,7 +27,7 @@ TELEMETRY_SERVICE_TYPE_VALUES = {
    ServiceTypeEnum.SERVICETYPE_INT
}

# Map allowed filter fields to allowed values per Filter field. If no restriction (free text) None is specified
# Maps filter fields to allowed values per Filter field. # If no restriction (free text) None is specified
ZSM_FILTER_FIELD_ALLOWED_VALUES = {
    ZSMFilterFieldEnum.TARGET_SERVICE_TYPE.value  : TARGET_SERVICE_TYPE_VALUES,
    ZSMFilterFieldEnum.TELEMETRY_SERVICE_TYPE.value : TELEMETRY_SERVICE_TYPE_VALUES,
+13 −9
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -22,12 +22,16 @@ class ZSMHandler:
        LOGGER.info('Init Scenario')

    def zsmCreate(self, request : ZSMCreateRequest, context : grpc.ServicerContext):
        LOGGER.info('Init zsmCreate method')
        LOGGER.info('zsmCreate method')

    def zsmUpdate(self):
        LOGGER.info('Init zsmUpdate method')
        LOGGER.info('zsmUpdate method')

    def zsmDelete(self):
        LOGGER.info('Init zsmDelete method')
    def ZSMGetById(self):
        LOGGER.info('Init ZSMGetById method')
    def ZSMGetByService(self):
        LOGGER.info('Init ZSMGetByService method')
 No newline at end of file
        LOGGER.info('zsmDelete method')

    def zsmGetById(self):
        LOGGER.info('zsmGetById method')

    def zsmGetByService(self):
        LOGGER.info('zsmGetByService method')
+47 −30
Original line number Diff line number Diff line
@@ -13,63 +13,80 @@
# limitations under the License.

import grpc , logging
from uuid import uuid4
from common.proto.analytics_frontend_pb2 import Analyzer, AnalyzerId
from common.proto.kpi_manager_pb2 import KpiId, KpiDescriptor
from common.proto.policy_pb2 import PolicyRuleService, PolicyRuleState
from common.proto.policy_action_pb2 import PolicyRuleAction, PolicyRuleActionConfig
from common.proto.policy_condition_pb2 import PolicyRuleCondition
from common.proto.telemetry_frontend_pb2 import Collector, CollectorId
from common.proto.automation_pb2 import ZSMCreateRequest, ZSMService, ZSMServiceID, ZSMServiceState, ZSMCreateUpdate
from common.proto.analytics_frontend_pb2 import AnalyzerId
from common.proto.policy_pb2 import PolicyRuleState
from common.proto.automation_pb2 import ZSMCreateRequest, ZSMService

from analytics.frontend.client.AnalyticsFrontendClient import AnalyticsFrontendClient
from automation.client.PolicyClient import PolicyClient
from context.client.ContextClient import ContextClient
from kpi_manager.client.KpiManagerClient import KpiManagerClient
from telemetry.frontend.client.TelemetryFrontendClient import TelemetryFrontendClient
from .ZSMHandler import ZSMHandler
from src.automation.service.zsm_handler_api.ZSMHandler import ZSMHandler

LOGGER = logging.getLogger(__name__)

class P4INTZSMPlugin(ZSMHandler):
    def __init__(self):
        LOGGER.info('Init Scenario')
        LOGGER.info('Init P4INTZSMPlugin')

    def zsmCreate(self,request : ZSMCreateRequest, context : grpc.ServicerContext):
        # check that service does not exist
        context_client = ContextClient()
        kpi_manager_client = KpiManagerClient()
        policy_client = PolicyClient()
        telemetry_frontend_client = TelemetryFrontendClient()
        analytics_frontend_client = AnalyticsFrontendClient()

        # Verify the input target service ID
        try:
            analyzer_id_lat: AnalyzerId = analytics_frontend_client.StartAnalyzer(request.analyzer)
            target_service_id = context_client.GetService(request.target_service_id)
        except grpc.RpcError as ex:
            if ex.code() != grpc.StatusCode.NOT_FOUND: raise  # pylint: disable=no-member
            LOGGER.exception('Unable to get target service({:s})'.format(str(target_service_id)))
            context_client.close()
            return None

        # Verify the input telemetry service ID
        try:
            telemetry_service_id = context_client.GetService(request.telemetry_service_id)
        except grpc.RpcError as ex:
            if ex.code() != grpc.StatusCode.NOT_FOUND: raise  # pylint: disable=no-member
            LOGGER.exception('Unable to get telemetry service({:s})'.format(str(telemetry_service_id)))
            context_client.close()
            return None

        # Start an analyzer
        try:
            analyzer_id_lat: AnalyzerId = analytics_frontend_client.StartAnalyzer(request.analyzer) # type: ignore
            LOGGER.info('analyzer_id_lat({:s})'.format(str(analyzer_id_lat)))
        except grpc.RpcError as ex:
            if ex.code() != grpc.StatusCode.NOT_FOUND: raise  # pylint: disable=no-member
            LOGGER.exception('Unable to start analyzer({:s})'.format(str(request.analyzer)))
            context_client.close()
            analytics_frontend_client.close()
            return None

            policy_rule_state: PolicyRuleState = policy_client.PolicyAddService(request.policy)
        # Create a policy
        try:
            policy_rule_state: PolicyRuleState = policy_client.PolicyAddService(request.policy) # type: ignore
            LOGGER.info('policy_rule_state({:s})'.format(str(policy_rule_state)))

        except grpc.RpcError as e:
            if e.code() != grpc.StatusCode.NOT_FOUND: raise  # pylint: disable=no-member
            LOGGER.exception('Unable to get Service({:s})'.format(str(request)))
        except grpc.RpcError as ex:
            if ex.code() != grpc.StatusCode.NOT_FOUND: raise  # pylint: disable=no-member
            LOGGER.exception('Unable to create policy({:s})'.format(str(request.policy)))
            context_client.close()
            kpi_manager_client.close()
            policy_client.close()
            telemetry_frontend_client.close()
            return None

        context_client.close()
        kpi_manager_client.close()
        analytics_frontend_client.close()
        policy_client.close()
        telemetry_frontend_client.close()
        return ZSMService()

    def zsmUpdate(self):
        LOGGER.info('Init zsmUpdate method')
        LOGGER.info('zsmUpdate method')

    def zsmDelete(self):
        LOGGER.info('Init zsmDelete method')
    def ZSMGetById(self):
        LOGGER.info('Init ZSMGetById method')
    def ZSMGetByService(self):
        LOGGER.info('Init ZSMGetByService method')
 No newline at end of file
        LOGGER.info('zsmDelete method')

    def zsmGetById(self):
        LOGGER.info('zsmGetById method')

    def zsmGetByService(self):
        LOGGER.info('zsmGetByService method')
+0 −49
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import grpc , logging
from uuid import uuid4
from common.proto.analytics_frontend_pb2 import Analyzer, AnalyzerId
from common.proto.kpi_manager_pb2 import KpiId, KpiDescriptor
from common.proto.policy_pb2 import PolicyRuleService, PolicyRuleState
from common.proto.policy_action_pb2 import PolicyRuleAction, PolicyRuleActionConfig
from common.proto.policy_condition_pb2 import PolicyRuleCondition
from common.proto.telemetry_frontend_pb2 import Collector, CollectorId
from common.proto.automation_pb2 import ZSMCreateRequest, ZSMService, ZSMServiceID, ZSMServiceState, ZSMCreateUpdate

from analytics.frontend.client.AnalyticsFrontendClient import AnalyticsFrontendClient
from automation.client.PolicyClient import PolicyClient
from context.client.ContextClient import ContextClient
from kpi_manager.client.KpiManagerClient import KpiManagerClient
from telemetry.frontend.client.TelemetryFrontendClient import TelemetryFrontendClient

from .ZSMHandler import ZSMHandler

LOGGER = logging.getLogger(__name__)

class Poc2(ZSMHandler):
    def __init__(self):
        LOGGER.info('Init Init Poc2')

    def zsmCreate(self,request : ZSMCreateRequest, context : grpc.ServicerContext):
        LOGGER.info('Init zsmCreate')

    def zsmUpdate(self):
        LOGGER.info('Init zsmUpdate method')
    def zsmDelete(self):
        LOGGER.info('Init zsmDelete method')
    def ZSMGetById(self):
        LOGGER.info('Init ZSMGetById method')
    def ZSMGetByService(self):
        LOGGER.info('Init ZSMGetByService method')
 No newline at end of file
Loading