Search in sources :

Example 1 with PinpointZookeeperException

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

the class ZookeeperClusterService method setUp.

@Override
public void setUp() {
    logger.info("pinpoint-collector cluster setUp");
    switch(this.serviceState.getCurrentState()) {
        case NEW:
            if (this.serviceState.changeStateInitializing()) {
                logger.info("{} initialization started.", this.getClass().getSimpleName());
                ClusterManagerWatcher watcher = new ClusterManagerWatcher();
                this.client = new CuratorZookeeperClient(config.getClusterAddress(), config.getClusterSessionTimeout(), watcher);
                try {
                    this.client.connect();
                } catch (PinpointZookeeperException e) {
                    throw new RuntimeException("ZookeeperClient connect failed", e);
                }
                final String connectedAgentZNodePath = ZKPaths.makePath(config.getCollectorZNodePath(), serverIdentifier);
                this.profilerClusterManager = new ZookeeperProfilerClusterManager(client, connectedAgentZNodePath, clusterPointRouter.getTargetClusterPointRepository());
                this.profilerClusterManager.start();
                this.webClusterManager = new ZookeeperClusterManager(client, webZNodePath, clusterConnectionManager);
                this.webClusterManager.start();
                this.serviceState.changeStateStarted();
                logger.info("{} initialization completed.", this.getClass().getSimpleName());
                if (client.isConnected()) {
                    watcher.handleConnected();
                }
            }
            break;
        case INITIALIZING:
            logger.info("{} already initializing.", this.getClass().getSimpleName());
            break;
        case STARTED:
            logger.info("{} already started.", this.getClass().getSimpleName());
            break;
        case DESTROYING:
            throw new IllegalStateException("Already destroying.");
        case STOPPED:
            throw new IllegalStateException("Already stopped.");
        case ILLEGAL_STATE:
            throw new IllegalStateException("Invalid State.");
    }
}
Also used : PinpointZookeeperException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException) CuratorZookeeperClient(com.navercorp.pinpoint.common.server.cluster.zookeeper.CuratorZookeeperClient)

Example 2 with PinpointZookeeperException

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

the class CuratorZookeeperClient method createPath.

@Override
public void createPath(String value) throws PinpointZookeeperException {
    checkState();
    String path = getPath(value, false);
    logger.debug("createPath() started. value:{}, path:{}", value, path);
    CuratorFramework curator = connectionManager.getCuratorFramework();
    Stat stat = null;
    try {
        stat = curator.checkExists().forPath(path);
    } catch (Exception e) {
        ZookeeperExceptionResolver.resolveAndThrow(e);
    }
    if (stat == null) {
        try {
            curator.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(path);
        } catch (KeeperException.NodeExistsException nodeExists) {
        // skip
        } catch (Exception e) {
            ZookeeperExceptionResolver.resolveAndThrow(e);
        }
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Stat(org.apache.zookeeper.data.Stat) PinpointZookeeperException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException) KeeperException(org.apache.zookeeper.KeeperException) ConnectionException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.ConnectionException) KeeperException(org.apache.zookeeper.KeeperException)

Example 3 with PinpointZookeeperException

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

the class CuratorZookeeperClient method createNode0.

private void createNode0(CreateNodeMessage message, boolean orSet) throws PinpointZookeeperException {
    checkState();
    try {
        CuratorFramework curator = connectionManager.getCuratorFramework();
        CreateBuilder createBuilder = curator.create();
        if (message.isCreatingParentPathsIfNeeded()) {
            createBuilder.creatingParentsIfNeeded();
        }
        if (orSet) {
            createBuilder.orSetData();
        }
        String nodePath = message.getNodePath();
        byte[] data = message.getData();
        createBuilder.withMode(CreateMode.EPHEMERAL).forPath(nodePath, data);
    } catch (Exception e) {
        ZookeeperExceptionResolver.resolveAndThrow(e);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) CreateBuilder(org.apache.curator.framework.api.CreateBuilder) PinpointZookeeperException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException) KeeperException(org.apache.zookeeper.KeeperException) ConnectionException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.ConnectionException)

Example 4 with PinpointZookeeperException

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

the class CuratorZookeeperClient method checkState.

private void checkState() throws PinpointZookeeperException {
    if (!isConnected()) {
        notConnectedStatus.update();
        if (reconnectCondition.check(notConnectedStatus)) {
            notConnectedStatus.reset();
            try {
                final org.apache.curator.CuratorZookeeperClient zookeeperClient = connectionManager.getCuratorFramework().getZookeeperClient();
                logger.warn("ConnectionState looks something wrong. It will be reset.");
                zookeeperClient.reset();
                return;
            } catch (Exception e) {
                logger.warn("Could not reset connection. cause:{}", e.getMessage(), e);
            }
        }
        final ConnectionState connectionState = connectionManager.getConnectionState();
        throw new ConnectionException("Instance must be connected. connectionState:" + connectionState);
    } else {
        notConnectedStatus.reset();
    }
}
Also used : ConnectionState(org.apache.curator.framework.state.ConnectionState) PinpointZookeeperException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException) KeeperException(org.apache.zookeeper.KeeperException) ConnectionException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.ConnectionException) ConnectionException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.ConnectionException)

Example 5 with PinpointZookeeperException

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

the class CuratorZookeeperClient method getChildNodeList.

@Override
public List<String> getChildNodeList(String value, boolean watch) throws PinpointZookeeperException {
    checkState();
    String path = getPath(value, true);
    logger.debug("getChildNodeList() started. path:{}, watch:{}", path, watch);
    try {
        CuratorFramework curator = connectionManager.getCuratorFramework();
        final GetChildrenBuilder children = curator.getChildren();
        if (watch) {
            return children.usingWatcher(zookeeperEventWatcher).forPath(path);
        } else {
            return children.forPath(path);
        }
    } catch (KeeperException.NoNodeException noNode) {
    // skip
    } catch (Exception e) {
        ZookeeperExceptionResolver.resolveAndThrow(e);
    }
    return Collections.emptyList();
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) GetChildrenBuilder(org.apache.curator.framework.api.GetChildrenBuilder) KeeperException(org.apache.zookeeper.KeeperException) PinpointZookeeperException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException) KeeperException(org.apache.zookeeper.KeeperException) ConnectionException(com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.ConnectionException)

Aggregations

PinpointZookeeperException (com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException)9 ConnectionException (com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.ConnectionException)6 KeeperException (org.apache.zookeeper.KeeperException)6 CuratorFramework (org.apache.curator.framework.CuratorFramework)5 CuratorZookeeperClient (com.navercorp.pinpoint.common.server.cluster.zookeeper.CuratorZookeeperClient)3 ZookeeperClusterManager (com.navercorp.pinpoint.collector.cluster.zookeeper.ZookeeperClusterManager)1 PostConstruct (javax.annotation.PostConstruct)1 CreateBuilder (org.apache.curator.framework.api.CreateBuilder)1 GetChildrenBuilder (org.apache.curator.framework.api.GetChildrenBuilder)1 GetDataBuilder (org.apache.curator.framework.api.GetDataBuilder)1 ConnectionState (org.apache.curator.framework.state.ConnectionState)1 Stat (org.apache.zookeeper.data.Stat)1