Search in sources :

Example 1 with StatusException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.

the class GoogleAuthLibraryCallCredentials method applyRequestMetadata.

@Override
public void applyRequestMetadata(MethodDescriptor<?, ?> method, Attributes attrs, Executor appExecutor, final MetadataApplier applier) {
    String authority = checkNotNull(attrs.get(ATTR_AUTHORITY), "authority");
    final URI uri;
    try {
        uri = serviceUri(authority, method);
    } catch (StatusException e) {
        applier.fail(e.getStatus());
        return;
    }
    appExecutor.execute(new Runnable() {

        @Override
        public void run() {
            try {
                // Credentials is expected to manage caching internally if the metadata is fetched over
                // the network.
                //
                // TODO(zhangkun83): we don't know whether there is valid cache data. If there is, we
                // would waste a context switch by always scheduling in executor. However, we have to
                // do so because we can't risk blocking the network thread. This can be resolved after
                // https://github.com/google/google-auth-library-java/issues/3 is resolved.
                //
                // Some implementations may return null here.
                Map<String, List<String>> metadata = creds.getRequestMetadata(uri);
                // Re-use the headers if getRequestMetadata() returns the same map. It may return a
                // different map based on the provided URI, i.e., for JWT. However, today it does not
                // cache JWT and so we won't bother tring to save its return value based on the URI.
                Metadata headers;
                synchronized (GoogleAuthLibraryCallCredentials.this) {
                    if (lastMetadata == null || lastMetadata != metadata) {
                        lastMetadata = metadata;
                        lastHeaders = toHeaders(metadata);
                    }
                    headers = lastHeaders;
                }
                applier.apply(headers);
            } catch (Throwable e) {
                applier.fail(Status.UNAUTHENTICATED.withCause(e));
            }
        }
    });
}
Also used : StatusException(io.grpc.StatusException) Metadata(io.grpc.Metadata) URI(java.net.URI) Map(java.util.Map)

Example 2 with StatusException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.

the class HealthStatusManagerTest method checkStatusNotFound.

@Test
public void checkStatusNotFound() throws Exception {
    //setup
    manager.setStatus("", status);
    HealthCheckRequest request = HealthCheckRequest.newBuilder().setService("invalid").build();
    @SuppressWarnings("unchecked") StreamObserver<HealthCheckResponse> observer = mock(StreamObserver.class);
    //test
    health.check(request, observer);
    //verify
    ArgumentCaptor<StatusException> exception = ArgumentCaptor.forClass(StatusException.class);
    verify(observer, times(1)).onError(exception.capture());
    assertEquals(Status.NOT_FOUND, exception.getValue().getStatus());
    verify(observer, never()).onCompleted();
}
Also used : StatusException(io.grpc.StatusException) HealthCheckResponse(io.grpc.health.v1.HealthCheckResponse) HealthCheckRequest(io.grpc.health.v1.HealthCheckRequest) Test(org.junit.Test)

Example 3 with StatusException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project core-java by SpineEventEngine.

the class StreamObserversShould method return_Error_extracted_form_StatusException_metadata.

@Test
public void return_Error_extracted_form_StatusException_metadata() {
    final Error expectedError = Error.getDefaultInstance();
    final Metadata metadata = MetadataConverter.toMetadata(expectedError);
    final StatusException statusException = INVALID_ARGUMENT.asException(metadata);
    assertEquals(expectedError, StreamObservers.fromStreamError(statusException).get());
}
Also used : StatusException(io.grpc.StatusException) Metadata(io.grpc.Metadata) Error(io.spine.base.Error) Test(org.junit.Test)

Example 4 with StatusException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project bookkeeper by apache.

the class TestStorageContainerResponseHandler method testStatusException.

