gpt4 book ai didi

kafka.utils.ZkUtils.getReplicasForPartition()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 00:44:40 29 4
gpt4 key购买 nike

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

ZkUtils.getReplicasForPartition介绍

暂无

代码示例

代码示例来源:origin: linkedin/cruise-control

private void executeAndVerifyProposals(ZkUtils zkUtils,
                    Collection<ExecutionProposal> proposalsToExecute,
                    Collection<ExecutionProposal> proposalsToCheck) {
 KafkaCruiseControlConfig configs = new KafkaCruiseControlConfig(getExecutorProperties());
 Executor executor = new Executor(configs, new SystemTime(), new MetricRegistry(), 86400000L, 43200000L);
 executor.setExecutionMode(false);
 executor.executeProposals(proposalsToExecute, Collections.emptySet(), null, EasyMock.mock(LoadMonitor.class), null, null, null);
 Map<TopicPartition, Integer> replicationFactors = new HashMap<>();
 for (ExecutionProposal proposal : proposalsToCheck) {
  int replicationFactor = zkUtils.getReplicasForPartition(proposal.topic(), proposal.partitionId()).size();
  replicationFactors.put(new TopicPartition(proposal.topic(), proposal.partitionId()), replicationFactor);
 }
 waitUntilExecutionFinishes(executor);
 for (ExecutionProposal proposal : proposalsToCheck) {
  TopicPartition tp = new TopicPartition(proposal.topic(), proposal.partitionId());
  int expectedReplicationFactor = replicationFactors.get(tp);
  assertEquals("Replication factor for partition " + tp + " should be " + expectedReplicationFactor,
         expectedReplicationFactor, zkUtils.getReplicasForPartition(tp.topic(), tp.partition()).size());
  if (proposal.hasReplicaAction()) {
   for (int brokerId : proposal.newReplicas()) {
    assertTrue("The partition should have moved for " + tp,
          zkUtils.getReplicasForPartition(tp.topic(), tp.partition()).contains(brokerId));
   }
  }
  assertEquals("The leader should have moved for " + tp,
         proposal.newLeader(), zkUtils.getLeaderForPartition(tp.topic(), tp.partition()).get());
 }
}

代码示例来源:origin: com.cerner.common.kafka/common-kafka-admin

/**
 * Returns the replication factor for the given topic
 *
 * @param topic
 *      a Kafka topic
 * @return the replication factor for the given topic
 *
 * @throws IllegalArgumentException
 *      if topic is null, empty or blank
 * @throws AdminOperationException
 *      if there is an issue retrieving the replication factor
 */
public int getTopicReplicationFactor(String topic) {
  if (StringUtils.isBlank(topic))
    throw new IllegalArgumentException("topic cannot be null, empty or blank");
  try {
    return convertToJavaSet(zkUtils.getReplicasForPartition(topic, 0).iterator()).size();
  } catch (ZkException | KafkaException e) {
    throw new AdminOperationException("Unable to read replication factor for topic: " + topic, e);
  }
}

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