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 #2
0
    def fill_reservation(*, reservation: ABCReservationMixin,
                         full: bool) -> ReservationMng:
        rsv_mng = None
        if isinstance(reservation, ABCControllerReservation):
            rsv_mng = LeaseReservationAvro()
            if reservation.get_redeem_predecessors() is not None and len(
                    reservation.get_redeem_predecessors()) > 0:
                rsv_mng.redeem_processors = []
                for p in reservation.get_redeem_predecessors():
                    pred = Converter.fill_reservation_predecessor(pred=p)
                    rsv_mng.redeem_processors.append(pred)

        elif isinstance(reservation, ABCClientReservation):
            rsv_mng = TicketReservationAvro()
        else:
            rsv_mng = ReservationMng()

        rsv_mng.set_reservation_id(str(reservation.get_reservation_id()))
        rsv_mng.set_slice_id(str(reservation.get_slice_id()))

        if reservation.get_type() is not None:
            rsv_mng.set_resource_type(str(reservation.get_type()))

        rsv_mng.set_units(reservation.get_units())
        rsv_mng.set_state(reservation.get_state().value)
        rsv_mng.set_pending_state(reservation.get_pending_state().value)

        if isinstance(reservation, ABCControllerReservation):
            rsv_mng.set_leased_units(reservation.get_leased_abstract_units())
            rsv_mng.set_join_state(reservation.get_join_state().value)
            authority = reservation.get_authority()

            if authority is not None:
                rsv_mng.set_authority(str(authority.get_guid()))

        if isinstance(reservation, ABCClientReservation):
            broker = reservation.get_broker()
            if broker is not None:
                rsv_mng.set_broker(str(broker.get_guid()))
            rsv_mng.set_renewable(reservation.is_renewable())
            rsv_mng.set_renew_time(reservation.get_renew_time())

        if reservation.get_term() is not None:
            rsv_mng.set_start(
                ActorClock.to_milliseconds(
                    when=reservation.get_term().get_start_time()))
            rsv_mng.set_end(
                ActorClock.to_milliseconds(
                    when=reservation.get_term().get_end_time()))
        else:
            if reservation.get_requested_term() is not None:
                rsv_mng.set_start(
                    ActorClock.to_milliseconds(
                        when=reservation.get_requested_term().get_start_time())
                )
                rsv_mng.set_end(
                    ActorClock.to_milliseconds(
                        when=reservation.get_requested_term().get_end_time()))

        if reservation.get_requested_term() is not None:
            rsv_mng.set_requested_end(
                ActorClock.to_milliseconds(
                    when=reservation.get_requested_term().get_end_time()))

        rsv_mng.set_notices(reservation.get_notices())

        if full:
            rsv_mng = Converter.attach_res_properties(mng=rsv_mng,
                                                      reservation=reservation)

        return rsv_mng