Search in sources :

Example 1 with PCmdResponse

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

the class PinpointGrpcServerTest method requestTest.

@Test
public void requestTest() {
    RecordedStreamObserver<PCmdRequest> recordedStreamObserver = new RecordedStreamObserver<PCmdRequest>();
    PinpointGrpcServer pinpointGrpcServer = new PinpointGrpcServer(Mockito.mock(InetSocketAddress.class), agentInfo, new RequestManager(testTimer, 3000), Mockito.mock(ProfilerClusterManager.class), recordedStreamObserver);
    pinpointGrpcServer.connected();
    List<Integer> supportCommandList = Collections.singletonList(Short.toUnsignedInt(TCommandType.ECHO.getCode()));
    pinpointGrpcServer.handleHandshake(supportCommandList);
    Future<ResponseMessage> future = pinpointGrpcServer.request(this.request);
    Assert.assertEquals(1, recordedStreamObserver.getRequestCount());
    // timeout
    awaitAndAssert(future, false);
    future = pinpointGrpcServer.request(this.request);
    Assert.assertEquals(2, recordedStreamObserver.getRequestCount());
    PCmdRequest latestRequest = recordedStreamObserver.getLatestRequest();
    pinpointGrpcServer.handleMessage(latestRequest.getRequestId(), PCmdEchoResponse.newBuilder().setMessage(latestRequest.getCommandEcho().getMessage()).build());
    // success
    awaitAndAssert(future, true);
    future = pinpointGrpcServer.request(this.request);
    Assert.assertEquals(3, recordedStreamObserver.getRequestCount());
    latestRequest = recordedStreamObserver.getLatestRequest();
    PCmdResponse.Builder builder = PCmdResponse.newBuilder();
    PCmdResponse response = builder.setMessage(StringValue.of("fail")).setResponseId(latestRequest.getRequestId()).build();
    pinpointGrpcServer.handleFail(response);
    // fail
    awaitAndAssert(future, false);
    pinpointGrpcServer.close();
    assertCurrentState(SocketStateCode.CLOSED_BY_SERVER, pinpointGrpcServer);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ResponseMessage(com.navercorp.pinpoint.rpc.ResponseMessage) RequestManager(com.navercorp.pinpoint.rpc.client.RequestManager) PCmdRequest(com.navercorp.pinpoint.grpc.trace.PCmdRequest) ProfilerClusterManager(com.navercorp.pinpoint.collector.cluster.ProfilerClusterManager) PCmdResponse(com.navercorp.pinpoint.grpc.trace.PCmdResponse) Test(org.junit.Test)

Example 2 with PCmdResponse

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

the class GrpcActiveThreadDumpService method handle.

@Override
public void handle(PCmdRequest request, ProfilerCommandServiceGrpc.ProfilerCommandServiceStub profilerCommandServiceStub) {
    logger.info("simpleCommandService:{}", request);
    PCmdActiveThreadDump commandActiveThreadDump = request.getCommandActiveThreadDump();
    PCmdActiveThreadDumpRes.Builder builder = PCmdActiveThreadDumpRes.newBuilder();
    PCmdResponse commonResponse = PCmdResponse.newBuilder().setResponseId(request.getRequestId()).build();
    builder.setCommonResponse(commonResponse);
    builder.setType(JAVA);
    builder.setSubType(JvmUtils.getType().name());
    builder.setVersion(JvmUtils.getVersion().name());
    List<PActiveThreadDump> activeThreadDumpList = getActiveThreadDumpList(commandActiveThreadDump);
    builder.addAllThreadDump(activeThreadDumpList);
    profilerCommandServiceStub.commandActiveThreadDump(builder.build(), EmptyStreamObserver.create());
}
Also used : PCmdActiveThreadDumpRes(com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadDumpRes) PCmdActiveThreadDump(com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadDump) PActiveThreadDump(com.navercorp.pinpoint.grpc.trace.PActiveThreadDump) PCmdResponse(com.navercorp.pinpoint.grpc.trace.PCmdResponse)

Example 3 with PCmdResponse

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

the class GrpcActiveThreadLightDumpService method handle.

@Override
public void handle(PCmdRequest request, ProfilerCommandServiceGrpc.ProfilerCommandServiceStub profilerCommandServiceStub) {
    logger.info("simpleCommandService:{}", request);
    PCmdActiveThreadLightDump commandActiveThreadLightDump = request.getCommandActiveThreadLightDump();
    PCmdActiveThreadLightDumpRes.Builder builder = PCmdActiveThreadLightDumpRes.newBuilder();
    PCmdResponse commonResponse = PCmdResponse.newBuilder().setResponseId(request.getRequestId()).build();
    builder.setCommonResponse(commonResponse);
    builder.setType(JAVA);
    builder.setSubType(JvmUtils.getType().name());
    builder.setVersion(JvmUtils.getVersion().name());
    List<PActiveThreadLightDump> activeThreadDumpList = getActiveThreadDumpList(commandActiveThreadLightDump);
    builder.addAllThreadDump(activeThreadDumpList);
    profilerCommandServiceStub.commandActiveThreadLightDump(builder.build(), EmptyStreamObserver.create());
}
Also used : PCmdActiveThreadLightDump(com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadLightDump) PCmdActiveThreadLightDumpRes(com.navercorp.pinpoint.grpc.trace.PCmdActiveThreadLightDumpRes) PActiveThreadLightDump(com.navercorp.pinpoint.grpc.trace.PActiveThreadLightDump) PCmdResponse(com.navercorp.pinpoint.grpc.trace.PCmdResponse)

Example 4 with PCmdResponse

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

the class GrpcCommandDispatcher method handle.

public void handle(PCmdRequest commandRequest, StreamObserver<PCmdMessage> streamObserver) {
    int value = commandRequest.getCommandCase().getNumber();
    final ProfilerGrpcCommandService grpcCommandService = commandServiceLocator.getGrpcService((short) value);
    if (grpcCommandService != null) {
        try {
            grpcCommandService.handle(commandRequest, profilerCommandServiceStub);
        } catch (Exception e) {
            logger.warn("Failed to handle commandService. message:{}", e.getMessage(), e);
            PCmdResponse failMessage = createFailMessage(commandRequest, e.getMessage());
            if (streamObserver != null) {
                streamObserver.onNext(PCmdMessage.newBuilder().setFailMessage(failMessage).build());
            }
        }
    } else {
        PCmdResponse failMessage = createFailMessage(commandRequest, TRouteResult.NOT_SUPPORTED_REQUEST.name());
        if (streamObserver != null) {
            streamObserver.onNext(PCmdMessage.newBuilder().setFailMessage(failMessage).build());
        }
    }
}
Also used : PCmdResponse(com.navercorp.pinpoint.grpc.trace.PCmdResponse)

Example 5 with PCmdResponse

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

the class GrpcEchoService method handle.

@Override
public void handle(PCmdRequest request, ProfilerCommandServiceGrpc.ProfilerCommandServiceStub profilerCommandServiceStub) {
    logger.info("simpleCommandService:{}", request);
    PCmdEcho commandEcho = request.getCommandEcho();
    PCmdEchoResponse.Builder responseBuilder = PCmdEchoResponse.newBuilder();
    responseBuilder.setMessage(commandEcho.getMessage());
    PCmdResponse commonResponse = PCmdResponse.newBuilder().setResponseId(request.getRequestId()).build();
    responseBuilder.setCommonResponse(commonResponse);
    profilerCommandServiceStub.commandEcho(responseBuilder.build(), EmptyStreamObserver.create());
}
Also used : PCmdEchoResponse(com.navercorp.pinpoint.grpc.trace.PCmdEchoResponse) PCmdResponse(com.navercorp.pinpoint.grpc.trace.PCmdResponse) PCmdEcho(com.navercorp.pinpoint.grpc.trace.PCmdEcho)

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