Search in sources :

Example 1 with CreateNodeMessage

use of com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage in project pinpoint by naver.

the class ZookeeperJobWorker method handleClear.

private boolean handleClear(List<ZookeeperJob> zookeeperJobList) {
    if (logger.isDebugEnabled()) {
        logger.debug("handleClear zookeeperJobList:{}", zookeeperJobList);
    }
    try {
        CreateNodeMessage createNodeMessage = new CreateNodeMessage(collectorUniqPath, EMPTY_DATA_BYTES, true);
        zookeeperClient.createOrSetNode(createNodeMessage);
        return true;
    } catch (Exception e) {
        logger.warn("handleClear failed. caused:{}, jobSize:{}", e.getMessage(), zookeeperJobList.size(), e);
    }
    return false;
}
Also used : CreateNodeMessage(com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage) PinpointZookeeperException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException)

Example 2 with CreateNodeMessage

use of com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage in project pinpoint by naver.

the class ZookeeperJobWorker method handleDelete.

private boolean handleDelete(List<ZookeeperJob> zookeeperJobList) {
    if (logger.isDebugEnabled()) {
        logger.debug("handleDelete zookeeperJobList:{}", zookeeperJobList);
    }
    final List<String> removeContentCandidateList = getZookeeperKeyList(zookeeperJobList);
    try {
        zookeeperClient.createPath(collectorUniqPath);
        final String currentData = getClusterData();
        final String newData = removeIfExistContents(currentData, removeContentCandidateList);
        CreateNodeMessage createNodeMessage = new CreateNodeMessage(collectorUniqPath, BytesUtils.toBytes(newData), true);
        zookeeperClient.createOrSetNode(createNodeMessage);
        return true;
    } catch (Exception e) {
        logger.warn("handleDelete failed. caused:{}, jobSize:{}", e.getMessage(), zookeeperJobList.size(), e);
    }
    return false;
}
Also used : CreateNodeMessage(com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage) PinpointZookeeperException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException)

Example 3 with CreateNodeMessage

use of com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage in project pinpoint by naver.

the class ZookeeperJobWorker method handleUpdate.

private boolean handleUpdate(List<ZookeeperJob> zookeeperJobList) {
    if (logger.isDebugEnabled()) {
        logger.debug("handleUpdate zookeeperJobList:{}", zookeeperJobList);
    }
    final List<String> addContentCandidateList = getZookeeperKeyList(zookeeperJobList);
    try {
        zookeeperClient.createPath(collectorUniqPath);
        String currentData = getClusterData();
        final String newData = addIfAbsentContents(currentData, addContentCandidateList);
        CreateNodeMessage createNodeMessage = new CreateNodeMessage(collectorUniqPath, BytesUtils.toBytes(newData), true);
        zookeeperClient.createOrSetNode(createNodeMessage);
        return true;
    } catch (Exception e) {
        logger.warn("handleUpdate failed. caused:{}, jobSize:{}", e.getMessage(), zookeeperJobList.size(), e);
    }
    return false;
}
Also used : CreateNodeMessage(com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage) PinpointZookeeperException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException)

Example 4 with CreateNodeMessage

use of com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage in project pinpoint by naver.

the class ZookeeperClusterDataManager method registerWebCluster.

// Retry upon failure (1 min retry period)
// not too much overhead, just logging
@Override
public boolean registerWebCluster(String zNodeName, byte[] contents) {
    String zNodeFullPath = ZKPaths.makePath(webZNodePath, zNodeName);
    logger.info("registerWebCluster() started. create UniqPath={}.", zNodeFullPath);
    CreateNodeMessage createNodeMessage = new CreateNodeMessage(zNodeFullPath, contents);
    PushWebClusterJob job = new PushWebClusterJob(createNodeMessage, retryInterval);
    if (!this.job.compareAndSet(null, job)) {
        logger.warn("Already Register Web Cluster Node.");
        return false;
    }
    // successful even for scheduler registration completion
    if (!isConnected()) {
        logger.info("Zookeeper is Disconnected.");
        return true;
    }
    if (!clusterDataManagerHelper.pushZnode(client, job.getCreateNodeMessage())) {
        timer.newTimeout(job, job.getRetryInterval(), TimeUnit.MILLISECONDS);
    }
    return true;
}
Also used : CreateNodeMessage(com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage)

Example 5 with CreateNodeMessage

use of com.navercorp.pinpoint.common.server.cluster.zookeeper.CreateNodeMessage 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)

Aggregations

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