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