Search in sources :

Example 1 with Errors

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

the class PartitionsResource method getOffsets.

/**
 * Returns a summary with beginning and end offsets for the given {@code topic} and {@code
 * partition}.
 *
 * @throws io.confluent.rest.exceptions.RestNotFoundException if either {@code topic} or {@code
 *     partition} don't exist.
 */
@GET
@Path("/{partition}/offsets")
@ResourceName("api.v2.partitions.get-offsets")
public void getOffsets(@Suspended AsyncResponse asyncResponse, @PathParam("topic") String topic, @PathParam("partition") int partitionId) {
    CompletableFuture<TopicPartitionOffsetResponse> response = partitionManager.get().getLocalPartition(topic, partitionId).thenApply(partition -> partition.orElseThrow(Errors::partitionNotFoundException)).thenApply(partition -> new TopicPartitionOffsetResponse(partition.getEarliestOffset(), partition.getLatestOffset()));
    AsyncResponses.asyncResume(asyncResponse, response);
}
Also used : TopicPartitionOffsetResponse(io.confluent.kafkarest.entities.v2.TopicPartitionOffsetResponse) PathParam(javax.ws.rs.PathParam) PartitionManager(io.confluent.kafkarest.controllers.PartitionManager) 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) 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) Inject(javax.inject.Inject) List(java.util.List) Consumes(javax.ws.rs.Consumes) Errors(io.confluent.kafkarest.Errors) TopicPartitionOffsetResponse(io.confluent.kafkarest.entities.v2.TopicPartitionOffsetResponse) Objects.requireNonNull(java.util.Objects.requireNonNull) GetPartitionResponse(io.confluent.kafkarest.entities.v2.GetPartitionResponse) Errors(io.confluent.kafkarest.Errors) Path(javax.ws.rs.Path) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) GET(javax.ws.rs.GET)

Example 2 with Errors

use of io.confluent.kafkarest.Errors 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

Errors (io.confluent.kafkarest.Errors)2 Versions (io.confluent.kafkarest.Versions)2 ResourceName (io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName)2 AsyncResponses (io.confluent.kafkarest.resources.AsyncResponses)2 PerformanceMetric (io.confluent.rest.annotations.PerformanceMetric)2 List (java.util.List)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 Consumes (javax.ws.rs.Consumes)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 PartitionManager (io.confluent.kafkarest.controllers.PartitionManager)1 TopicConfigManager (io.confluent.kafkarest.controllers.TopicConfigManager)1