Search in sources :

Example 1 with ResourceName

use of io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName 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 ResourceName

use of io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName 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 3 with ResourceName

use of io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName in project kafka-rest by confluentinc.

the class ProduceAction method produce.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@PerformanceMetric("v3.produce.produce-to-topic")
@ResourceName("api.v3.produce.produce-to-topic")
public void produce(@Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("topicName") String topicName, MappingIterator<ProduceRequest> requests) throws Exception {
    if (requests == null) {
        throw Errors.invalidPayloadException("Null input provided. Data is required.");
    }
    ProduceController controller = produceControllerProvider.get();
    streamingResponseFactory.from(requests).compose(request -> produce(clusterId, topicName, request, controller)).resume(asyncResponse);
}
Also used : PathParam(javax.ws.rs.PathParam) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) ProduceRequest(io.confluent.kafkarest.entities.v3.ProduceRequest) SerializationException(org.apache.kafka.common.errors.SerializationException) MappingIterator(com.fasterxml.jackson.databind.MappingIterator) StacklessCompletionException(io.confluent.kafkarest.exceptions.StacklessCompletionException) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) ProduceRequestHeader(io.confluent.kafkarest.entities.v3.ProduceRequest.ProduceRequestHeader) Function(java.util.function.Function) Inject(javax.inject.Inject) NullNode(com.fasterxml.jackson.databind.node.NullNode) RateLimitExceededException(io.confluent.kafkarest.ratelimit.RateLimitExceededException) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) ProduceRequestData(io.confluent.kafkarest.entities.v3.ProduceRequest.ProduceRequestData) Objects.requireNonNull(java.util.Objects.requireNonNull) Duration(java.time.Duration) ProduceResponseData(io.confluent.kafkarest.entities.v3.ProduceResponse.ProduceResponseData) Collector(java.util.stream.Collector) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) RegisteredSchema(io.confluent.kafkarest.entities.RegisteredSchema) BadRequestException(io.confluent.kafkarest.exceptions.BadRequestException) ProducerMetricsRegistry(io.confluent.kafkarest.ProducerMetricsRegistry) ExecutorService(java.util.concurrent.ExecutorService) EmbeddedFormat(io.confluent.kafkarest.entities.EmbeddedFormat) SchemaManager(io.confluent.kafkarest.controllers.SchemaManager) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) ProduceController(io.confluent.kafkarest.controllers.ProduceController) ProduceResult(io.confluent.kafkarest.entities.ProduceResult) AsyncResponse(javax.ws.rs.container.AsyncResponse) DoNotRateLimit(io.confluent.kafkarest.ratelimit.DoNotRateLimit) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) Instant(java.time.Instant) Suspended(javax.ws.rs.container.Suspended) ByteString(com.google.protobuf.ByteString) ProducerMetrics(io.confluent.kafkarest.ProducerMetrics) StreamingResponseFactory(io.confluent.kafkarest.response.StreamingResponseFactory) Errors(io.confluent.kafkarest.Errors) ProduceResponse(io.confluent.kafkarest.entities.v3.ProduceResponse) Optional(java.util.Optional) RecordSerializer(io.confluent.kafkarest.controllers.RecordSerializer) ProduceResponseThreadPool(io.confluent.kafkarest.resources.v3.V3ResourcesModule.ProduceResponseThreadPool) Collections(java.util.Collections) ProduceController(io.confluent.kafkarest.controllers.ProduceController) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName)

Example 4 with ResourceName

use of io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName in project kafka-rest by confluentinc.

the class ListAllBrokersConfigsAction method listBrokersConfigs.

@GET
@Produces(MediaType.APPLICATION_JSON)
@PerformanceMetric("v3.brokers.configs.list")
@ResourceName("api.v3.brokers-configs.list")
public void listBrokersConfigs(@Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) {
    BrokerConfigManager resolvedBrokerConfigManager = brokerConfigManager.get();
    CompletableFuture<ListBrokerConfigsResponse> response = brokerManager.get().listBrokers(clusterId).thenCompose(brokers -> resolvedBrokerConfigManager.listAllBrokerConfigs(clusterId, brokers.stream().map(Broker::getBrokerId).collect(Collectors.toList())).thenApply(configs -> ListBrokerConfigsResponse.create(BrokerConfigDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf(urlFactory.create("v3", "clusters", clusterId, "brokers", "-", "configs")).build()).setData(configs.values().stream().flatMap(brokerConfigs -> brokerConfigs.stream().sorted(Comparator.comparing(BrokerConfig::getBrokerId))).map(brokerConfig -> BrokerConfigsResource.toBrokerConfigData(brokerConfig, crnFactory, urlFactory)).collect(Collectors.toList())).build())));
    AsyncResponses.asyncResume(asyncResponse, response);
}
Also used : PathParam(javax.ws.rs.PathParam) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) CrnFactory(io.confluent.kafkarest.response.CrnFactory) CompletableFuture(java.util.concurrent.CompletableFuture) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) Inject(javax.inject.Inject) ResourceCollection(io.confluent.kafkarest.entities.v3.ResourceCollection) UrlFactory(io.confluent.kafkarest.response.UrlFactory) MediaType(javax.ws.rs.core.MediaType) Objects.requireNonNull(java.util.Objects.requireNonNull) BrokerConfig(io.confluent.kafkarest.entities.BrokerConfig) Broker(io.confluent.kafkarest.entities.Broker) AsyncResponses(io.confluent.kafkarest.resources.AsyncResponses) AsyncResponse(javax.ws.rs.container.AsyncResponse) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) Collectors(java.util.stream.Collectors) Suspended(javax.ws.rs.container.Suspended) BrokerConfigManager(io.confluent.kafkarest.controllers.BrokerConfigManager) BrokerManager(io.confluent.kafkarest.controllers.BrokerManager) Comparator(java.util.Comparator) BrokerConfigDataList(io.confluent.kafkarest.entities.v3.BrokerConfigDataList) Broker(io.confluent.kafkarest.entities.Broker) ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) BrokerConfigManager(io.confluent.kafkarest.controllers.BrokerConfigManager) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) Produces(javax.ws.rs.Produces) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) GET(javax.ws.rs.GET)

