diff --git a/src/nbi/service/tfs_api/Resources.py b/src/nbi/service/tfs_api/Resources.py index 9e7286c43dd18f7a1d01d99e791e4c0d267b8724..c6a6a8cf2f5d4215c48f6cd1a1a217c6d9f343ec 100644 --- a/src/nbi/service/tfs_api/Resources.py +++ b/src/nbi/service/tfs_api/Resources.py @@ -591,7 +591,7 @@ 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): +class E2EOpticalPathComputation(Resource): def __init__(self): super().__init__() self.e2e_client = E2EOrchestratorClient() @@ -635,3 +635,54 @@ class E2epathcomp(Resource): except Exception as e: LOGGER.error(f"Error calling E2E Orchestrator: {str(e)}", exc_info=True) return {"status": "error", "message": str(e)}, 500 + +class E2EOpticalPathRecomputation(Resource): + def __init__(self): + super().__init__() + self.e2e_client = E2EOrchestratorClient() + + def post(self): + data = request.get_json() + LOGGER.info(f"Received E2E Optical Path Recomputation request: {json.dumps(data, indent=2)}") + + try: + # Construct a Service protobuf to encapsulate the intent for the E2E Orchestrator + service = GrpcService() + 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 + + # Add recompute flag as custom config rule + cr_recompute = ConfigRule() + cr_recompute.action = ConfigActionEnum.CONFIGACTION_SET + cr_recompute.custom.resource_key = "recompute" + cr_recompute.custom.resource_value = "true" + service.service_config.config_rules.append(cr_recompute) + + # 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 recompute 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)}") + return reply_json, 200 + + except Exception as e: + LOGGER.error(f"Error in RecomputeOpticalPath: {str(e)}", exc_info=True) + return {"status": "error", "message": str(e)}, 500 diff --git a/src/nbi/service/tfs_api/__init__.py b/src/nbi/service/tfs_api/__init__.py index 9f01898173f5b589d8cae06dc98e198ad7e0abb2..3291c95bdb131610f033bbb99ba8244aa3bbe581 100644 --- a/src/nbi/service/tfs_api/__init__.py +++ b/src/nbi/service/tfs_api/__init__.py @@ -27,7 +27,7 @@ from .Resources import ( Service, ServiceIds, Services, OpticalServiceAllocation, Slice, SliceIds, Slices, Topologies, Topology, TopologyDetails, TopologyIds, - E2epathcomp + E2EOpticalPathComputation, E2EOpticalPathRecomputation ) @@ -37,7 +37,6 @@ 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'), @@ -85,6 +84,9 @@ _RESOURCES = [ ('api.policyrule_ids', PolicyRuleIds, '/policyrule_ids'), ('api.policyrules', PolicyRules, '/policyrules'), ('api.policyrule', PolicyRule, '/policyrule/'), + + ('api.e2e_optical_path_computation', E2EOpticalPathComputation, '/e2e_optical_path_computation'), + ('api.e2e_optical_path_recomputation', E2EOpticalPathRecomputation,'/e2e_optical_path_recomputation'), ] RESOURCES = [ (ENDPOINT_PREFIX + endpoint_name, resource_class, URL_PREFIX + resource_url)