Search in sources :

Example 21 with TopicDescription

use of org.apache.kafka.clients.admin.TopicDescription in project apache-kafka-on-k8s by banzaicloud.

the class InternalTopicManagerTest method shouldCreateRequiredTopics.

@Test
public void shouldCreateRequiredTopics() throws Exception {
    final InternalTopicConfig topicConfig = new RepartitionTopicConfig(topic, Collections.<String, String>emptyMap());
    topicConfig.setNumberOfPartitions(1);
    final InternalTopicConfig topicConfig2 = new UnwindowedChangelogTopicConfig(topic2, Collections.<String, String>emptyMap());
    topicConfig2.setNumberOfPartitions(1);
    final InternalTopicConfig topicConfig3 = new WindowedChangelogTopicConfig(topic3, Collections.<String, String>emptyMap());
    topicConfig3.setNumberOfPartitions(1);
    internalTopicManager.makeReady(Collections.singletonMap(topic, topicConfig));
    internalTopicManager.makeReady(Collections.singletonMap(topic2, topicConfig2));
    internalTopicManager.makeReady(Collections.singletonMap(topic3, topicConfig3));
    assertEquals(Utils.mkSet(topic, topic2, topic3), mockAdminClient.listTopics().names().get());
    assertEquals(new TopicDescription(topic, false, new ArrayList<TopicPartitionInfo>() {

        {
            add(new TopicPartitionInfo(0, broker1, singleReplica, Collections.<Node>emptyList()));
        }
    }), mockAdminClient.describeTopics(Collections.singleton(topic)).values().get(topic).get());
    assertEquals(new TopicDescription(topic2, false, new ArrayList<TopicPartitionInfo>() {

        {
            add(new TopicPartitionInfo(0, broker1, singleReplica, Collections.<Node>emptyList()));
        }
    }), mockAdminClient.describeTopics(Collections.singleton(topic2)).values().get(topic2).get());
    assertEquals(new TopicDescription(topic3, false, new ArrayList<TopicPartitionInfo>() {

        {
            add(new TopicPartitionInfo(0, broker1, singleReplica, Collections.<Node>emptyList()));
        }
    }), mockAdminClient.describeTopics(Collections.singleton(topic3)).values().get(topic3).get());
    ConfigResource resource = new ConfigResource(ConfigResource.Type.TOPIC, topic);
    ConfigResource resource2 = new ConfigResource(ConfigResource.Type.TOPIC, topic2);
    ConfigResource resource3 = new ConfigResource(ConfigResource.Type.TOPIC, topic3);
    assertEquals(new ConfigEntry(TopicConfig.CLEANUP_POLICY_CONFIG, TopicConfig.CLEANUP_POLICY_DELETE), mockAdminClient.describeConfigs(Collections.singleton(resource)).values().get(resource).get().get(TopicConfig.CLEANUP_POLICY_CONFIG));
    assertEquals(new ConfigEntry(TopicConfig.CLEANUP_POLICY_CONFIG, TopicConfig.CLEANUP_POLICY_COMPACT), mockAdminClient.describeConfigs(Collections.singleton(resource2)).values().get(resource2).get().get(TopicConfig.CLEANUP_POLICY_CONFIG));
    assertEquals(new ConfigEntry(TopicConfig.CLEANUP_POLICY_CONFIG, TopicConfig.CLEANUP_POLICY_COMPACT + "," + TopicConfig.CLEANUP_POLICY_DELETE), mockAdminClient.describeConfigs(Collections.singleton(resource3)).values().get(resource3).get().get(TopicConfig.CLEANUP_POLICY_CONFIG));
}
Also used : ConfigEntry(org.apache.kafka.clients.admin.ConfigEntry) TopicPartitionInfo(org.apache.kafka.common.TopicPartitionInfo) Node(org.apache.kafka.common.Node) ArrayList(java.util.ArrayList) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) ConfigResource(org.apache.kafka.common.config.ConfigResource) Test(org.junit.Test)

Example 22 with TopicDescription

use of org.apache.kafka.clients.admin.TopicDescription in project core-ng-project by neowu.

the class KafkaController method topics.

public Response topics(Request request) throws ExecutionException, InterruptedException {
    ControllerHelper.assertFromLocalNetwork(request.clientIP());
    List<KafkaTopic> views = Lists.newArrayList();
    try (AdminClient admin = kafka.admin()) {
        Set<String> topics = admin.listTopics().names().get();
        DescribeTopicsResult descriptions = admin.describeTopics(topics);
        for (Map.Entry<String, KafkaFuture<TopicDescription>> entry : descriptions.values().entrySet()) {
            String name = entry.getKey();
            TopicDescription description = entry.getValue().get();
            KafkaTopic view = view(name, description);
            views.add(view);
        }
    }
    return Response.bean(views);
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) DescribeTopicsResult(org.apache.kafka.clients.admin.DescribeTopicsResult) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) Map(java.util.Map) AdminClient(org.apache.kafka.clients.admin.AdminClient)

Aggregations

TopicDescription (org.apache.kafka.clients.admin.TopicDescription)22 Test (org.junit.Test)10 TopicPartitionInfo (org.apache.kafka.common.TopicPartitionInfo)9 Node (org.apache.kafka.common.Node)8 Map (java.util.Map)6 HashMap (java.util.HashMap)4 AdminClient (org.apache.kafka.clients.admin.AdminClient)4 KsqlConfig (io.confluent.ksql.util.KsqlConfig)3 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 ExecutionException (java.util.concurrent.ExecutionException)3 DescribeTopicsResult (org.apache.kafka.clients.admin.DescribeTopicsResult)3 NewTopic (org.apache.kafka.clients.admin.NewTopic)3 KafkaFuture (org.apache.kafka.common.KafkaFuture)3 KsqlTopic (io.confluent.ksql.metastore.KsqlTopic)2 KafkaConsumerGroupClient (io.confluent.ksql.util.KafkaConsumerGroupClient)2 KafkaConsumerGroupClientImpl (io.confluent.ksql.util.KafkaConsumerGroupClientImpl)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2