gpt4 book ai didi

org.apache.zookeeper.ZKUtil类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 13:04:40 26 4
gpt4 key购买 nike

本文整理了Java中org.apache.zookeeper.ZKUtil类的一些代码示例,展示了ZKUtil类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKUtil类的具体详情如下:
包路径:org.apache.zookeeper.ZKUtil
类名称:ZKUtil

ZKUtil介绍

暂无

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-common

@Override
 public Void run() throws KeeperException, InterruptedException {
  ZKUtil.deleteRecursive(zkClient, znodeWorkingDir);
  return null;
 }
});

代码示例来源:origin: apache/zookeeper

/**
 * Recursively delete the node with the given path.
 * <p>
 * Important: All versions, of all nodes, under the given node are deleted.
 * <p>
 * If there is an error with deleting one of the sub-nodes in the tree,
 * this operation would abort and would be the responsibility of the app to handle the same.
 *
 * See {@link #delete(String, int)} for more details.
 *
 * @throws IllegalArgumentException if an invalid path is specified
 */
public static void deleteRecursive(ZooKeeper zk, final String pathRoot)
  throws InterruptedException, KeeperException
{
  PathUtils.validatePath(pathRoot);
  List<String> tree = listSubTreeBFS(zk, pathRoot);
  LOG.debug("Deleting " + tree);
  LOG.debug("Deleting " + tree.size() + " subnodes ");
  for (int i = tree.size() - 1; i >= 0 ; --i) {
    //Delete the leaves first and eventually get rid of the root
    zk.delete(tree.get(i), -1); //Delete all versions of the node with -1.
  }
}

代码示例来源:origin: apache/zookeeper

