use of io.confluent.kafkarest.entities.TopicConfig in project kafka-rest by confluentinc.
the class ListAllTopicsConfigsActionTest method listTopicConfigs_existingTopic_returnsConfigs.
@Test
public void listTopicConfigs_existingTopic_returnsConfigs() {
expect(topicManager.listTopics(CLUSTER_ID)).andReturn(completedFuture(Arrays.asList(Topic.create(CLUSTER_ID, TOPIC_NAME, new ArrayList<>(), (short) 1, false, emptySet()))));
expect(topicConfigManager.listTopicConfigs(CLUSTER_ID, Arrays.asList(TOPIC_NAME))).andReturn(completedFuture(new HashMap<String, List<TopicConfig>>() {
{
put(TOPIC_NAME, Arrays.asList(CONFIG_1, CONFIG_2, CONFIG_3));
}
}));
replay(topicManager, topicConfigManager);
FakeAsyncResponse response = new FakeAsyncResponse();
allTopicConfigsResource.listTopicConfigs(response, CLUSTER_ID);
ListTopicConfigsResponse expected = ListTopicConfigsResponse.create(TopicConfigDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/-/configs").build()).setData(Arrays.asList(TopicConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/configs/config-1").setResourceName("crn:///kafka=cluster-1/topic=topic-1/config=config-1").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).setName(CONFIG_1.getName()).setValue(CONFIG_1.getValue()).setDefault(CONFIG_1.isDefault()).setReadOnly(CONFIG_1.isReadOnly()).setSensitive(CONFIG_1.isSensitive()).setSource(CONFIG_1.getSource()).setSynonyms(CONFIG_1.getSynonyms().stream().map(ConfigSynonymData::fromConfigSynonym).collect(Collectors.toList())).build(), TopicConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/configs/config-2").setResourceName("crn:///kafka=cluster-1/topic=topic-1/config=config-2").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).setName(CONFIG_2.getName()).setValue(CONFIG_2.getValue()).setDefault(CONFIG_2.isDefault()).setReadOnly(CONFIG_2.isReadOnly()).setSensitive(CONFIG_2.isSensitive()).setSource(CONFIG_2.getSource()).setSynonyms(CONFIG_2.getSynonyms().stream().map(ConfigSynonymData::fromConfigSynonym).collect(Collectors.toList())).build(), TopicConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/configs/config-3").setResourceName("crn:///kafka=cluster-1/topic=topic-1/config=config-3").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).setName(CONFIG_3.getName()).setValue(CONFIG_3.getValue()).setDefault(CONFIG_3.isDefault()).setReadOnly(CONFIG_3.isReadOnly()).setSensitive(CONFIG_3.isSensitive()).setSource(CONFIG_3.getSource()).setSynonyms(CONFIG_3.getSynonyms().stream().map(ConfigSynonymData::fromConfigSynonym).collect(Collectors.toList())).build())).build());
assertEquals(expected, response.getValue());
}
use of io.confluent.kafkarest.entities.TopicConfig in project kafka-rest by confluentinc.
the class TopicConfigManagerImplTest method getTopicConfig_existingConfig_returnsConfig.
@Test
public void getTopicConfig_existingConfig_returnsConfig() throws Exception {
expect(clusterManager.getCluster(CLUSTER_ID)).andReturn(completedFuture(Optional.of(CLUSTER)));
expect(adminClient.describeConfigs(eq(singletonList(new ConfigResource(ConfigResource.Type.TOPIC, TOPIC_NAME))), anyObject(DescribeConfigsOptions.class))).andReturn(describeConfigsResult);
expect(describeConfigsResult.all()).andReturn(KafkaFuture.completedFuture(singletonMap(new ConfigResource(ConfigResource.Type.TOPIC, TOPIC_NAME), CONFIG)));
replay(adminClient, clusterManager, describeConfigsResult);
TopicConfig config = topicConfigManager.getTopicConfig(CLUSTER_ID, TOPIC_NAME, CONFIG_1.getName()).get().get();
assertEquals(CONFIG_1, config);
}
use of io.confluent.kafkarest.entities.TopicConfig in project kafka-rest by confluentinc.
the class ListAllTopicsConfigsAction method listTopicConfigs.
@GET
@Produces(MediaType.APPLICATION_JSON)
@PerformanceMetric("v3.topics.configs.list")
@ResourceName("api.v3.topic-configs.list")
public void listTopicConfigs(@Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) {
// have to resolve dependencies here in request scope
TopicConfigManager resolvedTopicConfigManager = topicConfigManager.get();
CompletableFuture<ListTopicConfigsResponse> response = topicManager.get().listTopics(clusterId).thenCompose(topics -> resolvedTopicConfigManager.listTopicConfigs(clusterId, topics.stream().map(topic -> topic.getName()).collect(Collectors.toList())).thenApply(configs -> ListTopicConfigsResponse.create(TopicConfigDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf(urlFactory.create("v3", "clusters", clusterId, "topics", "-", "configs")).build()).setData(configs.values().stream().flatMap(topicConfigs -> topicConfigs.stream().sorted(Comparator.comparing(TopicConfig::getName))).map(topicConfig -> TopicConfigsResource.toTopicConfigData(topicConfig, crnFactory, urlFactory)).collect(Collectors.toList())).build())));
AsyncResponses.asyncResume(asyncResponse, response);
}
use of io.confluent.kafkarest.entities.TopicConfig in project kafka-rest by confluentinc.
the class TopicConfigManagerImplTest method getTopicConfig_nonExistingConfig_returnsEmpty.
@Test
public void getTopicConfig_nonExistingConfig_returnsEmpty() throws Exception {
expect(clusterManager.getCluster(CLUSTER_ID)).andReturn(completedFuture(Optional.of(CLUSTER)));
expect(adminClient.describeConfigs(eq(singletonList(new ConfigResource(ConfigResource.Type.TOPIC, TOPIC_NAME))), anyObject(DescribeConfigsOptions.class))).andReturn(describeConfigsResult);
expect(describeConfigsResult.all()).andReturn(KafkaFuture.completedFuture(singletonMap(new ConfigResource(ConfigResource.Type.TOPIC, TOPIC_NAME), CONFIG)));
replay(adminClient, clusterManager, describeConfigsResult);
Optional<TopicConfig> config = topicConfigManager.getTopicConfig(CLUSTER_ID, TOPIC_NAME, "foobar").get();
assertFalse(config.isPresent());
}
use of io.confluent.kafkarest.entities.TopicConfig in project kafka-rest by confluentinc.
the class TopicConfigManagerImplTest method listTopicConfigs_existingTopic_returnsConfigs.
@Test
public void listTopicConfigs_existingTopic_returnsConfigs() throws Exception {
expect(clusterManager.getCluster(CLUSTER_ID)).andReturn(completedFuture(Optional.of(CLUSTER)));
expect(adminClient.describeConfigs(eq(singletonList(new ConfigResource(ConfigResource.Type.TOPIC, TOPIC_NAME))), anyObject(DescribeConfigsOptions.class))).andReturn(describeConfigsResult);
expect(describeConfigsResult.all()).andReturn(KafkaFuture.completedFuture(singletonMap(new ConfigResource(ConfigResource.Type.TOPIC, TOPIC_NAME), CONFIG)));
replay(adminClient, clusterManager, describeConfigsResult);
List<TopicConfig> configs = topicConfigManager.listTopicConfigs(CLUSTER_ID, TOPIC_NAME).get();
assertEquals(new HashSet<>(Arrays.asList(CONFIG_1, CONFIG_2, CONFIG_3)), new HashSet<>(configs));
}
Aggregations