Class GrpcRequestResponseConverter
java.lang.Object
com.linkedin.venice.controller.grpc.GrpcRequestResponseConverter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ClusterStoreGrpcInfogetClusterStoreGrpcInfo(ControllerResponse response) parseControllerGrpcError(io.grpc.StatusRuntimeException e) Parses aStatusRuntimeExceptionto extract aVeniceControllerGrpcErrorInfoobject.static voidsendErrorResponse(io.grpc.Status.Code code, ControllerGrpcErrorType errorType, Exception exception, String clusterName, String storeName, io.grpc.stub.StreamObserver<?> responseObserver) static voidsendErrorResponse(io.grpc.Status.Code code, ControllerGrpcErrorType errorType, String errorMessage, String clusterName, String storeName, io.grpc.stub.StreamObserver<?> responseObserver) Sends an error response to the client using the provided error details.toExecutionStatusMap(Map<String, String> grpcMap) Converts a gRPC map with string statuses to a ConcurrentHashMap with AdminCommandExecutionStatus.toGrpcExecutionStatusMap(Map<String, AdminCommandExecutionStatus> executionStatusMap) Converts a ConcurrentHashMap with AdminCommandExecutionStatus to a map with string statuses.
-
Constructor Details
-
GrpcRequestResponseConverter
public GrpcRequestResponseConverter()
-
-
Method Details
-
getClusterStoreGrpcInfo
-
sendErrorResponse
public static void sendErrorResponse(io.grpc.Status.Code code, ControllerGrpcErrorType errorType, String errorMessage, 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.errorMessage- The error message to be included in the response.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- TheStreamObserverto 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.
-
sendErrorResponse
public static void sendErrorResponse(io.grpc.Status.Code code, ControllerGrpcErrorType errorType, Exception exception, String clusterName, String storeName, io.grpc.stub.StreamObserver<?> responseObserver) -
parseControllerGrpcError
public static VeniceControllerGrpcErrorInfo parseControllerGrpcError(io.grpc.StatusRuntimeException e) Parses aStatusRuntimeExceptionto extract aVeniceControllerGrpcErrorInfoobject.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, aVeniceClientExceptionis thrown.- Parameters:
e- TheStatusRuntimeExceptioncontaining the gRPC error details.- Returns:
- A
VeniceControllerGrpcErrorInfoobject 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()); }
-
toExecutionStatusMap
public static ConcurrentHashMap<String,AdminCommandExecutionStatus> toExecutionStatusMap(Map<String, String> grpcMap) Converts a gRPC map with string statuses to a ConcurrentHashMap with AdminCommandExecutionStatus.- Parameters:
grpcMap- Map with keys as fabric names and values as string statuses.- Returns:
- A ConcurrentHashMap with keys as fabric names and values as AdminCommandExecutionStatus.
-
toGrpcExecutionStatusMap
public static Map<String,String> toGrpcExecutionStatusMap(Map<String, AdminCommandExecutionStatus> executionStatusMap) Converts a ConcurrentHashMap with AdminCommandExecutionStatus to a map with string statuses.- Parameters:
executionStatusMap- ConcurrentHashMap with keys as fabric names and values as AdminCommandExecutionStatus.- Returns:
- A Map with keys as fabric names and values as string statuses.
-