Search in sources :

Example 66 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project fabric-sdk-java by hyperledger.

the class ChannelTest method testQueryInstalledChaincodesStatusRuntimeException.

@Test
public void testQueryInstalledChaincodesStatusRuntimeException() throws Exception {
    thrown.expect(ProposalException.class);
    thrown.expectMessage("ABORTED");
    final Channel channel = createRunningChannel(null);
    Peer peer = channel.getPeers().iterator().next();
    final SettableFuture<FabricProposalResponse.ProposalResponse> settableFuture = SettableFuture.create();
    settableFuture.setException(new StatusRuntimeException(Status.ABORTED));
    setField(peer, "endorserClent", new MockEndorserClient(settableFuture));
    hfclient.queryChannels(peer);
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) FabricProposalResponse(org.hyperledger.fabric.protos.peer.FabricProposalResponse) Test(org.junit.Test)

Example 67 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project ballerina by ballerina-lang.

the class MessageUtils method getConnectorError.

/**
 * Returns error struct of input type
 * Error type can be either ServerError or ClientError. This utility method is used inside Observer onError
 * method to construct error struct from message.
 *
 * @param errorType this is either ServerError or ClientError.
 * @param error     this is StatusRuntimeException send by opposite party.
 * @return error struct.
 */
public static BStruct getConnectorError(BStructType errorType, Throwable error) {
    BStruct errorStruct = new BStruct(errorType);
    if (error instanceof StatusRuntimeException) {
        StatusRuntimeException statusException = (StatusRuntimeException) error;
        int status = statusException.getStatus() != null ? statusException.getStatus().getCode().value() : -1;
        String message = statusException.getMessage();
        errorStruct.setStringField(0, message);
        errorStruct.setIntField(0, status);
    } else {
        if (error.getMessage() == null) {
            errorStruct.setStringField(0, UNKNOWN_ERROR);
        } else {
            errorStruct.setStringField(0, error.getMessage());
        }
    }
    return errorStruct;
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) StatusRuntimeException(io.grpc.StatusRuntimeException) BString(org.ballerinalang.model.values.BString)

Example 68 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project ballerina by ballerina-lang.

the class MessageUtils method handleFailure.

/**
 * Handles faliures in GRPC callable unit callback.
 *
 * @param streamObserver observer used the send the error back
 * @param error          error message struct
 */
static void handleFailure(StreamObserver<Message> streamObserver, BStruct error) {
    int statusCode = Integer.parseInt(String.valueOf(error.getIntField(0)));
    String errorMsg = error.getStringField(0);
    LOG.error(errorMsg);
    ErrorHandlerUtils.printError("error: " + BLangVMErrors.getPrintableStackTrace(error));
    if (streamObserver != null) {
        streamObserver.onError(new StatusRuntimeException(Status.fromCodeValue(statusCode).withDescription(errorMsg)));
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) BString(org.ballerinalang.model.values.BString)

Example 69 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project ballerina by ballerina-lang.

the class ErrorResponse method execute.

@Override
public void execute(Context context) {
    BStruct endpointClient = (BStruct) context.getRefArgument(CLIENT_RESPONDER_REF_INDEX);
    BValue responseValue = context.getRefArgument(RESPONSE_MESSAGE_REF_INDEX);
    if (responseValue instanceof BStruct) {
        BStruct responseStruct = (BStruct) responseValue;
        int statusCode = Integer.parseInt(String.valueOf(responseStruct.getIntField(0)));
        String errorMsg = responseStruct.getStringField(0);
        StreamObserver responseObserver = MessageUtils.getResponseObserver(endpointClient);
        if (responseObserver == null) {
            context.setError(MessageUtils.getConnectorError(context, new StatusRuntimeException(Status.fromCode(Status.INTERNAL.getCode()).withDescription("Error while sending the error. Response" + " observer not found."))));
        } else {
            responseObserver.onError(new StatusRuntimeException(Status.fromCodeValue(statusCode).withDescription(errorMsg)));
        }
    }
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) BStruct(org.ballerinalang.model.values.BStruct) BValue(org.ballerinalang.model.values.BValue) StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 70 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project ballerina by ballerina-lang.

the class Send method execute.

@Override
public void execute(Context context) {
    BStruct clientEndpoint = (BStruct) context.getRefArgument(CLIENT_RESPONDER_REF_INDEX);
    BValue responseValue = context.getRefArgument(RESPONSE_MESSAGE_REF_INDEX);
    StreamObserver<Message> responseObserver = MessageUtils.getResponseObserver(clientEndpoint);
    Descriptors.Descriptor outputType = (Descriptors.Descriptor) clientEndpoint.getNativeData(MessageConstants.RESPONSE_MESSAGE_DEFINITION);
    if (responseObserver == null) {
        context.setError(MessageUtils.getConnectorError(context, new StatusRuntimeException(Status.fromCode(Status.INTERNAL.getCode()).withDescription("Error while initializing connector. " + "response sender doesnot exist"))));
    } else {
        try {
            // If there is no response message like conn -> send(), system doesn't send the message.
            if (!MessageUtils.isEmptyResponse(outputType)) {
                Message responseMessage = MessageUtils.generateProtoMessage(responseValue, outputType);
                responseObserver.onNext(responseMessage);
            }
        } catch (Throwable e) {
            LOG.error("Error while sending client response.", e);
            context.setError(MessageUtils.getConnectorError(context, e));
        }
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Message(org.ballerinalang.net.grpc.Message) BValue(org.ballerinalang.model.values.BValue) StatusRuntimeException(io.grpc.StatusRuntimeException) Descriptors(com.google.protobuf.Descriptors)

Aggregations

StatusRuntimeException (io.grpc.StatusRuntimeException)240 Test (org.junit.Test)164 ApiException (com.google.api.gax.grpc.ApiException)74 Status (io.grpc.Status)25 StreamObserver (io.grpc.stub.StreamObserver)20 ByteString (com.google.protobuf.ByteString)18 ArrayList (java.util.ArrayList)18 Metadata (io.grpc.Metadata)14 SimpleServiceGrpc (io.grpc.testing.protobuf.SimpleServiceGrpc)13 ExecutionException (java.util.concurrent.ExecutionException)12 JanusGraphGrpcServerBaseTest (org.janusgraph.graphdb.grpc.JanusGraphGrpcServerBaseTest)12 Test (org.junit.jupiter.api.Test)12 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 ManagedChannel (io.grpc.ManagedChannel)9 StatusRuntimeException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException)8 BStruct (org.ballerinalang.model.values.BStruct)8 SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)7 ChannelCredentials (io.grpc.ChannelCredentials)6 ServerCredentials (io.grpc.ServerCredentials)6 TlsChannelCredentials (io.grpc.TlsChannelCredentials)6