def get_extend_lease_request(self, authority: ABCAuthority, delegation: ABCDelegation, request: ABCAuthorityReservation): req_start = authority.get_actor_clock().cycle_start_date(cycle=self.TicketStartCycle) req_new_start = authority.get_actor_clock().cycle_start_date(cycle=self.TicketEndCycle + 1) req_end = authority.get_actor_clock().cycle_end_date(cycle=self.TicketNewEndCycle) req_term = Term(start=req_start, end=req_end, new_start=req_new_start) rtype = ResourceType(resource_type=request.get_requested_resources().get_sliver().resource_type.name) ticket = self.get_ticket(self.TicketUnits, rtype, req_term, delegation, authority) new_request = self.get_request_from_request(request, req_term, ticket) return new_request
def assign( self, *, reservation: ABCAuthorityReservation, delegation_name: str, graph_node: BaseSliver, existing_reservations: List[ABCReservationMixin]) -> ResourceSet: """ Assign a reservation :param reservation: reservation :param delegation_name: Name of delegation serving the request :param graph_node: ARM Graph Node serving the reservation :param existing_reservations: Existing Reservations served by the same ARM node :return: ResourceSet with updated sliver annotated with properties :raises: AuthorityException in case the request cannot be satisfied """ reservation.set_send_with_deficit(value=True) requested = reservation.get_requested_resources().get_sliver() self.__dump_sliver(sliver=requested) if not isinstance(requested, NetworkServiceSliver): raise AuthorityException( f"Invalid resource type {requested.get_type()}") current = reservation.get_resources() resource_type = ResourceType(resource_type=str(requested.get_type())) gained = None lost = None if current is None: self.logger.debug("check if sliver can be provisioned") # FIXME Add validation to check ticketed sliver against ARM # Refer Network Node Control for reference self.logger.debug( f"Slice properties: {reservation.get_slice().get_config_properties()}" ) unit = Unit( rid=reservation.get_reservation_id(), slice_id=reservation.get_slice_id(), actor_id=self.authority.get_guid(), sliver=requested, rtype=resource_type, properties=reservation.get_slice().get_config_properties()) gained = UnitSet(plugin=self.authority.get_plugin(), units={unit.reservation_id: unit}) else: # FIXME: handle modify self.logger.info( f"Extend Lease for now, no modify supported res# {reservation}" ) return current result = ResourceSet(gained=gained, lost=lost, rtype=resource_type) result.set_sliver(sliver=requested) return result
def assign( self, *, reservation: ABCAuthorityReservation, delegation_name: str, graph_node: BaseSliver, existing_reservations: List[ABCReservationMixin]) -> ResourceSet: """ Assign a reservation :param reservation: reservation :param delegation_name: Name of delegation serving the request :param graph_node: ARM Graph Node serving the reservation :param existing_reservations: Existing Reservations served by the same ARM node :return: ResourceSet with updated sliver annotated with properties :raises: AuthorityException in case the request cannot be satisfied """ if graph_node.capacity_delegations is None or reservation is None: raise AuthorityException(Constants.INVALID_ARGUMENT) delegated_capacities = graph_node.get_capacity_delegations() available_delegated_capacity = FimHelper.get_delegation( delegated_capacities=delegated_capacities, delegation_name=delegation_name) if available_delegated_capacity is None: raise AuthorityException( f"Allocated node {graph_node.node_id} does not have delegation: {delegation_name}" ) reservation.set_send_with_deficit(value=True) requested = reservation.get_requested_resources().get_sliver() if not isinstance(requested, NodeSliver): raise AuthorityException( f"Invalid resource type {requested.get_type()}") current = reservation.get_resources() resource_type = ResourceType(resource_type=str(requested.get_type())) gained = None lost = None if current is None: # Check if Capacities can be satisfied by Delegated Capacities self.__check_capacities( rid=reservation.get_reservation_id(), requested_capacities=requested.get_capacity_allocations(), available_capacities=available_delegated_capacity, existing_reservations=existing_reservations) # Check if Capacities can be satisfied by Capacities self.__check_capacities( rid=reservation.get_reservation_id(), requested_capacities=requested.get_capacity_allocations(), available_capacities=graph_node.get_capacities(), existing_reservations=existing_reservations) # Check components # Check if Components can be allocated if requested.attached_components_info is not None: self.__check_components( rid=reservation.get_reservation_id(), requested_components=requested.attached_components_info, graph_node=graph_node, existing_reservations=existing_reservations) self.logger.debug( f"Slice properties: {reservation.get_slice().get_config_properties()}" ) unit = Unit( rid=reservation.get_reservation_id(), slice_id=reservation.get_slice_id(), actor_id=self.authority.get_guid(), sliver=requested, rtype=resource_type, properties=reservation.get_slice().get_config_properties()) gained = UnitSet(plugin=self.authority.get_plugin(), units={unit.reservation_id: unit}) else: # FIX ME: handle modify self.logger.info( f"Extend Lease for now, no modify supported res# {reservation}" ) return current result = ResourceSet(gained=gained, lost=lost, rtype=resource_type) result.set_sliver(sliver=requested) return result
def assign_reservation(self, *, reservation: ABCAuthorityReservation, node_id_to_reservations: dict): """ Assign resources for the given reservation @params reservation the request @params node_id_to_reservations node_id_to_reservations @returns a set of resources for the request @raises Exception in case of error """ requested = reservation.get_requested_resources() rtype = requested.get_type() rc = self.get_control_by_type(rtype=rtype) if rc is not None: try: ticketed_sliver = requested.get_sliver() node_id = ticketed_sliver.get_node_map()[1] self.logger.debug( f"node_id {node_id} serving reservation# {reservation}") if node_id is None: raise AuthorityException( f"Unable to find node_id {node_id} for reservation# {reservation}" ) graph_node = None if isinstance(ticketed_sliver, NodeSliver): graph_node = self.get_network_node_from_graph( node_id=node_id) elif isinstance(ticketed_sliver, NetworkServiceSliver): graph_node = self.get_network_service_from_graph( node_id=node_id) else: msg = f'Reservation {reservation} sliver type is neither Node, nor NetworkServiceSliver' self.logger.error(msg) raise AuthorityException(msg) self.logger.debug( f"Node {graph_node} serving reservation# {reservation}") existing_reservations = self.get_existing_reservations( node_id=node_id, node_id_to_reservations=node_id_to_reservations) delegation_name, broker_callback = self.get_delegation_name_and_callback( delegation_id=requested.get_resources().get_delegation_id( )) rset = rc.assign(reservation=reservation, delegation_name=delegation_name, graph_node=graph_node, existing_reservations=existing_reservations) if rset is None or rset.get_sliver( ) is None or rset.get_sliver().get_node_map() is None: raise AuthorityException( f"Could not assign resources to reservation# {reservation}" ) reservation.set_broker_callback( broker_callback=broker_callback) return rset except Exception as e: self.logger.error(traceback.format_exc()) self.logger.error(f"Could not assign {e}") return None else: raise AuthorityException( Constants.UNSUPPORTED_RESOURCE_TYPE.format( reservation.get_type()))