|
@@ -1,5 +1,7 @@
|
|
|
package com.provectus.kafka.ui.service;
|
|
|
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.provectus.kafka.ui.client.KafkaConnectClients;
|
|
|
import com.provectus.kafka.ui.exception.ClusterNotFoundException;
|
|
|
import com.provectus.kafka.ui.exception.ConnectNotFoundException;
|
|
@@ -10,16 +12,21 @@ import com.provectus.kafka.ui.model.Connector;
|
|
|
import com.provectus.kafka.ui.model.ConnectorAction;
|
|
|
import com.provectus.kafka.ui.model.ConnectorPlugin;
|
|
|
import com.provectus.kafka.ui.model.ConnectorPluginConfigValidationResponse;
|
|
|
+import com.provectus.kafka.ui.model.FullConnectorInfo;
|
|
|
import com.provectus.kafka.ui.model.KafkaCluster;
|
|
|
import com.provectus.kafka.ui.model.KafkaConnectCluster;
|
|
|
import com.provectus.kafka.ui.model.NewConnector;
|
|
|
import com.provectus.kafka.ui.model.Task;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.lang3.tuple.Pair;
|
|
|
+import org.apache.commons.lang3.tuple.Triple;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import reactor.core.publisher.Flux;
|
|
|
import reactor.core.publisher.Mono;
|
|
@@ -31,6 +38,7 @@ public class KafkaConnectService {
|
|
|
private final ClustersStorage clustersStorage;
|
|
|
private final ClusterMapper clusterMapper;
|
|
|
private final KafkaConnectMapper kafkaConnectMapper;
|
|
|
+ private final ObjectMapper objectMapper;
|
|
|
|
|
|
public Mono<Flux<Connect>> getConnects(String clusterName) {
|
|
|
return Mono.just(
|
|
@@ -43,6 +51,38 @@ public class KafkaConnectService {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ public Flux<FullConnectorInfo> getAllConnectors(String clusterName) {
|
|
|
+ return getConnects(clusterName)
|
|
|
+ .flatMapMany(Function.identity())
|
|
|
+ .flatMap(connect -> getConnectorNames(clusterName, connect))
|
|
|
+ .flatMap(pair -> getConnector(clusterName, pair.getLeft(), pair.getRight()))
|
|
|
+ .flatMap(connector ->
|
|
|
+ getConnectorConfig(clusterName, connector.getConnect(), connector.getName())
|
|
|
+ .map(config -> Pair.of(connector, config))
|
|
|
+ )
|
|
|
+ .flatMap(pair ->
|
|
|
+ getConnectorTasks(clusterName, pair.getLeft().getConnect(), pair.getLeft().getName())
|
|
|
+ .collectList()
|
|
|
+ .map(tasks -> Triple.of(pair.getLeft(), pair.getRight(), tasks))
|
|
|
+ )
|
|
|
+ .map(kafkaConnectMapper::fullConnectorInfoFromTuple);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Flux<Pair<String, String>> getConnectorNames(String clusterName, Connect connect) {
|
|
|
+ return getConnectors(clusterName, connect.getName())
|
|
|
+ .collectList().map(e -> e.get(0))
|
|
|
+ // for some reason `getConnectors` method returns the response as a single string
|
|
|
+ .map(this::parseToList)
|
|
|
+ .flatMapMany(Flux::fromIterable)
|
|
|
+ .map(connector -> Pair.of(connect.getName(), connector));
|
|
|
+ }
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ private List<String> parseToList(String json) {
|
|
|
+ return objectMapper.readValue(json, new TypeReference<>() {
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
public Flux<String> getConnectors(String clusterName, String connectName) {
|
|
|
return getConnectAddress(clusterName, connectName)
|
|
|
.flatMapMany(connect ->
|
|
@@ -76,6 +116,7 @@ public class KafkaConnectService {
|
|
|
var status = connectorStatus.getConnector();
|
|
|
connector.status(kafkaConnectMapper.fromClient(status));
|
|
|
return (Connector) new Connector()
|
|
|
+ .connect(connectName)
|
|
|
.status(kafkaConnectMapper.fromClient(status))
|
|
|
.type(connector.getType())
|
|
|
.tasks(connector.getTasks())
|