use of io.confluent.kafkarest.controllers.TopicConfigManager 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.controllers.TopicConfigManager in project kafka-rest by confluentinc.
the class TopicsResource method getTopic.
@GET
@Path("/{topic}")
@PerformanceMetric("topic.get+v2")
@ResourceName("api.v2.topics.get")
public void getTopic(@Suspended AsyncResponse asyncResponse, @PathParam("topic") String topicName) {
TopicManager topicManager = topicManagerProvider.get();
TopicConfigManager topicConfigManager = topicConfigManagerProvider.get();
CompletableFuture<Topic> topicFuture = topicManager.getLocalTopic(topicName).thenApply(topic -> topic.orElseThrow(Errors::topicNotFoundException));
CompletableFuture<GetTopicResponse> response = topicFuture.thenCompose(topic -> topicConfigManager.listTopicConfigs(topic.getClusterId(), topicName)).thenCombine(topicFuture, (configs, topic) -> GetTopicResponse.fromTopic(topic, configs));
AsyncResponses.asyncResume(asyncResponse, response);
}
Aggregations