public static KafkaTopicsList build( final String statementText, final Collection<KsqlTopic> ksqlTopics, final Map<String, TopicDescription> kafkaTopicDescriptions, final KsqlConfig ksqlConfig, final KafkaConsumerGroupClient consumerGroupClient ) { final Set<String> registeredNames = getRegisteredKafkaTopicNames(ksqlTopics); final List<KafkaTopicInfo> kafkaTopicInfoList = new ArrayList<>(); final Map<String, TopicDescription> filteredDescriptions = new TreeMap<>( filterKsqlInternalTopics(kafkaTopicDescriptions, ksqlConfig)); final Map<String, List<Integer>> topicConsumersAndGroupCount = getTopicConsumerAndGroupCounts( consumerGroupClient); for (final TopicDescription desp : filteredDescriptions.values()) { kafkaTopicInfoList.add(new KafkaTopicInfo( desp.name(), registeredNames.contains(desp.name()), desp.partitions() .stream().map(partition -> partition.replicas().size()).collect(Collectors.toList()), topicConsumersAndGroupCount.getOrDefault(desp.name(), Arrays.asList(0, 0)).get(0), topicConsumersAndGroupCount.getOrDefault(desp.name(), Arrays.asList(0, 0)).get(1) )); } return new KafkaTopicsList(statementText, kafkaTopicInfoList); }
@Test public void testSerde() throws Exception { final ObjectMapper mapper = JsonMapper.INSTANCE.mapper; final KafkaTopicsList expected = new KafkaTopicsList( "SHOW TOPICS;", ImmutableList.of(new KafkaTopicInfo("thetopic", true, ImmutableList.of(1, 2, 3), 42, 12)) ); final String json = mapper.writeValueAsString(expected); assertEquals( "{\"@type\":\"kafka_topics\",\"statementText\":\"SHOW TOPICS;\"," + "\"topics\":[{\"name\":\"thetopic\",\"registered\":true," + "\"replicaInfo\":[1,2,3],\"consumerCount\":42," + "\"consumerGroupCount\":12}]}", json); final KafkaTopicsList actual = mapper.readValue(json, KafkaTopicsList.class); assertEquals(expected, actual); } }
new TablesList("e", ImmutableList.of(new SourceInfo.Table("TestTable", "TestTopic", "JSON", false))), new KsqlTopicsList("e", ImmutableList.of(new KsqlTopicInfo("TestTopic", "TestKafkaTopic", DataSource.DataSourceSerDe.JSON))), new KafkaTopicsList("e", ImmutableList.of(new KafkaTopicInfo("TestKafkaTopic", true, ImmutableList.of(1), 1, 1))), new ExecutionPlan("Test Execution Plan") ));