Exemplo n.º 1
0
        return self.call(self._stub.Start, request, None, None, **kwargs)

    def start_async(self, **kwargs):
        """Async version of the start() RPC."""
        request = auto_return_pb2.StartRequest()
        return self.call_async(self._stub.Start, request, None, None, **kwargs)

    def _configure_request(self, params, leases):
        request = auto_return_pb2.ConfigureRequest(params=params)
        for lease in leases:
            request.leases.add().CopyFrom(lease.lease_proto)
        return request


_CONFIGURE_STATUS_TO_ERROR = collections.defaultdict(lambda: (None, None))
_CONFIGURE_STATUS_TO_ERROR.update({
    auto_return_pb2.ConfigureResponse.STATUS_INVALID_PARAMS:
    error_pair(InvalidParameterError)
})


@handle_common_header_errors
@handle_unset_status_error(unset='STATUS_UNKNOWN')
def configure_error(response):
    """Return a custom exception based on the Configure response, None if no error."""
    return error_factory(
        response,
        response.status,
        status_to_string=auto_return_pb2.ConfigureResponse.Status.Name,
        status_to_error=_CONFIGURE_STATUS_TO_ERROR)
Exemplo n.º 2
0
            data = resp.chunk.data
        else:
            data += resp.chunk.data
        num_chunks += 1
    edge_snapshot = map_pb2.EdgeSnapshot()
    if (num_chunks > 0):
        edge_snapshot.ParseFromString(data)
    return edge_snapshot


_SET_LOCALIZATION_STATUS_TO_ERROR = collections.defaultdict(
    lambda: (ResponseError, None))
_SET_LOCALIZATION_STATUS_TO_ERROR.update({
    graph_nav_pb2.SetLocalizationResponse.STATUS_OK: (None, None),
    graph_nav_pb2.SetLocalizationResponse.STATUS_ROBOT_IMPAIRED:
    error_pair(RobotFaultedError),
    graph_nav_pb2.SetLocalizationResponse.STATUS_UNKNOWN_WAYPOINT:
    (UnknownMapInformationError,
     UnknownMapInformationError.__doc__ + " The waypoint is unknown."),
    graph_nav_pb2.SetLocalizationResponse.STATUS_ABORTED:
    error_pair(RequestAbortedError),
    graph_nav_pb2.SetLocalizationResponse.STATUS_FAILED:
    error_pair(RequestFailedError),
})


@handle_common_header_errors
@handle_lease_use_result_errors
@handle_unset_status_error(unset='STATUS_UNKNOWN')
def _set_localization_error(response):
    """Return a custom exception based on set localization response, None if no error."""
Exemplo n.º 3
0
                         error_from_response=_cancel_acquisition_error, **kwargs)

    def cancel_acquisition_async(self, request_id, **kwargs):
        """Async version of the cancel_acquisition() RPC."""
        request = data_acquisition.CancelAcquisitionRequest(request_id=request_id)
        return self.call_async(self._stub.CancelAcquisition, request,
                               error_from_response=_cancel_acquisition_error, **kwargs)


_ACQUIRE_DATA_STATUS_TO_ERROR = collections.defaultdict(lambda:
                                                        (DataAcquisitionResponseError, None))

_ACQUIRE_DATA_STATUS_TO_ERROR.update({
    data_acquisition.AcquireDataResponse.STATUS_OK: (None, None),
    data_acquisition.AcquireDataResponse.STATUS_UNKNOWN_CAPTURE_TYPE:
        error_pair(UnknownCaptureTypeError)
})

_GET_STATUS_STATUS_TO_ERROR = collections.defaultdict(lambda: (None, None))
_GET_STATUS_STATUS_TO_ERROR.update({
    data_acquisition.GetStatusResponse.STATUS_REQUEST_ID_DOES_NOT_EXIST:
        error_pair(RequestIdDoesNotExistError)
})

_CANCEL_ACQUISITION_STATUS_TO_ERROR = collections.defaultdict(lambda: (None, None))
_CANCEL_ACQUISITION_STATUS_TO_ERROR.update({
    data_acquisition.CancelAcquisitionResponse.STATUS_REQUEST_ID_DOES_NOT_EXIST:
        error_pair(RequestIdDoesNotExistError),
    data_acquisition.CancelAcquisitionResponse.STATUS_FAILED_TO_CANCEL:
        error_pair(CancellationFailedError)
})
Exemplo n.º 4
0
    """System cannot generate the ImageSource at this time."""


