Search in sources :

Example 6 with PinpointGrpcServer

use of com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer in project pinpoint by naver.

the class ClusterPointRepository method getAvailableAgentKeyList.

public Set<String> getAvailableAgentKeyList() {
    synchronized (this) {
        Set<String> availableAgentKeySet = new HashSet<>(clusterPointRepository.size());
        for (Map.Entry<String, Set<T>> entry : clusterPointRepository.entrySet()) {
            final String key = entry.getKey();
            final Set<T> clusterPointSet = entry.getValue();
            for (T clusterPoint : clusterPointSet) {
                if (clusterPoint instanceof ThriftAgentConnection) {
                    PinpointServer pinpointServer = ((ThriftAgentConnection) clusterPoint).getPinpointServer();
                    if (SocketStateCode.isRunDuplex(pinpointServer.getCurrentStateCode())) {
                        availableAgentKeySet.add(key);
                    }
                } else if (clusterPoint instanceof GrpcAgentConnection) {
                    PinpointGrpcServer pinpointGrpcServer = ((GrpcAgentConnection) clusterPoint).getPinpointGrpcServer();
                    if (SocketStateCode.isRunDuplex(pinpointGrpcServer.getState())) {
                        availableAgentKeySet.add(key);
                    }
                }
            }
        }
        return availableAgentKeySet;
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) PinpointGrpcServer(com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 7 with PinpointGrpcServer

use of com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer in project pinpoint by naver.

the class GrpcCommandService method commandEcho.

@Override
public void commandEcho(PCmdEchoResponse echoResponse, StreamObserver<Empty> responseObserver) {
    final Long transportId = getTransportId();
    PinpointGrpcServer pinpointGrpcServer = grpcServerRepository.get(transportId);
    if (pinpointGrpcServer != null) {
        echoService.handle(pinpointGrpcServer, echoResponse, responseObserver);
        responseObserver.onNext(Empty.getDefaultInstance());
        responseObserver.onCompleted();
    } else {
        logger.info("{} => local. Can't find PinpointGrpcServer(transportId={})", getAgentInfo().getAgentKey(), transportId);
        responseObserver.onError(new StatusException(Status.NOT_FOUND));
    }
}
Also used : StatusException(io.grpc.StatusException) PinpointGrpcServer(com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer)

Example 8 with PinpointGrpcServer

use of com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer 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 9 with PinpointGrpcServer

use of com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer 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)

Example 10 with PinpointGrpcServer

use of com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer in project pinpoint by naver.

the class GrpcCommandService method commandActiveThreadDump.

@Override
public void commandActiveThreadDump(PCmdActiveThreadDumpRes activeThreadDumpRes, StreamObserver<Empty> responseObserver) {
    final Long transportId = getTransportId();
    PinpointGrpcServer pinpointGrpcServer = grpcServerRepository.get(transportId);
    if (pinpointGrpcServer != null) {
        activeThreadDumpService.handle(pinpointGrpcServer, activeThreadDumpRes, responseObserver);
        responseObserver.onNext(Empty.getDefaultInstance());
        responseObserver.onCompleted();
    } else {
        logger.info("{} => local. Can't find PinpointGrpcServer(transportId={})", getAgentInfo().getAgentKey(), transportId);
        responseObserver.onError(new StatusException(Status.NOT_FOUND));
    }
}
Also used : StatusException(io.grpc.StatusException) PinpointGrpcServer(com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer)

Aggregations

PinpointGrpcServer (com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer)11 StatusException (io.grpc.StatusException)6 AgentInfo (com.navercorp.pinpoint.collector.cluster.AgentInfo)2 GrpcAgentConnection (com.navercorp.pinpoint.collector.cluster.GrpcAgentConnection)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 ServerCallStreamObserver (io.grpc.stub.ServerCallStreamObserver)2 StreamObserver (io.grpc.stub.StreamObserver)2 Test (org.junit.Test)2 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)1 PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)1 TResult (com.navercorp.pinpoint.thrift.dto.TResult)1 TCommandEcho (com.navercorp.pinpoint.thrift.dto.command.TCommandEcho)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1