Search in sources :

Example 1 with StreamException

use of com.navercorp.pinpoint.rpc.stream.StreamException in project pinpoint by naver.

the class GrpcClientStreamChannelTest method connect.

private CountDownLatch connect(GrpcClientStreamChannel grpcClientStreamChannel, CountDownLatch connectCompleteLatch) {
    CountDownLatch threadCompleteLatch = new CountDownLatch(1);
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                grpcClientStreamChannel.connect(new Runnable() {

                    @Override
                    public void run() {
                        connectCompleteLatch.countDown();
                    }
                }, 1000);
            } catch (StreamException e) {
                e.printStackTrace();
            } finally {
                threadCompleteLatch.countDown();
            }
        }
    });
    thread.setDaemon(true);
    thread.start();
    return threadCompleteLatch;
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException)

Example 2 with StreamException

use of com.navercorp.pinpoint.rpc.stream.StreamException in project pinpoint by naver.

the class StreamRouteHandler method onRoute0.

private TCommandTransferResponse onRoute0(StreamEvent event) {
    TBase<?, ?> requestObject = event.getRequestObject();
    if (requestObject == null) {
        return createResponse(TRouteResult.EMPTY_REQUEST);
    }
    ClusterPoint<?> clusterPoint = findClusterPoint(event.getDeliveryCommand());
    if (clusterPoint == null) {
        return createResponse(TRouteResult.NOT_FOUND);
    }
    if (!clusterPoint.isSupportCommand(requestObject)) {
        logger.warn("Create StreamChannel failed. target:{}, message:{} is not supported command", clusterPoint, requestObject.getClass().getName());
        return createResponse(TRouteResult.NOT_SUPPORTED_REQUEST);
    }
    try {
        if (clusterPoint instanceof ThriftAgentConnection) {
            StreamRouteManager routeManager = new StreamRouteManager(event);
            ServerStreamChannel consumerStreamChannel = event.getStreamChannel();
            consumerStreamChannel.setAttributeIfAbsent(ATTACHMENT_KEY, routeManager);
            ClientStreamChannel producerStreamChannel = createStreamChannel((ThriftAgentConnection) clusterPoint, event.getDeliveryCommand().getPayload(), routeManager);
            routeManager.setProducer(producerStreamChannel);
            return createResponse(TRouteResult.OK);
        } else if (clusterPoint instanceof GrpcAgentConnection) {
            StreamRouteManager routeManager = new StreamRouteManager(event);
            ServerStreamChannel consumerStreamChannel = event.getStreamChannel();
            consumerStreamChannel.setAttributeIfAbsent(ATTACHMENT_KEY, routeManager);
            ClientStreamChannel producerStreamChannel = ((GrpcAgentConnection) clusterPoint).openStream(event.getRequestObject(), routeManager);
            routeManager.setProducer(producerStreamChannel);
            return createResponse(TRouteResult.OK);
        } else {
            return createResponse(TRouteResult.NOT_SUPPORTED_SERVICE);
        }
    } catch (StreamException e) {
        StreamCode streamCode = e.getStreamCode();
        return createResponse(TRouteResult.STREAM_CREATE_ERROR, streamCode.name());
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn("Create StreamChannel failed. target:{}, message:{}", clusterPoint, e.getMessage(), e);
        }
    }
    return createResponse(TRouteResult.UNKNOWN);
}
Also used : ThriftAgentConnection(com.navercorp.pinpoint.collector.cluster.ThriftAgentConnection) GrpcAgentConnection(com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection) ClientStreamChannel(com.navercorp.pinpoint.rpc.stream.ClientStreamChannel) StreamCode(com.navercorp.pinpoint.rpc.packet.stream.StreamCode) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException) ServerStreamChannel(com.navercorp.pinpoint.rpc.stream.ServerStreamChannel) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException)

Example 3 with StreamException

use of com.navercorp.pinpoint.rpc.stream.StreamException in project pinpoint by naver.

the class PinpointGrpcServer method handleStreamMessage.

