Search in sources :

Example 1 with TopicConfigManager

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);
}
Also used : ListTopicConfigsResponse(io.confluent.kafkarest.entities.v3.ListTopicConfigsResponse) 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) AsyncResponse(javax.ws.rs.container.AsyncResponse) Path(javax.ws.rs.Path) CrnFactory(io.confluent.kafkarest.response.CrnFactory) 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) ResourceCollection(io.confluent.kafkarest.entities.v3.ResourceCollection) UrlFactory(io.confluent.kafkarest.response.UrlFactory) MediaType(javax.ws.rs.core.MediaType) TopicManager(io.confluent.kafkarest.controllers.TopicManager) TopicConfig(io.confluent.kafkarest.entities.TopicConfig) Objects.requireNonNull(java.util.Objects.requireNonNull) Comparator(java.util.Comparator) TopicConfigDataList(io.confluent.kafkarest.entities.v3.TopicConfigDataList) TopicConfigManager(io.confluent.kafkarest.controllers.TopicConfigManager) ListTopicConfigsResponse(io.confluent.kafkarest.entities.v3.ListTopicConfigsResponse) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) Produces(javax.ws.rs.Produces) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) GET(javax.ws.rs.GET)

Example 2 with TopicConfigManager

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);
}
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

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