use of io.confluent.kafkarest.entities.Topic 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.entities.Topic in project kafka-rest by confluentinc.
the class TopicManagerImpl method createTopic.
@Override
public CompletableFuture<Void> createTopic(String clusterId, String topicName, Optional<Integer> partitionsCount, Optional<Short> replicationFactor, Map<Integer, List<Integer>> replicasAssignments, Map<String, Optional<String>> configs) {
requireNonNull(topicName);
Map<String, String> nullableConfigs = new HashMap<>();
configs.forEach((key, value) -> nullableConfigs.put(key, value.orElse(null)));
// A new topic can be created with either uniform replication according to the given partitions
// count and replication factor, or explicitly specified partition-to-replicas assignments.
NewTopic createTopicRequest = replicasAssignments.isEmpty() ? new NewTopic(topicName, partitionsCount, replicationFactor).configs(nullableConfigs) : new NewTopic(topicName, replicasAssignments).configs(nullableConfigs);
return clusterManager.getCluster(clusterId).thenApply(cluster -> checkEntityExists(cluster, "Cluster %s cannot be found.", clusterId)).thenCompose(cluster -> KafkaFutures.toCompletableFuture(adminClient.createTopics(singletonList(createTopicRequest)).all()));
}
use of io.confluent.kafkarest.entities.Topic in project kafka-rest by confluentinc.
the class TopicManagerImplTest method getLocalTopic_existingTopic_returnsTopic.
@Test
public void getLocalTopic_existingTopic_returnsTopic() throws Exception {
expect(clusterManager.getLocalCluster()).andReturn(completedFuture(CLUSTER));
expect(adminClient.describeTopics(isA(Collection.class), anyObject())).andReturn(describeTopicResult);
expect(describeTopicResult.all()).andReturn(KafkaFuture.completedFuture(createTopicDescriptionMap(TOPIC_DESCRIPTION_1)));
replay(clusterManager, adminClient, describeTopicResult);
Topic topic = topicManager.getLocalTopic(TOPIC_1.getName()).get().get();
assertEquals(TOPIC_1, topic);
}
use of io.confluent.kafkarest.entities.Topic in project kafka-rest by confluentinc.
the class TopicManagerImplTest method getTopic_existingTopic_returnsTopic.
@Test
public void getTopic_existingTopic_returnsTopic() throws Exception {
expect(clusterManager.getCluster(CLUSTER_ID)).andReturn(completedFuture(Optional.of(CLUSTER)));
expect(adminClient.describeTopics(isA(Collection.class), anyObject())).andReturn(describeTopicResult);
expect(describeTopicResult.all()).andReturn(KafkaFuture.completedFuture(createTopicDescriptionMap(TOPIC_DESCRIPTION_1)));
replay(clusterManager, adminClient, describeTopicResult);
Topic topic = topicManager.getTopic(CLUSTER_ID, TOPIC_1.getName()).get().get();
assertEquals(TOPIC_1, topic);
}
use of io.confluent.kafkarest.entities.Topic 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);
}
Aggregations