From 9c62d1450711910b1ebb841bbf6fbe15e4deb3a8 Mon Sep 17 00:00:00 2001 From: Komal Thareja Date: Tue, 5 Nov 2024 15:10:39 -0500 Subject: [PATCH] Add slivers only after lease time has been computed --- .../core/advance_scheduling_thread.py | 22 ++++++++++++++---- .../orchestrator/core/orchestrator_handler.py | 23 +++++++++++-------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/fabric_cf/orchestrator/core/advance_scheduling_thread.py b/fabric_cf/orchestrator/core/advance_scheduling_thread.py index f5a55126..3265e0de 100644 --- a/fabric_cf/orchestrator/core/advance_scheduling_thread.py +++ b/fabric_cf/orchestrator/core/advance_scheduling_thread.py @@ -149,29 +149,41 @@ def run(self): def process_slice(self, *, controller_slice: OrchestratorSliceWrapper): """ - Determine nearest start time + Determine nearest start time for a slice requested in future and + add to deferred slice thread for further processing :param controller_slice: - :param lease_start_time: Lease Start Time (UTC) - :param lease_end_time: Lease End Time (UTC) - :param lifetime: Lifetime of the slice in hours """ computed_reservations = controller_slice.get_computed_reservations() try: controller_slice.lock() + + # Determine nearest start time in the time range requested + # If not found, start time specified in the request is used as start resulting in slice failing + # with insufficient resources error future_start, future_end = self.kernel.determine_future_lease_time( computed_reservations=computed_reservations, start=controller_slice.start, end=controller_slice.end, duration=controller_slice.lifetime) + self.logger.debug(f"Slice: {controller_slice.slice_obj.slice_name}/{controller_slice.slice_obj.get_slice_id()}" + f" Start Time: {future_start} End: {future_end}") + + # Update slice start/end time controller_slice.slice_obj.set_lease_start(lease_start=future_start) controller_slice.slice_obj.set_lease_end(lease_end=future_end) self.logger.debug(f"Update Slice {controller_slice.slice_obj.slice_name}") self.mgmt_actor.update_slice(slice_obj=controller_slice.slice_obj) + + # Update the reservations start/end time for r in computed_reservations: r.set_start(value=ActorClock.to_milliseconds(when=future_start)) r.set_end(value=ActorClock.to_milliseconds(when=future_end)) - self.mgmt_actor.update_reservation(reservation=r) + + # Add Reservations to relational database; + controller_slice.add_reservations() + + # Queue the slice to be demanded on Slice Defer Thread self.kernel.get_defer_thread().queue_slice(controller_slice=controller_slice) except Exception as e: self.logger.error(traceback.format_exc()) diff --git a/fabric_cf/orchestrator/core/orchestrator_handler.py b/fabric_cf/orchestrator/core/orchestrator_handler.py index ce2060b8..ef50ac66 100644 --- a/fabric_cf/orchestrator/core/orchestrator_handler.py +++ b/fabric_cf/orchestrator/core/orchestrator_handler.py @@ -342,20 +342,23 @@ def create_slice(self, *, token: str, slice_name: str, slice_graph: str, ssh_key r.set_end(value=ActorClock.to_milliseconds(when=future_end)) ''' - # Add Reservations to relational database; - new_slice_object.add_reservations() - - self.logger.info(f"OC wrapper: TIME= {time.time() - create_ts:.0f}") - - # Enqueue the slice on the demand thread - # Demand thread is responsible for demanding the reservations - # Helps improve the create response time create_ts = time.time() if lease_start_time and lease_end_time and lifetime: - self.controller_state.get_advance_scheduling_thread().queue_slice(controller_slice=controller) + # Enqueue future slices on Advanced Scheduling Thread to determine possible start time + # Determining start time may take time so this is done asynchronously to avoid increasing response time + # of create slice API + self.controller_state.get_advance_scheduling_thread().queue_slice(controller_slice=new_slice_object) else: + # Enqueue the slice on the demand thread + # Demand thread is responsible for demanding the reservations + # Helps improve the create response time + + # Add Reservations to relational database; + new_slice_object.add_reservations() + self.logger.info(f"OC wrapper: TIME= {time.time() - create_ts:.0f}") self.controller_state.get_defer_thread().queue_slice(controller_slice=new_slice_object) - self.logger.info(f"QU queue: TIME= {time.time() - create_ts:.0f}") + self.logger.info(f"QU queue: TIME= {time.time() - create_ts:.0f}") + EventLoggerSingleton.get().log_slice_event(slice_object=slice_obj, action=ActionId.create, topology=topology)