Explorar o código

Adding new fields to TopicConfig

Adding tests for TopicConfigs consumer and service

Refactoring the tests

Fixing checkstyle violation
Diego Ching %!s(int64=3) %!d(string=hai) anos
pai
achega
2a2e651d81

+ 2 - 0
kafka-ui-api/src/main/java/com/provectus/kafka/ui/mapper/ClusterMapper.java

@@ -123,6 +123,8 @@ public interface ClusterMapper {
     return result;
   }
 
+  @Mapping(target = "isReadOnly", source = "readOnly")
+  @Mapping(target = "isSensitive", source = "sensitive")
   TopicConfig toTopicConfig(InternalTopicConfig topic);
 
   Replica toReplica(InternalReplica replica);

+ 6 - 0
kafka-ui-api/src/main/java/com/provectus/kafka/ui/model/InternalTopicConfig.java

@@ -1,8 +1,10 @@
 package com.provectus.kafka.ui.model;
 
 
+import java.util.List;
 import lombok.Builder;
 import lombok.Data;
+import org.apache.kafka.clients.admin.ConfigEntry;
 
 @Data
 @Builder
@@ -10,4 +12,8 @@ public class InternalTopicConfig {
   private final String name;
   private final String value;
   private final String defaultValue;
+  private final ConfigEntry.ConfigSource source;
+  private final boolean isSensitive;
+  private final boolean isReadOnly;
+  private final List<ConfigEntry.ConfigSynonym> synonyms;
 }

+ 25 - 1
kafka-ui-api/src/test/java/com/provectus/kafka/ui/KafkaConsumerTests.java

@@ -6,8 +6,8 @@ import com.provectus.kafka.ui.model.PartitionsIncreaseResponse;
 import com.provectus.kafka.ui.model.TopicCreation;
 import com.provectus.kafka.ui.model.TopicDetails;
 import com.provectus.kafka.ui.model.TopicMessage;
+import com.provectus.kafka.ui.api.model.TopicConfig;
 import com.provectus.kafka.ui.producer.KafkaTestProducer;
-import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 import java.util.stream.Stream;
@@ -164,4 +164,28 @@ public class KafkaConsumerTests extends AbstractBaseTest {
         .expectStatus()
         .isNotFound();
   }
+
+  @Test
+  public void shouldRetrieveConfig() {
+    var topicName = UUID.randomUUID().toString();
+
+    webTestClient.post()
+            .uri("/api/clusters/{clusterName}/topics", LOCAL)
+            .bodyValue(new TopicCreation()
+                    .name(topicName)
+                    .partitions(1)
+                    .replicationFactor(1)
+                    .configs(Map.of())
+            )
+            .exchange()
+            .expectStatus()
+            .isOk();
+
+    WebTestClient.ListBodySpec result = webTestClient.get()
+            .uri("/api/clusters/{clusterName}/topics/{topicName}/config", LOCAL, topicName)
+            .exchange()
+            .expectStatus()
+            .isOk()
+            .expectBodyList(TopicConfig.class);
+  }
 }

+ 44 - 0
kafka-ui-api/src/test/java/com/provectus/kafka/ui/service/ClusterServiceTest.java

@@ -6,9 +6,11 @@ import static org.mockito.Mockito.when;
 
 import com.provectus.kafka.ui.mapper.ClusterMapper;
 import com.provectus.kafka.ui.model.InternalTopic;
+import com.provectus.kafka.ui.model.InternalTopicConfig;
 import com.provectus.kafka.ui.model.KafkaCluster;
 import com.provectus.kafka.ui.model.Topic;
 import com.provectus.kafka.ui.model.TopicColumnsToSort;
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
@@ -16,6 +18,7 @@ import java.util.UUID;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
+import org.apache.kafka.clients.admin.ConfigEntry;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.mapstruct.factory.Mappers;
@@ -256,4 +259,45 @@ class ClusterServiceTest {
     assertThat(topics.getTopics()).map(Topic::getPartitionCount).isSorted();
   }
 
+  @Test
+  public void shouldRetrieveTopicConfigs() {
+    var topicName = UUID.randomUUID().toString();
+
+    when(clustersStorage.getClusterByName(topicName))
+        .thenReturn(Optional.of(KafkaCluster.builder()
+            .topics(
+                IntStream.rangeClosed(1, 100).boxed()
+                    .map(Objects::toString)
+                    .collect(Collectors.toMap(Function.identity(), e -> InternalTopic.builder()
+                        .name(e)
+                        .topicConfigs(
+                            List.of(InternalTopicConfig.builder()
+                                .name("testName")
+                                .value("testValue")
+                                .defaultValue("testDefaultValue")
+                                .source(ConfigEntry.ConfigSource.DEFAULT_CONFIG)
+                                .isReadOnly(true)
+                                .isSensitive(true)
+                                .synonyms(List.of())
+                                .build()
+                            )
+                        )
+                        .build()))
+            )
+            .build()));
+
+    var configs = clusterService.getTopicConfigs(topicName, "1");
+    var topicConfig = configs.isPresent() ? configs.get().get(0) : null;
+
+    assertThat(configs.isPresent()).isTrue();
+    assertThat(topicConfig.getName()).isEqualTo("testName");
+    assertThat(topicConfig.getValue()).isEqualTo("testValue");
+    assertThat(topicConfig.getDefaultValue()).isEqualTo("testDefaultValue");
+    assertThat(topicConfig.getSource().getValue())
+            .isEqualTo(ConfigEntry.ConfigSource.DEFAULT_CONFIG.name());
+    assertThat(topicConfig.getSynonyms()).isNotNull();
+    assertThat(topicConfig.getIsReadOnly()).isTrue();
+    assertThat(topicConfig.getIsSensitive()).isTrue();
+  }
+
 }

+ 36 - 0
kafka-ui-contract/src/main/resources/swagger/kafka-ui-api.yaml

@@ -1717,9 +1717,45 @@ components:
           type: string
         defaultValue:
           type: string
+        source:
+          type: string
+          enum:
+            - DYNAMIC_TOPIC_CONFIG
+            - DYNAMIC_BROKER_LOGGER_CONFIG
+            - DYNAMIC_BROKER_CONFIG
+            - DYNAMIC_DEFAULT_BROKER_CONFIG
+            - STATIC_BROKER_CONFIG
+            - DEFAULT_CONFIG
+            - UNKNOWN
+        isSensitive:
+          type: boolean
+        isReadOnly:
+          type: boolean
+        synonyms:
+          type: array
+          items:
+            $ref: "#/components/schemas/ConfigSynonym"
       required:
         - name
 
+    ConfigSynonym:
+      type: object
+      properties:
+        name:
+          type: string
+        value:
+          type: string
+        source:
+          type: string
+          enum:
+            - DYNAMIC_TOPIC_CONFIG
+            - DYNAMIC_BROKER_LOGGER_CONFIG
+            - DYNAMIC_BROKER_CONFIG
+            - DYNAMIC_DEFAULT_BROKER_CONFIG
+            - STATIC_BROKER_CONFIG
+            - DEFAULT_CONFIG
+            - UNKNOWN
+
     TopicCreation:
       type: object
       properties: