Loading src/common/Constants.py +1 −2 Original line number Original line Diff line number Diff line Loading @@ -83,7 +83,6 @@ DEFAULT_SERVICE_HTTP_PORTS = { # Default HTTP/REST-API service base URLs # Default HTTP/REST-API service base URLs DEFAULT_SERVICE_HTTP_BASEURLS = { DEFAULT_SERVICE_HTTP_BASEURLS = { ServiceNameEnum.CONTEXT .value : '/api', ServiceNameEnum.COMPUTE .value : '/restconf', ServiceNameEnum.COMPUTE .value : '/restconf/data', ServiceNameEnum.WEBUI .value : None, ServiceNameEnum.WEBUI .value : None, } } src/common/tools/descriptor/Loader.py +27 −9 Original line number Original line Diff line number Diff line Loading @@ -31,8 +31,8 @@ # for message,level in compose_notifications(results): # for message,level in compose_notifications(results): # loggers.get(level)(message) # loggers.get(level)(message) import json import concurrent.futures, json, logging, operator from typing import Dict, List, Optional, Tuple, Union from typing import Any, Dict, List, Optional, Tuple, Union from common.proto.context_pb2 import Connection, Context, Device, Link, Service, Slice, Topology from common.proto.context_pb2 import Connection, Context, Device, Link, Service, Slice, Topology from context.client.ContextClient import ContextClient from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from device.client.DeviceClient import DeviceClient Loading @@ -43,6 +43,8 @@ from .Tools import ( get_descriptors_add_contexts, get_descriptors_add_services, get_descriptors_add_slices, get_descriptors_add_contexts, get_descriptors_add_services, get_descriptors_add_slices, get_descriptors_add_topologies, split_devices_by_rules) get_descriptors_add_topologies, split_devices_by_rules) LOGGER = logging.getLogger(__name__) ENTITY_TO_TEXT = { ENTITY_TO_TEXT = { # name => singular, plural # name => singular, plural 'context' : ('Context', 'Contexts' ), 'context' : ('Context', 'Contexts' ), Loading Loading @@ -79,7 +81,7 @@ def compose_notifications(results : TypeResults) -> TypeNotificationList: class DescriptorLoader: class DescriptorLoader: def __init__( def __init__( self, descriptors : Union[str, Dict], self, descriptors : Union[str, Dict], num_workers : int = 1, context_client : Optional[ContextClient] = None, device_client : Optional[DeviceClient] = None, context_client : Optional[ContextClient] = None, device_client : Optional[DeviceClient] = None, service_client : Optional[ServiceClient] = None, slice_client : Optional[SliceClient] = None service_client : Optional[ServiceClient] = None, slice_client : Optional[SliceClient] = None ) -> None: ) -> None: Loading @@ -93,6 +95,8 @@ class DescriptorLoader: self.__slices = self.__descriptors.get('slices' , []) self.__slices = self.__descriptors.get('slices' , []) self.__connections = self.__descriptors.get('connections', []) self.__connections = self.__descriptors.get('connections', []) self.__num_workers = num_workers self.__contexts_add = None self.__contexts_add = None self.__topologies_add = None self.__topologies_add = None self.__devices_add = None self.__devices_add = None Loading Loading @@ -242,12 +246,26 @@ class DescriptorLoader: #self.__dev_cli.close() #self.__dev_cli.close() #self.__ctx_cli.close() #self.__ctx_cli.close() @staticmethod def worker(grpc_method, grpc_class, entity) -> Any: return grpc_method(grpc_class(**entity)) def _process_descr(self, entity_name, action_name, grpc_method, grpc_class, entities) -> None: def _process_descr(self, entity_name, action_name, grpc_method, grpc_class, entities) -> None: num_ok, error_list = 0, [] num_ok, error_list = 0, [] for entity in entities: with concurrent.futures.ThreadPoolExecutor(max_workers=self.__num_workers) as executor: future_to_entity = { executor.submit(DescriptorLoader.worker, grpc_method, grpc_class, entity): (i, entity) for i,entity in enumerate(entities) } for future in concurrent.futures.as_completed(future_to_entity): i, entity = future_to_entity[future] try: try: grpc_method(grpc_class(**entity)) _ = future.result() num_ok += 1 num_ok += 1 except Exception as e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except error_list.append(f'{str(entity)}: {str(e)}') error_list.append((i, f'{str(entity)}: {str(e)}')) error_list = [str_error for _,str_error in sorted(error_list, key=operator.itemgetter(0))] self.__results.append((entity_name, action_name, num_ok, error_list)) self.__results.append((entity_name, action_name, num_ok, error_list)) src/compute/service/__main__.py +1 −1 Original line number Original line Diff line number Diff line Loading @@ -27,7 +27,7 @@ from .rest_server.nbi_plugins.ietf_network_slice import register_ietf_nss terminate = threading.Event() terminate = threading.Event() LOGGER = None LOGGER = None def signal_handler(signal, frame): # pylint: disable=redefined-outer-name def signal_handler(signal, frame): # pylint: disable=redefined-outer-name, unused-argument LOGGER.warning('Terminate signal received') LOGGER.warning('Terminate signal received') terminate.set() terminate.set() Loading src/compute/service/rest_server/nbi_plugins/debug_api/Resources.py +4 −40 Original line number Original line Diff line number Diff line Loading @@ -12,48 +12,12 @@ # 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. from flask.json import jsonify from flask_restful import Resource from flask_restful import Resource from common.proto.context_pb2 import ConnectionId, ContextId, DeviceId, Empty, LinkId, ServiceId, SliceId, TopologyId from common.proto.context_pb2 import Empty from common.proto.policy_pb2 import PolicyRuleId from common.tools.grpc.Tools import grpc_message_to_json from common.tools.object_factory.Connection import json_connection_id 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.Link import json_link_id from common.tools.object_factory.PolicyRule import json_policyrule_id from common.tools.object_factory.Service import json_service_id from common.tools.object_factory.Slice import json_slice_id from common.tools.object_factory.Topology import json_topology_id from context.client.ContextClient import ContextClient from context.client.ContextClient import ContextClient from .Tools import ( format_grpc_to_json, grpc_connection_id, grpc_context_id, grpc_device_id, grpc_link_id, grpc_policy_rule_id, def format_grpc_to_json(grpc_reply): grpc_service_id, grpc_slice_id, grpc_topology_id) return jsonify(grpc_message_to_json(grpc_reply)) def grpc_connection_id(connection_uuid): return ConnectionId(**json_connection_id(connection_uuid)) def grpc_context_id(context_uuid): return ContextId(**json_context_id(context_uuid)) def grpc_device_id(device_uuid): return DeviceId(**json_device_id(device_uuid)) def grpc_link_id(link_uuid): return LinkId(**json_link_id(link_uuid)) def grpc_service_id(context_uuid, service_uuid): return ServiceId(**json_service_id(service_uuid, context_id=json_context_id(context_uuid))) def grpc_slice_id(context_uuid, slice_uuid): return SliceId(**json_slice_id(slice_uuid, context_id=json_context_id(context_uuid))) def grpc_topology_id(context_uuid, topology_uuid): return TopologyId(**json_topology_id(topology_uuid, context_id=json_context_id(context_uuid))) def grpc_policy_rule_id(policy_rule_uuid): return PolicyRuleId(**json_policyrule_id(policy_rule_uuid)) class _Resource(Resource): class _Resource(Resource): Loading src/compute/service/rest_server/nbi_plugins/debug_api/Tools.py 0 → 100644 +54 −0 Original line number Original line Diff line number Diff line # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (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. from flask.json import jsonify from common.proto.context_pb2 import ConnectionId, ContextId, DeviceId, LinkId, ServiceId, SliceId, TopologyId from common.proto.policy_pb2 import PolicyRuleId from common.tools.grpc.Tools import grpc_message_to_json from common.tools.object_factory.Connection import json_connection_id 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.Link import json_link_id from common.tools.object_factory.PolicyRule import json_policyrule_id from common.tools.object_factory.Service import json_service_id from common.tools.object_factory.Slice import json_slice_id from common.tools.object_factory.Topology import json_topology_id def format_grpc_to_json(grpc_reply): return jsonify(grpc_message_to_json(grpc_reply)) def grpc_connection_id(connection_uuid): return ConnectionId(**json_connection_id(connection_uuid)) def grpc_context_id(context_uuid): return ContextId(**json_context_id(context_uuid)) def grpc_device_id(device_uuid): return DeviceId(**json_device_id(device_uuid)) def grpc_link_id(link_uuid): return LinkId(**json_link_id(link_uuid)) def grpc_service_id(context_uuid, service_uuid): return ServiceId(**json_service_id(service_uuid, context_id=json_context_id(context_uuid))) def grpc_slice_id(context_uuid, slice_uuid): return SliceId(**json_slice_id(slice_uuid, context_id=json_context_id(context_uuid))) def grpc_topology_id(context_uuid, topology_uuid): return TopologyId(**json_topology_id(topology_uuid, context_id=json_context_id(context_uuid))) def grpc_policy_rule_id(policy_rule_uuid): return PolicyRuleId(**json_policyrule_id(policy_rule_uuid)) Loading
src/common/Constants.py +1 −2 Original line number Original line Diff line number Diff line Loading @@ -83,7 +83,6 @@ DEFAULT_SERVICE_HTTP_PORTS = { # Default HTTP/REST-API service base URLs # Default HTTP/REST-API service base URLs DEFAULT_SERVICE_HTTP_BASEURLS = { DEFAULT_SERVICE_HTTP_BASEURLS = { ServiceNameEnum.CONTEXT .value : '/api', ServiceNameEnum.COMPUTE .value : '/restconf', ServiceNameEnum.COMPUTE .value : '/restconf/data', ServiceNameEnum.WEBUI .value : None, ServiceNameEnum.WEBUI .value : None, } }
src/common/tools/descriptor/Loader.py +27 −9 Original line number Original line Diff line number Diff line Loading @@ -31,8 +31,8 @@ # for message,level in compose_notifications(results): # for message,level in compose_notifications(results): # loggers.get(level)(message) # loggers.get(level)(message) import json import concurrent.futures, json, logging, operator from typing import Dict, List, Optional, Tuple, Union from typing import Any, Dict, List, Optional, Tuple, Union from common.proto.context_pb2 import Connection, Context, Device, Link, Service, Slice, Topology from common.proto.context_pb2 import Connection, Context, Device, Link, Service, Slice, Topology from context.client.ContextClient import ContextClient from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient from device.client.DeviceClient import DeviceClient Loading @@ -43,6 +43,8 @@ from .Tools import ( get_descriptors_add_contexts, get_descriptors_add_services, get_descriptors_add_slices, get_descriptors_add_contexts, get_descriptors_add_services, get_descriptors_add_slices, get_descriptors_add_topologies, split_devices_by_rules) get_descriptors_add_topologies, split_devices_by_rules) LOGGER = logging.getLogger(__name__) ENTITY_TO_TEXT = { ENTITY_TO_TEXT = { # name => singular, plural # name => singular, plural 'context' : ('Context', 'Contexts' ), 'context' : ('Context', 'Contexts' ), Loading Loading @@ -79,7 +81,7 @@ def compose_notifications(results : TypeResults) -> TypeNotificationList: class DescriptorLoader: class DescriptorLoader: def __init__( def __init__( self, descriptors : Union[str, Dict], self, descriptors : Union[str, Dict], num_workers : int = 1, context_client : Optional[ContextClient] = None, device_client : Optional[DeviceClient] = None, context_client : Optional[ContextClient] = None, device_client : Optional[DeviceClient] = None, service_client : Optional[ServiceClient] = None, slice_client : Optional[SliceClient] = None service_client : Optional[ServiceClient] = None, slice_client : Optional[SliceClient] = None ) -> None: ) -> None: Loading @@ -93,6 +95,8 @@ class DescriptorLoader: self.__slices = self.__descriptors.get('slices' , []) self.__slices = self.__descriptors.get('slices' , []) self.__connections = self.__descriptors.get('connections', []) self.__connections = self.__descriptors.get('connections', []) self.__num_workers = num_workers self.__contexts_add = None self.__contexts_add = None self.__topologies_add = None self.__topologies_add = None self.__devices_add = None self.__devices_add = None Loading Loading @@ -242,12 +246,26 @@ class DescriptorLoader: #self.__dev_cli.close() #self.__dev_cli.close() #self.__ctx_cli.close() #self.__ctx_cli.close() @staticmethod def worker(grpc_method, grpc_class, entity) -> Any: return grpc_method(grpc_class(**entity)) def _process_descr(self, entity_name, action_name, grpc_method, grpc_class, entities) -> None: def _process_descr(self, entity_name, action_name, grpc_method, grpc_class, entities) -> None: num_ok, error_list = 0, [] num_ok, error_list = 0, [] for entity in entities: with concurrent.futures.ThreadPoolExecutor(max_workers=self.__num_workers) as executor: future_to_entity = { executor.submit(DescriptorLoader.worker, grpc_method, grpc_class, entity): (i, entity) for i,entity in enumerate(entities) } for future in concurrent.futures.as_completed(future_to_entity): i, entity = future_to_entity[future] try: try: grpc_method(grpc_class(**entity)) _ = future.result() num_ok += 1 num_ok += 1 except Exception as e: # pylint: disable=broad-except except Exception as e: # pylint: disable=broad-except error_list.append(f'{str(entity)}: {str(e)}') error_list.append((i, f'{str(entity)}: {str(e)}')) error_list = [str_error for _,str_error in sorted(error_list, key=operator.itemgetter(0))] self.__results.append((entity_name, action_name, num_ok, error_list)) self.__results.append((entity_name, action_name, num_ok, error_list))
src/compute/service/__main__.py +1 −1 Original line number Original line Diff line number Diff line Loading @@ -27,7 +27,7 @@ from .rest_server.nbi_plugins.ietf_network_slice import register_ietf_nss terminate = threading.Event() terminate = threading.Event() LOGGER = None LOGGER = None def signal_handler(signal, frame): # pylint: disable=redefined-outer-name def signal_handler(signal, frame): # pylint: disable=redefined-outer-name, unused-argument LOGGER.warning('Terminate signal received') LOGGER.warning('Terminate signal received') terminate.set() terminate.set() Loading
src/compute/service/rest_server/nbi_plugins/debug_api/Resources.py +4 −40 Original line number Original line Diff line number Diff line Loading @@ -12,48 +12,12 @@ # 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. from flask.json import jsonify from flask_restful import Resource from flask_restful import Resource from common.proto.context_pb2 import ConnectionId, ContextId, DeviceId, Empty, LinkId, ServiceId, SliceId, TopologyId from common.proto.context_pb2 import Empty from common.proto.policy_pb2 import PolicyRuleId from common.tools.grpc.Tools import grpc_message_to_json from common.tools.object_factory.Connection import json_connection_id 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.Link import json_link_id from common.tools.object_factory.PolicyRule import json_policyrule_id from common.tools.object_factory.Service import json_service_id from common.tools.object_factory.Slice import json_slice_id from common.tools.object_factory.Topology import json_topology_id from context.client.ContextClient import ContextClient from context.client.ContextClient import ContextClient from .Tools import ( format_grpc_to_json, grpc_connection_id, grpc_context_id, grpc_device_id, grpc_link_id, grpc_policy_rule_id, def format_grpc_to_json(grpc_reply): grpc_service_id, grpc_slice_id, grpc_topology_id) return jsonify(grpc_message_to_json(grpc_reply)) def grpc_connection_id(connection_uuid): return ConnectionId(**json_connection_id(connection_uuid)) def grpc_context_id(context_uuid): return ContextId(**json_context_id(context_uuid)) def grpc_device_id(device_uuid): return DeviceId(**json_device_id(device_uuid)) def grpc_link_id(link_uuid): return LinkId(**json_link_id(link_uuid)) def grpc_service_id(context_uuid, service_uuid): return ServiceId(**json_service_id(service_uuid, context_id=json_context_id(context_uuid))) def grpc_slice_id(context_uuid, slice_uuid): return SliceId(**json_slice_id(slice_uuid, context_id=json_context_id(context_uuid))) def grpc_topology_id(context_uuid, topology_uuid): return TopologyId(**json_topology_id(topology_uuid, context_id=json_context_id(context_uuid))) def grpc_policy_rule_id(policy_rule_uuid): return PolicyRuleId(**json_policyrule_id(policy_rule_uuid)) class _Resource(Resource): class _Resource(Resource): Loading
src/compute/service/rest_server/nbi_plugins/debug_api/Tools.py 0 → 100644 +54 −0 Original line number Original line Diff line number Diff line # Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (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. from flask.json import jsonify from common.proto.context_pb2 import ConnectionId, ContextId, DeviceId, LinkId, ServiceId, SliceId, TopologyId from common.proto.policy_pb2 import PolicyRuleId from common.tools.grpc.Tools import grpc_message_to_json from common.tools.object_factory.Connection import json_connection_id 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.Link import json_link_id from common.tools.object_factory.PolicyRule import json_policyrule_id from common.tools.object_factory.Service import json_service_id from common.tools.object_factory.Slice import json_slice_id from common.tools.object_factory.Topology import json_topology_id def format_grpc_to_json(grpc_reply): return jsonify(grpc_message_to_json(grpc_reply)) def grpc_connection_id(connection_uuid): return ConnectionId(**json_connection_id(connection_uuid)) def grpc_context_id(context_uuid): return ContextId(**json_context_id(context_uuid)) def grpc_device_id(device_uuid): return DeviceId(**json_device_id(device_uuid)) def grpc_link_id(link_uuid): return LinkId(**json_link_id(link_uuid)) def grpc_service_id(context_uuid, service_uuid): return ServiceId(**json_service_id(service_uuid, context_id=json_context_id(context_uuid))) def grpc_slice_id(context_uuid, slice_uuid): return SliceId(**json_slice_id(slice_uuid, context_id=json_context_id(context_uuid))) def grpc_topology_id(context_uuid, topology_uuid): return TopologyId(**json_topology_id(topology_uuid, context_id=json_context_id(context_uuid))) def grpc_policy_rule_id(policy_rule_uuid): return PolicyRuleId(**json_policyrule_id(policy_rule_uuid))