Search in sources :

Example 1 with TopicManager

use of io.confluent.kafkarest.controllers.TopicManager in project kafka-rest by confluentinc.

the class TopicsResource method list.

@GET
@PerformanceMetric("topics.list+v2")
@ResourceName("api.v2.topics.list")
public void list(@Suspended AsyncResponse asyncResponse) {
    TopicManager topicManager = topicManagerProvider.get();
    CompletableFuture<List<String>> response = topicManager.listLocalTopics().thenApply(topics -> topics.stream().map(Topic::getName).collect(Collectors.toList()));
    AsyncResponses.asyncResume(asyncResponse, response);
}
Also used : TopicManager(io.confluent.kafkarest.controllers.TopicManager) List(java.util.List) Topic(io.confluent.kafkarest.entities.Topic) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) GET(javax.ws.rs.GET)

Example 2 with TopicManager

use of io.confluent.kafkarest.controllers.TopicManager 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);
}
Also used : PathParam(javax.ws.rs.PathParam) AsyncResponses(io.confluent.kafkarest.resources.AsyncResponses) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GetTopicResponse(io.confluent.kafkarest.entities.v2.GetTopicResponse) AsyncResponse(javax.ws.rs.container.AsyncResponse) Path(javax.ws.rs.Path) Versions(io.confluent.kafkarest.Versions) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) CompletableFuture(java.util.concurrent.CompletableFuture) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) Collectors(java.util.stream.Collectors) Suspended(javax.ws.rs.container.Suspended) TopicConfigManager(io.confluent.kafkarest.controllers.TopicConfigManager) Inject(javax.inject.Inject) List(java.util.List) Consumes(javax.ws.rs.Consumes) Errors(io.confluent.kafkarest.Errors) TopicManager(io.confluent.kafkarest.controllers.TopicManager) Objects.requireNonNull(java.util.Objects.requireNonNull) Topic(io.confluent.kafkarest.entities.Topic) TopicManager(io.confluent.kafkarest.controllers.TopicManager) TopicConfigManager(io.confluent.kafkarest.controllers.TopicConfigManager) GetTopicResponse(io.confluent.kafkarest.entities.v2.GetTopicResponse) Topic(io.confluent.kafkarest.entities.Topic) Path(javax.ws.rs.Path) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) GET(javax.ws.rs.GET)

Aggregations

TopicManager (io.confluent.kafkarest.controllers.TopicManager)2 Topic (io.confluent.kafkarest.entities.Topic)2 ResourceName (io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName)2 PerformanceMetric (io.confluent.rest.annotations.PerformanceMetric)2 List (java.util.List)2 GET (javax.ws.rs.GET)2 Errors (io.confluent.kafkarest.Errors)1 Versions (io.confluent.kafkarest.Versions)1 TopicConfigManager (io.confluent.kafkarest.controllers.TopicConfigManager)1 GetTopicResponse (io.confluent.kafkarest.entities.v2.GetTopicResponse)1 AsyncResponses (io.confluent.kafkarest.resources.AsyncResponses)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Provider (javax.inject.Provider)1 Consumes (javax.ws.rs.Consumes)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1