def pass_authority_reservation(reservation: ABCReservationMixin,
                                   caller: AuthToken) -> ReservationAvro:
        concrete = reservation.get_resources().get_resources()
        if concrete is None:
            raise ProxyException(
                Constants.NOT_SPECIFIED_PREFIX.format("ticket"))

        avro_reservation = ReservationAvro()
        avro_reservation.slice = Translate.translate_slice_to_avro(
            slice_obj=reservation.get_slice())
        avro_reservation.term = Translate.translate_term(
            term=reservation.get_requested_term())
        avro_reservation.reservation_id = str(reservation.get_reservation_id())
        avro_reservation.sequence = reservation.get_lease_sequence_out()

        rset = Translate.translate_resource_set(
            resource_set=reservation.get_resources())

        if concrete is not None and isinstance(concrete, Ticket):
            rset.ticket = Translate.translate_ticket(ticket=concrete)

        if concrete is not None and isinstance(concrete, UnitSet):
            rset.unit_set = Translate.translate_unit_set(unit_set=concrete)

        avro_reservation.resource_set = rset

        return avro_reservation
Example #2
0
    def add_reservation(self, *, reservation: ABCReservationMixin):
        try:
            self.lock.acquire()
            self.logger.debug("Adding reservation {} to slice {}".format(
                reservation.get_reservation_id(), reservation.get_slice()))
            properties = pickle.dumps(reservation)
            oidc_claim_sub = None
            email = None
            if reservation.get_slice() is not None and reservation.get_slice(
            ).get_owner() is not None:
                oidc_claim_sub = reservation.get_slice().get_owner(
                ).get_oidc_sub_claim()
                email = reservation.get_slice().get_owner().get_email()

            self.db.add_reservation(
                slc_guid=str(reservation.get_slice_id()),
                rsv_resid=str(reservation.get_reservation_id()),
                rsv_category=reservation.get_category().value,
                rsv_state=reservation.get_state().value,
                rsv_pending=reservation.get_pending_state().value,
                rsv_joining=reservation.get_join_state().value,
                properties=properties,
                rsv_graph_node_id=reservation.get_graph_node_id(),
                oidc_claim_sub=oidc_claim_sub,
                email=email)
            self.logger.debug("Reservation {} added to slice {}".format(
                reservation.get_reservation_id(), reservation.get_slice()))
        finally:
            self.lock.release()
Example #3
0
 def update_reservation(self, *, reservation: ABCReservationMixin):
     # Update the reservation only when there are changes to be reflected in database
     if not reservation.is_dirty():
         return
     reservation.clear_dirty()
     try:
         self.lock.acquire()
         self.logger.debug("Updating reservation {} in slice {}".format(
             reservation.get_reservation_id(), reservation.get_slice()))
         properties = pickle.dumps(reservation)
         self.db.update_reservation(
             slc_guid=str(reservation.get_slice_id()),
             rsv_resid=str(reservation.get_reservation_id()),
             rsv_category=reservation.get_category().value,
             rsv_state=reservation.get_state().value,
             rsv_pending=reservation.get_pending_state().value,
             rsv_joining=reservation.get_join_state().value,
             properties=properties,
             rsv_graph_node_id=reservation.get_graph_node_id())
     finally:
         self.lock.release()
    def pass_broker_reservation(reservation: ABCReservationMixin, auth: AuthToken) -> ReservationAvro:
        avro_reservation = ReservationAvro()
        avro_reservation.slice = Translate.translate_slice_to_avro(slice_obj=reservation.get_slice())
        avro_reservation.term = Translate.translate_term(term=reservation.get_requested_term())
        avro_reservation.reservation_id = str(reservation.get_reservation_id())
        avro_reservation.sequence = reservation.get_ticket_sequence_out()

        rset = Translate.translate_resource_set(resource_set=reservation.get_requested_resources())

        if reservation.get_requested_resources() is not None:
            cset = reservation.get_requested_resources().get_resources()

            if cset is not None and isinstance(cset, Ticket):
                rset.ticket = Translate.translate_ticket(ticket=cset)

            if cset is not None and isinstance(cset, UnitSet):
                rset.units = Translate.translate_unit_set(unit_set=cset)

        avro_reservation.resource_set = rset

        return avro_reservation
    def validate(*,
                 reservation: ABCReservationMixin,
                 check_requested: bool = False):
        if reservation is None:
            raise RPCException(
                message=Constants.NOT_SPECIFIED_PREFIX.format("reservation"))

        if reservation.get_slice() is None:
            raise RPCException(
                message=Constants.NOT_SPECIFIED_PREFIX.format("slice"))

        if check_requested:
            if reservation.get_requested_resources() is None:
                raise RPCException(message=Constants.NOT_SPECIFIED_PREFIX.
                                   format("requested resources"))

            if reservation.get_requested_term() is None:
                raise RPCException(message=Constants.NOT_SPECIFIED_PREFIX.
                                   format("requested term"))

        if isinstance(reservation, ABCClientReservation):
            if reservation.get_broker() is None:
                raise RPCException(message=Constants.NOT_SPECIFIED_PREFIX.
                                   format("broker proxy"))

            if reservation.get_client_callback_proxy() is None:
                raise RPCException(message=Constants.NOT_SPECIFIED_PREFIX.
                                   format("client callback proxy"))

        elif isinstance(reservation, ABCControllerReservation):
            if reservation.get_authority() is None:
                raise RPCException(message=Constants.NOT_SPECIFIED_PREFIX.
                                   format("authority proxy"))

            if reservation.get_client_callback_proxy() is None:
                raise RPCException(message=Constants.NOT_SPECIFIED_PREFIX.
                                   format("client callback proxy"))
Example #6
0
    def ticket(self, *, reservation: ABCReservationMixin, callback: ABCClientCallbackProxy, caller: AuthToken):
        slice_obj = reservation.get_slice()
        if slice_obj is not None:
            slice_obj.set_broker_client()

        self.wrapper.ticket_request(reservation=reservation, caller=caller, callback=callback, compare_seq_numbers=True)
Example #7
0
    def extend_ticket(self, *, reservation: ABCReservationMixin, caller: AuthToken):
        slice_obj = reservation.get_slice()
        if slice_obj is not None:
            slice_obj.set_broker_client()

        self.wrapper.extend_ticket_request(reservation=reservation, caller=caller, compare_sequence_numbers=True)