public void handleStreamMessage(int streamId, GeneratedMessageV3 message) throws StreamException {
    if (logger.isDebugEnabled()) {
        logger.debug("handleStreamMessage() streamId:{}, message:{}", streamId, MessageFormatUtils.debugLog(message));
    }
    GrpcClientStreamChannel streamChannel = (GrpcClientStreamChannel) streamChannelRepository.getStreamChannel(streamId);
    if (streamChannel == null) {
        throw new StreamException(StreamCode.ID_NOT_FOUND, "Can't find suitable streamChannel.(streamId:" + streamId + ")");
    }
    TBase<?, ?> tBase = messageConverter.toMessage(message);
    if (tBase == null) {
        throw new StreamException(StreamCode.TYPE_ERROR, "Failed to convert message.(message:" + MessageFormatUtils.debugLog(message).toString() + ")");
    }
    if (logger.isDebugEnabled()) {
        logger.debug("handleStreamMessage() streamId:{}, message:{}", streamId, tBase);
    }
    try {
        byte[] serialize = SerializationUtils.serialize(tBase, commandHeaderTBaseSerializerFactory);
        streamChannel.handleStreamResponsePacket(new StreamResponsePacket(streamId, serialize));
    } catch (TException t) {
        throw new StreamException(StreamCode.TYPE_UNKNOWN, "Failed to serialize message.(tBase:" + tBase + ")");
    } catch (StreamException e) {
        throw e;
    }
}
Also used : TException(org.apache.thrift.TException) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException) StreamResponsePacket(com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket)

Example 4 with StreamException

use of com.navercorp.pinpoint.rpc.stream.StreamException in project pinpoint by naver.

the class PinpointGrpcServer method openStream.

// 1st message : client(collector) -> server(agent)
public ClientStreamChannel openStream(GeneratedMessageV3 message, ClientStreamChannelEventHandler streamChannelEventHandler) throws StreamException {
    if (!state.checkState(SocketStateCode.RUN_DUPLEX)) {
        throw new StreamException(StreamCode.STATE_NOT_CONNECTED);
    }
    PCmdRequest request = createRequest(message);
    if (request == null) {
        throw new StreamException(StreamCode.TYPE_UNSUPPORT);
    }
    GrpcClientStreamChannel grpcClientStreamChannel = new GrpcClientStreamChannel(remoteAddress, request.getRequestId(), streamChannelRepository, streamChannelEventHandler);
    try {
        grpcClientStreamChannel.init();
        grpcClientStreamChannel.connect(new Runnable() {

            @Override
            public void run() {
                requestObserver.onNext(request);
            }
        }, 1000);
    } catch (StreamException e) {
        grpcClientStreamChannel.close(e.getStreamCode());
        throw e;
    }
    return grpcClientStreamChannel;
}
Also used : PCmdRequest(com.navercorp.pinpoint.grpc.trace.PCmdRequest) StreamException(com.navercorp.pinpoint.rpc.stream.StreamException)

Example 5 with StreamException

use of com.navercorp.pinpoint.rpc.stream.StreamException in project pinpoint by naver.

the class GrpcClientStreamChannel method connect.

public void connect(Runnable connectRunnable, long timeout) throws StreamException {
    changeStateTo(StreamChannelStateCode.CONNECT_AWAIT, true);
    try {
        connectRunnable.run();
    } catch (RuntimeException e) {
        changeStateTo(StreamChannelStateCode.CLOSED);
        throw new StreamException(StreamCode.CONNECTION_ERRROR, e.getMessage());
    }
    boolean connected = awaitOpen(timeout);
    if (connected) {
        logger.info("Open streamChannel initialization completed. streamChannel:{} ", this);
    } else {
        changeStateTo(StreamChannelStateCode.CLOSED);
        throw new StreamException(StreamCode.CONNECTION_TIMEOUT);
    }
}
Also used : StreamException(com.navercorp.pinpoint.rpc.stream.StreamException)

Aggregations

StreamException (com.navercorp.pinpoint.rpc.stream.StreamException)10 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)2 StreamCode (com.navercorp.pinpoint.rpc.packet.stream.StreamCode)2 ClientStreamChannel (com.navercorp.pinpoint.rpc.stream.ClientStreamChannel)2 StreamChannelRepository (com.navercorp.pinpoint.rpc.stream.StreamChannelRepository)2 TCommandTransfer (com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer)2 TException (org.apache.thrift.TException)2 Test (org.junit.Test)2 GrpcAgentConnection (com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection)1 ThriftAgentConnection (com.navercorp.pinpoint.collector.cluster.ThriftAgentConnection)1 PCmdRequest (com.navercorp.pinpoint.grpc.trace.PCmdRequest)1 StreamResponsePacket (com.navercorp.pinpoint.rpc.packet.stream.StreamResponsePacket)1 ServerStreamChannel (com.navercorp.pinpoint.rpc.stream.ServerStreamChannel)1 StreamChannel (com.navercorp.pinpoint.rpc.stream.StreamChannel)1 CountDownLatch (java.util.concurrent.CountDownLatch)1