Search in sources :

Example 1 with KafkaTopicInfoExtended

use of io.confluent.ksql.rest.entity.KafkaTopicInfoExtended in project ksql by confluentinc.

the class ListTopicsExecutor method execute.

public static StatementExecutorResponse execute(final ConfiguredStatement<ListTopics> statement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext) {
    final KafkaTopicClient client = serviceContext.getTopicClient();
    final Map<String, TopicDescription> topicDescriptions = listTopics(client, statement);
    if (statement.getStatement().getShowExtended()) {
        final KafkaConsumerGroupClient consumerGroupClient = new KafkaConsumerGroupClientImpl(serviceContext::getAdminClient);
        final Map<String, List<Integer>> topicConsumersAndGroupCount = getTopicConsumerAndGroupCounts(consumerGroupClient);
        final List<KafkaTopicInfoExtended> topicInfoExtendedList = topicDescriptions.values().stream().map(desc -> topicDescriptionToTopicInfoExtended(desc, topicConsumersAndGroupCount)).collect(Collectors.toList());
        return StatementExecutorResponse.handled(Optional.of(new KafkaTopicsListExtended(statement.getStatementText(), topicInfoExtendedList)));
    } else {
        final List<KafkaTopicInfo> topicInfoList = topicDescriptions.values().stream().map(ListTopicsExecutor::topicDescriptionToTopicInfo).collect(Collectors.toList());
        return StatementExecutorResponse.handled(Optional.of(new KafkaTopicsList(statement.getStatementText(), topicInfoList)));
    }
}
Also used : Arrays(java.util.Arrays) SessionProperties(io.confluent.ksql.rest.SessionProperties) ListTopics(io.confluent.ksql.parser.tree.ListTopics) ServiceContext(io.confluent.ksql.services.ServiceContext) ConsumerSummary(io.confluent.ksql.services.KafkaConsumerGroupClient.ConsumerSummary) HashMap(java.util.HashMap) KafkaTopicsList(io.confluent.ksql.rest.entity.KafkaTopicsList) KafkaTopicsListExtended(io.confluent.ksql.rest.entity.KafkaTopicsListExtended) ReservedInternalTopics(io.confluent.ksql.util.ReservedInternalTopics) KafkaTopicClient(io.confluent.ksql.services.KafkaTopicClient) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) TopicPartition(org.apache.kafka.common.TopicPartition) KafkaConsumerGroupClientImpl(io.confluent.ksql.services.KafkaConsumerGroupClientImpl) Collection(java.util.Collection) Set(java.util.Set) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Collectors(java.util.stream.Collectors) List(java.util.List) TreeMap(java.util.TreeMap) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) KafkaConsumerGroupClient(io.confluent.ksql.services.KafkaConsumerGroupClient) KafkaTopicInfoExtended(io.confluent.ksql.rest.entity.KafkaTopicInfoExtended) KafkaTopicInfo(io.confluent.ksql.rest.entity.KafkaTopicInfo) Optional(java.util.Optional) KafkaTopicsList(io.confluent.ksql.rest.entity.KafkaTopicsList) KafkaTopicsListExtended(io.confluent.ksql.rest.entity.KafkaTopicsListExtended) KafkaTopicInfo(io.confluent.ksql.rest.entity.KafkaTopicInfo) KafkaTopicClient(io.confluent.ksql.services.KafkaTopicClient) KafkaConsumerGroupClientImpl(io.confluent.ksql.services.KafkaConsumerGroupClientImpl) KafkaTopicInfoExtended(io.confluent.ksql.rest.entity.KafkaTopicInfoExtended) TopicDescription(org.apache.kafka.clients.admin.TopicDescription) KafkaTopicsList(io.confluent.ksql.rest.entity.KafkaTopicsList) ArrayList(java.util.ArrayList) List(java.util.List) KafkaConsumerGroupClient(io.confluent.ksql.services.KafkaConsumerGroupClient)

Example 2 with KafkaTopicInfoExtended

use of io.confluent.ksql.rest.entity.KafkaTopicInfoExtended in project ksql by confluentinc.

the class ListTopicsExecutorTest method shouldListKafkaTopicsExtended.

@Test
public void shouldListKafkaTopicsExtended() {
    // Given:
    engine.givenKafkaTopic("topic1");
    engine.givenKafkaTopic("topic2");
    final ListConsumerGroupsResult result = mock(ListConsumerGroupsResult.class);
    final KafkaFutureImpl<Collection<ConsumerGroupListing>> groups = new KafkaFutureImpl<>();
    when(result.all()).thenReturn(groups);
    when(adminClient.listConsumerGroups()).thenReturn(result);
    groups.complete(ImmutableList.of());
    // When:
    final KafkaTopicsListExtended topicsList = (KafkaTopicsListExtended) CUSTOM_EXECUTORS.listTopics().execute((ConfiguredStatement<ListTopics>) engine.configure("LIST TOPICS EXTENDED;"), mock(SessionProperties.class), engine.getEngine(), serviceContext).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(topicsList.getTopics(), containsInAnyOrder(new KafkaTopicInfoExtended("topic1", ImmutableList.of(1), 0, 0), new KafkaTopicInfoExtended("topic2", ImmutableList.of(1), 0, 0)));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) KafkaTopicInfoExtended(io.confluent.ksql.rest.entity.KafkaTopicInfoExtended) Collection(java.util.Collection) KafkaTopicsListExtended(io.confluent.ksql.rest.entity.KafkaTopicsListExtended) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) ListConsumerGroupsResult(org.apache.kafka.clients.admin.ListConsumerGroupsResult) Test(org.junit.Test)

Aggregations

KafkaTopicInfoExtended (io.confluent.ksql.rest.entity.KafkaTopicInfoExtended)2 KafkaTopicsListExtended (io.confluent.ksql.rest.entity.KafkaTopicsListExtended)2 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)2 Collection (java.util.Collection)2 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)1 ListTopics (io.confluent.ksql.parser.tree.ListTopics)1 SessionProperties (io.confluent.ksql.rest.SessionProperties)1 KafkaTopicInfo (io.confluent.ksql.rest.entity.KafkaTopicInfo)1 KafkaTopicsList (io.confluent.ksql.rest.entity.KafkaTopicsList)1 KafkaConsumerGroupClient (io.confluent.ksql.services.KafkaConsumerGroupClient)1 ConsumerSummary (io.confluent.ksql.services.KafkaConsumerGroupClient.ConsumerSummary)1 KafkaConsumerGroupClientImpl (io.confluent.ksql.services.KafkaConsumerGroupClientImpl)1 KafkaTopicClient (io.confluent.ksql.services.KafkaTopicClient)1 ServiceContext (io.confluent.ksql.services.ServiceContext)1 ReservedInternalTopics (io.confluent.ksql.util.ReservedInternalTopics)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1