class ImageDataError(ImageResponseError):
    """System cannot generate image data for the ImageCapture at this time."""


class UnsupportedImageFormatRequestedError(ImageResponseError):
    """The image service cannot return data in the requested format."""


_STATUS_TO_ERROR = collections.defaultdict(lambda: (ResponseError, None))
_STATUS_TO_ERROR.update({
    image_pb2.ImageResponse.STATUS_OK: (None, None),
    image_pb2.ImageResponse.STATUS_UNKNOWN_CAMERA:
    error_pair(UnknownImageSourceError),
    image_pb2.ImageResponse.STATUS_SOURCE_DATA_ERROR:
    error_pair(SourceDataError),
    image_pb2.ImageResponse.STATUS_IMAGE_DATA_ERROR:
    error_pair(ImageDataError),
    image_pb2.ImageResponse.STATUS_UNSUPPORTED_IMAGE_FORMAT_REQUESTED:
    error_pair(UnsupportedImageFormatRequestedError),
    image_pb2.ImageResponse.STATUS_UNKNOWN:
    error_pair(UnsetStatusError),
})


@handle_common_header_errors
def _error_from_response(response):
    """Return a custom exception based on the first invalid image response, None if no error."""
    for image_response in response.image_responses:
Exemplo n.º 5
0
class UnknownPointCloudSourceError(PointCloudResponseError):
    """System cannot find the requested point cloud source name."""


class SourceDataError(PointCloudResponseError):
    """System cannot generate the PointCloudSource at this time."""


class PointCloudDataError(PointCloudResponseError):
    """System cannot generate point cloud data at this time."""


_STATUS_TO_ERROR = collections.defaultdict(lambda: (PointCloudResponseError, None))
_STATUS_TO_ERROR.update({
    point_cloud_protos.PointCloudResponse.STATUS_OK: (None, None),
    point_cloud_protos.PointCloudResponse.STATUS_UNKNOWN_SOURCE: error_pair(UnknownPointCloudSourceError),
    point_cloud_protos.PointCloudResponse.STATUS_SOURCE_DATA_ERROR: error_pair(SourceDataError),
    point_cloud_protos.PointCloudResponse.STATUS_UNKNOWN: error_pair(UnsetStatusError),
    point_cloud_protos.PointCloudResponse.STATUS_POINT_CLOUD_DATA_ERROR: error_pair(PointCloudDataError),
})

@handle_common_header_errors
def _error_from_response(response):
    """Return a custom exception based on the first invalid point_cloud response, None if no error."""
    for point_cloud_response in response.point_cloud_responses:

        result = error_factory(response, point_cloud_response.status,
                               status_to_string=point_cloud_protos.PointCloudResponse.Status.Name,
                               status_to_error=_STATUS_TO_ERROR)
        if result is not None:
            return result
Exemplo n.º 6
0
        req.fault_id.CopyFrom(service_fault_id)
        req.clear_all_service_faults = clear_all_service_faults
        req.clear_all_payload_faults = clear_all_payload_faults
        return self.call_async(self._stub.ClearServiceFault,
                               req,
                               None,
                               error_from_response=_clear_service_fault_error,
                               **kwargs)


_TRIGGER_STATUS_TO_ERROR = collections.defaultdict(lambda:
                                                   (FaultResponseError, None))
_TRIGGER_STATUS_TO_ERROR.update({
    service_fault_pb2.TriggerServiceFaultResponse.STATUS_OK: (None, None),
    service_fault_pb2.TriggerServiceFaultResponse.STATUS_FAULT_ALREADY_ACTIVE:
    error_pair(ServiceFaultAlreadyExistsError),
})


@handle_common_header_errors
@handle_unset_status_error(unset='STATUS_UNKNOWN')
def _trigger_service_fault_error(response):
    """Return an exception based on response from Trigger RPC, None if no error."""
    return error_factory(response,
                         response.status,
                         status_to_string=service_fault_pb2.
                         TriggerServiceFaultResponse.Status.Name,
                         status_to_error=_TRIGGER_STATUS_TO_ERROR)


