Java Code Examples for org.apache.kafka.common.requests.MetadataResponse#PartitionMetadata
The following examples show how to use
org.apache.kafka.common.requests.MetadataResponse#PartitionMetadata .
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: KafkaTestEnvironmentImpl.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public int getLeaderToShutDown(String topic) throws Exception { ZkUtils zkUtils = getZkUtils(); try { MetadataResponse.PartitionMetadata firstPart = null; do { if (firstPart != null) { LOG.info("Unable to find leader. error code {}", firstPart.error().code()); // not the first try. Sleep a bit Thread.sleep(150); } List<MetadataResponse.PartitionMetadata> partitionMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils).partitionMetadata(); firstPart = partitionMetadata.get(0); } while (firstPart.error().code() != 0); return firstPart.leader().id(); } finally { zkUtils.close(); } }
Example 2
Source File: KafkaTestEnvironmentImpl.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override public int getLeaderToShutDown(String topic) throws Exception { ZkUtils zkUtils = getZkUtils(); try { MetadataResponse.PartitionMetadata firstPart = null; do { if (firstPart != null) { LOG.info("Unable to find leader. error code {}", firstPart.error().code()); // not the first try. Sleep a bit Thread.sleep(150); } List<MetadataResponse.PartitionMetadata> partitionMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils).partitionMetadata(); firstPart = partitionMetadata.get(0); } while (firstPart.error().code() != 0); return firstPart.leader().id(); } finally { zkUtils.close(); } }
Example 3
Source File: KafkaTestEnvironmentImpl.java From flink with Apache License 2.0 | 6 votes |
@Override public int getLeaderToShutDown(String topic) throws Exception { ZkUtils zkUtils = getZkUtils(); try { MetadataResponse.PartitionMetadata firstPart = null; do { if (firstPart != null) { LOG.info("Unable to find leader. error code {}", firstPart.error().code()); // not the first try. Sleep a bit Thread.sleep(150); } List<MetadataResponse.PartitionMetadata> partitionMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils).partitionMetadata(); firstPart = partitionMetadata.get(0); } while (firstPart.error().code() != 0); return firstPart.leader().id(); } finally { zkUtils.close(); } }
Example 4
Source File: KafkaTestEnvironmentImpl.java From flink with Apache License 2.0 | 6 votes |
@Override public int getLeaderToShutDown(String topic) throws Exception { ZkUtils zkUtils = getZkUtils(); try { MetadataResponse.PartitionMetadata firstPart = null; do { if (firstPart != null) { LOG.info("Unable to find leader. error code {}", firstPart.error().code()); // not the first try. Sleep a bit Thread.sleep(150); } List<MetadataResponse.PartitionMetadata> partitionMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils).partitionMetadata(); firstPart = partitionMetadata.get(0); } while (firstPart.error().code() != 0); return firstPart.leader().id(); } finally { zkUtils.close(); } }
Example 5
Source File: KafkaCruiseControlUtils.java From cruise-control with BSD 2-Clause "Simplified" License | 6 votes |
private static MetadataResponseData.MetadataResponseTopic prepareMetadataResponseTopic(MetadataResponse.TopicMetadata topicMetadata) { MetadataResponseData.MetadataResponseTopic metadataResponseTopic = new MetadataResponseData.MetadataResponseTopic(); metadataResponseTopic.setErrorCode(topicMetadata.error().code()) .setName(topicMetadata.topic()) .setIsInternal(topicMetadata.isInternal()) .setTopicAuthorizedOperations(topicMetadata.authorizedOperations()); for (MetadataResponse.PartitionMetadata partitionMetadata : topicMetadata.partitionMetadata()) { metadataResponseTopic.partitions().add( new MetadataResponseData.MetadataResponsePartition() .setErrorCode(partitionMetadata.error().code()) .setPartitionIndex(partitionMetadata.partition()) .setLeaderId(partitionMetadata.leader() == null ? -1 : partitionMetadata.leader().id()) .setLeaderEpoch(partitionMetadata.leaderEpoch().orElse(RecordBatch.NO_PARTITION_LEADER_EPOCH)) .setReplicaNodes(partitionMetadata.replicas().stream().map(Node::id).collect(Collectors.toList())) .setIsrNodes(partitionMetadata.isr().stream().map(Node::id).collect(Collectors.toList())) .setOfflineReplicas(partitionMetadata.offlineReplicas().stream().map(Node::id).collect(Collectors.toList()))); } return metadataResponseTopic; }
Example 6
Source File: KafkaTestEnvironmentImpl.java From flink with Apache License 2.0 | 6 votes |
@Override public int getLeaderToShutDown(String topic) throws Exception { ZkUtils zkUtils = getZkUtils(); try { MetadataResponse.PartitionMetadata firstPart = null; do { if (firstPart != null) { LOG.info("Unable to find leader. error code {}", firstPart.error().code()); // not the first try. Sleep a bit Thread.sleep(150); } List<MetadataResponse.PartitionMetadata> partitionMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils).partitionMetadata(); firstPart = partitionMetadata.get(0); } while (firstPart.error().code() != 0); return firstPart.leader().id(); } finally { zkUtils.close(); } }
Example 7
Source File: KafkaTestEnvironmentImpl.java From flink with Apache License 2.0 | 6 votes |
@Override public int getLeaderToShutDown(String topic) throws Exception { ZkUtils zkUtils = getZkUtils(); try { MetadataResponse.PartitionMetadata firstPart = null; do { if (firstPart != null) { LOG.info("Unable to find leader. error code {}", firstPart.error().code()); // not the first try. Sleep a bit Thread.sleep(150); } List<MetadataResponse.PartitionMetadata> partitionMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils).partitionMetadata(); firstPart = partitionMetadata.get(0); } while (firstPart.error().code() != 0); return firstPart.leader().id(); } finally { zkUtils.close(); } }
Example 8
Source File: KafkaPartitionMetricSampleAggregatorTest.java From cruise-control with BSD 2-Clause "Simplified" License | 4 votes |
@Test public void testAggregateWithPartitionExtrapolations() throws NotEnoughValidWindowsException { KafkaCruiseControlConfig config = new KafkaCruiseControlConfig(getLoadMonitorProperties()); Metadata metadata = getMetadata(Collections.singleton(TP)); KafkaPartitionMetricSampleAggregator metricSampleAggregator = new KafkaPartitionMetricSampleAggregator(config, metadata); TopicPartition tp1 = new TopicPartition(TOPIC0, 1); Cluster cluster = getCluster(Arrays.asList(TP, tp1)); PartitionEntity pe1 = new PartitionEntity(tp1); List<MetadataResponse.PartitionMetadata> partitionMetadata = Collections.singletonList(new MetadataResponse.PartitionMetadata(Errors.NONE, 1, NODE_0, Optional.of(RecordBatch.NO_PARTITION_LEADER_EPOCH), Arrays.asList(nodes()), Arrays.asList(nodes()), Collections.emptyList())); List<MetadataResponse.TopicMetadata> topicMetadata = Collections.singletonList( new MetadataResponse.TopicMetadata(Errors.NONE, TOPIC0, false, partitionMetadata)); MetadataResponse metadataResponse = KafkaCruiseControlUtils.prepareMetadataResponse(cluster.nodes(), cluster.clusterResource().clusterId(), MetadataResponse.NO_CONTROLLER_ID, topicMetadata); metadata.update(KafkaCruiseControlUtils.REQUEST_VERSION_UPDATE, metadataResponse, 1); populateSampleAggregator(NUM_WINDOWS + 1, MIN_SAMPLES_PER_WINDOW, metricSampleAggregator); //Populate partition 1 but leave 1 hole at NUM_WINDOWS'th window. CruiseControlUnitTestUtils.populateSampleAggregator(NUM_WINDOWS - 2, MIN_SAMPLES_PER_WINDOW, metricSampleAggregator, pe1, 0, WINDOW_MS, KafkaMetricDef.commonMetricDef()); CruiseControlUnitTestUtils.populateSampleAggregator(2, MIN_SAMPLES_PER_WINDOW, metricSampleAggregator, pe1, NUM_WINDOWS - 1, WINDOW_MS, KafkaMetricDef.commonMetricDef()); MetricSampleAggregationResult<String, PartitionEntity> result = metricSampleAggregator.aggregate(cluster, Long.MAX_VALUE, new OperationProgress()); assertEquals(2, result.valuesAndExtrapolations().size()); assertTrue(result.valuesAndExtrapolations().get(PE).extrapolations().isEmpty()); assertEquals(1, result.valuesAndExtrapolations().get(pe1).extrapolations().size()); assertTrue(result.valuesAndExtrapolations().get(pe1).extrapolations().containsKey(1)); assertEquals((NUM_WINDOWS - 1) * WINDOW_MS, result.valuesAndExtrapolations().get(pe1).window(1)); assertEquals(Extrapolation.AVG_ADJACENT, result.valuesAndExtrapolations().get(pe1).extrapolations().get(1)); }