Search in sources :

Example 21 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.

the class RestartAndDumpService method initRestart.

private void initRestart() throws Exception {
    restartES = Executors.newSingleThreadExecutor(new SaturnThreadFactory(executorName + "-restart-watcher-thread", false));
    // Remove the restart node, before add watcher that watches the create and update event
    String nodePath = SaturnExecutorsNode.EXECUTORS_ROOT + "/" + executorName + "/restart";
    coordinatorRegistryCenter.remove(nodePath);
    restartNC = new NodeCache(curatorFramework, nodePath);
    restartNC.getListenable().addListener(new NodeCacheListener() {

        @Override
        public void nodeChanged() throws Exception {
            // Watch create, update event
            if (restartNC.getCurrentData() != null) {
                LogUtils.info(log, LogEvents.ExecutorEvent.RESTART, "The executor {} restart event is received", executorName);
                restartES.execute(new Runnable() {

                    @Override
                    public void run() {
                        executeRestartOrDumpCmd("restart", LogEvents.ExecutorEvent.RESTART);
                    }
                });
            }
        }
    });
    // Start, with not buildInitial.
    // The initial data is null, so the create event will be triggered firstly.
    restartNC.start(false);
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) NodeCacheListener(org.apache.curator.framework.recipes.cache.NodeCacheListener) SaturnThreadFactory(com.vip.saturn.job.threads.SaturnThreadFactory) SaturnJobException(com.vip.saturn.job.exception.SaturnJobException)

Example 22 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.

the class ZkCacheManager method closeAllNodeCache.

public void closeAllNodeCache() {
    Iterator<Entry<String, NodeCache>> iterator = nodeCacheMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, NodeCache> next = iterator.next();
        NodeCache nc = next.getValue();
        String path = next.getKey();
        try {
            nc.close();
            iterator.remove();
            LogUtils.info(log, jobName, "{} - {} closed nodeCache, path is {}", executorName, jobName, path);
        } catch (Exception e) {
            LogUtils.error(log, jobName, e.getMessage(), e);
        }
    }
}
Also used : Entry(java.util.Map.Entry) NodeCache(org.apache.curator.framework.recipes.cache.NodeCache)

Example 23 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.

the class ZkCacheManager method buildAndStartNodeCache.

public NodeCache buildAndStartNodeCache(String path) {
    try {
        NodeCache nc = nodeCacheMap.get(path);
        if (nc == null) {
            nc = new NodeCache(client, path);
            nodeCacheMap.put(path, nc);
            nc.start();
            LogUtils.info(log, jobName, "{} - {} builds nodeCache for path = {}", executorName, jobName, path);
        }
        return nc;
    } catch (Exception e) {
        LogUtils.error(log, jobName, "{} - {}  fails in building nodeCache for path = {}, saturn will not work correctly.", executorName, jobName, path);
        LogUtils.error(log, jobName, e.getMessage(), e);
    }
    return null;
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache)

Example 24 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project Saturn by vipshop.

the class ZkCacheManager method closeNodeCache.

public void closeNodeCache(String path) {
    NodeCache nc = nodeCacheMap.get(path);
    if (nc != null) {
        try {
            nc.close();
            nodeCacheMap.remove(path);
            LogUtils.info(log, jobName, "{} - {} closed nodeCache, path is {}", executorName, jobName, path);
        } catch (Exception e) {
            LogUtils.error(log, jobName, e.getMessage(), e);
        }
    }
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache)

Example 25 with NodeCache

use of org.apache.flink.shaded.curator5.org.apache.curator.framework.recipes.cache.NodeCache in project dubbo by alibaba.

the class CuratorZookeeperClient method addTargetDataListener.

@Override
protected void addTargetDataListener(String path, CuratorZookeeperClient.NodeCacheListenerImpl nodeCacheListener, Executor executor) {
    try {
        NodeCache nodeCache = new NodeCache(client, path);
        if (nodeCacheMap.putIfAbsent(path, nodeCache) != null) {
            return;
        }
        if (executor == null) {
            nodeCache.getListenable().addListener(nodeCacheListener);
        } else {
            nodeCache.getListenable().addListener(nodeCacheListener, executor);
        }
        nodeCache.start();
    } catch (Exception e) {
        throw new IllegalStateException("Add nodeCache listener for path:" + path, e);
    }
}
Also used : NodeCache(org.apache.curator.framework.recipes.cache.NodeCache) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException)

Aggregations

NodeCache (org.apache.curator.framework.recipes.cache.NodeCache)32 NodeCacheListener (org.apache.curator.framework.recipes.cache.NodeCacheListener)14 IOException (java.io.IOException)6 KeeperException (org.apache.zookeeper.KeeperException)6 TimeoutException (java.util.concurrent.TimeoutException)3 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)2 ConsoleThreadFactory (com.vip.saturn.job.console.utils.ConsoleThreadFactory)2 SaturnJobException (com.vip.saturn.job.exception.SaturnJobException)2 SaturnThreadFactory (com.vip.saturn.job.threads.SaturnThreadFactory)2 ChildData (org.apache.curator.framework.recipes.cache.ChildData)2 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)2 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)2 SaturnExecutorException (com.vip.saturn.job.exception.SaturnExecutorException)1 Entry (java.util.Map.Entry)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 SneakyThrows (lombok.SneakyThrows)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 CuratorFrameworkWithUnhandledErrorListener (org.apache.flink.runtime.highavailability.zookeeper.CuratorFrameworkWithUnhandledErrorListener)1 LeaderRetrievalDriver (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalDriver)1