_CLEAR_STATUS_TO_ERROR = collections.defaultdict(lambda:
Exemplo n.º 7
0
          RpcError: Problem communicating with the robot.
          ServiceDoesNotExistError: The service does not exist.
          DirectoryRegistrationResponseError: Something went wrong during the directory registration.
        """
        req = directory_registration_pb2.UnregisterServiceRequest(service_name=name)

        return self.call(self._stub.UnregisterService, req,
                         error_from_response=_directory_unregister_error, **kwargs)


_REGISTER_STATUS_TO_ERROR = collections.defaultdict(lambda:
                                                    (DirectoryRegistrationResponseError, None))
_REGISTER_STATUS_TO_ERROR.update({
    directory_registration_pb2.RegisterServiceResponse.STATUS_OK: (None, None),
    directory_registration_pb2.RegisterServiceResponse.STATUS_ALREADY_EXISTS:
        error_pair(ServiceAlreadyExistsError),
})


@handle_common_header_errors
@handle_unset_status_error(unset='STATUS_UNKNOWN')
def _directory_register_error(response):
    """Return an exception based on response from Register RPC, None if no error."""
    return error_factory(
        response, response.status,
        status_to_string=directory_registration_pb2.RegisterServiceResponse.Status.Name,
        status_to_error=_REGISTER_STATUS_TO_ERROR)


_UPDATE_STATUS_TO_ERROR = collections.defaultdict(lambda:
                                                  (DirectoryRegistrationResponseError, None))
Exemplo n.º 8
0
    for resp in response:
        if num_chunks == 0:
            data = resp.chunk.data
        else:
            data += resp.chunk.data
        num_chunks += 1
    edge_snapshot = map_pb2.EdgeSnapshot()
    if (num_chunks > 0):
        edge_snapshot.ParseFromString(data)
    return edge_snapshot


_SET_LOCALIZATION_STATUS_TO_ERROR = collections.defaultdict(lambda: (ResponseError, None))
_SET_LOCALIZATION_STATUS_TO_ERROR.update({
    graph_nav_pb2.SetLocalizationResponse.STATUS_OK: (None, None),
    graph_nav_pb2.SetLocalizationResponse.STATUS_ROBOT_IMPAIRED: error_pair(RobotFaultedError),
    graph_nav_pb2.SetLocalizationResponse.STATUS_UNKNOWN_WAYPOINT:
        (UnknownMapInformationError,
         UnknownMapInformationError.__doc__ + " The waypoint is unknown."),
    graph_nav_pb2.SetLocalizationResponse.STATUS_ABORTED: error_pair(RequestAbortedError),
    graph_nav_pb2.SetLocalizationResponse.STATUS_FAILED: error_pair(RequestFailedError),
})


@handle_common_header_errors
@handle_lease_use_result_errors
@handle_unset_status_error(unset='STATUS_UNKNOWN')
def _set_localization_error(response):
    """Return a custom exception based on set localization response, None if no error."""
    return error_factory(response, response.status,
                         status_to_string=graph_nav_pb2.SetLocalizationResponse.Status.Name,
        """Async version of network_compute_bridge_command()."""
        return self.call_async(self._stub.NetworkCompute, network_compute_request, None, _network_compute_error, **kwargs)

@handle_common_header_errors
def _network_compute_error(response):
    """Return a custom exception based on response, None if no error."""
    error_type, message = _NETWORK_COMPUTE_STATUS_TO_ERROR[response.status]
    # This status is not an error.
    if error_type is None:
        return None

    return error_type(response=response, error_message=message)

_NETWORK_COMPUTE_STATUS_TO_ERROR = collections.defaultdict(lambda: (ResponseError, None))
_NETWORK_COMPUTE_STATUS_TO_ERROR.update({
    network_compute_bridge_pb2.NETWORK_COMPUTE_STATUS_UNKNOWN: error_pair(UnsetStatusError),
    network_compute_bridge_pb2.NETWORK_COMPUTE_STATUS_SUCCESS: (None, None),
    network_compute_bridge_pb2.NETWORK_COMPUTE_STATUS_EXTERNAL_SERVICE_NOT_FOUND: (ExternalServiceNotFoundError,
                                             ExternalServiceNotFoundError.__doc__),
    network_compute_bridge_pb2.NETWORK_COMPUTE_STATUS_EXTERNAL_SERVER_ERROR: (ExternalServerError, None),
    network_compute_bridge_pb2.NETWORK_COMPUTE_STATUS_ROTATION_ERROR: (NetworkComputeRotationError, None),
})


@handle_common_header_errors
def _list_available_models_error(response):
    """Return a custom exception based on response, None if no error."""
    error_type, message = _LIST_AVAILABLE_MODELS_STATUS_TO_ERROR[response.status]
    # This status is not an error.
    if error_type is None:
        return None
Exemplo n.º 10
0

class SourceDataError(PointCloudResponseError):
    """System cannot generate the PointCloudSource at this time."""


class PointCloudDataError(PointCloudResponseError):
    """System cannot generate point cloud data at this time."""


_STATUS_TO_ERROR = collections.defaultdict(lambda:
                                           (PointCloudResponseError, None))
_STATUS_TO_ERROR.update({
    point_cloud_protos.PointCloudResponse.STATUS_OK: (None, None),
    point_cloud_protos.PointCloudResponse.STATUS_UNKNOWN_SOURCE:
    error_pair(UnknownPointCloudSourceError),
    point_cloud_protos.PointCloudResponse.STATUS_SOURCE_DATA_ERROR:
    error_pair(SourceDataError),
    point_cloud_protos.PointCloudResponse.STATUS_UNKNOWN:
    error_pair(UnsetStatusError),
    point_cloud_protos.PointCloudResponse.STATUS_POINT_CLOUD_DATA_ERROR:
    error_pair(PointCloudDataError),
})


@handle_common_header_errors
def _error_from_response(response):
    """Return a custom exception based on the first invalid point_cloud response, None if no error."""
    for point_cloud_response in response.point_cloud_responses:

        result = error_factory(
@handle_common_header_errors
def _network_compute_error(response):
    """Return a custom exception based on response, None if no error."""
    error_type, message = _NETWORK_COMPUTE_STATUS_TO_ERROR[response.status]
    # This status is not an error.
    if error_type is None:
        return None

    return error_type(response=response, error_message=message)


_NETWORK_COMPUTE_STATUS_TO_ERROR = collections.defaultdict(
    lambda: (ResponseError, None))
_NETWORK_COMPUTE_STATUS_TO_ERROR.update({
    network_compute_bridge_pb2.NETWORK_COMPUTE_STATUS_UNKNOWN:
    error_pair(UnsetStatusError),
    network_compute_bridge_pb2.NETWORK_COMPUTE_STATUS_SUCCESS: (None, None),
    network_compute_bridge_pb2.NETWORK_COMPUTE_STATUS_EXTERNAL_SERVICE_NOT_FOUND:
    (ExternalServiceNotFoundError, ExternalServiceNotFoundError.__doc__),
    network_compute_bridge_pb2.NETWORK_COMPUTE_STATUS_EXTERNAL_SERVER_ERROR:
    (ExternalServerError, None),
    network_compute_bridge_pb2.NETWORK_COMPUTE_STATUS_ROTATION_ERROR:
    (NetworkComputeRotationError, None),
})


@handle_common_header_errors
def _list_available_models_error(response):
    """Return a custom exception based on response, None if no error."""
    error_type, message = _LIST_AVAILABLE_MODELS_STATUS_TO_ERROR[
        response.status]
Exemplo n.º 12
0
    Args:
        response: RobotCommandResponse message.

    Returns:
        Robot Command id in the response message.
    """
    return response.robot_command_id


_ROBOT_COMMAND_STATUS_TO_ERROR = collections.defaultdict(
    lambda: (RobotCommandResponseError, None))
_ROBOT_COMMAND_STATUS_TO_ERROR.update({
    robot_command_pb2.RobotCommandResponse.STATUS_OK: (None, None),
    robot_command_pb2.RobotCommandResponse.STATUS_INVALID_REQUEST:
    error_pair(InvalidRequestError),
    robot_command_pb2.RobotCommandResponse.STATUS_UNSUPPORTED:
    error_pair(UnsupportedError),
    robot_command_pb2.RobotCommandResponse.STATUS_NO_TIMESYNC:
    error_pair(NoTimeSyncError),
    robot_command_pb2.RobotCommandResponse.STATUS_EXPIRED:
    error_pair(ExpiredError),
    robot_command_pb2.RobotCommandResponse.STATUS_TOO_DISTANT:
    error_pair(TooDistantError),
    robot_command_pb2.RobotCommandResponse.STATUS_NOT_POWERED_ON:
    error_pair(NotPoweredOnError),
    robot_command_pb2.RobotCommandResponse.STATUS_BEHAVIOR_FAULT:
    error_pair(BehaviorFaultError),
    robot_command_pb2.RobotCommandResponse.STATUS_UNKNOWN_FRAME:
    error_pair(UnknownFrameError),
})