Class GrpcRequestResponseConverter
java.lang.Object
com.linkedin.venice.controllerapi.transport.GrpcRequestResponseConverter
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ClusterStoreGrpcInfo
getClusterStoreGrpcInfo
(ControllerResponse response) parseControllerGrpcError
(io.grpc.StatusRuntimeException e) Parses aStatusRuntimeException
to extract aVeniceControllerGrpcErrorInfo
object.static void
sendErrorResponse
(io.grpc.Status.Code code, ControllerGrpcErrorType errorType, Exception e, String clusterName, String storeName, io.grpc.stub.StreamObserver<?> responseObserver) Sends an error response to the client using the provided error details.
-
Constructor Details
-
GrpcRequestResponseConverter
public GrpcRequestResponseConverter()
-
-
Method Details
-
getClusterStoreGrpcInfo
-
sendErrorResponse
public static void sendErrorResponse(io.grpc.Status.Code code, ControllerGrpcErrorType errorType, Exception e, String clusterName, String storeName, io.grpc.stub.StreamObserver<?> responseObserver) Sends an error response to the client using the provided error details.This method constructs a detailed gRPC error response, including the error type, status code, message, and optional cluster or store-specific information. The constructed error is sent to the client via the provided
StreamObserver
.- Parameters:
code
- The gRPC status code representing the error (e.g.,Status.Code
).errorType
- The specific controller error type represented byControllerGrpcErrorType
.e
- The exception containing the error message.clusterName
- The name of the cluster associated with the error (can be null).storeName
- The name of the store associated with the error (can be null).responseObserver
- TheStreamObserver
to send the error response back to the client.Example usage:
sendErrorResponse( Status.Code.INTERNAL, ControllerGrpcErrorType.UNKNOWN_ERROR, new RuntimeException("Something went wrong"), "test-cluster", "test-store", responseObserver);
The error response includes the following:
- gRPC status code (e.g., INTERNAL, FAILED_PRECONDITION).
- Error type (e.g., BAD_REQUEST, CONCURRENT_BATCH_PUSH).
- Error message extracted from the provided exception.
- Optional cluster name and store name if provided.
-
parseControllerGrpcError
public static VeniceControllerGrpcErrorInfo parseControllerGrpcError(io.grpc.StatusRuntimeException e) Parses aStatusRuntimeException
to extract aVeniceControllerGrpcErrorInfo
object.This method processes the gRPC error details embedded within a
StatusRuntimeException
. If the error details contain aVeniceControllerGrpcErrorInfo
, it unpacks and returns it. If no valid details are found or the unpacking fails, aVeniceClientException
is thrown.- Parameters:
e
- TheStatusRuntimeException
containing the gRPC error details.- Returns:
- A
VeniceControllerGrpcErrorInfo
object extracted from the error details. - Throws:
VeniceClientException
- If the error details cannot be unpacked or no valid information is found.Example usage:
try { // Call a gRPC method that might throw StatusRuntimeException } catch (StatusRuntimeException e) { VeniceControllerGrpcErrorInfo errorInfo = parseControllerGrpcError(e); System.out.println("Error Type: " + errorInfo.getErrorType()); System.out.println("Error Message: " + errorInfo.getErrorMessage()); }
-