diff --git a/proto/automation.proto b/proto/automation.proto index 95e777f364ab0b4c3cdc9cf89293d0df64b8b3ef..80ca0b7b9383ed2a248c04abdcb95e1bb24e29bf 100644 --- a/proto/automation.proto +++ b/proto/automation.proto @@ -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; } diff --git a/src/automation/service/zsm_handler_api/ZSMFilterFields.py b/src/automation/service/zsm_handler_api/ZSMFilterFields.py index c2a6270544f1c8f8784a0d8ed5e330ad9e1445fa..7b00de5bc474f8ac4a6a711acf9f7200723ddaae 100644 --- a/src/automation/service/zsm_handler_api/ZSMFilterFields.py +++ b/src/automation/service/zsm_handler_api/ZSMFilterFields.py @@ -1,4 +1,4 @@ -# 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, diff --git a/src/automation/service/zsm_handlers/ZSMHandler.py b/src/automation/service/zsm_handler_api/ZSMHandler.py similarity index 64% rename from src/automation/service/zsm_handlers/ZSMHandler.py rename to src/automation/service/zsm_handler_api/ZSMHandler.py index b364eeaabdbd38f69ef25d5c29dbcef34e949196..165489793cc91bf07cf7c7a281fed979819120b1 100644 --- a/src/automation/service/zsm_handlers/ZSMHandler.py +++ b/src/automation/service/zsm_handler_api/ZSMHandler.py @@ -1,4 +1,4 @@ -# 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. @@ -21,13 +21,17 @@ class ZSMHandler: def __init__(self): LOGGER.info('Init Scenario') - def zsmCreate(self,request : ZSMCreateRequest, context : grpc.ServicerContext): - LOGGER.info('Init zsmCreate method') + def zsmCreate(self, request : ZSMCreateRequest, context : grpc.ServicerContext): + 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') diff --git a/src/automation/service/zsm_handlers/P4INTZSMPlugin.py b/src/automation/service/zsm_handlers/P4INTZSMPlugin.py index 152b381cb901b0ecf6a5c058fdd6a3a6b9c85f6a..d70ef513cdd52976903bab7872336ef4567616bd 100644 --- a/src/automation/service/zsm_handlers/P4INTZSMPlugin.py +++ b/src/automation/service/zsm_handlers/P4INTZSMPlugin.py @@ -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') diff --git a/src/automation/service/zsm_handlers/Poc2.py b/src/automation/service/zsm_handlers/Poc2.py deleted file mode 100644 index cec1f2dca2ca2861565806b1889bbbc178e5fe32..0000000000000000000000000000000000000000 --- a/src/automation/service/zsm_handlers/Poc2.py +++ /dev/null @@ -1,49 +0,0 @@ -# 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 diff --git a/src/automation/service/zsm_handlers/__init__.py b/src/automation/service/zsm_handlers/__init__.py index 6c42c6ec76575c99f17e6977622d8177d9466072..cf26eaa10fe838db5fc72ba76c298975a7a6ce5a 100644 --- a/src/automation/service/zsm_handlers/__init__.py +++ b/src/automation/service/zsm_handlers/__init__.py @@ -12,10 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from common.proto.context_pb2 import DeviceDriverEnum, ServiceTypeEnum +from common.proto.context_pb2 import ServiceTypeEnum from ..zsm_handler_api.ZSMFilterFields import ZSMFilterFieldEnum -from .P4INTZSMPlugin import P4INTZSMPlugin -from .Poc2 import Poc2 +from src.automation.service.zsm_handlers.P4INTZSMPlugin import P4INTZSMPlugin ZSM_SERVICE_HANDLERS = [ (P4INTZSMPlugin, [ @@ -24,5 +23,4 @@ ZSM_SERVICE_HANDLERS = [ ZSMFilterFieldEnum.TELEMETRY_SERVICE_TYPE : ServiceTypeEnum.SERVICETYPE_INT, } ]) - ]