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
def get_concrete(self, *, reservation: ReservationAvro) -> ABCConcreteSet: ticket = reservation.resource_set.ticket if reservation.resource_set.ticket is not None: return Translate.translate_ticket_from_avro(avro_ticket=ticket) unit_set = reservation.resource_set.unit_set if unit_set is not None: return Translate.translate_unit_set_from_avro(unit_list=unit_set) return None
def reclaim(self, *, request: ReclaimResourcesAvro): result = ResultDelegationAvro() result.status = ResultAvro() result.message_id = request.message_id try: if request.guid is None or request.broker_id is None or request.delegation_id is None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret()) return result auth = Translate.translate_auth_from_avro(auth_avro=request.auth) mo = self.get_actor_mo(guid=ID(uid=request.guid)) if mo is None: self.logger.debug("Management object could not be found: guid: {} auth: {}".format(request.guid, auth)) result.status.set_code(ErrorCodes.ErrorNoSuchBroker.value) result.status.set_message(ErrorCodes.ErrorNoSuchBroker.interpret()) return result result = mo.reclaim_delegations(broker=ID(uid=request.broker_id), did=request.delegation_id, caller=auth, id_token=request.id_token) except Exception as e: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret()) result.status.set_message(str(e)) result.status.set_details(traceback.format_exc()) result.message_id = request.message_id return result
def extend_reservation(self, *, request: ExtendReservationAvro) -> ResultStringAvro: result = ResultStringAvro() result.message_id = request.message_id try: if request.guid is None or request.reservation_id is None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret()) return result auth = Translate.translate_auth_from_avro(auth_avro=request.auth) mo = self.get_actor_mo(guid=ID(uid=request.guid)) end_time = ActorClock.from_milliseconds(milli_seconds=request.end_time) rtype = None if request.new_resource_type is not None: rtype = ResourceType(resource_type=request.new_resource_type) result.status = mo.extend_reservation(rid=ID(uid=request.reservation_id), new_end_time=end_time, new_units=request.new_units, new_resource_type=rtype, request_properties=request.request_properties, config_properties=request.config_properties, caller=auth) except Exception as e: result.status.set_code(ErrorCodes.ErrorInternalError.value) result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e)) result.status = ManagementObject.set_exception_details(result=result.status, e=e) result.message_id = request.message_id return result
def failed_rpc(self, *, request: FailedRpcAvro): rpc = None auth_token = Translate.translate_auth_from_avro(auth_avro=request.auth) try: failed_request_type = RPCRequestType(request.request_type) if request.reservation_id is not None and request.reservation_id != "": rpc = IncomingFailedRPC( message_id=ID(uid=request.message_id), failed_request_type=failed_request_type, request_id=request.request_id, failed_reservation_id=ID(uid=request.reservation_id), error_details=request.error_details, caller=auth_token) else: rpc = IncomingFailedRPC( message_id=ID(uid=request.message_id), failed_request_type=failed_request_type, request_id=request.request_id, failed_reservation_id=None, error_details=request.error_details, caller=auth_token) except Exception as e: self.logger.error("Invalid failedRequest request: {}".format(e)) raise e self.do_dispatch(rpc=rpc)
def demand_reservation(self, *, request: DemandReservationAvro) -> ResultStringAvro: result = ResultStringAvro() result.status = ResultAvro() result.message_id = request.message_id try: if request.guid is None or (request.reservation_id is None and request.reservation_obj is None): result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret()) return result if request.reservation_obj is not None and request.reservation_id is not None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret()) return result auth = Translate.translate_auth_from_avro(auth_avro=request.auth) mo = self.get_actor_mo(guid=ID(uid=request.guid)) if request.reservation_id is not None: result.status = mo.demand_reservation_rid(rid=ID(uid=request.reservation_id), caller=auth) else: result.status = mo.demand_reservation(reservation=request.reservation_obj, caller=auth) except Exception as e: result.status.set_code(ErrorCodes.ErrorInternalError.value) result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e)) result.status = ManagementObject.set_exception_details(result=result.status, e=e) result.message_id = request.message_id return result
def get_delegations(self, *, request: GetDelegationsAvro) -> ResultDelegationAvro: result = ResultDelegationAvro() result.status = ResultAvro() result.message_id = request.message_id try: if request.guid is None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret()) return result auth = Translate.translate_auth_from_avro(auth_avro=request.auth) mo = self.get_actor_mo(guid=ID(uid=request.guid)) if request.get_delegation_id() is not None: result = mo.get_delegations(caller=auth, did=ID(uid=request.get_delegation_id()), id_token=request.get_id_token(), state=request.delegation_state) elif request.get_slice_id() is not None: result = mo.get_delegations(caller=auth, slice_id=ID(uid=request.get_slice_id()), id_token=request.get_id_token(), state=request.delegation_state) else: result = mo.get_delegations(caller=auth, id_token=request.get_id_token(), state=request.delegation_state) except Exception as e: result.status.set_code(ErrorCodes.ErrorInternalError.value) result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e)) result.status = ManagementObject.set_exception_details(result=result.status, e=e) result.message_id = request.message_id return result
def get_broker_query_model(self, *, request: GetBrokerQueryModelRequestAvro) -> ResultBrokerQueryModelAvro: result = ResultBrokerQueryModelAvro() result.status = ResultAvro() result.message_id = request.message_id try: if request.guid is None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret()) return result auth = Translate.translate_auth_from_avro(auth_avro=request.auth) mo = self.get_actor_mo(guid=ID(uid=request.guid)) graph_format = GraphFormat(request.graph_format) result = mo.get_broker_query_model(broker=ID(uid=request.broker_id), caller=auth, id_token=request.get_id_token(), graph_format=graph_format) except Exception as e: result.status.set_code(ErrorCodes.ErrorInternalError.value) result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e)) result.status = ManagementObject.set_exception_details(result=result.status, e=e) result.message_id = request.message_id return result
def close_reservations(self, *, request: CloseReservationsAvro) -> ResultStringAvro: result = ResultStringAvro() result.status = ResultAvro() result.message_id = request.message_id try: if request.guid is None or (request.get_slice_id() is None and request.get_reservation_id() is None): result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret()) return result auth = Translate.translate_auth_from_avro(auth_avro=request.auth) mo = self.get_actor_mo(guid=ID(uid=request.guid)) if request.get_slice_id() is not None: result.status = mo.close_slice_reservations(caller=auth, slice_id=ID(uid=request.slice_id), id_token=request.id_token) else: result.status = mo.close_reservation(caller=auth, rid=ID(uid=request.reservation_id), id_token=request.id_token) except Exception as e: result.status.set_code(ErrorCodes.ErrorInternalError.value) result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e)) result.status = ManagementObject.set_exception_details(result=result.status, e=e) result.message_id = request.message_id return result
def add_client_slice(self, *, request: AddSliceAvro) -> ResultStringAvro: result = ResultStringAvro() result.status = ResultAvro() result.message_id = request.message_id try: if request.guid is None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message( ErrorCodes.ErrorInvalidArguments.interpret()) return result auth = Translate.translate_auth_from_avro(auth_avro=request.auth) mo = self.get_actor_mo(guid=ID(uid=request.guid)) result = mo.add_client_slice(caller=auth, slice_obj=request.slice_obj) except Exception as e: result.status.set_code(ErrorCodes.ErrorInternalError.value) result.status.set_message( ErrorCodes.ErrorInternalError.interpret(exception=e)) result.status = ManagementObject.set_exception_details( result=result.status, e=e) result.message_id = request.message_id return result
def get_slices(self, *, request: GetSlicesRequestAvro) -> ResultSliceAvro: result = ResultSliceAvro() result.status = ResultAvro() result.message_id = request.message_id try: if request.guid is None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret()) return result auth = Translate.translate_auth_from_avro(auth_avro=request.auth) mo = self.get_actor_mo(guid=ID(uid=request.guid)) slice_id = None if request.slice_id is not None: slice_id = ID(uid=request.slice_id) result = mo.get_slices(slice_id=slice_id, caller=auth, id_token=request.get_id_token(), slice_name=request.slice_name, email=request.get_email()) except Exception as e: self.logger.error(traceback.format_exc()) result.status.set_code(ErrorCodes.ErrorInternalError.value) result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e)) result.status = ManagementObject.set_exception_details(result=result.status, e=e) result.message_id = request.message_id return result
def get_reservations_by_category( self, *, request: GetReservationsRequestAvro, category: ReservationCategory) -> ResultReservationAvro: result = ResultReservationAvro() result.status = ResultAvro() result.message_id = request.message_id try: if request.guid is None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message( ErrorCodes.ErrorInvalidArguments.interpret()) return result auth = Translate.translate_auth_from_avro(auth_avro=request.auth) mo = self.get_actor_mo(guid=ID(uid=request.guid)) result = mo.get_reservations_by_category( caller=auth, category=category, id_token=request.get_id_token(), slice_id=request.slice_id) except Exception as e: result.status.set_code(ErrorCodes.ErrorInternalError.value) result.status.set_message( ErrorCodes.ErrorInternalError.interpret(exception=e)) result.status = ManagementObject.set_exception_details( result=result.status, e=e) result.message_id = request.message_id return result
def get_slices_by_slice_type(self, *, request: GetSlicesRequestAvro, slice_type: SliceTypes) -> ResultSliceAvro: result = ResultSliceAvro() result.status = ResultAvro() result.message_id = request.message_id try: if request.guid is None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message( ErrorCodes.ErrorInvalidArguments.interpret()) return result auth = Translate.translate_auth_from_avro(auth_avro=request.auth) mo = self.get_actor_mo(guid=ID(uid=request.guid)) result = mo.get_slices_by_slice_type( caller=auth, slice_type=slice_type, id_token=request.get_id_token()) except Exception as e: result.status.set_code(ErrorCodes.ErrorInternalError.value) result.status.set_message( ErrorCodes.ErrorInternalError.interpret(exception=e)) result.status = ManagementObject.set_exception_details( result=result.status, e=e) result.message_id = request.message_id return result
def update_ticket(self, *, request: UpdateTicketAvro): rpc = None auth_token = Translate.translate_auth_from_avro(auth_avro=request.auth) try: rsvn = self.pass_client(reservation=request.reservation) udd = Translate.translate_udd_from_avro(udd=request.update_data) rpc = IncomingReservationRPC( message_id=ID(uid=request.message_id), request_type=RPCRequestType.UpdateTicket, reservation=rsvn, update_data=udd, caller=auth_token) except Exception as e: self.logger.error("Invalid update_ticket request: {}".format(e)) raise e self.do_dispatch(rpc=rpc)
def pass_client(self, *, reservation: ReservationAvro) -> ABCClientReservation: slice_obj = Translate.translate_slice(slice_avro=reservation.slice) term = Translate.translate_term_from_avro(term=reservation.term) resource_set = Translate.translate_resource_set_from_avro( rset=reservation.resource_set) resource_set.set_resources(cset=self.get_concrete( reservation=reservation)) return ClientReservationFactory.create( rid=ID(uid=reservation.reservation_id), resources=resource_set, term=term, slice_object=slice_obj, actor=self.actor)
def execute(self, *, request: ABCRPCRequestState, producer: AvroProducerApi): avro_message = None if request.get_type() == RPCRequestType.Redeem: avro_message = RedeemAvro() avro_message.message_id = str(request.get_message_id()) avro_message.callback_topic = request.callback_topic avro_message.reservation = request.reservation avro_message.auth = Translate.translate_auth_to_avro( auth=request.caller) elif request.get_type() == RPCRequestType.ExtendLease: avro_message = ExtendLeaseAvro() avro_message.message_id = str(request.get_message_id()) avro_message.callback_topic = request.callback_topic avro_message.reservation = request.reservation avro_message.auth = Translate.translate_auth_to_avro( auth=request.caller) elif request.get_type() == RPCRequestType.ModifyLease: avro_message = ModifyLeaseAvro() avro_message.message_id = str(request.get_message_id()) avro_message.callback_topic = request.callback_topic avro_message.reservation = request.reservation avro_message.auth = Translate.translate_auth_to_avro( auth=request.caller) elif request.get_type() == RPCRequestType.Close: avro_message = CloseAvro() avro_message.message_id = str(request.get_message_id()) avro_message.callback_topic = request.callback_topic avro_message.reservation = request.reservation avro_message.auth = Translate.translate_auth_to_avro( auth=request.caller) else: super().execute(request=request, producer=producer) return if producer is not None and producer.produce(topic=self.kafka_topic, record=avro_message): self.logger.debug("Message {} written to {}".format( avro_message.name, self.kafka_topic)) else: self.logger.error( "Failed to send message {} to {} via producer {}".format( avro_message.name, self.kafka_topic, producer))
def pass_agent(self, *, reservation: ReservationAvro) -> ABCBrokerReservation: slice_obj = Translate.translate_slice(slice_avro=reservation.slice) term = Translate.translate_term_from_avro(term=reservation.term) resource_set = Translate.translate_resource_set_from_avro( rset=reservation.resource_set) rid = ID(uid=reservation.reservation_id) result = BrokerReservationFactory.create(rid=rid, resources=resource_set, term=term, slice_obj=slice_obj, actor=self.actor) result.set_owner(owner=self.actor.get_identity()) result.set_sequence_in(sequence=reservation.sequence) return result
def execute(self, *, request: ABCRPCRequestState, producer: AvroProducerApi): avro_message = None if request.get_type() == RPCRequestType.Query: avro_message = QueryAvro() avro_message.message_id = str(request.get_message_id()) avro_message.properties = request.query avro_message.callback_topic = request.callback_topic avro_message.auth = Translate.translate_auth_to_avro( auth=request.caller) avro_message.id_token = request.get_id_token() elif request.get_type() == RPCRequestType.QueryResult: avro_message = QueryResultAvro() avro_message.message_id = str(request.get_message_id()) avro_message.request_id = str(request.request_id) avro_message.properties = request.query avro_message.auth = Translate.translate_auth_to_avro( auth=request.caller) elif request.get_type() == RPCRequestType.FailedRPC: avro_message = FailedRpcAvro() avro_message.message_id = str(request.get_message_id()) avro_message.request_id = str(request.request_id) avro_message.request_type = request.failed_request_type.value avro_message.auth = Translate.translate_auth_to_avro( auth=request.caller) if request.failed_reservation_id is not None: avro_message.reservation_id = request.failed_reservation_id else: avro_message.reservation_id = "" avro_message.error_details = request.error_details else: raise ProxyException("Unsupported RPC: type={}".format( request.get_type())) if producer is not None and producer.produce(topic=self.kafka_topic, record=avro_message): self.logger.debug("Message {} written to {}".format( avro_message.name, self.kafka_topic)) else: self.logger.error( "Failed to send message {} to {} via producer {}".format( avro_message.name, self.kafka_topic, producer))
def update_delegation(self, *, request: UpdateDelegationAvro): rpc = None auth_token = Translate.translate_auth_from_avro(auth_avro=request.auth) try: dlg = self.pass_client_delegation(delegation=request.delegation, caller=auth_token) udd = Translate.translate_udd_from_avro(udd=request.update_data) rpc = IncomingDelegationRPC( message_id=ID(uid=request.message_id), request_type=RPCRequestType.UpdateDelegation, delegation=dlg, update_data=udd, caller=auth_token) except Exception as e: self.logger.error( "Invalid update_delegation request: {}".format(e)) raise e self.do_dispatch(rpc=rpc)
def pass_authority(self, *, reservation: ReservationAvro) -> ABCAuthorityReservation: slice_obj = Translate.translate_slice(slice_avro=reservation.slice) term = Translate.translate_term_from_avro(term=reservation.term) resource_set = Translate.translate_resource_set_from_avro(rset=reservation.resource_set) cset = self.get_concrete(reservation=reservation) if cset is None: raise ProxyException("Unsupported Concrete type") resource_set.set_resources(cset=cset) rid = ID(uid=reservation.reservation_id) result = AuthorityReservationFactory.create(resources=resource_set, term=term, slice_obj=slice_obj, rid=rid, actor=self.actor) result.set_owner(owner=self.actor.get_identity()) result.set_sequence_in(sequence=reservation.sequence) return result
def get_reservations(self, *, request: GetReservationsRequestAvro) -> ResultReservationAvro: result = ResultReservationAvro() result.status = ResultAvro() result.message_id = request.message_id try: if request.guid is None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message(ErrorCodes.ErrorInvalidArguments.interpret()) return result auth = Translate.translate_auth_from_avro(auth_avro=request.auth) mo = self.get_actor_mo(guid=ID(uid=request.guid)) slice_id = None if request.slice_id is not None: slice_id = ID(uid=request.slice_id) rid = None if request.get_reservation_id() is not None: rid = ID(uid=request.get_reservation_id()) if rid is not None: result = mo.get_reservations(caller=auth, rid=rid, id_token=request.get_id_token()) elif slice_id is not None: if request.get_reservation_state() is not None and \ request.get_reservation_state() != Constants.ALL_RESERVATION_STATES: result = mo.get_reservations(caller=auth, slice_id=slice_id, state=request.get_reservation_state(), id_token=request.get_id_token()) else: result = mo.get_reservations(caller=auth, slice_id=slice_id, id_token=request.get_id_token()) else: if request.get_reservation_state() is not None and \ request.get_reservation_state() != Constants.ALL_RESERVATION_STATES: result = mo.get_reservations(caller=auth, state=request.get_reservation_state(), id_token=request.get_id_token(), email=request.get_email()) else: result = mo.get_reservations(caller=auth, id_token=request.get_id_token(), email=request.get_email()) except Exception as e: result.status.set_code(ErrorCodes.ErrorInternalError.value) result.status.set_message(ErrorCodes.ErrorInternalError.interpret(exception=e)) result.status = ManagementObject.set_exception_details(result=result.status, e=e) result.message_id = request.message_id return result
def _prepare(self, *, reservation: ABCServerReservation, update_data: UpdateData, callback: ABCCallbackProxy, caller: AuthToken) -> ABCRPCRequestState: request = KafkaProxyRequestState() request.reservation = self.pass_reservation(reservation=reservation, auth=caller) request.udd = Translate.translate_udd(udd=update_data) request.callback_topic = callback.get_kafka_topic() request.caller = caller return request
def extend_lease(self, *, request: ExtendLeaseAvro): rpc = None auth_token = Translate.translate_auth_from_avro(auth_avro=request.auth) try: rsvn = self.pass_authority(reservation=request.reservation) rpc = IncomingReservationRPC(message_id=ID(uid=request.message_id), request_type=RPCRequestType.ExtendLease, reservation=rsvn, caller=auth_token) except Exception as e: self.logger.error("Invalid extend_lease request: {}".format(e)) raise e self.do_dispatch(rpc=rpc)
def prepare_update_delegation(self, *, delegation: ABCDelegation, update_data: UpdateData, callback: ABCCallbackProxy, caller: AuthToken) -> ABCRPCRequestState: request = KafkaProxyRequestState() request.delegation = self.pass_delegation(delegation=delegation, auth=caller) request.udd = Translate.translate_udd(udd=update_data) request.callback_topic = callback.get_kafka_topic() request.caller = caller return request
def pass_agent_delegation(self, *, delegation: DelegationAvro) -> ABCDelegation: slice_obj = Translate.translate_slice(slice_avro=delegation.slice) result = DelegationFactory.create(did=delegation.get_delegation_id(), slice_id=slice_obj.get_slice_id()) result.set_slice_object(slice_object=slice_obj) result.set_owner(owner=self.actor.get_identity()) result.set_sequence_in(value=delegation.sequence) return result
def redeem(self, *, request: RedeemAvro): rpc = None auth_token = Translate.translate_auth_from_avro(auth_avro=request.auth) try: rsvn = self.pass_authority(reservation=request.reservation) callback = self.get_callback(kafka_topic=request.callback_topic, auth=auth_token) rpc = IncomingReservationRPC(message_id=ID(uid=request.message_id), request_type=RPCRequestType.Redeem, reservation=rsvn, callback=callback, caller=auth_token) except Exception as e: self.logger.error("Invalid redeem request: {}".format(e)) raise e self.do_dispatch(rpc=rpc)
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 pass_reservation(reservation: ABCServerReservation, auth: AuthToken) -> ReservationAvro: avro_reservation = ReservationAvro() avro_reservation.slice = Translate.translate_slice_to_avro( slice_obj=reservation.get_slice()) term = None if reservation.get_term() is None: term = reservation.get_requested_term().clone() else: term = reservation.get_term().clone() avro_reservation.term = Translate.translate_term(term=term) avro_reservation.reservation_id = str(reservation.get_reservation_id()) rset = None if reservation.get_resources() is None: from fabric_cf.actor.core.kernel.resource_set import ResourceSet rset = Translate.translate_resource_set(resource_set=ResourceSet( units=0, rtype=reservation.get_requested_type())) else: rset = Translate.translate_resource_set( resource_set=reservation.get_resources()) if reservation.get_resources() is not None: cset = reservation.get_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.unit_set = Translate.translate_unit_set(unit_set=cset) avro_reservation.resource_set = rset return avro_reservation
def query_result(self, *, request: QueryResultAvro): rpc = None auth_token = Translate.translate_auth_from_avro(auth_avro=request.auth) try: query = request.properties rpc = IncomingQueryRPC(request_type=RPCRequestType.QueryResult, message_id=ID(uid=request.get_message_id()), query=query, caller=auth_token, request_id=ID(uid=request.request_id), id_token=None) except Exception as e: self.logger.error("Invalid query_result request: {}".format(e)) raise e self.do_dispatch(rpc=rpc)
def get_slices_by_slice_type(self, *, caller: AuthToken, slice_type: SliceTypes, id_token: str = None) -> ResultSliceAvro: result = ResultSliceAvro() result.status = ResultAvro() if caller is None: result.status.set_code(ErrorCodes.ErrorInvalidArguments.value) result.status.set_message( ErrorCodes.ErrorInvalidArguments.interpret()) return result try: slc_list = None try: if slice_type == SliceTypes.ClientSlice: slc_list = self.db.get_client_slices() elif slice_type == SliceTypes.InventorySlice: slc_list = self.db.get_inventory_slices() except Exception as e: self.logger.error( "get_slices_by_slice_type:db access {}".format(e)) result.status.set_code(ErrorCodes.ErrorDatabaseError.value) result.status.set_message( ErrorCodes.ErrorDatabaseError.interpret(exception=e)) result.status = ManagementObject.set_exception_details( result=result.status, e=e) return result if slc_list is not None: result.result = Translate.fill_slices(slice_list=slc_list, full=True) except Exception as e: self.logger.error("get_slices_by_slice_type: {}".format(e)) result.status.set_code(ErrorCodes.ErrorInternalError.value) result.status.set_message( ErrorCodes.ErrorInternalError.interpret(exception=e)) result.status = ManagementObject.set_exception_details( result=result.status, e=e) return result