gpt4 book ai didi

org.apache.twill.zookeeper.ZKClientService.getData()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 21:18:40 28 4
gpt4 key购买 nike

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

ZKClientService.getData介绍

暂无

代码示例

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

private void updateController(final String appName, final RunId runId, final AtomicBoolean cancelled) {
 String instancePath = String.format("/%s/instances/%s", appName, runId.getId());
 // Fetch the content node.
 Futures.addCallback(zkClientService.getData(instancePath), new FutureCallback<NodeData>() {
  @Override
  public void onSuccess(NodeData result) {
   if (cancelled.get()) {
    return;
   }
   ApplicationMasterLiveNodeData amLiveNodeData = ApplicationMasterLiveNodeDecoder.decode(result);
   if (amLiveNodeData == null) {
    return;
   }
   synchronized (YarnTwillRunnerService.this) {
    if (!controllers.contains(appName, runId)) {
     ZKClient zkClient = ZKClients.namespace(zkClientService, "/" + appName);
     YarnAppClient yarnAppClient = new VersionDetectYarnAppClientFactory().create(new Configuration(yarnConfig));
     YarnTwillController controller = listenController(
      new YarnTwillController(appName, runId, zkClient, amLiveNodeData, yarnAppClient));
     controllers.put(appName, runId, controller);
     controller.start();
    }
   }
  }
  @Override
  public void onFailure(Throwable t) {
   LOG.warn("Failed in fetching application instance node.", t);
  }
 }, Threads.SAME_THREAD_EXECUTOR);
}

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

private void updateController(final String appName, final RunId runId, final AtomicBoolean cancelled) {
 String instancePath = String.format("/%s/instances/%s", appName, runId.getId());
 // Fetch the content node.
 Futures.addCallback(zkClientService.getData(instancePath), new FutureCallback<NodeData>() {
  @Override
  public void onSuccess(NodeData result) {
   if (cancelled.get()) {
    return;
   }
   ApplicationMasterLiveNodeData amLiveNodeData = ApplicationMasterLiveNodeDecoder.decode(result);
   if (amLiveNodeData == null) {
    return;
   }
   synchronized (YarnTwillRunnerService.this) {
    if (!controllers.contains(appName, runId)) {
     ZKClient zkClient = ZKClients.namespace(zkClientService, "/" + appName);
     YarnAppClient yarnAppClient = new VersionDetectYarnAppClientFactory().create(new Configuration(yarnConfig));
     YarnTwillController controller = listenController(
      new YarnTwillController(appName, runId, zkClient, amLiveNodeData, yarnAppClient));
     controllers.put(appName, runId, controller);
     controller.start();
    }
   }
  }
  @Override
  public void onFailure(Throwable t) {
   LOG.warn("Failed in fetching application instance node.", t);
  }
 }, Threads.SAME_THREAD_EXECUTOR);
}

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

/**
 * Checks for appfabric service path on zookeeper, if they exist, CDAP master is still running, so throw
 * exception message with information on where its running.
 * @throws Exception if at least one master is running
 */
private void ensureCDAPMasterStopped() throws Exception {
 String appFabricPath = String.format("/discoverable/%s", Constants.Service.APP_FABRIC_HTTP);
 NodeChildren nodeChildren = zkClientService.getChildren(appFabricPath).get();
 List<String> runningNodes = new ArrayList<>();
 // if no children nodes at appfabric path, all master nodes are stopped
 if (!nodeChildren.getChildren().isEmpty()) {
  for (String runId : nodeChildren.getChildren()) {
   // only one children would be present, as only the active master will be registered at this path
   NodeData nodeData = zkClientService.getData(String.format("%s/%s", appFabricPath, runId)).get();
   Discoverable discoverable = GSON.fromJson(Bytes.toString(nodeData.getData()), Discoverable.class);
   runningNodes.add(discoverable.getSocketAddress().getHostName());
  }
  String exceptionMessage =
   String.format("CDAP Master is still running on %s, please stop it before running upgrade.",
          com.google.common.base.Joiner.on(",").join(runningNodes));
  throw new Exception(exceptionMessage);
 }
 // CDAP-11733 As a future improvement, the upgrade tool can register as a CDAP master to become the leader
 // and prevent other masters from starting.
}

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

@Test
public void testCreateOrSet() throws Exception {
 String path = "/parent/testCreateOrSet";
 ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
 zkClient.startAndWait();
 // Create with "1"
 Assert.assertEquals(1, ZKExtOperations.createOrSet(zkClient, path,
                           Suppliers.ofInstance(1), INT_CODEC, 0).get().intValue());
 // Should get "1" back
 Assert.assertEquals(1, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue());
 // Set with "2"
 Assert.assertEquals(2, ZKExtOperations.createOrSet(zkClient, path,
                           Suppliers.ofInstance(2), INT_CODEC, 0).get().intValue());
 // Should get "2" back
 Assert.assertEquals(2, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue());
 zkClient.stopAndWait();
}

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

@Test
public void testSetOrCreate() throws Exception {
 String path = "/parent/testSetOrCreate";
 ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
 zkClient.startAndWait();
 // Create with "1"
 Assert.assertEquals(1, ZKExtOperations.setOrCreate(zkClient, path,
                           Suppliers.ofInstance(1), INT_CODEC, 0).get().intValue());
 // Should get "1" back
 Assert.assertEquals(1, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue());
 // Set with "2"
 Assert.assertEquals(2, ZKExtOperations.setOrCreate(zkClient, path,
                           Suppliers.ofInstance(2), INT_CODEC, 0).get().intValue());
 // Should get "2" back
 Assert.assertEquals(2, INT_CODEC.decode(zkClient.getData(path).get().getData()).intValue());
 zkClient.stopAndWait();
}

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