Search in sources :

Example 6 with PCmdResponse

use of com.navercorp.pinpoint.grpc.trace.PCmdResponse in project pinpoint by naver.

the class GrpcCommandService method handleCommandV2.

@Override
public StreamObserver<PCmdMessage> handleCommandV2(StreamObserver<PCmdRequest> requestObserver) {
    final Long transportId = getTransportId();
    final AgentInfo agentInfo = getAgentInfo();
    final List<Integer> supportCommandCodeList = getSupportCommandCodeList();
    logger.info("{} => local. handleCommandV2(). transportId:{}, supportCommandCodeList{}", agentInfo, transportId, supportCommandCodeList);
    if (supportCommandCodeList == Header.SUPPORT_COMMAND_CODE_LIST_NOT_EXIST) {
        logger.warn("handleCommandV2() not allow empty Header:{}. Connection will be disconnected.", Header.SUPPORT_COMMAND_CODE.name());
        requestObserver.onError(new StatusException(Status.INVALID_ARGUMENT));
        return DisabledStreamObserver.instance();
    }
    final PinpointGrpcServer pinpointGrpcServer = registerNewPinpointGrpcServer(requestObserver, agentInfo, transportId);
    if (pinpointGrpcServer == null) {
        return handleServerRegistrationFailed(requestObserver, agentInfo, transportId);
    }
    final ServerCallStreamObserver<PCmdRequest> serverCallStreamObserver = (ServerCallStreamObserver<PCmdRequest>) requestObserver;
    serverCallStreamObserver.setOnReadyHandler(new Runnable() {

        public void run() {
            if (serverCallStreamObserver.isReady()) {
                logger.info("{} => local. ready() transportId:{}", agentInfo.getAgentKey(), transportId);
                pinpointGrpcServer.connected();
                registerAgentCommandList(pinpointGrpcServer, supportCommandCodeList);
            }
            pinpointGrpcServer.setOnCloseHandler(new Runnable() {

                @Override
                public void run() {
                    unregisterPinpointGrpcServer(transportId);
                }
            });
        }
    });
    final StreamObserver<PCmdMessage> responseObserver = new StreamObserver<PCmdMessage>() {

        @Override
        public void onNext(PCmdMessage value) {
            if (value.hasFailMessage()) {
                PCmdResponse failMessage = value.getFailMessage();
                pinpointGrpcServer.handleFail(failMessage);
            }
        }

        @Override
        public void onError(Throwable t) {
            handleOnError(t, pinpointGrpcServer, agentInfo);
        }

        @Override
        public void onCompleted() {
            handleOnCompleted(pinpointGrpcServer, agentInfo);
        }
    };
    return responseObserver;
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) PinpointGrpcServer(com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer) StatusException(io.grpc.StatusException) PCmdMessage(com.navercorp.pinpoint.grpc.trace.PCmdMessage) PCmdRequest(com.navercorp.pinpoint.grpc.trace.PCmdRequest) AgentInfo(com.navercorp.pinpoint.collector.cluster.AgentInfo) PCmdResponse(com.navercorp.pinpoint.grpc.trace.PCmdResponse)

Example 7 with PCmdResponse

use of com.navercorp.pinpoint.grpc.trace.PCmdResponse in project pinpoint by naver.

the class GrpcCommandService method handleCommand.

