Search in sources :

Example 1 with ClusterPointStateChangedEventHandler

use of com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler in project pinpoint by naver.

the class ZookeeperJobWorkerTest method test1.

@Test
public void test1() throws Exception {
    InMemoryZookeeperClient zookeeperClient = new InMemoryZookeeperClient(true);
    zookeeperClient.connect();
    ZookeeperProfilerClusterManager manager = new ZookeeperProfilerClusterManager(zookeeperClient, PATH, new ClusterPointRepository());
    manager.start();
    ClusterPointStateChangedEventHandler clusterPointStateChangedEventHandler = new ClusterPointStateChangedEventHandler(channelPropertiesFactory, manager);
    try {
        int random = ThreadLocalRandom.current().nextInt(10, 20);
        for (int i = 0; i < random; i++) {
            PinpointServer mockServer = createMockPinpointServer("app" + i, "agent" + i, System.currentTimeMillis());
            clusterPointStateChangedEventHandler.stateUpdated(mockServer, SocketStateCode.RUN_DUPLEX);
        }
        waitZookeeperServerData(random, zookeeperClient);
        Assert.assertEquals(random, manager.getClusterData().size());
    } finally {
        manager.stop();
    }
}
Also used : ClusterPointRepository(com.navercorp.pinpoint.collector.cluster.ClusterPointRepository) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) ClusterPointStateChangedEventHandler(com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler) Test(org.junit.Test)

Example 2 with ClusterPointStateChangedEventHandler

use of com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler in project pinpoint by naver.

the class AgentBaseDataReceiver method prepare.

private void prepare(PinpointServerAcceptor acceptor) {
    if (clusterService != null && clusterService.isEnable()) {
        ProfilerClusterManager profilerClusterManager = clusterService.getProfilerClusterManager();
        final ServerStateChangeEventHandler stateChangeEventHandler = new ClusterPointStateChangedEventHandler(channelPropertiesFactory, profilerClusterManager);
        logger.info("Add Cluster channel state change event handlers {}", stateChangeEventHandler);
        acceptor.addStateChangeEventHandler(stateChangeEventHandler);
    } else {
        logger.info("clusterService is disabled");
    }
    for (ServerStateChangeEventHandler channelStateChangeEventHandler : this.channelStateChangeEventHandlers) {
        logger.info("Add channel state change event handlers {}", channelStateChangeEventHandler);
        acceptor.addStateChangeEventHandler(channelStateChangeEventHandler);
    }
}
Also used : ServerStateChangeEventHandler(com.navercorp.pinpoint.rpc.server.handler.ServerStateChangeEventHandler) ProfilerClusterManager(com.navercorp.pinpoint.collector.cluster.ProfilerClusterManager) ClusterPointStateChangedEventHandler(com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler)

Example 3 with ClusterPointStateChangedEventHandler

use of com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler in project pinpoint by naver.

the class ZookeeperJobWorkerTest method test3.

@Test
public void test3() throws Exception {
    InMemoryZookeeperClient zookeeperClient = new InMemoryZookeeperClient(true);
    zookeeperClient.connect();
    ZookeeperProfilerClusterManager manager = new ZookeeperProfilerClusterManager(zookeeperClient, PATH, new ClusterPointRepository());
    manager.start();
    ClusterPointStateChangedEventHandler clusterPointStateChangedEventHandler = new ClusterPointStateChangedEventHandler(channelPropertiesFactory, manager);
    try {
        PinpointServer mockServer = createMockPinpointServer("app", "agent", System.currentTimeMillis());
        clusterPointStateChangedEventHandler.stateUpdated(mockServer, SocketStateCode.RUN_DUPLEX);
        waitZookeeperServerData(1, zookeeperClient);
        Assert.assertEquals(1, manager.getClusterData().size());
        zookeeperClient.createPath(PATH);
        CreateNodeMessage createNodeMessage = new CreateNodeMessage(PATH, new byte[0]);
        try {
            zookeeperClient.createOrSetNode(createNodeMessage);
        } catch (Exception ignore) {
        }
        try {
            zookeeperClient.createOrSetNode(createNodeMessage);
        } catch (Exception ignore) {
        }
        waitZookeeperServerData(0, zookeeperClient);
        Assert.assertEquals(0, manager.getClusterData().size());
        manager.refresh();
        waitZookeeperServerData(1, zookeeperClient);
        Assert.assertEquals(1, manager.getClusterData().size());
    } finally {
        manager.stop();
    }
}
Also used : ClusterPointRepository(com.navercorp.pinpoint.collector.cluster.ClusterPointRepository) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) CreateNodeMessage(com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage) PinpointZookeeperException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException) ClusterPointStateChangedEventHandler(com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler) Test(org.junit.Test)

