Search in sources :

Example 1 with TransportMetadata

use of com.navercorp.pinpoint.grpc.server.TransportMetadata in project pinpoint by naver.

the class GrpcCommandServiceTest method oldVersionHandshakeTest.

@Test
public void oldVersionHandshakeTest() throws IOException, PinpointZookeeperException {
    ZookeeperProfilerClusterManager manager = creteMemoryClusterManager();
    ZookeeperClusterService mockClusterService = Mockito.mock(ZookeeperClusterService.class);
    Mockito.when(mockClusterService.getProfilerClusterManager()).thenReturn(manager);
    try (GrpcCommandService commandService = new GrpcCommandService(mockClusterService)) {
        TransportMetadata transportMetaData = createTransportMetaData(new InetSocketAddress("127.0.0.1", 61613), 10);
        attachContext(transportMetaData);
        attachContext(new Header("test", "agentId", "agentName", "applicationName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis(), Header.SOCKET_ID_NOT_EXIST, null));
        StreamObserver<PCmdMessage> handleMessageObserver = commandService.handleCommand(new TempServerCallStreamObserver<>());
        handleMessageObserver.onNext(createHandshakeMessage());
        awaitility().await("oldVersionHandshakeTest").until(manager::getClusterData, hasSize(1));
        assertHandleMessage(commandService, transportMetaData);
    }
}
Also used : PCmdMessage(com.navercorp.pinpoint.grpc.trace.PCmdMessage) ZookeeperClusterService(com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperClusterService) ZookeeperProfilerClusterManager(com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperProfilerClusterManager) Header(com.navercorp.pinpoint.grpc.Header) DefaultTransportMetadata(com.navercorp.pinpoint.grpc.server.DefaultTransportMetadata) TransportMetadata(com.navercorp.pinpoint.grpc.server.TransportMetadata) InetSocketAddress(java.net.InetSocketAddress) GrpcCommandService(com.navercorp.pinpoint.collector.receiver.grpc.service.command.GrpcCommandService) Test(org.junit.Test)

Example 2 with TransportMetadata

use of com.navercorp.pinpoint.grpc.server.TransportMetadata in project pinpoint by naver.

the class GrpcCommandServiceTest method oldVersionHandshakeFailTest.

@Test
public void oldVersionHandshakeFailTest() throws IOException, PinpointZookeeperException {
    ZookeeperProfilerClusterManager manager = creteMemoryClusterManager();
    ZookeeperClusterService mockClusterService = Mockito.mock(ZookeeperClusterService.class);
    Mockito.when(mockClusterService.getProfilerClusterManager()).thenReturn(manager);
    try (GrpcCommandService commandService = new GrpcCommandService(mockClusterService)) {
        TransportMetadata transportMetaData = createTransportMetaData(new InetSocketAddress("127.0.0.1", 61613), 10);
        attachContext(transportMetaData);
        attachContext(new Header("test", "agentId", "agentName", "applicationName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis(), Header.SOCKET_ID_NOT_EXIST, getCodeList()));
        final TempServerCallStreamObserver<PCmdRequest> requestObserver = new TempServerCallStreamObserver<>();
        StreamObserver<PCmdMessage> handleMessageObserver = commandService.handleCommand(requestObserver);
        Assert.assertThrows(ConditionTimeoutException.class, () -> {
            Awaitility.await("oldVersionHandshakeFailTest").timeout(400, TimeUnit.MILLISECONDS).until(manager::getClusterData, hasSize(1));
        });
        Assert.assertNotNull(requestObserver.getLatestException());
    }
}
Also used : PCmdMessage(com.navercorp.pinpoint.grpc.trace.PCmdMessage) ZookeeperClusterService(com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperClusterService) ZookeeperProfilerClusterManager(com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperProfilerClusterManager) Header(com.navercorp.pinpoint.grpc.Header) DefaultTransportMetadata(com.navercorp.pinpoint.grpc.server.DefaultTransportMetadata) TransportMetadata(com.navercorp.pinpoint.grpc.server.TransportMetadata) PCmdRequest(com.navercorp.pinpoint.grpc.trace.PCmdRequest) InetSocketAddress(java.net.InetSocketAddress) GrpcCommandService(com.navercorp.pinpoint.collector.receiver.grpc.service.command.GrpcCommandService) Test(org.junit.Test)

Example 3 with TransportMetadata

use of com.navercorp.pinpoint.grpc.server.TransportMetadata in project pinpoint by naver.

the class DefaultServerRequestFactory method newServerRequest.

@Override
public <T> ServerRequest<T> newServerRequest(Message<T> message) throws StatusException {
    final Context current = Context.current();
    final Header header = ServerContext.getAgentInfo(current);
    if (header == null) {
        throw Status.INTERNAL.withDescription("Not found request header").asException();
    }
    final TransportMetadata transportMetadata = ServerContext.getTransportMetadata(current);
    if (transportMetadata == null) {
        throw Status.INTERNAL.withDescription("Not found transportMetadata").asException();
    }
    InetSocketAddress inetSocketAddress = transportMetadata.getRemoteAddress();
    ServerRequest<T> request = new DefaultServerRequest<>(message, inetSocketAddress.getHostString(), inetSocketAddress.getPort());
    return request;
}
Also used : ServerContext(com.navercorp.pinpoint.grpc.server.ServerContext) Context(io.grpc.Context) Header(com.navercorp.pinpoint.grpc.Header) TransportMetadata(com.navercorp.pinpoint.grpc.server.TransportMetadata) InetSocketAddress(java.net.InetSocketAddress) DefaultServerRequest(com.navercorp.pinpoint.io.request.DefaultServerRequest)

Example 4 with TransportMetadata

use of com.navercorp.pinpoint.grpc.server.TransportMetadata in project pinpoint by naver.

the class DefaultPingEventHandler method close.

@Override
public void close() {
    final TransportMetadata transportMetadata = ServerContext.getTransportMetadata();
    if (transportMetadata == null) {
        logger.info("Skip close event handle of ping, not found TransportMetadata. header={}", ServerContext.getAgentInfo());
        return;
    }
    final PingSession removedSession = pingSessionRegistry.remove(transportMetadata.getTransportId());
    if (removedSession == null) {
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Remove ping session. pingSession={}", removedSession);
    }
    lifecycleListener.close(removedSession);
}
Also used : TransportMetadata(com.navercorp.pinpoint.grpc.server.TransportMetadata)

Example 5 with TransportMetadata

use of com.navercorp.pinpoint.grpc.server.TransportMetadata in project pinpoint by naver.

the class GrpcCommandServiceTest method newVersionHandshakeTest.

@Test
public void newVersionHandshakeTest() throws IOException, PinpointZookeeperException {
    ZookeeperProfilerClusterManager manager = creteMemoryClusterManager();
    ZookeeperClusterService mockClusterService = Mockito.mock(ZookeeperClusterService.class);
    Mockito.when(mockClusterService.getProfilerClusterManager()).thenReturn(manager);
    try (GrpcCommandService commandService = new GrpcCommandService(mockClusterService)) {
        TransportMetadata transportMetaData = createTransportMetaData(new InetSocketAddress("127.0.0.1", 61613), 10);
        attachContext(transportMetaData);
        attachContext(new Header("test", "agentId", null, "applicationName", ServiceType.UNDEFINED.getCode(), System.currentTimeMillis(), Header.SOCKET_ID_NOT_EXIST, getCodeList()));
        StreamObserver<PCmdMessage> handleMessageObserver = commandService.handleCommandV2(new TempServerCallStreamObserver<>());
        awaitility().until(manager::getClusterData, hasSize(1));
        assertHandleMessage(commandService, transportMetaData);
    }
}
Also used : PCmdMessage(com.navercorp.pinpoint.grpc.trace.PCmdMessage) ZookeeperClusterService(com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperClusterService) ZookeeperProfilerClusterManager(com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperProfilerClusterManager) Header(com.navercorp.pinpoint.grpc.Header) DefaultTransportMetadata(com.navercorp.pinpoint.grpc.server.DefaultTransportMetadata) TransportMetadata(com.navercorp.pinpoint.grpc.server.TransportMetadata) InetSocketAddress(java.net.InetSocketAddress) GrpcCommandService(com.navercorp.pinpoint.collector.receiver.grpc.service.command.GrpcCommandService) Test(org.junit.Test)

Aggregations

TransportMetadata (com.navercorp.pinpoint.grpc.server.TransportMetadata)10 InetSocketAddress (java.net.InetSocketAddress)6 Header (com.navercorp.pinpoint.grpc.Header)5 ZookeeperClusterService (com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperClusterService)3 ZookeeperProfilerClusterManager (com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperProfilerClusterManager)3 GrpcCommandService (com.navercorp.pinpoint.collector.receiver.grpc.service.command.GrpcCommandService)3 DefaultTransportMetadata (com.navercorp.pinpoint.grpc.server.DefaultTransportMetadata)3 PCmdMessage (com.navercorp.pinpoint.grpc.trace.PCmdMessage)3 Test (org.junit.Test)3 ServerContext (com.navercorp.pinpoint.grpc.server.ServerContext)1 PCmdRequest (com.navercorp.pinpoint.grpc.trace.PCmdRequest)1 DefaultServerRequest (com.navercorp.pinpoint.io.request.DefaultServerRequest)1 Context (io.grpc.Context)1