gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-14 12:52:49 28 4
gpt4 key购买 nike

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

ZKOperations介绍

[英]Collection of helper methods for common operations that usually needed when interacting with ZooKeeper.
[中]

代码示例

代码示例来源:origin: co.cask.cdap/cdap-common

/**
 * Fetches the {@link ResourceRequirement} for the given resource.
 *
 * @param resourceName Name of the resource.
 * @return A {@link ListenableFuture} that will be completed when the requirement is fetch. A {@code null} result
 *         will be set into the future if no such requirement exists. The future will fail if failed to fetch
 *         the requirement due to error other than requirement not exists.
 *         Calling {@link ListenableFuture#cancel(boolean)} has no effect.
 */
public ListenableFuture<ResourceRequirement> fetchRequirement(String resourceName) {
 String zkPath = CoordinationConstants.REQUIREMENTS_PATH + "/" + resourceName;
 return Futures.transform(
  ZKOperations.ignoreError(zkClient.getData(zkPath), KeeperException.NoNodeException.class, null),
  NODE_DATA_TO_REQUIREMENT
 );
}

代码示例来源:origin: caskdata/cdap

@Override
protected void startUp() throws Exception {
 cancellable = ZKOperations.watchChildren(zkClient, leaderElectionPath, new ZKOperations.ChildrenCallback() {
  @Override
  public void updated(NodeChildren nodeChildren) {
   childrenUpdated(nodeChildren, participants, readyFuture);
  }
 });
}

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

public static ListenableFuture<String> watchDeleted(final ZKClient zkClient, final String path) {
 SettableFuture<String> completion = SettableFuture.create();
 watchDeleted(zkClient, path, completion);
 return completion;
}

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

@Nullable Location logLevelLocation) {
Futures.getUnchecked(ZKOperations.ignoreError(
 ZKOperations.recursiveDelete(zkClient, "/" + runId), KeeperException.NoNodeException.class, null));

代码示例来源:origin: org.apache.twill/twill-yarn

@Override
 protected void shutDown() throws Exception {
  LOG.info("Removing container ZK path: {}{}", zkClient.getConnectString(), path);
  ZKOperations.recursiveDelete(zkClient, path).get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
 }
}

代码示例来源:origin: org.apache.twill/twill-core

/**
 * Creates the live node for the service. If the node already exists, it will be deleted before creation.
 *
 * @return A {@link OperationFuture} that will be completed when the creation is done.
 */
private OperationFuture<String> createLiveNode() {
 final String liveNodePath = getLiveNodePath();
 LOG.info("Creating live node {}{}", zkClient.getConnectString(), liveNodePath);
 return ZKOperations.createDeleteIfExists(zkClient, liveNodePath, serializeLiveNode(), CreateMode.EPHEMERAL, true);
}

代码示例来源:origin: org.apache.twill/twill-core

@Nullable Location logLevelLocation) {
Futures.getUnchecked(ZKOperations.ignoreError(
 ZKOperations.recursiveDelete(zkClient, "/" + runId), KeeperException.NoNodeException.class, null));

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

@Override
 protected void shutDown() throws Exception {
  LOG.info("Removing container ZK path: {}{}", zkClient.getConnectString(), path);
  ZKOperations.recursiveDelete(zkClient, path).get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
 }
}

代码示例来源:origin: org.apache.twill/twill-yarn

@Override
protected void startUp() throws Exception {
 // Create the ZK node for Kafka to use. If the node already exists, delete it to make sure there is
 // no left over content from previous AM attempt.
 LOG.info("Preparing Kafka ZK path {}{}", zkClient.getConnectString(), kafkaZKPath);
 ZKOperations.createDeleteIfExists(zkClient, kafkaZKPath, null, CreateMode.PERSISTENT, true).get();
 kafkaServer.startAndWait();
}

代码示例来源:origin: caskdata/cdap

/**
 * Fetches the {@link ResourceRequirement} for the given resource.
 *
 * @param resourceName Name of the resource.
 * @return A {@link ListenableFuture} that will be completed when the requirement is fetch. A {@code null} result
 *         will be set into the future if no such requirement exists. The future will fail if failed to fetch
 *         the requirement due to error other than requirement not exists.
 *         Calling {@link ListenableFuture#cancel(boolean)} has no effect.
 */
public ListenableFuture<ResourceRequirement> fetchRequirement(String resourceName) {
 String zkPath = CoordinationConstants.REQUIREMENTS_PATH + "/" + resourceName;
 return Futures.transform(
  ZKOperations.ignoreError(zkClient.getData(zkPath), KeeperException.NoNodeException.class, null),
  NODE_DATA_TO_REQUIREMENT
 );
}

代码示例来源:origin: co.cask.cdap/cdap-common

@Override
protected void startUp() throws Exception {
 cancellable = ZKOperations.watchChildren(zkClient, leaderElectionPath, new ZKOperations.ChildrenCallback() {
  @Override
  public void updated(NodeChildren nodeChildren) {
   childrenUpdated(nodeChildren, participants, readyFuture);
  }
 });
}

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

