forked from provectus/kafka-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature refactoring, structure simplifying (provectus#250)
- Loading branch information
1 parent
c4e146a
commit 38f4b0c
Showing
69 changed files
with
578 additions
and
447 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
kafka-ui-api/src/main/java/com/provectus/kafka/ui/client/KafkaConnectClients.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.provectus.kafka.ui.client; | ||
|
||
import com.provectus.kafka.ui.connect.api.KafkaConnectClientApi; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public final class KafkaConnectClients { | ||
|
||
private static final Map<String, KafkaConnectClientApi> CACHE = new ConcurrentHashMap<>(); | ||
|
||
public static KafkaConnectClientApi withBaseUrl(String basePath) { | ||
return CACHE.computeIfAbsent(basePath, RetryingKafkaConnectClient::new); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
kafka-ui-api/src/main/java/com/provectus/kafka/ui/cluster/client/KafkaConnectClients.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ui/cluster/config/ClustersProperties.java → ...s/kafka/ui/config/ClustersProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ectus/kafka/ui/cluster/config/Config.java → ...com/provectus/kafka/ui/config/Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../rest/config/CorsGlobalConfiguration.java → ...ka/ui/config/CorsGlobalConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...kafka/ui/rest/config/CustomWebFilter.java → ...ctus/kafka/ui/config/CustomWebFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...ka/ui/rest/config/ReadOnlyModeFilter.java → ...s/kafka/ui/config/ReadOnlyModeFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...fka/ui/cluster/config/SecurityConfig.java → ...ectus/kafka/ui/config/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
kafka-ui-api/src/main/java/com/provectus/kafka/ui/controller/BrokersController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.provectus.kafka.ui.controller; | ||
|
||
import com.provectus.kafka.ui.api.BrokersApi; | ||
import com.provectus.kafka.ui.service.ClusterService; | ||
import com.provectus.kafka.ui.model.Broker; | ||
import com.provectus.kafka.ui.model.BrokerMetrics; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Log4j2 | ||
public class BrokersController implements BrokersApi { | ||
private final ClusterService clusterService; | ||
|
||
@Override | ||
public Mono<ResponseEntity<BrokerMetrics>> getBrokersMetrics(String clusterName, Integer id, ServerWebExchange exchange) { | ||
return clusterService.getBrokerMetrics(clusterName, id) | ||
.map(ResponseEntity::ok) | ||
.onErrorReturn(ResponseEntity.notFound().build()); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<Flux<Broker>>> getBrokers(String clusterName, ServerWebExchange exchange) { | ||
return Mono.just(ResponseEntity.ok(clusterService.getBrokers(clusterName))); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
kafka-ui-api/src/main/java/com/provectus/kafka/ui/controller/ClustersController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.provectus.kafka.ui.controller; | ||
|
||
import com.provectus.kafka.ui.api.ClustersApi; | ||
import com.provectus.kafka.ui.service.ClusterService; | ||
import com.provectus.kafka.ui.model.Cluster; | ||
import com.provectus.kafka.ui.model.ClusterMetrics; | ||
import com.provectus.kafka.ui.model.ClusterStats; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Log4j2 | ||
public class ClustersController implements ClustersApi { | ||
private final ClusterService clusterService; | ||
|
||
@Override | ||
public Mono<ResponseEntity<ClusterMetrics>> getClusterMetrics(String clusterName, ServerWebExchange exchange) { | ||
return clusterService.getClusterMetrics(clusterName) | ||
.map(ResponseEntity::ok) | ||
.onErrorReturn(ResponseEntity.notFound().build()); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<ClusterStats>> getClusterStats(String clusterName, ServerWebExchange exchange) { | ||
return clusterService.getClusterStats(clusterName) | ||
.map(ResponseEntity::ok) | ||
.onErrorReturn(ResponseEntity.notFound().build()); | ||
} | ||
|
||
@Override | ||
public Mono<ResponseEntity<Flux<Cluster>>> getClusters(ServerWebExchange exchange) { | ||
return Mono.just(ResponseEntity.ok(Flux.fromIterable(clusterService.getClusters()))); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
kafka-ui-api/src/main/java/com/provectus/kafka/ui/controller/ConsumerGroupsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.provectus.kafka.ui.controller; | ||
|
||
import com.provectus.kafka.ui.api.ConsumerGroupsApi; | ||
import com.provectus.kafka.ui.service.ClusterService; | ||
import com.provectus.kafka.ui.model.ConsumerGroup; | ||
import com.provectus.kafka.ui.model.ConsumerGroupDetails; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Log4j2 | ||
public class ConsumerGroupsController implements ConsumerGroupsApi { | ||
private final ClusterService clusterService; | ||
|
||
@Override | ||
public Mono<ResponseEntity<ConsumerGroupDetails>> getConsumerGroup( | ||
String clusterName, String consumerGroupId, ServerWebExchange exchange) { | ||
return clusterService.getConsumerGroupDetail(clusterName, consumerGroupId).map(ResponseEntity::ok); | ||
} | ||
|
||
|
||
@Override | ||
public Mono<ResponseEntity<Flux<ConsumerGroup>>> getConsumerGroups(String clusterName, ServerWebExchange exchange) { | ||
return clusterService.getConsumerGroups(clusterName) | ||
.map(Flux::fromIterable) | ||
.map(ResponseEntity::ok) | ||
.switchIfEmpty(Mono.just(ResponseEntity.notFound().build())); // TODO: check behaviour on cluster not found and empty groups list | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
kafka-ui-api/src/main/java/com/provectus/kafka/ui/controller/MessagesController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.provectus.kafka.ui.controller; | ||
|
||
import com.provectus.kafka.ui.api.MessagesApi; | ||
import com.provectus.kafka.ui.model.ConsumerPosition; | ||
import com.provectus.kafka.ui.service.ClusterService; | ||
import com.provectus.kafka.ui.model.SeekType; | ||
import com.provectus.kafka.ui.model.TopicMessage; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import javax.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Log4j2 | ||
public class MessagesController implements MessagesApi { | ||
private final ClusterService clusterService; | ||
|
||
@Override | ||
public Mono<ResponseEntity<Void>> deleteTopicMessages( | ||
String clusterName, String topicName, @Valid List<Integer> partitions, ServerWebExchange exchange) { | ||
return clusterService.deleteTopicMessages( | ||
clusterName, | ||
topicName, | ||
Optional.ofNullable(partitions).orElse(List.of()) | ||
).map(ResponseEntity::ok); | ||
} | ||
|
||
|
||
@Override | ||
public Mono<ResponseEntity<Flux<TopicMessage>>> getTopicMessages( | ||
String clusterName, String topicName, @Valid SeekType seekType, @Valid List<String> seekTo, | ||
@Valid Integer limit, @Valid String q, ServerWebExchange exchange) { | ||
return parseConsumerPosition(seekType, seekTo) | ||
.map(consumerPosition -> ResponseEntity.ok(clusterService.getMessages(clusterName, topicName, consumerPosition, q, limit))); | ||
} | ||
|
||
private Mono<ConsumerPosition> parseConsumerPosition(SeekType seekType, List<String> seekTo) { | ||
return Mono.justOrEmpty(seekTo) | ||
.defaultIfEmpty(Collections.emptyList()) | ||
.flatMapIterable(Function.identity()) | ||
.map(p -> { | ||
String[] splited = p.split("::"); | ||
if (splited.length != 2) { | ||
throw new IllegalArgumentException("Wrong seekTo argument format. See API docs for details"); | ||
} | ||
|
||
return Pair.of(Integer.parseInt(splited[0]), Long.parseLong(splited[1])); | ||
}) | ||
.collectMap(Pair::getKey, Pair::getValue) | ||
.map(positions -> new ConsumerPosition(seekType != null ? seekType : SeekType.BEGINNING, positions)); | ||
} | ||
|
||
} |
Oops, something went wrong.