Commit cbc8dde4 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'feat/325-tid-nbi-e2e-to-manage-e2e-path-computation' into 'develop'

Resolve "(TID) NBI E2E to manage E2E path computation"

See merge request !388
parents e9863e69 78af2c96
Loading
Loading
Loading
Loading
+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'),