@SuppressWarnings("unchecked")
@Test
public void testStatusException() {
    StreamObserver<StorageContainerResponse> observer = mock(StreamObserver.class);
    StorageContainerResponseHandler handler = StorageContainerResponseHandler.of(observer);
    StatusException exception = new StatusException(Status.NOT_FOUND);
    handler.accept(null, exception);
    verify(observer, times(0)).onNext(any());
    verify(observer, times(0)).onCompleted();
    verify(observer, times(1)).onError(exception);
}
Also used : StatusException(io.grpc.StatusException) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 5 with StatusException

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project pinpoint by naver.

the class PinpointGrpcServer method close.

public void close(SocketStateCode toState) {
    logger.info("close() will be started. ( remoteAddress:{}, agentInfo:{}, closeState:{}", remoteAddress, agentInfo.getAgentKey(), toState);
    if (onCloseHandler != null) {
        onCloseHandler.run();
    }
    synchronized (this) {
        try {
            SocketStateCode currentState = getState();
            if (SocketStateCode.isRun(currentState)) {
                if (toState == SocketStateCode.BEING_CLOSE_BY_SERVER || toState == SocketStateCode.BEING_CLOSE_BY_CLIENT) {
                    toState(toState);
                    requestObserver.onCompleted();
                } else {
                    toState(toState);
                    requestObserver.onError(new StatusException(Status.UNKNOWN));
                }
            }
        } catch (Exception e) {
            // It could throw exception when requestObserver is already completed.
            logger.warn("Exception occurred while requestObserver invokes onCompleted. message:{}", e.getMessage(), e);
        }
        try {
            SocketStateCode currentStateCode = getState();
            if (SocketStateCode.BEING_CLOSE_BY_SERVER == currentStateCode) {
                toState(SocketStateCode.CLOSED_BY_SERVER);
            } else if (SocketStateCode.BEING_CLOSE_BY_CLIENT == currentStateCode) {
                toState(SocketStateCode.CLOSED_BY_CLIENT);
            } else if (SocketStateCode.isClosed(currentStateCode)) {
                logger.warn("stop(). Socket has closed state({}).", currentStateCode);
            } else {
                toState(SocketStateCode.ERROR_ILLEGAL_STATE_CHANGE);
                logger.warn("stop(). Socket has unexpected state({})", currentStateCode);
            }
        } finally {
            logger.info("{} <=> local all streamChannels will be close.", agentInfo.getAgentKey());
            streamChannelRepository.close(StreamCode.STATE_CLOSED);
        }
    }
}
Also used : StatusException(io.grpc.StatusException) SocketStateCode(com.navercorp.pinpoint.rpc.common.SocketStateCode) StatusException(io.grpc.StatusException) PinpointSocketException(com.navercorp.pinpoint.rpc.PinpointSocketException) TException(org.apache.thrift.TException) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException)

Aggregations

StatusException (io.grpc.StatusException)45 Test (org.junit.Test)20 Status (io.grpc.Status)9 IOException (java.io.IOException)9 StatusException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException)9 ExecutionException (java.util.concurrent.ExecutionException)8 PinpointGrpcServer (com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer)6 Metadata (io.grpc.Metadata)6 StatusRuntimeException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException)5 HealthCheckResponse (io.grpc.health.v1.HealthCheckResponse)4 TrackingObjectPoolForTest (io.grpc.netty.NettyTestUtil.TrackingObjectPoolForTest)4 TimeoutException (java.util.concurrent.TimeoutException)4 StatusRuntimeException (io.grpc.StatusRuntimeException)3 InetSocketAddress (java.net.InetSocketAddress)3 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 RunnerApi (org.apache.beam.model.pipeline.v1.RunnerApi)3 AgentInfo (com.navercorp.pinpoint.collector.cluster.AgentInfo)2 PCmdMessage (com.navercorp.pinpoint.grpc.trace.PCmdMessage)2 PCmdRequest (com.navercorp.pinpoint.grpc.trace.PCmdRequest)2 PCmdResponse (com.navercorp.pinpoint.grpc.trace.PCmdResponse)2