Example 4 with ClusterPointStateChangedEventHandler

use of com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler in project pinpoint by naver.

the class ZookeeperJobWorkerTest method test2.

@Test
public void test2() throws Exception {
    InMemoryZookeeperClient zookeeperClient = new InMemoryZookeeperClient(true);
    zookeeperClient.connect();
    ZookeeperProfilerClusterManager manager = new ZookeeperProfilerClusterManager(zookeeperClient, PATH, new ClusterPointRepository());
    manager.start();
    ClusterPointStateChangedEventHandler clusterPointStateChangedEventHandler = new ClusterPointStateChangedEventHandler(channelPropertiesFactory, manager);
    try {
        PinpointServer mockServer = createMockPinpointServer("app", "agent", System.currentTimeMillis());
        clusterPointStateChangedEventHandler.stateUpdated(mockServer, SocketStateCode.RUN_DUPLEX);
        waitZookeeperServerData(1, zookeeperClient);
        Assert.assertEquals(1, manager.getClusterData().size());
        clusterPointStateChangedEventHandler.stateUpdated(mockServer, SocketStateCode.CLOSED_BY_CLIENT);
        waitZookeeperServerData(0, zookeeperClient);
        Assert.assertEquals(0, manager.getClusterData().size());
    } finally {
        manager.stop();
    }
}
Also used : ClusterPointRepository(com.navercorp.pinpoint.collector.cluster.ClusterPointRepository) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) ClusterPointStateChangedEventHandler(com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler) Test(org.junit.Test)

Example 5 with ClusterPointStateChangedEventHandler

use of com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler in project pinpoint by naver.

the class ZookeeperJobWorkerTest method test4.

@Test
public void test4() throws Exception {
    InMemoryZookeeperClient zookeeperClient = new InMemoryZookeeperClient(true);
    zookeeperClient.connect();
    ZookeeperProfilerClusterManager manager = new ZookeeperProfilerClusterManager(zookeeperClient, PATH, new ClusterPointRepository());
    manager.start();
    ClusterPointStateChangedEventHandler clusterPointStateChangedEventHandler = new ClusterPointStateChangedEventHandler(channelPropertiesFactory, manager);
    try {
        PinpointServer mockServer1 = createMockPinpointServer("app", "agent", System.currentTimeMillis());
        clusterPointStateChangedEventHandler.stateUpdated(mockServer1, SocketStateCode.RUN_DUPLEX);
        PinpointServer mockServer2 = createMockPinpointServer("app", "agent", System.currentTimeMillis() + 1000);
        clusterPointStateChangedEventHandler.stateUpdated(mockServer2, SocketStateCode.RUN_DUPLEX);
        waitZookeeperServerData(2, zookeeperClient);
        Assert.assertEquals(2, manager.getClusterData().size());
        clusterPointStateChangedEventHandler.stateUpdated(mockServer1, SocketStateCode.CLOSED_BY_SERVER);
        waitZookeeperServerData(1, zookeeperClient);
        Assert.assertEquals(1, manager.getClusterData().size());
    } finally {
        manager.stop();
    }
}
Also used : ClusterPointRepository(com.navercorp.pinpoint.collector.cluster.ClusterPointRepository) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) ClusterPointStateChangedEventHandler(com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler) Test(org.junit.Test)

Aggregations

ClusterPointStateChangedEventHandler (com.navercorp.pinpoint.collector.cluster.ClusterPointStateChangedEventHandler)5 ClusterPointRepository (com.navercorp.pinpoint.collector.cluster.ClusterPointRepository)4 PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)4 Test (org.junit.Test)4 ProfilerClusterManager (com.navercorp.pinpoint.collector.cluster.ProfilerClusterManager)1 CreateNodeMessage (com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage)1 PinpointZookeeperException (com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException)1 ServerStateChangeEventHandler (com.navercorp.pinpoint.rpc.server.handler.ServerStateChangeEventHandler)1