Example 5 with ResourceName

use of io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName in project kafka-rest by confluentinc.

the class ConsumerLagsResource method listConsumerLags.

@GET
@Produces(MediaType.APPLICATION_JSON)
@PerformanceMetric("v3.consumer-lags.list")
@ResourceName("api.v3.consumer-lags.list")
public void listConsumerLags(@Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId, @PathParam("consumerGroupId") String consumerGroupId) {
    CompletableFuture<ListConsumerLagsResponse> response = consumerLagManager.get().listConsumerLags(clusterId, consumerGroupId).thenApply(lags -> {
        if (lags.isEmpty()) {
            throw new NotFoundException("Consumer lags not found.");
        }
        return lags;
    }).thenApply(lags -> ListConsumerLagsResponse.create(ConsumerLagDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf(urlFactory.create("v3", "clusters", clusterId, "consumer-groups", consumerGroupId, "lags")).build()).setData(lags.stream().map(this::toConsumerLagData).sorted(Comparator.comparing(ConsumerLagData::getLag).reversed().thenComparing(ConsumerLagData::getTopicName).thenComparing(ConsumerLagData::getPartitionId)).collect(Collectors.toList())).build()));
    AsyncResponses.asyncResume(asyncResponse, response);
}
Also used : PathParam(javax.ws.rs.PathParam) ConsumerLagManager(io.confluent.kafkarest.controllers.ConsumerLagManager) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) CrnFactory(io.confluent.kafkarest.response.CrnFactory) CompletableFuture(java.util.concurrent.CompletableFuture) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) GetConsumerLagResponse(io.confluent.kafkarest.entities.v3.GetConsumerLagResponse) Inject(javax.inject.Inject) ConsumerLag(io.confluent.kafkarest.entities.ConsumerLag) ResourceCollection(io.confluent.kafkarest.entities.v3.ResourceCollection) UrlFactory(io.confluent.kafkarest.response.UrlFactory) MediaType(javax.ws.rs.core.MediaType) Resource(io.confluent.kafkarest.entities.v3.Resource) Objects.requireNonNull(java.util.Objects.requireNonNull) ConsumerLagData(io.confluent.kafkarest.entities.v3.ConsumerLagData) ListConsumerLagsResponse(io.confluent.kafkarest.entities.v3.ListConsumerLagsResponse) AsyncResponses(io.confluent.kafkarest.resources.AsyncResponses) AsyncResponse(javax.ws.rs.container.AsyncResponse) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) ConsumerLagDataList(io.confluent.kafkarest.entities.v3.ConsumerLagDataList) Collectors(java.util.stream.Collectors) Suspended(javax.ws.rs.container.Suspended) NotFoundException(javax.ws.rs.NotFoundException) Comparator(java.util.Comparator) NotFoundException(javax.ws.rs.NotFoundException) ConsumerLagData(io.confluent.kafkarest.entities.v3.ConsumerLagData) ListConsumerLagsResponse(io.confluent.kafkarest.entities.v3.ListConsumerLagsResponse) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) Produces(javax.ws.rs.Produces) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) GET(javax.ws.rs.GET)

Aggregations

ResourceName (io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName)10 PerformanceMetric (io.confluent.rest.annotations.PerformanceMetric)9 GET (javax.ws.rs.GET)7 Produces (javax.ws.rs.Produces)7 Objects.requireNonNull (java.util.Objects.requireNonNull)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Inject (javax.inject.Inject)6 Provider (javax.inject.Provider)6 Path (javax.ws.rs.Path)6 PathParam (javax.ws.rs.PathParam)6 AsyncResponse (javax.ws.rs.container.AsyncResponse)6 Suspended (javax.ws.rs.container.Suspended)6 AsyncResponses (io.confluent.kafkarest.resources.AsyncResponses)5 Collectors (java.util.stream.Collectors)5 List (java.util.List)4 Consumes (javax.ws.rs.Consumes)4 MediaType (javax.ws.rs.core.MediaType)4 Errors (io.confluent.kafkarest.Errors)3 TopicManager (io.confluent.kafkarest.controllers.TopicManager)3 ResourceCollection (io.confluent.kafkarest.entities.v3.ResourceCollection)3