Java Code Examples for kafka.zk.KafkaZkClient#getEntityConfigs()

The following examples show how to use kafka.zk.KafkaZkClient#getEntityConfigs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReplicationThrottleHelperTest.java    From cruise-control with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void assertExpectedThrottledRateForBroker(KafkaZkClient kafkaZkClient, int broker, Long expectedRate) {
  Properties brokerConfig = kafkaZkClient.getEntityConfigs(ConfigType.Broker(), String.valueOf(broker));
  String expectedString = expectedRate == null ? null : String.valueOf(expectedRate);
  assertEquals(expectedString, brokerConfig.getProperty(ReplicationThrottleHelper.LEADER_THROTTLED_RATE));
  assertEquals(expectedString, brokerConfig.getProperty(ReplicationThrottleHelper.FOLLOWER_THROTTLED_RATE));
}
 
Example 2
Source File: ReplicationThrottleHelperTest.java    From cruise-control with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void assertExpectedThrottledReplicas(KafkaZkClient kafkaZkClient, String topic, String expectedReplicas) {
  Properties topicConfig = kafkaZkClient.getEntityConfigs(ConfigType.Topic(), topic);
  assertEquals(expectedReplicas, topicConfig.getProperty(ReplicationThrottleHelper.LEADER_THROTTLED_REPLICAS));
  assertEquals(expectedReplicas, topicConfig.getProperty(ReplicationThrottleHelper.FOLLOWER_THROTTLED_REPLICAS));
}
 
Example 3
Source File: ReplicationThrottleHelperTest.java    From cruise-control with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Test
public void testAddingThrottlesWithPreExistingThrottles() throws InterruptedException {
  createTopics();
  KafkaZkClient kafkaZkClient = KafkaCruiseControlUtils.createKafkaZkClient(zookeeper().connectionString(),
      "ReplicationThrottleHelperTestMetricGroup",
      "AddingThrottlesWithNoPreExistingThrottles",
          false);

  final long throttleRate = 100L;

  ReplicationThrottleHelper throttleHelper = new ReplicationThrottleHelper(kafkaZkClient, throttleRate);
  ExecutionProposal proposal = new ExecutionProposal(
      new TopicPartition(TOPIC0, 0),
      100,
      new ReplicaPlacementInfo(0),
      Arrays.asList(new ReplicaPlacementInfo(0), new ReplicaPlacementInfo(1)),
      Arrays.asList(new ReplicaPlacementInfo(0), new ReplicaPlacementInfo(2)));

  ExecutionTask task = completedTaskForProposal(0, proposal);

  // Broker 0 has an existing leader and follower throttle; we expect these to be preserved.
  Properties broker0Config = new Properties();
  long preExistingBroker0ThrottleRate = 200L;
  broker0Config.setProperty(ReplicationThrottleHelper.LEADER_THROTTLED_RATE, String.valueOf(preExistingBroker0ThrottleRate));
  broker0Config.setProperty(ReplicationThrottleHelper.FOLLOWER_THROTTLED_RATE, String.valueOf(preExistingBroker0ThrottleRate));
  ExecutorUtils.changeBrokerConfig(new AdminZkClient(kafkaZkClient), 0, broker0Config);

  // Partition 1 (which is not involved in any execution proposal) has pre-existing throttled
  // replicas (on both leaders and followers); we expect these configurations to be merged
  // with our new throttled replicas.
  Properties topic0Config = kafkaZkClient.getEntityConfigs(ConfigType.Topic(), TOPIC0);
  topic0Config.setProperty(ReplicationThrottleHelper.LEADER_THROTTLED_REPLICAS, "1:0,1:1");
  topic0Config.setProperty(ReplicationThrottleHelper.FOLLOWER_THROTTLED_REPLICAS, "1:0,1:1");
  ExecutorUtils.changeTopicConfig(new AdminZkClient(kafkaZkClient), TOPIC0, topic0Config);

  // Topic 1 is not involved in any execution proposal. It has pre-existing throttled replicas.
  Properties topic1Config = kafkaZkClient.getEntityConfigs(ConfigType.Topic(), TOPIC1);
  topic1Config.setProperty(ReplicationThrottleHelper.LEADER_THROTTLED_REPLICAS, "1:1");
  topic1Config.setProperty(ReplicationThrottleHelper.FOLLOWER_THROTTLED_REPLICAS, "1:1");
  ExecutorUtils.changeTopicConfig(new AdminZkClient(kafkaZkClient), TOPIC1, topic1Config);

  throttleHelper.setThrottles(Collections.singletonList(proposal));

  assertExpectedThrottledRateForBroker(kafkaZkClient, 0, preExistingBroker0ThrottleRate);
  assertExpectedThrottledRateForBroker(kafkaZkClient, 1, throttleRate);
  assertExpectedThrottledRateForBroker(kafkaZkClient, 2, throttleRate);
  // No throttle on broker 3 because it's not involved in any of the execution proposals:
  assertExpectedThrottledRateForBroker(kafkaZkClient, 3, null);
  // Existing throttled replicas are merged with new throttled replicas for topic 0:
  assertExpectedThrottledReplicas(kafkaZkClient, TOPIC0, "0:0,0:1,0:2,1:0,1:1");
  // Existing throttled replicas are unchanged for topic 1:
  assertExpectedThrottledReplicas(kafkaZkClient, TOPIC1, "1:1");

  throttleHelper.clearThrottles(Collections.singletonList(task), Collections.emptyList());

  // We expect all throttles related to replica movement to be removed. Specifically,
  // any throttles related to partitions which were not moved will remain.
  // However, we do expect the broker throttles to be removed.
  throttleHelper.clearThrottles(Collections.singletonList(task), Collections.emptyList());
  Arrays.asList(0, 1, 2, 3).forEach((i) -> assertExpectedThrottledRateForBroker(kafkaZkClient, i, null));
  assertExpectedThrottledReplicas(kafkaZkClient, TOPIC0, "1:0,1:1");
  assertExpectedThrottledReplicas(kafkaZkClient, TOPIC1, "1:1");
}