Skip to content
Snippets Groups Projects
Commit a89e0fe4 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Service component:

- Replaced old local ContextGetters by new Common.Tools.ContextQueries
parent 0e5066f9
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!87Context & Device Performance Enhancements
...@@ -19,12 +19,12 @@ from common.method_wrappers.ServiceExceptions import AlreadyExistsException, Inv ...@@ -19,12 +19,12 @@ from common.method_wrappers.ServiceExceptions import AlreadyExistsException, Inv
from common.proto.context_pb2 import Empty, Service, ServiceId, ServiceStatusEnum, ServiceTypeEnum from common.proto.context_pb2 import Empty, Service, ServiceId, ServiceStatusEnum, ServiceTypeEnum
from common.proto.pathcomp_pb2 import PathCompRequest from common.proto.pathcomp_pb2 import PathCompRequest
from common.proto.service_pb2_grpc import ServiceServiceServicer from common.proto.service_pb2_grpc import ServiceServiceServicer
from common.tools.context_queries.Service import get_service_by_id
from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_string
from context.client.ContextClient import ContextClient from context.client.ContextClient import ContextClient
from pathcomp.frontend.client.PathCompClient import PathCompClient from pathcomp.frontend.client.PathCompClient import PathCompClient
from .service_handler_api.ServiceHandlerFactory import ServiceHandlerFactory from .service_handler_api.ServiceHandlerFactory import ServiceHandlerFactory
from .task_scheduler.TaskScheduler import TasksScheduler from .task_scheduler.TaskScheduler import TasksScheduler
from .tools.ContextGetters import get_service
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
...@@ -69,7 +69,9 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): ...@@ -69,7 +69,9 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
# check that service does not exist # check that service does not exist
context_client = ContextClient() context_client = ContextClient()
current_service = get_service(context_client, request.service_id) current_service = get_service_by_id(
context_client, request.service_id, rw_copy=False,
include_config_rules=False, include_constraints=False, include_endpoint_ids=False)
if current_service is not None: if current_service is not None:
context_uuid = request.service_id.context_id.context_uuid.uuid context_uuid = request.service_id.context_id.context_uuid.uuid
service_uuid = request.service_id.service_uuid.uuid service_uuid = request.service_id.service_uuid.uuid
...@@ -86,7 +88,9 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): ...@@ -86,7 +88,9 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
# Set service status to "SERVICESTATUS_PLANNED" to ensure rest of components are aware the service is # Set service status to "SERVICESTATUS_PLANNED" to ensure rest of components are aware the service is
# being modified. # being modified.
context_client = ContextClient() context_client = ContextClient()
_service : Optional[Service] = get_service(context_client, request.service_id) _service : Optional[Service] = get_service_by_id(
context_client, request.service_id, rw_copy=False,
include_config_rules=False, include_constraints=False, include_endpoint_ids=False)
service = Service() service = Service()
service.CopyFrom(request if _service is None else _service) service.CopyFrom(request if _service is None else _service)
if service.service_type == ServiceTypeEnum.SERVICETYPE_UNKNOWN: # pylint: disable=no-member if service.service_type == ServiceTypeEnum.SERVICETYPE_UNKNOWN: # pylint: disable=no-member
...@@ -106,7 +110,11 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): ...@@ -106,7 +110,11 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
service.service_config.config_rules.add().CopyFrom(config_rule) # pylint: disable=no-member service.service_config.config_rules.add().CopyFrom(config_rule) # pylint: disable=no-member
service_id_with_uuids = context_client.SetService(service) service_id_with_uuids = context_client.SetService(service)
service_with_uuids = context_client.GetService(service_id_with_uuids)
# PathComp requires endpoints, constraints and config rules
service_with_uuids = get_service_by_id(
context_client, service_id_with_uuids, rw_copy=False,
include_config_rules=True, include_constraints=True, include_endpoint_ids=True)
num_disjoint_paths = 0 num_disjoint_paths = 0
for constraint in request.service_constraints: for constraint in request.service_constraints:
...@@ -147,10 +155,8 @@ class ServiceServiceServicerImpl(ServiceServiceServicer): ...@@ -147,10 +155,8 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
# Set service status to "SERVICESTATUS_PENDING_REMOVAL" to ensure rest of components are aware the service is # Set service status to "SERVICESTATUS_PENDING_REMOVAL" to ensure rest of components are aware the service is
# being modified. # being modified.
_service : Optional[Service] = get_service(context_client, request) service : Optional[Service] = get_service_by_id(context_client, request, rw_copy=True)
if _service is None: raise Exception('Service({:s}) not found'.format(grpc_message_to_json_string(request))) if service is None: raise Exception('Service({:s}) not found'.format(grpc_message_to_json_string(request)))
service = Service()
service.CopyFrom(_service)
# pylint: disable=no-member # pylint: disable=no-member
service.service_status.service_status = ServiceStatusEnum.SERVICESTATUS_PENDING_REMOVAL service.service_status.service_status = ServiceStatusEnum.SERVICESTATUS_PENDING_REMOVAL
context_client.SetService(service) context_client.SetService(service)
......
...@@ -17,11 +17,13 @@ from enum import Enum ...@@ -17,11 +17,13 @@ from enum import Enum
from typing import TYPE_CHECKING, Any, Dict, Optional, Union from typing import TYPE_CHECKING, Any, Dict, Optional, Union
from common.method_wrappers.ServiceExceptions import NotFoundException from common.method_wrappers.ServiceExceptions import NotFoundException
from common.proto.context_pb2 import Connection, ConnectionId, Device, DeviceId, Service, ServiceId from common.proto.context_pb2 import Connection, ConnectionId, Device, DeviceId, Service, ServiceId
from common.tools.context_queries.Connection import get_connection_by_id
from common.tools.context_queries.Device import get_device
from common.tools.context_queries.Service import get_service_by_id
from common.tools.object_factory.Device import json_device_id from common.tools.object_factory.Device import json_device_id
from context.client.ContextClient import ContextClient from context.client.ContextClient import ContextClient
from device.client.DeviceClient import DeviceClient from device.client.DeviceClient import DeviceClient
from service.service.service_handler_api.ServiceHandlerFactory import ServiceHandlerFactory, get_service_handler_class from service.service.service_handler_api.ServiceHandlerFactory import ServiceHandlerFactory, get_service_handler_class
from service.service.tools.ContextGetters import get_connection, get_device, get_service
from service.service.tools.ObjectKeys import get_connection_key, get_device_key, get_service_key from service.service.tools.ObjectKeys import get_connection_key, get_device_key, get_service_key
if TYPE_CHECKING: if TYPE_CHECKING:
...@@ -72,7 +74,7 @@ class TaskExecutor: ...@@ -72,7 +74,7 @@ class TaskExecutor:
connection_key = get_connection_key(connection_id) connection_key = get_connection_key(connection_id)
connection = self._load_grpc_object(CacheableObjectType.CONNECTION, connection_key) connection = self._load_grpc_object(CacheableObjectType.CONNECTION, connection_key)
if connection is None: if connection is None:
connection = get_connection(self._context_client, connection_id) connection = get_connection_by_id(self._context_client, connection_id)
if connection is None: raise NotFoundException('Connection', connection_key) if connection is None: raise NotFoundException('Connection', connection_key)
connection : Connection = self._store_editable_grpc_object( connection : Connection = self._store_editable_grpc_object(
CacheableObjectType.CONNECTION, connection_key, Connection, connection) CacheableObjectType.CONNECTION, connection_key, Connection, connection)
...@@ -94,7 +96,7 @@ class TaskExecutor: ...@@ -94,7 +96,7 @@ class TaskExecutor:
device_key = get_device_key(device_id) device_key = get_device_key(device_id)
device = self._load_grpc_object(CacheableObjectType.DEVICE, device_key) device = self._load_grpc_object(CacheableObjectType.DEVICE, device_key)
if device is None: if device is None:
device = get_device(self._context_client, device_id) device = get_device(self._context_client, device_id.device_uuid.uuid)
if device is None: raise NotFoundException('Device', device_key) if device is None: raise NotFoundException('Device', device_key)
device : Device = self._store_editable_grpc_object( device : Device = self._store_editable_grpc_object(
CacheableObjectType.DEVICE, device_key, Device, device) CacheableObjectType.DEVICE, device_key, Device, device)
...@@ -145,7 +147,7 @@ class TaskExecutor: ...@@ -145,7 +147,7 @@ class TaskExecutor:
service_key = get_service_key(service_id) service_key = get_service_key(service_id)
service = self._load_grpc_object(CacheableObjectType.SERVICE, service_key) service = self._load_grpc_object(CacheableObjectType.SERVICE, service_key)
if service is None: if service is None:
service = get_service(self._context_client, service_id) service = get_service_by_id(self._context_client, service_id)
if service is None: raise NotFoundException('Service', service_key) if service is None: raise NotFoundException('Service', service_key)
service : service = self._store_editable_grpc_object( service : service = self._store_editable_grpc_object(
CacheableObjectType.SERVICE, service_key, Service, service) CacheableObjectType.SERVICE, service_key, Service, service)
......
# 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.
import grpc
from typing import Optional
from common.proto.context_pb2 import Connection, ConnectionId, Device, DeviceId, Service, ServiceId
from context.client.ContextClient import ContextClient
def get_connection(context_client : ContextClient, connection_id : ConnectionId) -> Optional[Connection]:
try:
connection : Connection = context_client.GetConnection(connection_id)
return connection
except grpc.RpcError as e:
if e.code() != grpc.StatusCode.NOT_FOUND: raise # pylint: disable=no-member
return None
def get_device(context_client : ContextClient, device_id : DeviceId) -> Optional[Device]:
try:
device : Device = context_client.GetDevice(device_id)
return device
except grpc.RpcError as e:
if e.code() != grpc.StatusCode.NOT_FOUND: raise # pylint: disable=no-member
return None
def get_service(context_client : ContextClient, service_id : ServiceId) -> Optional[Service]:
try:
service : Service = context_client.GetService(service_id)
return service
except grpc.RpcError as e:
if e.code() != grpc.StatusCode.NOT_FOUND: raise # pylint: disable=no-member
return None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment