Search in sources :

Example 1 with PartitionMetadata

use of kafka.api.PartitionMetadata in project flink by apache.

the class KafkaTestEnvironmentImpl method getLeaderToShutDown.

@Override
public int getLeaderToShutDown(String topic) throws Exception {
    ZkUtils zkUtils = getZkUtils();
    try {
        PartitionMetadata firstPart = null;
        do {
            if (firstPart != null) {
                LOG.info("Unable to find leader. error code {}", firstPart.errorCode());
                // not the first try. Sleep a bit
                Thread.sleep(150);
            }
            Seq<PartitionMetadata> partitionMetadata = AdminUtils.fetchTopicMetadataFromZk(topic, zkUtils).partitionsMetadata();
            firstPart = partitionMetadata.head();
        } while (firstPart.errorCode() != 0);
        return firstPart.leader().get().id();
    } finally {
        zkUtils.close();
    }
}
Also used : PartitionMetadata(kafka.api.PartitionMetadata) ZkUtils(kafka.utils.ZkUtils)

Aggregations

PartitionMetadata (kafka.api.PartitionMetadata)1 ZkUtils (kafka.utils.ZkUtils)1