@Override
 public void onFailure(final Throwable createFailure) {
  // If create failed not because of the NodeExistsException, just set the exception to the result future
  if (!(createFailure instanceof KeeperException.NodeExistsException)) {
   resultFuture.setException(createFailure);
   return;
  }
  // Try to delete the path
  LOG.info("Node {}{} already exists. Deleting it and retry creation", zkClient.getConnectString(), path);
  Futures.addCallback(recursiveDelete(zkClient, path), new FutureCallback<String>() {
   @Override
   public void onSuccess(String result) {
    // If delete succeeded, perform the creation again.
    createNode(zkClient, path, data, createMode, createParent, createACLs, createCallback);
   }
   @Override
   public void onFailure(Throwable t) {
    // If deletion failed because of NoNodeException, fail the result operation future
    if (!(t instanceof KeeperException.NoNodeException)) {
     createFailure.addSuppressed(t);
     resultFuture.setException(createFailure);
     return;
    }
    // If can't delete because the node no longer exists, just go ahead and recreate the node
    createNode(zkClient, path, data, createMode, createParent, createACLs, createCallback);
   }
  }, Threads.SAME_THREAD_EXECUTOR);
 }
});

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

public static ListenableFuture<String> watchDeleted(final ZKClient zkClient, final String path) {
 SettableFuture<String> completion = SettableFuture.create();
 watchDeleted(zkClient, path, completion);
 return completion;
}

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

@Override
protected void startUp() throws Exception {
 // Create the ZK node for Kafka to use. If the node already exists, delete it to make sure there is
 // no left over content from previous AM attempt.
 LOG.info("Preparing Kafka ZK path {}{}", zkClient.getConnectString(), kafkaZKPath);
 ZKOperations.createDeleteIfExists(zkClient, kafkaZKPath, null, CreateMode.PERSISTENT, true).get();
 kafkaServer.startAndWait();
}

代码示例来源:origin: caskdata/cdap

/**
 * Deletes the {@link ResourceRequirement} for the given resource.
 *
 * @param resourceName Name of the resource.
 * @return A {@link ListenableFuture} that will be completed when the requirement is successfully removed.
 *         If the requirement doesn't exists, the deletion would still be treated as successful.
 */
public ListenableFuture<String> deleteRequirement(String resourceName) {
 String zkPath = CoordinationConstants.REQUIREMENTS_PATH + "/" + resourceName;
 return Futures.transform(
  ZKOperations.ignoreError(zkClient.delete(zkPath), KeeperException.NoNodeException.class, resourceName),
  Functions.constant(resourceName)
 );
}

代码示例来源:origin: org.apache.twill/twill-yarn

/**
 * Watch for changes to services under given path.
 * @param path to check for changes.
 */
void addWatcher(String path) {
 ZKOperations.watchChildren(zkClient, path, new ZKOperations.ChildrenCallback() {
  @Override
  public void updated(NodeChildren nodeChildren) {
   resourceReport.setServices(nodeChildren.getChildren());
  }
 });
}

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

@Override
 public void onFailure(final Throwable createFailure) {
  // If create failed not because of the NodeExistsException, just set the exception to the result future
  if (!(createFailure instanceof KeeperException.NodeExistsException)) {
   resultFuture.setException(createFailure);
   return;
  }
  // Try to delete the path
  LOG.info("Node {}{} already exists. Deleting it and retry creation", zkClient.getConnectString(), path);
  Futures.addCallback(recursiveDelete(zkClient, path), new FutureCallback<String>() {
   @Override
   public void onSuccess(String result) {
    // If delete succeeded, perform the creation again.
    createNode(zkClient, path, data, createMode, createParent, createACLs, createCallback);
   }
   @Override
   public void onFailure(Throwable t) {
    // If deletion failed because of NoNodeException, fail the result operation future
    if (!(t instanceof KeeperException.NoNodeException)) {
     createFailure.addSuppressed(t);
     resultFuture.setException(createFailure);
     return;
    }
    // If can't delete because the node no longer exists, just go ahead and recreate the node
    createNode(zkClient, path, data, createMode, createParent, createACLs, createCallback);
   }
  }, Threads.SAME_THREAD_EXECUTOR);
 }
});

代码示例来源:origin: org.apache.twill/twill-core

@Override
public void onSuccess(String path) {
 Futures.addCallback(ZKOperations.watchDeleted(zkClient, path), new FutureCallback<String>() {
  @Override
  public void onSuccess(String result) {
   completion.set(completionResult);
  }
  @Override
  public void onFailure(Throwable t) {
   completion.setException(t);
  }
 });
}

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

/**
 * Creates the live node for the service. If the node already exists, it will be deleted before creation.
 *
 * @return A {@link OperationFuture} that will be completed when the creation is done.
 */
private OperationFuture<String> createLiveNode() {
 final String liveNodePath = getLiveNodePath();
 LOG.info("Creating live node {}{}", zkClient.getConnectString(), liveNodePath);
 return ZKOperations.createDeleteIfExists(zkClient, liveNodePath, serializeLiveNode(), CreateMode.EPHEMERAL, true);
}

代码示例来源:origin: co.cask.cdap/cdap-common

/**
 * Deletes the {@link ResourceRequirement} for the given resource.
 *
 * @param resourceName Name of the resource.
 * @return A {@link ListenableFuture} that will be completed when the requirement is successfully removed.
 *         If the requirement doesn't exists, the deletion would still be treated as successful.
 */
public ListenableFuture<String> deleteRequirement(String resourceName) {
 String zkPath = CoordinationConstants.REQUIREMENTS_PATH + "/" + resourceName;
 return Futures.transform(
  ZKOperations.ignoreError(zkClient.delete(zkPath), KeeperException.NoNodeException.class, resourceName),
  Functions.constant(resourceName)
 );
}

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