Commit c4aead19 authored by Pablo Armingol's avatar Pablo Armingol
Browse files

Merge branch 'develop' of https://labs.etsi.org/rep/tfs/controller into...

Merge branch 'develop' of https://labs.etsi.org/rep/tfs/controller into feat/264-tid-nbi-fot-sap-topology
parents 7ed17e45 e2b02e46
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -82,6 +82,9 @@ COPY src/context/client/. context/client/
COPY src/context/service/database/uuids/. context/service/database/uuids/
COPY src/service/__init__.py service/__init__.py
COPY src/service/client/. service/client/
COPY src/pathcomp/__init__.py pathcomp/__init__.py
COPY src/pathcomp/frontend/__init__.py pathcomp/frontend/__init__.py
COPY src/pathcomp/frontend/client/. pathcomp/frontend/client/
COPY src/e2e_orchestrator/. e2e_orchestrator/

# Start the service
+15 −0
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ from common.proto.context_pb2 import Empty, Connection, EndPointId
from common.proto.e2eorchestrator_pb2_grpc import E2EOrchestratorServiceServicer
from context.client.ContextClient import ContextClient
from context.service.database.uuids.EndPoint import endpoint_get_uuid
from common.proto.context_pb2 import ServiceTypeEnum
from pathcomp.frontend.client.PathCompClient import PathCompClient
from common.proto.pathcomp_pb2 import PathCompRequest

LOGGER = logging.getLogger(__name__)

@@ -33,6 +36,18 @@ class E2EOrchestratorServiceServicerImpl(E2EOrchestratorServiceServicer):
    def Compute(
        self, request: E2EOrchestratorRequest, context: grpc.ServicerContext
    ) -> E2EOrchestratorReply:
        if request.service.service_type == ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY:
            LOGGER.info("E2E Orchestrator: Detected OPTICAL_CONNECTIVITY service. Calling PathComp.")
            pathcomp_client = PathCompClient()
            pathcomp_req = PathCompRequest()
            pathcomp_req.services.append(request.service)
            pathcomp_reply = pathcomp_client.Compute(pathcomp_req)
            
            e2e_reply = E2EOrchestratorReply()
            e2e_reply.services.extend(pathcomp_reply.services)
            e2e_reply.connections.extend(pathcomp_reply.connections)
            return e2e_reply

        endpoints_ids = [
            endpoint_get_uuid(endpoint_id)[2]
            for endpoint_id in request.service.service_endpoint_ids
+4 −0
Original line number Diff line number Diff line
@@ -92,6 +92,10 @@ COPY src/slice/__init__.py slice/__init__.py
COPY src/slice/client/. slice/client/
COPY src/vnt_manager/__init__.py vnt_manager/__init__.py
COPY src/vnt_manager/client/. vnt_manager/client/

COPY src/e2e_orchestrator/. e2e_orchestrator/__init__.py
COPY src/e2e_orchestrator/client/. e2e_orchestrator/client/

RUN mkdir -p /var/teraflow/tests/tools
COPY src/tests/tools/mock_osm/. tests/tools/mock_osm/
COPY src/nbi/. nbi/
+49 −1
Original line number Diff line number Diff line
@@ -18,15 +18,18 @@ from typing import Dict, List
from flask.json import jsonify
from flask_restful import Resource, request
from werkzeug.exceptions import BadRequest
from common.proto.context_pb2 import Empty, LinkTypeEnum
from common.proto.context_pb2 import Empty, LinkTypeEnum, Service, ServiceTypeEnum, ConfigActionEnum, ConfigRule
from common.proto.e2eorchestrator_pb2 import E2EOrchestratorRequest
from common.tools.descriptor.Tools import format_device_custom_config_rules, format_service_custom_config_rules
from common.tools.grpc.Tools import grpc_message_to_json
from context.client.ContextClient import ContextClient
from device.client.DeviceClient import DeviceClient
from e2e_orchestrator.client.E2EOrchestratorClient import E2EOrchestratorClient
from service.client.ServiceClient import ServiceClient
from slice.client.SliceClient import SliceClient
from vnt_manager.client.VNTManagerClient import VNTManagerClient


from .Tools import (
    format_grpc_to_json, grpc_connection_id, grpc_context, grpc_context_id, grpc_device,
    grpc_device_id, grpc_link, grpc_link_id, grpc_policy_rule_id,
@@ -368,3 +371,48 @@ class PolicyRules(_Resource):
class PolicyRule(_Resource):
    def get(self, policy_rule_uuid : str):
        return format_grpc_to_json(self.context_client.GetPolicyRule(grpc_policy_rule_id(policy_rule_uuid)))

class E2epathcomp(Resource):
    def __init__(self):
        super().__init__()
        self.e2e_client = E2EOrchestratorClient()

    def post(self):
        data = request.get_json()
        LOGGER.info(f"Received E2E Optical Path Computation request: {json.dumps(data, indent=2)}")

        try:
            # Construct a Service protobuf to encapsulate the intent for the E2E Orchestrator
            service = Service()
            service.service_id.service_uuid.uuid = "e2e-optical-service"
            service.service_id.context_id.context_uuid.uuid = "admin"
            service.service_type = ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY
            
            # Pack the original JSON payload into a config rule so E2E Orchestrator and PathComp can access it
            config_rule = ConfigRule()
            config_rule.action = ConfigActionEnum.CONFIGACTION_SET
            config_rule.custom.resource_key = "intent"
            config_rule.custom.resource_value = json.dumps(data)
            service.service_config.config_rules.append(config_rule)

            req = E2EOrchestratorRequest(service=service)
            
            LOGGER.info("Sending request to E2E Orchestrator Compute...")
            reply = self.e2e_client.Compute(req)
            
            reply_json = grpc_message_to_json(reply)
            
            # Check if there is an optical_path_result injected by PathComp
            if reply.services:
                for cr in reply.services[0].service_config.config_rules:
                    if cr.WhichOneof('config_rule') == 'custom' and cr.custom.resource_key == "optical_path_result":
                        LOGGER.info("Found optical_path_result, returning it directly.")
                        return json.loads(cr.custom.resource_value), 200

            LOGGER.info(f"Received reply from E2E Orchestrator: {json.dumps(reply_json)}")
            # The NBI returns the standard protobuf JSON response if no custom result is found
            return reply_json, 200

        except Exception as e:
            LOGGER.error(f"Error calling E2E Orchestrator: {str(e)}", exc_info=True)
            return {"status": "error", "message": str(e)}, 500
+4 −1
Original line number Diff line number Diff line
@@ -23,15 +23,18 @@ from .Resources import (
    PolicyRule, PolicyRuleIds, PolicyRules,
    Service, ServiceIds, Services,
    Slice, SliceIds, Slices,
    Topologies, Topology, TopologyDetails, TopologyIds
    Topologies, Topology, TopologyDetails, TopologyIds,
    E2epathcomp
)
 

ENDPOINT_PREFIX = 'tfs_api.'
URL_PREFIX = '/tfs-api'

# Use 'path' type since some identifiers might contain char '/' and Flask is unable to recognize them in 'string' type.
_RESOURCES = [
    # (endpoint_name, resource_class, resource_url)
    ('api.e2e_path_computation', E2epathcomp, '/e2e_path_computation'),
    ('api.context_ids',      ContextIds,      '/context_ids'),
    ('api.contexts',         Contexts,        '/contexts'),
    ('api.dummy_contexts',   DummyContexts,   '/dummy_contexts'),
Loading