String error = ZKUtil.validateFileInput(snapshotFile);
if (null != error) {
  System.err.println(error);

代码示例来源:origin: apache/zookeeper

@Override
public boolean exec() throws CliException {
  if (args.length < 2) {
    throw new MalformedCommandException(getUsageStr());
  }
  String path = args[1];
  boolean watch = cl.hasOption("w");
  boolean withStat = cl.hasOption("s");
  boolean recursive = cl.hasOption("R");
  try {
    if (recursive) {
      ZKUtil.visitSubTreeDFS(zk, path, watch, new StringCallback() {
        @Override
        public void processResult(int rc, String path, Object ctx, String name) {
          out.println(path);
        }
      });
    } else {
      Stat stat = withStat ? new Stat() : null;
      List<String> children = zk.getChildren(path, watch, stat);
      printChildren(children, stat);
    }
  } catch (IllegalArgumentException ex) {
    throw new MalformedPathException(ex.getMessage());
  } catch (KeeperException|InterruptedException ex) {
    throw new CliWrapperException(ex);
  }
  return watch;
}

代码示例来源:origin: apache/zookeeper

ZKUtil.visitSubTreeDFS(zk, path, false, new StringCallback() {
  @Override
  public void processResult(int rc, String p, Object ctx, String name) {

代码示例来源:origin: apache/zookeeper

@Override
public boolean exec() throws CliException {
  printDeprecatedWarning();
  
  String path = args[1];
  try {
    ZKUtil.deleteRecursive(zk, path);
  } catch (IllegalArgumentException ex) {
    throw new MalformedPathException(ex.getMessage());
  } catch (KeeperException|InterruptedException ex) {
    throw new CliWrapperException(ex);
  }
  return false;
}

代码示例来源:origin: apache/zookeeper

/**
 * Recursively delete the node with the given path. (async version).
 *
 * <p>
 * Important: All versions, of all nodes, under the given node are deleted.
 * <p>
 * If there is an error with deleting one of the sub-nodes in the tree,
 * this operation would abort and would be the responsibility of the app to handle the same.
 * <p>
 * @param zk the zookeeper handle
 * @param pathRoot the path to be deleted
 * @param cb call back method
 * @param ctx the context the callback method is called with
 * @throws IllegalArgumentException if an invalid path is specified
 */
public static void deleteRecursive(ZooKeeper zk, final String pathRoot, VoidCallback cb,
  Object ctx)
  throws InterruptedException, KeeperException
{
  PathUtils.validatePath(pathRoot);
  List<String> tree = listSubTreeBFS(zk, pathRoot);
  LOG.debug("Deleting " + tree);
  LOG.debug("Deleting " + tree.size() + " subnodes ");
  for (int i = tree.size() - 1; i >= 0 ; --i) {
    //Delete the leaves first and eventually get rid of the root
    zk.delete(tree.get(i), -1, cb, ctx); //Delete all versions of the node with -1.
  }
}

代码示例来源:origin: apache/zookeeper

@Test
public void testValidateFileInput() throws IOException {
  File file = File.createTempFile("test", ".junit", testData);
  file.deleteOnExit();
  String absolutePath = file.getAbsolutePath();
  String error = ZKUtil.validateFileInput(absolutePath);
  assertNull(error);
}

代码示例来源:origin: twitter/distributedlog

try {
  LOG.info("Delete the path associated with the log {}, ZK Path {}", name, zkPath);
  ZKUtil.deleteRecursive(writerZKC.get(), zkPath);
} catch (InterruptedException ie) {
  LOG.error("Interrupted while accessing ZK", ie);

代码示例来源:origin: org.apache.zookeeper/zookeeper

/**
 * Recursively delete the node with the given path. 
 * <p>
 * Important: All versions, of all nodes, under the given node are deleted.
 * <p>
 * If there is an error with deleting one of the sub-nodes in the tree, 
 * this operation would abort and would be the responsibility of the app to handle the same.
 * 
 * See {@link #delete(String, int)} for more details.
 * 
 * @throws IllegalArgumentException if an invalid path is specified
 */
public static void deleteRecursive(ZooKeeper zk, final String pathRoot)
  throws InterruptedException, KeeperException
{
  PathUtils.validatePath(pathRoot);
 
  List<String> tree = listSubTreeBFS(zk, pathRoot);
  LOG.debug("Deleting " + tree);
  LOG.debug("Deleting " + tree.size() + " subnodes ");
  for (int i = tree.size() - 1; i >= 0 ; --i) {
    //Delete the leaves first and eventually get rid of the root
    zk.delete(tree.get(i), -1); //Delete all versions of the node with -1.
  }
}

代码示例来源:origin: apache/zookeeper

@Test
public void testValidateFileInputNotExist() {
  String fileName = UUID.randomUUID().toString();
  File file = new File(testData, fileName);
  String absolutePath = file.getAbsolutePath();
  String error = ZKUtil.validateFileInput(absolutePath);
  assertNotNull(error);
  String expectedMessage = "File '" + absolutePath + "' does not exist.";
  assertEquals(expectedMessage, error);
}

代码示例来源:origin: apache/nifi

@Override
public void onComponentRemoved(final String componentId) throws IOException {
  try {
    ZKUtil.deleteRecursive(getZooKeeper(), getComponentPath(componentId));
  } catch (final KeeperException ke) {
    // Node doesn't exist so just ignore
    final Code exceptionCode = ke.code();
    if (Code.NONODE == exceptionCode) {
      return;
    }
    if (Code.SESSIONEXPIRED == exceptionCode) {
      invalidateClient();
      onComponentRemoved(componentId);
      return;
    }
    throw new IOException("Unable to remove state for component with ID '" + componentId + " with exception code " + exceptionCode, ke);
  } catch (final InterruptedException e) {
    Thread.currentThread().interrupt();
    throw new IOException("Failed to remove state for component with ID '" + componentId + "' from ZooKeeper due to being interrupted", e);
  }
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

/**
 * Recursively delete the node with the given path. (async version).
 * 
 * <p>
 * Important: All versions, of all nodes, under the given node are deleted.
 * <p>
 * If there is an error with deleting one of the sub-nodes in the tree, 
 * this operation would abort and would be the responsibility of the app to handle the same.
 * <p>
 * @param zk the zookeeper handle
 * @param pathRoot the path to be deleted
 * @param cb call back method
 * @param ctx the context the callback method is called with
 * @throws IllegalArgumentException if an invalid path is specified
 */
public static void deleteRecursive(ZooKeeper zk, final String pathRoot, VoidCallback cb,
  Object ctx)
  throws InterruptedException, KeeperException
{
  PathUtils.validatePath(pathRoot);
 
  List<String> tree = listSubTreeBFS(zk, pathRoot);
  LOG.debug("Deleting " + tree);
  LOG.debug("Deleting " + tree.size() + " subnodes ");
  for (int i = tree.size() - 1; i >= 0 ; --i) {
    //Delete the leaves first and eventually get rid of the root
    zk.delete(tree.get(i), -1, cb, ctx); //Delete all versions of the node with -1.
  }
}

代码示例来源:origin: apache/zookeeper

@Test
public void testValidateFileInputDirectory() throws Exception {
  File file = File.createTempFile("test", ".junit", testData);
  file.deleteOnExit();
  // delete file, as we need directory not file
  file.delete();
  file.mkdir();
  String absolutePath = file.getAbsolutePath();
  String error = ZKUtil.validateFileInput(absolutePath);
  assertNotNull(error);
  String expectedMessage = "'" + absolutePath + "' is a direcory. it must be a file.";
  assertEquals(expectedMessage, error);
}

代码示例来源:origin: twitter/distributedlog

public void deleteLog() throws IOException {
  lock.checkOwnershipAndReacquire();
  FutureUtils.result(purgeLogSegmentsOlderThanTxnId(-1));
  try {
    Utils.closeQuietly(lock);
    zooKeeperClient.get().exists(logMetadata.getLogSegmentsPath(), false);
    zooKeeperClient.get().exists(logMetadata.getMaxTxIdPath(), false);
    if (logMetadata.getLogRootPath().toLowerCase().contains("distributedlog")) {
      ZKUtil.deleteRecursive(zooKeeperClient.get(), logMetadata.getLogRootPath());
    } else {
      LOG.warn("Skip deletion of unrecognized ZK Path {}", logMetadata.getLogRootPath());
    }
  } catch (InterruptedException ie) {
    LOG.error("Interrupted while deleting log znodes", ie);
    throw new DLInterruptedException("Interrupted while deleting " + logMetadata.getLogRootPath(), ie);
  } catch (KeeperException ke) {
    LOG.error("Error deleting" + logMetadata.getLogRootPath() + " in zookeeper", ke);
  }
}

代码示例来源:origin: apache/ignite

/**
 * @param zk ZooKeeper client.
 * @param root Root path.
 * @return All children znodes for given path.
 * @throws Exception If failed/
 */
private List<String> listSubTree(ZooKeeper zk, String root) throws Exception {
  for (int i = 0; i < 30; i++) {
    try {
      return ZKUtil.listSubTreeBFS(zk, root);
    }
    catch (KeeperException.NoNodeException e) {
      info("NoNodeException when get znodes, will retry: " + e);
    }
  }
  throw new Exception("Failed to get znodes: " + root);
}

代码示例来源:origin: apache/zookeeper

@Test
public void testUnreadableFileInput() throws Exception {
  //skip this test on Windows, coverage on Linux
  assumeTrue(!org.apache.zookeeper.Shell.WINDOWS);
  File file = File.createTempFile("test", ".junit", testData);
  file.setReadable(false, false);
  file.deleteOnExit();
  String absolutePath = file.getAbsolutePath();
  String error = ZKUtil.validateFileInput(absolutePath);
  assertNotNull(error);
  String expectedMessage = "Read permission is denied on the file '" + absolutePath + "'";
  assertEquals(expectedMessage, error);
}

代码示例来源:origin: apache/zookeeper

ZKUtil.deleteRecursive(zk, "/a", cb, ctx);
synchronized (ctx) {
  ctx.wait();

代码示例来源:origin: at.molindo/helios-services

final List<String> paths = ZKUtil.listSubTreeBFS(
  client.getZookeeperClient().getZooKeeper(), namespacedPath);

代码示例来源:origin: apache/zookeeper

String error = ZKUtil.validateFileInput(args[0]);
if (null != error) {
  System.err.println(error);

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com