@Override
public StreamObserver<PCmdMessage> handleCommand(StreamObserver<PCmdRequest> requestObserver) {
    final Long transportId = getTransportId();
    final AgentInfo agentInfo = getAgentInfo();
    logger.info("{} => local. handleCommand(). transportId:{}.", agentInfo, transportId);
    final List<Integer> supportCommandCodeList = getSupportCommandCodeList();
    if (supportCommandCodeList != Header.SUPPORT_COMMAND_CODE_LIST_NOT_EXIST) {
        logger.warn("handleCommand() not support included Header:{}. Connection will be disconnected.", Header.SUPPORT_COMMAND_CODE.name());
        requestObserver.onError(new StatusException(Status.INVALID_ARGUMENT));
        return DisabledStreamObserver.instance();
    }
    final PinpointGrpcServer pinpointGrpcServer = registerNewPinpointGrpcServer(requestObserver, agentInfo, transportId);
    if (pinpointGrpcServer == null) {
        return handleServerRegistrationFailed(requestObserver, agentInfo, transportId);
    }
    final ServerCallStreamObserver<PCmdRequest> serverCallStreamObserver = (ServerCallStreamObserver<PCmdRequest>) requestObserver;
    serverCallStreamObserver.setOnReadyHandler(new Runnable() {

        public void run() {
            if (serverCallStreamObserver.isReady()) {
                logger.info("{} => local. ready() transportId:{}", agentInfo.getAgentKey(), transportId);
                pinpointGrpcServer.connected();
            }
            pinpointGrpcServer.setOnCloseHandler(new Runnable() {

                @Override
                public void run() {
                    unregisterPinpointGrpcServer(transportId);
                }
            });
        }
    });
    final StreamObserver<PCmdMessage> responseObserver = new StreamObserver<PCmdMessage>() {

        @Override
        public void onNext(PCmdMessage value) {
            // old operation for handshake
            if (value.hasHandshakeMessage()) {
                List<Integer> supportCommandServiceKeyList = value.getHandshakeMessage().getSupportCommandServiceKeyList();
                registerAgentCommandList(pinpointGrpcServer, supportCommandServiceKeyList);
            } else if (value.hasFailMessage()) {
                PCmdResponse failMessage = value.getFailMessage();
                pinpointGrpcServer.handleFail(failMessage);
            }
        }

        @Override
        public void onError(Throwable t) {
            handleOnError(t, pinpointGrpcServer, agentInfo);
        }

        @Override
        public void onCompleted() {
            handleOnCompleted(pinpointGrpcServer, agentInfo);
        }
    };
    return responseObserver;
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) PinpointGrpcServer(com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer) StatusException(io.grpc.StatusException) PCmdMessage(com.navercorp.pinpoint.grpc.trace.PCmdMessage) PCmdRequest(com.navercorp.pinpoint.grpc.trace.PCmdRequest) AgentInfo(com.navercorp.pinpoint.collector.cluster.AgentInfo) PCmdResponse(com.navercorp.pinpoint.grpc.trace.PCmdResponse)

Aggregations

PCmdResponse (com.navercorp.pinpoint.grpc.trace.PCmdResponse)7 PCmdRequest (com.navercorp.pinpoint.grpc.trace.PCmdRequest)3 AgentInfo (com.navercorp.pinpoint.collector.cluster.AgentInfo)2 PinpointGrpcServer (com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer)2 PCmdMessage (com.navercorp.pinpoint.grpc.trace.PCmdMessage)2 StatusException (io.grpc.StatusException)2 ServerCallStreamObserver (io.grpc.stub.ServerCallStreamObserver)2 StreamObserver (io.grpc.stub.StreamObserver)2 ProfilerClusterManager (com.navercorp.pinpoint.collector.cluster.ProfilerClusterManager)1 PActiveThreadDump (com.navercorp.pinpoint.grpc.trace.PActiveThreadDump)1 PActiveThreadLightDump (com.navercorp.pinpoint.grpc.trace.PActiveThreadLightDump)1 PCmdActiveThreadDump (com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadDump)1 PCmdActiveThreadDumpRes (com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadDumpRes)1 PCmdActiveThreadLightDump (com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadLightDump)1 PCmdActiveThreadLightDumpRes (com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadLightDumpRes)1 PCmdEcho (com.navercorp.pinpoint.grpc.trace.PCmdEcho)1 PCmdEchoResponse (com.navercorp.pinpoint.grpc.trace.PCmdEchoResponse)1 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)1 RequestManager (com.navercorp.pinpoint.rpc.client.RequestManager)1 InetSocketAddress (java.net.InetSocketAddress)1