added partition parameter
This commit is contained in:
parent
4694ccd1bf
commit
8585c86f96
3 changed files with 11 additions and 4 deletions
|
@ -197,14 +197,15 @@ public class ClusterService {
|
|||
.orElse(Flux.empty());
|
||||
}
|
||||
|
||||
public Mono<Void> deleteTopicMessages(String clusterName, String topicName) {
|
||||
public Mono<Void> deleteTopicMessages(String clusterName, String topicName, Optional<Integer> partition) {
|
||||
var cluster = clustersStorage.getClusterByName(clusterName)
|
||||
.orElseThrow(() -> new NotFoundException("No such cluster"));
|
||||
var partitions = getTopicDetails(clusterName, topicName)
|
||||
.orElseThrow(() -> new NotFoundException("No such topic"))
|
||||
.getPartitions().stream()
|
||||
.map(Partition::getPartition)
|
||||
.map(partition -> new TopicPartition(topicName, partition))
|
||||
.filter(p -> partition.isEmpty() || partition.get().equals(p))
|
||||
.map(p-> new TopicPartition(topicName, p))
|
||||
.collect(Collectors.toList());
|
||||
return consumingService.loadOffsets(cluster, partitions)
|
||||
.flatMap(offsets -> kafkaService.deleteTopicMessages(cluster, topicName, offsets));
|
||||
|
|
|
@ -18,6 +18,7 @@ import reactor.core.publisher.Mono;
|
|||
import javax.validation.Valid;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@RestController
|
||||
|
@ -85,8 +86,8 @@ public class MetricsRestController implements ApiClustersApi {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Mono<ResponseEntity<Void>> deleteTopicMessages(String clusterName, String topicName, ServerWebExchange exchange) {
|
||||
return clusterService.deleteTopicMessages(clusterName, topicName).map(ResponseEntity::ok);
|
||||
public Mono<ResponseEntity<Void>> deleteTopicMessages(String clusterName, String topicName, @Valid Integer partition, ServerWebExchange exchange) {
|
||||
return clusterService.deleteTopicMessages(clusterName, topicName, Optional.ofNullable(partition)).map(ResponseEntity::ok);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -325,6 +325,11 @@ paths:
|
|||
required: true
|
||||
schema:
|
||||
type: string
|
||||
- name: partition
|
||||
in: query
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
||||
|
|
Loading…
Add table
Reference in a new issue