From 1b5ae1f5e59bf761e38dadbaeb9fa62030895ae4 Mon Sep 17 00:00:00 2001 From: yeikel Date: Wed, 11 Dec 2024 19:55:49 -0500 Subject: [PATCH] refactor: use record classes --- .../kafbat/ui/model/InternalClusterState.java | 7 +-- .../ui/model/InternalPartitionsOffsets.java | 7 +-- .../io/kafbat/ui/model/InternalReplica.java | 9 +-- .../io/kafbat/ui/model/InternalTopic.java | 4 +- .../ui/serdes/ConsumerRecordDeserializer.java | 12 ++-- .../kafbat/ui/serdes/CustomSerdeLoader.java | 7 +-- .../kafbat/ui/serdes/SerdesInitializer.java | 4 +- .../io/kafbat/ui/service/BrokerService.java | 6 +- .../ui/service/DeserializationService.java | 4 +- .../io/kafbat/ui/service/FeatureService.java | 2 +- .../ui/service/ReactiveAdminClient.java | 57 +++++++++---------- .../kafbat/ui/service/StatisticsService.java | 6 +- .../io/kafbat/ui/service/TopicsService.java | 6 +- .../kafbat/ui/service/ksql/KsqlApiClient.java | 7 +-- .../kafbat/ui/service/ksql/KsqlGrammar.java | 5 +- .../kafbat/ui/service/ksql/KsqlServiceV2.java | 6 +- .../ui/service/masking/DataMasking.java | 10 +--- .../kafbat/ui/service/metrics/RawMetric.java | 24 +------- .../jsonschema/AvroJsonSchemaConverter.java | 4 +- .../ui/util/jsonschema/ObjectFieldSchema.java | 19 +------ .../jsonschema/ProtobufSchemaConverter.java | 2 +- .../ui/util/jsonschema/RefFieldSchema.java | 11 +--- .../serdes/builtin/AvroEmbeddedSerdeTest.java | 6 +- .../ui/serdes/builtin/Base64SerdeTest.java | 6 +- .../builtin/ConsumerOffsetsSerdeTest.java | 2 +- .../ui/serdes/builtin/HexSerdeTest.java | 6 +- .../ui/serdes/builtin/Int32SerdeTest.java | 4 +- .../ui/serdes/builtin/Int64SerdeTest.java | 4 +- .../serdes/builtin/ProtobufFileSerdeTest.java | 10 ++-- .../serdes/builtin/ProtobufRawSerdeTest.java | 6 +- .../ui/serdes/builtin/UInt32SerdeTest.java | 4 +- .../ui/serdes/builtin/UInt64SerdeTest.java | 4 +- .../serdes/builtin/UuidBinarySerdeTest.java | 12 ++-- .../builtin/sr/SchemaRegistrySerdeTest.java | 12 ++-- .../kafbat/ui/service/RecordEmitterTest.java | 32 +++++------ .../ui/serde/api/DeserializeResult.java | 28 ++++----- .../ui/serde/api/SchemaDescription.java | 20 +++---- 37 files changed, 137 insertions(+), 238 deletions(-) diff --git a/api/src/main/java/io/kafbat/ui/model/InternalClusterState.java b/api/src/main/java/io/kafbat/ui/model/InternalClusterState.java index 5e1874d10..4e60d8714 100644 --- a/api/src/main/java/io/kafbat/ui/model/InternalClusterState.java +++ b/api/src/main/java/io/kafbat/ui/model/InternalClusterState.java @@ -1,9 +1,6 @@ package io.kafbat.ui.model; import com.google.common.base.Throwables; -import io.kafbat.ui.model.BrokerDiskUsageDTO; -import io.kafbat.ui.model.MetricsCollectionErrorDTO; -import io.kafbat.ui.model.ServerStatusDTO; import java.math.BigDecimal; import java.util.List; import java.util.Optional; @@ -40,8 +37,8 @@ public InternalClusterState(KafkaCluster cluster, Statistics statistics) { .stackTrace(Throwables.getStackTraceAsString(e))) .orElse(null); topicCount = statistics.getTopicDescriptions().size(); - brokerCount = statistics.getClusterDescription().getNodes().size(); - activeControllers = Optional.ofNullable(statistics.getClusterDescription().getController()) + brokerCount = statistics.getClusterDescription().nodes().size(); + activeControllers = Optional.ofNullable(statistics.getClusterDescription().controller()) .map(Node::id) .orElse(null); version = statistics.getVersion(); diff --git a/api/src/main/java/io/kafbat/ui/model/InternalPartitionsOffsets.java b/api/src/main/java/io/kafbat/ui/model/InternalPartitionsOffsets.java index 3084be5c3..3facf2992 100644 --- a/api/src/main/java/io/kafbat/ui/model/InternalPartitionsOffsets.java +++ b/api/src/main/java/io/kafbat/ui/model/InternalPartitionsOffsets.java @@ -4,16 +4,11 @@ import com.google.common.collect.Table; import java.util.Map; import java.util.Optional; -import lombok.Value; import org.apache.kafka.common.TopicPartition; - public class InternalPartitionsOffsets { - @Value - public static class Offsets { - Long earliest; - Long latest; + public record Offsets(Long earliest, Long latest) { } private final Table offsets = HashBasedTable.create(); diff --git a/api/src/main/java/io/kafbat/ui/model/InternalReplica.java b/api/src/main/java/io/kafbat/ui/model/InternalReplica.java index 7db901565..1dcd6af12 100644 --- a/api/src/main/java/io/kafbat/ui/model/InternalReplica.java +++ b/api/src/main/java/io/kafbat/ui/model/InternalReplica.java @@ -1,14 +1,7 @@ package io.kafbat.ui.model; import lombok.Builder; -import lombok.Data; -import lombok.RequiredArgsConstructor; -@Data @Builder -@RequiredArgsConstructor -public class InternalReplica { - private final int broker; - private final boolean leader; - private final boolean inSync; +public record InternalReplica(int broker, boolean leader, boolean inSync) { } diff --git a/api/src/main/java/io/kafbat/ui/model/InternalTopic.java b/api/src/main/java/io/kafbat/ui/model/InternalTopic.java index 3a6134fa0..ffc30c622 100644 --- a/api/src/main/java/io/kafbat/ui/model/InternalTopic.java +++ b/api/src/main/java/io/kafbat/ui/model/InternalTopic.java @@ -77,8 +77,8 @@ public static InternalTopic from(TopicDescription topicDescription, partitionsOffsets.get(topicDescription.name(), partition.partition()) .ifPresent(offsets -> { - partitionDto.offsetMin(offsets.getEarliest()); - partitionDto.offsetMax(offsets.getLatest()); + partitionDto.offsetMin(offsets.earliest()); + partitionDto.offsetMax(offsets.latest()); }); var segmentStats = diff --git a/api/src/main/java/io/kafbat/ui/serdes/ConsumerRecordDeserializer.java b/api/src/main/java/io/kafbat/ui/serdes/ConsumerRecordDeserializer.java index b4eb51493..480a2df42 100644 --- a/api/src/main/java/io/kafbat/ui/serdes/ConsumerRecordDeserializer.java +++ b/api/src/main/java/io/kafbat/ui/serdes/ConsumerRecordDeserializer.java @@ -79,14 +79,14 @@ private void fillKey(TopicMessageDTO message, ConsumerRecord rec) } try { var deserResult = keyDeserializer.deserialize(new RecordHeadersImpl(), rec.key().get()); - message.setKey(deserResult.getResult()); + message.setKey(deserResult.result()); message.setKeySerde(keySerdeName); - message.setKeyDeserializeProperties(deserResult.getAdditionalProperties()); + message.setKeyDeserializeProperties(deserResult.additionalProperties()); } catch (Exception e) { log.trace("Error deserializing key for key topic: {}, partition {}, offset {}, with serde {}", rec.topic(), rec.partition(), rec.offset(), keySerdeName, e); var deserResult = fallbackKeyDeserializer.deserialize(new RecordHeadersImpl(), rec.key().get()); - message.setKey(deserResult.getResult()); + message.setKey(deserResult.result()); message.setKeySerde(fallbackSerdeName); } } @@ -98,15 +98,15 @@ private void fillValue(TopicMessageDTO message, ConsumerRecord rec try { var deserResult = valueDeserializer.deserialize( new RecordHeadersImpl(rec.headers()), rec.value().get()); - message.setContent(deserResult.getResult()); + message.setContent(deserResult.result()); message.setValueSerde(valueSerdeName); - message.setValueDeserializeProperties(deserResult.getAdditionalProperties()); + message.setValueDeserializeProperties(deserResult.additionalProperties()); } catch (Exception e) { log.trace("Error deserializing key for value topic: {}, partition {}, offset {}, with serde {}", rec.topic(), rec.partition(), rec.offset(), valueSerdeName, e); var deserResult = fallbackValueDeserializer.deserialize( new RecordHeadersImpl(rec.headers()), rec.value().get()); - message.setContent(deserResult.getResult()); + message.setContent(deserResult.result()); message.setValueSerde(fallbackSerdeName); } } diff --git a/api/src/main/java/io/kafbat/ui/serdes/CustomSerdeLoader.java b/api/src/main/java/io/kafbat/ui/serdes/CustomSerdeLoader.java index 87f453ca8..68cc90a20 100644 --- a/api/src/main/java/io/kafbat/ui/serdes/CustomSerdeLoader.java +++ b/api/src/main/java/io/kafbat/ui/serdes/CustomSerdeLoader.java @@ -18,15 +18,10 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import lombok.SneakyThrows; -import lombok.Value; - class CustomSerdeLoader { - @Value - static class CustomSerde { - Serde serde; - ClassLoader classLoader; + record CustomSerde(Serde serde, ClassLoader classLoader) { } // serde location -> classloader diff --git a/api/src/main/java/io/kafbat/ui/serdes/SerdesInitializer.java b/api/src/main/java/io/kafbat/ui/serdes/SerdesInitializer.java index bbdba76c4..22c21a63c 100644 --- a/api/src/main/java/io/kafbat/ui/serdes/SerdesInitializer.java +++ b/api/src/main/java/io/kafbat/ui/serdes/SerdesInitializer.java @@ -266,10 +266,10 @@ private SerdeInstance loadAndInitCustomSerde(ClustersProperties.SerdeConfig serd serdeConfig.getClassName(), serdeConfig.getFilePath(), serdeProps, clusterProps, globalProps); return new SerdeInstance( serdeConfig.getName(), - loaded.getSerde(), + loaded.serde(), nullablePattern(serdeConfig.getTopicKeysPattern()), nullablePattern(serdeConfig.getTopicValuesPattern()), - loaded.getClassLoader() + loaded.classLoader() ); } diff --git a/api/src/main/java/io/kafbat/ui/service/BrokerService.java b/api/src/main/java/io/kafbat/ui/service/BrokerService.java index 198685b93..ab75c5d45 100644 --- a/api/src/main/java/io/kafbat/ui/service/BrokerService.java +++ b/api/src/main/java/io/kafbat/ui/service/BrokerService.java @@ -52,7 +52,7 @@ private Mono> loadBrokersConfig( } private Flux getBrokersConfig(KafkaCluster cluster, Integer brokerId) { - if (statisticsCache.get(cluster).getClusterDescription().getNodes() + if (statisticsCache.get(cluster).getClusterDescription().nodes() .stream().noneMatch(node -> node.id() == brokerId)) { return Flux.error( new NotFoundException(String.format("Broker with id %s not found", brokerId))); @@ -70,7 +70,7 @@ public Flux getBrokers(KafkaCluster cluster) { return adminClientService .get(cluster) .flatMap(ReactiveAdminClient::describeCluster) - .map(description -> description.getNodes().stream() + .map(description -> description.nodes().stream() .map(node -> new InternalBroker(node, partitionsDistribution, stats)) .collect(Collectors.toList())) .flatMapMany(Flux::fromIterable); @@ -113,7 +113,7 @@ private Mono>> getC KafkaCluster cluster, List reqBrokers) { return adminClientService.get(cluster) .flatMap(admin -> { - List brokers = statisticsCache.get(cluster).getClusterDescription().getNodes() + List brokers = statisticsCache.get(cluster).getClusterDescription().nodes() .stream() .map(Node::id) .collect(Collectors.toList()); diff --git a/api/src/main/java/io/kafbat/ui/service/DeserializationService.java b/api/src/main/java/io/kafbat/ui/service/DeserializationService.java index 87e1b202d..291086207 100644 --- a/api/src/main/java/io/kafbat/ui/service/DeserializationService.java +++ b/api/src/main/java/io/kafbat/ui/service/DeserializationService.java @@ -143,8 +143,8 @@ private SerdeDescriptionDTO toDto(SerdeInstance serdeInstance, return new SerdeDescriptionDTO() .name(serdeInstance.getName()) .description(serdeInstance.description().orElse(null)) - .schema(schemaOpt.map(SchemaDescription::getSchema).orElse(null)) - .additionalProperties(schemaOpt.map(SchemaDescription::getAdditionalProperties).orElse(null)) + .schema(schemaOpt.map(SchemaDescription::schema).orElse(null)) + .additionalProperties(schemaOpt.map(SchemaDescription::additionalProperties).orElse(null)) .preferred(preferred); } diff --git a/api/src/main/java/io/kafbat/ui/service/FeatureService.java b/api/src/main/java/io/kafbat/ui/service/FeatureService.java index 59a23236b..36a619bff 100644 --- a/api/src/main/java/io/kafbat/ui/service/FeatureService.java +++ b/api/src/main/java/io/kafbat/ui/service/FeatureService.java @@ -61,7 +61,7 @@ private Mono quotaManagement(ReactiveAdminClient adminClient) { } private Mono aclEdit(ReactiveAdminClient adminClient, ClusterDescription clusterDescription) { - var authorizedOps = Optional.ofNullable(clusterDescription.getAuthorizedOperations()).orElse(Set.of()); + var authorizedOps = Optional.ofNullable(clusterDescription.authorizedOperations()).orElse(Set.of()); boolean canEdit = aclViewEnabled(adminClient) && (authorizedOps.contains(AclOperation.ALL) || authorizedOps.contains(AclOperation.ALTER)); return canEdit diff --git a/api/src/main/java/io/kafbat/ui/service/ReactiveAdminClient.java b/api/src/main/java/io/kafbat/ui/service/ReactiveAdminClient.java index 651f6d531..50a513a02 100644 --- a/api/src/main/java/io/kafbat/ui/service/ReactiveAdminClient.java +++ b/api/src/main/java/io/kafbat/ui/service/ReactiveAdminClient.java @@ -124,14 +124,11 @@ static Mono> forVersion(AdminClient ac, String kafkaVersio } } - @Value - public static class ClusterDescription { - @Nullable - Node controller; - String clusterId; - Collection nodes; - @Nullable // null, if ACL is disabled - Set authorizedOperations; + /** + * @param authorizedOperations null, if ACL is disabled + */ + public record ClusterDescription(@Nullable Node controller, String clusterId, Collection nodes, + @Nullable Set authorizedOperations) { } @Builder @@ -147,7 +144,7 @@ private static Mono extract(AdminClient ac) { // choosing node from which we will get configs (starting with controller) var targetNodeId = Optional.ofNullable(desc.controller) .map(Node::id) - .orElse(desc.getNodes().iterator().next().id()); + .orElse(desc.nodes().iterator().next().id()); return loadBrokersConfig(ac, List.of(targetNodeId)) .map(map -> map.isEmpty() ? List.of() : map.get(targetNodeId)) .flatMap(configs -> { @@ -191,18 +188,18 @@ private static Mono isAuthorizedSecurityEnabled(AdminClient ac, @Nullab // (see MonoSink.success(..) javadoc for details) public static Mono toMono(KafkaFuture future) { return Mono.create(sink -> future.whenComplete((res, ex) -> { - if (ex != null) { - // KafkaFuture doc is unclear about what exception wrapper will be used - // (from docs it should be ExecutionException, be we actually see CompletionException, so checking both - if (ex instanceof CompletionException || ex instanceof ExecutionException) { - sink.error(ex.getCause()); //unwrapping exception - } else { - sink.error(ex); - } - } else { - sink.success(res); - } - })).doOnCancel(() -> future.cancel(true)) + if (ex != null) { + // KafkaFuture doc is unclear about what exception wrapper will be used + // (from docs it should be ExecutionException, be we actually see CompletionException, so checking both + if (ex instanceof CompletionException || ex instanceof ExecutionException) { + sink.error(ex.getCause()); //unwrapping exception + } else { + sink.error(ex); + } + } else { + sink.success(res); + } + })).doOnCancel(() -> future.cancel(true)) // AdminClient is using single thread for kafka communication // and by default all downstream operations (like map(..)) on created Mono will be executed on this thread. // If some of downstream operation are blocking (by mistake) this can lead to @@ -391,7 +388,7 @@ static Mono> toMonoWithExceptionFilter(Map> v public Mono>> describeLogDirs() { return describeCluster() - .map(d -> d.getNodes().stream().map(Node::id).collect(toList())) + .map(d -> d.nodes().stream().map(Node::id).collect(toList())) .flatMap(this::describeLogDirs); } @@ -419,12 +416,12 @@ private static Mono describeClusterImpl(AdminClient client, result.controller(), result.clusterId(), result.nodes(), result.authorizedOperations()); return toMono(allOfFuture).then( Mono.fromCallable(() -> - new ClusterDescription( - result.controller().get(), - result.clusterId().get(), - result.nodes().get(), - result.authorizedOperations().get() - ) + new ClusterDescription( + result.controller().get(), + result.clusterId().get(), + result.nodes().get(), + result.authorizedOperations().get() + ) ) ); } @@ -599,8 +596,8 @@ private Mono> filterPartitionsWithLeaderCheck(Collect @VisibleForTesting static Set filterPartitionsWithLeaderCheck(Collection topicDescriptions, - Predicate partitionPredicate, - boolean failOnUnknownLeader) { + Predicate partitionPredicate, + boolean failOnUnknownLeader) { var goodPartitions = new HashSet(); for (TopicDescription description : topicDescriptions) { var goodTopicPartitions = new ArrayList(); diff --git a/api/src/main/java/io/kafbat/ui/service/StatisticsService.java b/api/src/main/java/io/kafbat/ui/service/StatisticsService.java index 8adadf1ed..34ab47f92 100644 --- a/api/src/main/java/io/kafbat/ui/service/StatisticsService.java +++ b/api/src/main/java/io/kafbat/ui/service/StatisticsService.java @@ -37,10 +37,10 @@ public Mono updateCache(KafkaCluster c) { private Mono getStatistics(KafkaCluster cluster) { return adminClientService.get(cluster).flatMap(ac -> ac.describeCluster().flatMap(description -> - ac.updateInternalStats(description.getController()).then( + ac.updateInternalStats(description.controller()).then( Mono.zip( List.of( - metricsCollector.getBrokerMetrics(cluster, description.getNodes()), + metricsCollector.getBrokerMetrics(cluster, description.nodes()), getLogDirInfo(description, ac), featureService.getAvailableFeatures(ac, cluster, description), loadTopicConfigs(cluster), @@ -64,7 +64,7 @@ private Mono getStatistics(KafkaCluster cluster) { } private Mono getLogDirInfo(ClusterDescription desc, ReactiveAdminClient ac) { - var brokerIds = desc.getNodes().stream().map(Node::id).collect(Collectors.toSet()); + var brokerIds = desc.nodes().stream().map(Node::id).collect(Collectors.toSet()); return ac.describeLogDirs(brokerIds).map(InternalLogDirStats::new); } diff --git a/api/src/main/java/io/kafbat/ui/service/TopicsService.java b/api/src/main/java/io/kafbat/ui/service/TopicsService.java index 015a86838..483eb3c8f 100644 --- a/api/src/main/java/io/kafbat/ui/service/TopicsService.java +++ b/api/src/main/java/io/kafbat/ui/service/TopicsService.java @@ -253,7 +253,7 @@ public Mono changeReplicationFactor( Integer actual = topic.getReplicationFactor(); Integer requested = replicationFactorChange.getTotalReplicationFactor(); Integer brokersCount = statisticsCache.get(cluster).getClusterDescription() - .getNodes().size(); + .nodes().size(); if (requested.equals(actual)) { return Mono.error( @@ -361,14 +361,14 @@ private Map> getCurrentAssignment(InternalTopic topic) { .collect(toMap( InternalPartition::getPartition, p -> p.getReplicas().stream() - .map(InternalReplica::getBroker) + .map(InternalReplica::broker) .collect(toList()) )); } private Map getBrokersMap(KafkaCluster cluster, Map> currentAssignment) { - Map result = statisticsCache.get(cluster).getClusterDescription().getNodes() + Map result = statisticsCache.get(cluster).getClusterDescription().nodes() .stream() .map(Node::id) .collect(toMap( diff --git a/api/src/main/java/io/kafbat/ui/service/ksql/KsqlApiClient.java b/api/src/main/java/io/kafbat/ui/service/ksql/KsqlApiClient.java index 3a0b46c81..82862bfa8 100644 --- a/api/src/main/java/io/kafbat/ui/service/ksql/KsqlApiClient.java +++ b/api/src/main/java/io/kafbat/ui/service/ksql/KsqlApiClient.java @@ -59,10 +59,7 @@ public Optional getColumnValue(List row, String column) { } } - @Value - private static class KsqlRequest { - String ksql; - Map streamsProperties; + private record KsqlRequest(String ksql, Map streamsProperties) { } //-------------------------------------------------------------------------------------------- @@ -172,7 +169,7 @@ public Flux execute(String ksql, Map streamPr if (parsedStatements.isEmpty()) { return errorTableFlux("Sql statement is invalid or unsupported"); } - var statements = parsedStatements.get().getStatements(); + var statements = parsedStatements.get().statements(); if (statements.size() > 1) { return errorTableFlux("Only single statement supported now"); } diff --git a/api/src/main/java/io/kafbat/ui/service/ksql/KsqlGrammar.java b/api/src/main/java/io/kafbat/ui/service/ksql/KsqlGrammar.java index 3243841eb..2de91347b 100644 --- a/api/src/main/java/io/kafbat/ui/service/ksql/KsqlGrammar.java +++ b/api/src/main/java/io/kafbat/ui/service/ksql/KsqlGrammar.java @@ -6,7 +6,6 @@ import ksql.KsqlGrammarLexer; import ksql.KsqlGrammarParser; import lombok.RequiredArgsConstructor; -import lombok.Value; import lombok.experimental.Delegate; import org.antlr.v4.runtime.BaseErrorListener; import org.antlr.v4.runtime.CharStream; @@ -22,9 +21,7 @@ class KsqlGrammar { private KsqlGrammar() { } - @Value - static class KsqlStatements { - List statements; + record KsqlStatements(List statements) { } // returns Empty if no valid statements found diff --git a/api/src/main/java/io/kafbat/ui/service/ksql/KsqlServiceV2.java b/api/src/main/java/io/kafbat/ui/service/ksql/KsqlServiceV2.java index 62df65553..c5050d7e1 100644 --- a/api/src/main/java/io/kafbat/ui/service/ksql/KsqlServiceV2.java +++ b/api/src/main/java/io/kafbat/ui/service/ksql/KsqlServiceV2.java @@ -20,11 +20,7 @@ @Service public class KsqlServiceV2 { - @lombok.Value - private static class KsqlExecuteCommand { - KafkaCluster cluster; - String ksql; - Map streamProperties; + private record KsqlExecuteCommand(KafkaCluster cluster, String ksql, Map streamProperties) { } private final Cache registeredCommands = diff --git a/api/src/main/java/io/kafbat/ui/service/masking/DataMasking.java b/api/src/main/java/io/kafbat/ui/service/masking/DataMasking.java index 13cc6ed0f..803fed0b1 100644 --- a/api/src/main/java/io/kafbat/ui/service/masking/DataMasking.java +++ b/api/src/main/java/io/kafbat/ui/service/masking/DataMasking.java @@ -22,15 +22,7 @@ public class DataMasking { private static final JsonMapper JSON_MAPPER = new JsonMapper(); - @Value - static class Mask { - @Nullable - Pattern topicKeysPattern; - @Nullable - Pattern topicValuesPattern; - - MaskingPolicy policy; - + record Mask(@Nullable Pattern topicKeysPattern, @Nullable Pattern topicValuesPattern, MaskingPolicy policy) { boolean shouldBeApplied(String topic, Serde.Target target) { return target == Serde.Target.KEY ? topicKeysPattern != null && topicKeysPattern.matcher(topic).matches() diff --git a/api/src/main/java/io/kafbat/ui/service/metrics/RawMetric.java b/api/src/main/java/io/kafbat/ui/service/metrics/RawMetric.java index 80cc6073b..2a7589fb5 100644 --- a/api/src/main/java/io/kafbat/ui/service/metrics/RawMetric.java +++ b/api/src/main/java/io/kafbat/ui/service/metrics/RawMetric.java @@ -27,29 +27,7 @@ static RawMetric create(String name, Map labels, BigDecimal valu return new SimpleMetric(name, labels, value); } - @AllArgsConstructor - @EqualsAndHashCode - @ToString - class SimpleMetric implements RawMetric { - - private final String name; - private final Map labels; - private final BigDecimal value; - - @Override - public String name() { - return name; - } - - @Override - public Map labels() { - return labels; - } - - @Override - public BigDecimal value() { - return value; - } + record SimpleMetric(String name, Map labels, BigDecimal value) implements RawMetric { @Override public RawMetric copyWithValue(BigDecimal newValue) { diff --git a/api/src/main/java/io/kafbat/ui/util/jsonschema/AvroJsonSchemaConverter.java b/api/src/main/java/io/kafbat/ui/util/jsonschema/AvroJsonSchemaConverter.java index 55c75c950..6e9a75a49 100644 --- a/api/src/main/java/io/kafbat/ui/util/jsonschema/AvroJsonSchemaConverter.java +++ b/api/src/main/java/io/kafbat/ui/util/jsonschema/AvroJsonSchemaConverter.java @@ -27,8 +27,8 @@ public JsonSchema convert(URI basePath, Schema schema) { if (type.getType().equals(JsonType.Type.OBJECT)) { final ObjectFieldSchema objectRoot = (ObjectFieldSchema) root; - builder.properties(objectRoot.getProperties()); - builder.required(objectRoot.getRequired()); + builder.properties(objectRoot.properties()); + builder.required(objectRoot.required()); } return builder.build(); diff --git a/api/src/main/java/io/kafbat/ui/util/jsonschema/ObjectFieldSchema.java b/api/src/main/java/io/kafbat/ui/util/jsonschema/ObjectFieldSchema.java index 4910c508e..4dc57552e 100644 --- a/api/src/main/java/io/kafbat/ui/util/jsonschema/ObjectFieldSchema.java +++ b/api/src/main/java/io/kafbat/ui/util/jsonschema/ObjectFieldSchema.java @@ -9,27 +9,10 @@ import reactor.util.function.Tuple2; import reactor.util.function.Tuples; -class ObjectFieldSchema implements FieldSchema { +record ObjectFieldSchema(Map properties, List required) implements FieldSchema { static final ObjectFieldSchema EMPTY = new ObjectFieldSchema(Map.of(), List.of()); - private final Map properties; - private final List required; - - ObjectFieldSchema(Map properties, - List required) { - this.properties = properties; - this.required = required; - } - - Map getProperties() { - return properties; - } - - List getRequired() { - return required; - } - @Override public JsonNode toJsonNode(ObjectMapper mapper) { final Map nodes = properties.entrySet().stream() diff --git a/api/src/main/java/io/kafbat/ui/util/jsonschema/ProtobufSchemaConverter.java b/api/src/main/java/io/kafbat/ui/util/jsonschema/ProtobufSchemaConverter.java index 8b391aa9b..4591c3461 100644 --- a/api/src/main/java/io/kafbat/ui/util/jsonschema/ProtobufSchemaConverter.java +++ b/api/src/main/java/io/kafbat/ui/util/jsonschema/ProtobufSchemaConverter.java @@ -59,7 +59,7 @@ public JsonSchema convert(URI basePath, Descriptors.Descriptor schema) { return JsonSchema.builder() .id(basePath.resolve(schema.getFullName())) .type(new SimpleJsonType(JsonType.Type.OBJECT)) - .rootRef(rootRef.getRef()) + .rootRef(rootRef.ref()) .definitions(definitions) .build(); } diff --git a/api/src/main/java/io/kafbat/ui/util/jsonschema/RefFieldSchema.java b/api/src/main/java/io/kafbat/ui/util/jsonschema/RefFieldSchema.java index fad5a351d..e418791f6 100644 --- a/api/src/main/java/io/kafbat/ui/util/jsonschema/RefFieldSchema.java +++ b/api/src/main/java/io/kafbat/ui/util/jsonschema/RefFieldSchema.java @@ -4,19 +4,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.TextNode; -class RefFieldSchema implements FieldSchema { - private final String ref; - - RefFieldSchema(String ref) { - this.ref = ref; - } +record RefFieldSchema(String ref) implements FieldSchema { @Override public JsonNode toJsonNode(ObjectMapper mapper) { return mapper.createObjectNode().set("$ref", new TextNode(ref)); } - - String getRef() { - return ref; - } } diff --git a/api/src/test/java/io/kafbat/ui/serdes/builtin/AvroEmbeddedSerdeTest.java b/api/src/test/java/io/kafbat/ui/serdes/builtin/AvroEmbeddedSerdeTest.java index 09184d100..60f04a4f1 100644 --- a/api/src/test/java/io/kafbat/ui/serdes/builtin/AvroEmbeddedSerdeTest.java +++ b/api/src/test/java/io/kafbat/ui/serdes/builtin/AvroEmbeddedSerdeTest.java @@ -69,9 +69,9 @@ void deserializerParsesAvroDataWithEmbeddedSchema() throws Exception { var deserializer = avroEmbeddedSerde.deserializer("anyTopic", Serde.Target.KEY); DeserializeResult result = deserializer.deserialize(null, serializedRecordBytes); - assertThat(result.getType()).isEqualTo(DeserializeResult.Type.JSON); - assertThat(result.getAdditionalProperties()).isEmpty(); - assertJsonEquals(jsonRecord, result.getResult()); + assertThat(result.type()).isEqualTo(DeserializeResult.Type.JSON); + assertThat(result.additionalProperties()).isEmpty(); + assertJsonEquals(jsonRecord, result.result()); } private void assertJsonEquals(String expected, String actual) throws IOException { diff --git a/api/src/test/java/io/kafbat/ui/serdes/builtin/Base64SerdeTest.java b/api/src/test/java/io/kafbat/ui/serdes/builtin/Base64SerdeTest.java index 8916ddd6c..3d5ce61c6 100644 --- a/api/src/test/java/io/kafbat/ui/serdes/builtin/Base64SerdeTest.java +++ b/api/src/test/java/io/kafbat/ui/serdes/builtin/Base64SerdeTest.java @@ -41,9 +41,9 @@ void serializesInputAsBase64String(Serde.Target type) { void deserializesDataAsBase64Bytes(Serde.Target type) { var deserializer = base64Serde.deserializer("anyTopic", type); var result = deserializer.deserialize(new RecordHeadersImpl(), TEST_BYTES); - assertThat(result.getResult()).isEqualTo(TEST_BYTES_BASE64_ENCODED); - assertThat(result.getType()).isEqualTo(DeserializeResult.Type.STRING); - assertThat(result.getAdditionalProperties()).isEmpty(); + assertThat(result.result()).isEqualTo(TEST_BYTES_BASE64_ENCODED); + assertThat(result.type()).isEqualTo(DeserializeResult.Type.STRING); + assertThat(result.additionalProperties()).isEmpty(); } @ParameterizedTest diff --git a/api/src/test/java/io/kafbat/ui/serdes/builtin/ConsumerOffsetsSerdeTest.java b/api/src/test/java/io/kafbat/ui/serdes/builtin/ConsumerOffsetsSerdeTest.java index c737b3ef7..7219350fe 100644 --- a/api/src/test/java/io/kafbat/ui/serdes/builtin/ConsumerOffsetsSerdeTest.java +++ b/api/src/test/java/io/kafbat/ui/serdes/builtin/ConsumerOffsetsSerdeTest.java @@ -170,7 +170,7 @@ private boolean isGroupMetadataMessage(DeserializeResult key, DeserializeResult @SneakyThrows @SuppressWarnings("unchecked") private Map toMapFromJsom(DeserializeResult result) { - return new JsonMapper().readValue(result.getResult(), Map.class); + return new JsonMapper().readValue(result.result(), Map.class); } private static KafkaConsumer createConsumer(String groupId) { diff --git a/api/src/test/java/io/kafbat/ui/serdes/builtin/HexSerdeTest.java b/api/src/test/java/io/kafbat/ui/serdes/builtin/HexSerdeTest.java index a13690c1e..9c3195272 100644 --- a/api/src/test/java/io/kafbat/ui/serdes/builtin/HexSerdeTest.java +++ b/api/src/test/java/io/kafbat/ui/serdes/builtin/HexSerdeTest.java @@ -55,9 +55,9 @@ void serializesEmptyStringAsEmptyBytesArray(Serde.Target type) { void deserializesDataAsHexBytes(Serde.Target type) { var deserializer = hexSerde.deserializer("anyTopic", type); var result = deserializer.deserialize(new RecordHeadersImpl(), TEST_BYTES); - assertThat(result.getResult()).isEqualTo(TEST_BYTES_HEX_ENCODED); - assertThat(result.getType()).isEqualTo(DeserializeResult.Type.STRING); - assertThat(result.getAdditionalProperties()).isEmpty(); + assertThat(result.result()).isEqualTo(TEST_BYTES_HEX_ENCODED); + assertThat(result.type()).isEqualTo(DeserializeResult.Type.STRING); + assertThat(result.additionalProperties()).isEmpty(); } @ParameterizedTest diff --git a/api/src/test/java/io/kafbat/ui/serdes/builtin/Int32SerdeTest.java b/api/src/test/java/io/kafbat/ui/serdes/builtin/Int32SerdeTest.java index c03dcbdcf..20403d5c3 100644 --- a/api/src/test/java/io/kafbat/ui/serdes/builtin/Int32SerdeTest.java +++ b/api/src/test/java/io/kafbat/ui/serdes/builtin/Int32SerdeTest.java @@ -38,8 +38,8 @@ void serializeUses4BytesIntRepresentation(Serde.Target type) { void deserializeUses4BytesIntRepresentation(Serde.Target type) { var deserializer = serde.deserializer("anyTopic", type); var result = deserializer.deserialize(new RecordHeadersImpl(), Ints.toByteArray(1234)); - assertThat(result.getResult()).isEqualTo("1234"); - assertThat(result.getType()).isEqualTo(DeserializeResult.Type.JSON); + assertThat(result.result()).isEqualTo("1234"); + assertThat(result.type()).isEqualTo(DeserializeResult.Type.JSON); } } diff --git a/api/src/test/java/io/kafbat/ui/serdes/builtin/Int64SerdeTest.java b/api/src/test/java/io/kafbat/ui/serdes/builtin/Int64SerdeTest.java index b8f74f92b..e59076e74 100644 --- a/api/src/test/java/io/kafbat/ui/serdes/builtin/Int64SerdeTest.java +++ b/api/src/test/java/io/kafbat/ui/serdes/builtin/Int64SerdeTest.java @@ -39,8 +39,8 @@ void serializeUses8BytesLongRepresentation(Serde.Target type) { void deserializeUses8BytesLongRepresentation(Serde.Target type) { var deserializer = serde.deserializer("anyTopic", type); var result = deserializer.deserialize(new RecordHeadersImpl(), Longs.toByteArray(1234)); - assertThat(result.getResult()).isEqualTo("1234"); - assertThat(result.getType()).isEqualTo(DeserializeResult.Type.JSON); + assertThat(result.result()).isEqualTo("1234"); + assertThat(result.type()).isEqualTo(DeserializeResult.Type.JSON); } } diff --git a/api/src/test/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerdeTest.java b/api/src/test/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerdeTest.java index 069f9ed45..10f396e12 100644 --- a/api/src/test/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerdeTest.java +++ b/api/src/test/java/io/kafbat/ui/serdes/builtin/ProtobufFileSerdeTest.java @@ -290,15 +290,15 @@ void deserializeUsesTopicsMappingToFindMsgDescriptor() { var deserializedPerson = serde.deserializer("persons", Serde.Target.VALUE) .deserialize(null, personMessageBytes); - assertJsonEquals(samplePersonMsgJson, deserializedPerson.getResult()); + assertJsonEquals(samplePersonMsgJson, deserializedPerson.result()); var deserializedBook = serde.deserializer("books", Serde.Target.KEY) .deserialize(null, addressBookMessageBytes); - assertJsonEquals(sampleBookMsgJson, deserializedBook.getResult()); + assertJsonEquals(sampleBookMsgJson, deserializedBook.result()); var deserializedSensor = serde.deserializer("langs", Serde.Target.VALUE) .deserialize(null, langDescriptionMessageBytes); - assertJsonEquals(sampleLangDescriptionMsgJson, deserializedSensor.getResult()); + assertJsonEquals(sampleLangDescriptionMsgJson, deserializedSensor.result()); } @Test @@ -316,11 +316,11 @@ void deserializeUsesDefaultDescriptorIfTopicMappingNotFound() { var deserializedPerson = serde.deserializer("persons", Serde.Target.VALUE) .deserialize(null, personMessageBytes); - assertJsonEquals(samplePersonMsgJson, deserializedPerson.getResult()); + assertJsonEquals(samplePersonMsgJson, deserializedPerson.result()); var deserializedBook = serde.deserializer("books", Serde.Target.KEY) .deserialize(null, addressBookMessageBytes); - assertJsonEquals(sampleBookMsgJson, deserializedBook.getResult()); + assertJsonEquals(sampleBookMsgJson, deserializedBook.result()); } @Test diff --git a/api/src/test/java/io/kafbat/ui/serdes/builtin/ProtobufRawSerdeTest.java b/api/src/test/java/io/kafbat/ui/serdes/builtin/ProtobufRawSerdeTest.java index ba88b2d37..27e2d7116 100644 --- a/api/src/test/java/io/kafbat/ui/serdes/builtin/ProtobufRawSerdeTest.java +++ b/api/src/test/java/io/kafbat/ui/serdes/builtin/ProtobufRawSerdeTest.java @@ -45,14 +45,14 @@ private byte[] getProtobufMessage() { void deserializeSimpleMessage() { var deserialized = serde.deserializer(DUMMY_TOPIC, Serde.Target.VALUE) .deserialize(null, getProtobufMessage()); - assertThat(deserialized.getResult()).isEqualTo("1: 5\n"); + assertThat(deserialized.result()).isEqualTo("1: 5\n"); } @Test void deserializeEmptyMessage() { var deserialized = serde.deserializer(DUMMY_TOPIC, Serde.Target.VALUE) .deserialize(null, new byte[0]); - assertThat(deserialized.getResult()).isEqualTo(""); + assertThat(deserialized.result()).isEqualTo(""); } @Test @@ -101,6 +101,6 @@ private byte[] getComplexProtobufMessage() { void deserializeNestedMessage() { var deserialized = serde.deserializer(DUMMY_TOPIC, Serde.Target.VALUE) .deserialize(null, getComplexProtobufMessage()); - assertThat(deserialized.getResult()).isEqualTo("1: 5\n2: {\n 1: 10\n}\n"); + assertThat(deserialized.result()).isEqualTo("1: 5\n2: {\n 1: 10\n}\n"); } } diff --git a/api/src/test/java/io/kafbat/ui/serdes/builtin/UInt32SerdeTest.java b/api/src/test/java/io/kafbat/ui/serdes/builtin/UInt32SerdeTest.java index 60535c395..3490bec07 100644 --- a/api/src/test/java/io/kafbat/ui/serdes/builtin/UInt32SerdeTest.java +++ b/api/src/test/java/io/kafbat/ui/serdes/builtin/UInt32SerdeTest.java @@ -51,8 +51,8 @@ void deserializeUses4BytesUInt32Representation(Serde.Target type) { var deserializer = serde.deserializer("anyTopic", type); byte[] uint32Bytes = Ints.toByteArray(UnsignedInteger.MAX_VALUE.intValue()); var result = deserializer.deserialize(new RecordHeadersImpl(), uint32Bytes); - assertThat(result.getResult()).isEqualTo(UnsignedInteger.MAX_VALUE.toString()); - assertThat(result.getType()).isEqualTo(DeserializeResult.Type.JSON); + assertThat(result.result()).isEqualTo(UnsignedInteger.MAX_VALUE.toString()); + assertThat(result.type()).isEqualTo(DeserializeResult.Type.JSON); } } diff --git a/api/src/test/java/io/kafbat/ui/serdes/builtin/UInt64SerdeTest.java b/api/src/test/java/io/kafbat/ui/serdes/builtin/UInt64SerdeTest.java index 8af8866eb..f946e00a0 100644 --- a/api/src/test/java/io/kafbat/ui/serdes/builtin/UInt64SerdeTest.java +++ b/api/src/test/java/io/kafbat/ui/serdes/builtin/UInt64SerdeTest.java @@ -51,8 +51,8 @@ void deserializeUses8BytesUIn64tRepresentation(Serde.Target type) { var deserializer = serde.deserializer("anyTopic", type); byte[] uint64Bytes = Longs.toByteArray(UnsignedLong.MAX_VALUE.longValue()); var result = deserializer.deserialize(new RecordHeadersImpl(), uint64Bytes); - assertThat(result.getResult()).isEqualTo(UnsignedLong.MAX_VALUE.toString()); - assertThat(result.getType()).isEqualTo(DeserializeResult.Type.JSON); + assertThat(result.result()).isEqualTo(UnsignedLong.MAX_VALUE.toString()); + assertThat(result.type()).isEqualTo(DeserializeResult.Type.JSON); } } diff --git a/api/src/test/java/io/kafbat/ui/serdes/builtin/UuidBinarySerdeTest.java b/api/src/test/java/io/kafbat/ui/serdes/builtin/UuidBinarySerdeTest.java index 39ceaac55..59eff291a 100644 --- a/api/src/test/java/io/kafbat/ui/serdes/builtin/UuidBinarySerdeTest.java +++ b/api/src/test/java/io/kafbat/ui/serdes/builtin/UuidBinarySerdeTest.java @@ -51,9 +51,9 @@ void deserializerUses16bytesUuidBinaryRepresentation(Serde.Target type) { bb.putLong(uuid.getLeastSignificantBits()); var result = serde.deserializer("anyTopic", type).deserialize(new RecordHeadersImpl(), bb.array()); - assertThat(result.getType()).isEqualTo(DeserializeResult.Type.STRING); - assertThat(result.getAdditionalProperties()).isEmpty(); - assertThat(result.getResult()).isEqualTo(uuid.toString()); + assertThat(result.type()).isEqualTo(DeserializeResult.Type.STRING); + assertThat(result.additionalProperties()).isEmpty(); + assertThat(result.result()).isEqualTo(uuid.toString()); } } @@ -92,9 +92,9 @@ void deserializerUses16bytesUuidBinaryRepresentation(Serde.Target type) { bb.putLong(uuid.getMostSignificantBits()); var result = serde.deserializer("anyTopic", type).deserialize(new RecordHeadersImpl(), bb.array()); - assertThat(result.getType()).isEqualTo(DeserializeResult.Type.STRING); - assertThat(result.getAdditionalProperties()).isEmpty(); - assertThat(result.getResult()).isEqualTo(uuid.toString()); + assertThat(result.type()).isEqualTo(DeserializeResult.Type.STRING); + assertThat(result.additionalProperties()).isEmpty(); + assertThat(result.result()).isEqualTo(uuid.toString()); } } diff --git a/api/src/test/java/io/kafbat/ui/serdes/builtin/sr/SchemaRegistrySerdeTest.java b/api/src/test/java/io/kafbat/ui/serdes/builtin/sr/SchemaRegistrySerdeTest.java index d66a8d004..29ee9afef 100644 --- a/api/src/test/java/io/kafbat/ui/serdes/builtin/sr/SchemaRegistrySerdeTest.java +++ b/api/src/test/java/io/kafbat/ui/serdes/builtin/sr/SchemaRegistrySerdeTest.java @@ -52,10 +52,10 @@ void returnsSchemaDescriptionIfSchemaRegisteredInSR(String topic, String subject assertThat(schemaOptional).isPresent(); SchemaDescription schemaDescription = schemaOptional.get(); - assertThat(schemaDescription.getSchema()) + assertThat(schemaDescription.schema()) .contains( "{\"$id\":\"int\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"type\":\"integer\"}"); - assertThat(schemaDescription.getAdditionalProperties()) + assertThat(schemaDescription.additionalProperties()) .containsOnlyKeys("subject", "schemaId", "latestVersion", "type") .containsEntry("subject", subject) .containsEntry("schemaId", schemaId) @@ -123,9 +123,9 @@ void deserializeReturnsJsonAvroMsgJsonRepresentation() throws RestClientExceptio byte[] data = toBytesWithMagicByteAndSchemaId(schemaId, jsonValue, schema); var result = serde.deserializer(topic, Serde.Target.VALUE).deserialize(null, data); - assertJsonsEqual(jsonValue, result.getResult()); - assertThat(result.getType()).isEqualTo(DeserializeResult.Type.JSON); - assertThat(result.getAdditionalProperties()) + assertJsonsEqual(jsonValue, result.result()); + assertThat(result.type()).isEqualTo(DeserializeResult.Type.JSON); + assertThat(result.additionalProperties()) .contains(Map.entry("type", "AVRO")) .contains(Map.entry("schemaId", schemaId)); } @@ -378,7 +378,7 @@ void assertSerdeCycle(String topic, String jsonInput) { byte[] serializedBytes = serde.serializer(topic, Serde.Target.VALUE).serialize(jsonInput); var deserializedJson = serde.deserializer(topic, Serde.Target.VALUE) .deserialize(null, serializedBytes) - .getResult(); + .result(); assertJsonsEqual(jsonInput, deserializedJson); } diff --git a/api/src/test/java/io/kafbat/ui/service/RecordEmitterTest.java b/api/src/test/java/io/kafbat/ui/service/RecordEmitterTest.java index 65bf1f49d..3bda6820b 100644 --- a/api/src/test/java/io/kafbat/ui/service/RecordEmitterTest.java +++ b/api/src/test/java/io/kafbat/ui/service/RecordEmitterTest.java @@ -174,7 +174,7 @@ void pollFullTopicFromBeginning() { CURSOR_MOCK ); - List expectedValues = SENT_RECORDS.stream().map(Record::getValue).collect(Collectors.toList()); + List expectedValues = SENT_RECORDS.stream().map(Record::value).collect(Collectors.toList()); expectEmitter(forwardEmitter, expectedValues); expectEmitter(backwardEmitter, expectedValues); @@ -211,15 +211,15 @@ void pollWithOffsets() { ); var expectedValues = SENT_RECORDS.stream() - .filter(r -> r.getOffset() >= targetOffsets.get(r.getTp())) - .map(Record::getValue) + .filter(r -> r.offset() >= targetOffsets.get(r.tp())) + .map(Record::value) .collect(Collectors.toList()); expectEmitter(forwardEmitter, expectedValues); expectedValues = SENT_RECORDS.stream() - .filter(r -> r.getOffset() < targetOffsets.get(r.getTp())) - .map(Record::getValue) + .filter(r -> r.offset() < targetOffsets.get(r.tp())) + .map(Record::value) .collect(Collectors.toList()); expectEmitter(backwardEmitter, expectedValues); @@ -227,7 +227,7 @@ void pollWithOffsets() { @Test void pollWithTimestamps() { - var tsStats = SENT_RECORDS.stream().mapToLong(Record::getTimestamp).summaryStatistics(); + var tsStats = SENT_RECORDS.stream().mapToLong(Record::timestamp).summaryStatistics(); //choosing ts in the middle long targetTimestamp = tsStats.getMin() + ((tsStats.getMax() - tsStats.getMin()) / 2); @@ -244,8 +244,8 @@ void pollWithTimestamps() { expectEmitter( forwardEmitter, SENT_RECORDS.stream() - .filter(r -> r.getTimestamp() >= targetTimestamp) - .map(Record::getValue) + .filter(r -> r.timestamp() >= targetTimestamp) + .map(Record::value) .collect(Collectors.toList()) ); @@ -262,8 +262,8 @@ void pollWithTimestamps() { expectEmitter( backwardEmitter, SENT_RECORDS.stream() - .filter(r -> r.getTimestamp() < targetTimestamp) - .map(Record::getValue) + .filter(r -> r.timestamp() < targetTimestamp) + .map(Record::value) .collect(Collectors.toList()) ); } @@ -288,9 +288,9 @@ void backwardEmitterSeekToEnd() { ); var expectedValues = SENT_RECORDS.stream() - .filter(r -> r.getOffset() < targetOffsets.get(r.getTp())) - .filter(r -> r.getOffset() >= (targetOffsets.get(r.getTp()) - (numMessages / PARTITIONS))) - .map(Record::getValue) + .filter(r -> r.offset() < targetOffsets.get(r.tp())) + .filter(r -> r.offset() >= (targetOffsets.get(r.tp()) - (numMessages / PARTITIONS))) + .map(Record::value) .collect(Collectors.toList()); assertThat(expectedValues).size().isEqualTo(numMessages); @@ -369,10 +369,6 @@ private EnhancedConsumer createConsumer(Map properties) { } @Value - static class Record { - String value; - TopicPartition tp; - long offset; - long timestamp; + record Record(String value, TopicPartition tp, long offset, long timestamp) { } } diff --git a/serde-api/src/main/java/io/kafbat/ui/serde/api/DeserializeResult.java b/serde-api/src/main/java/io/kafbat/ui/serde/api/DeserializeResult.java index 402690914..a90d9f2a2 100644 --- a/serde-api/src/main/java/io/kafbat/ui/serde/api/DeserializeResult.java +++ b/serde-api/src/main/java/io/kafbat/ui/serde/api/DeserializeResult.java @@ -6,21 +6,19 @@ /** * Result of {@code Deserializer} work. + * + * @param result nullable */ -public final class DeserializeResult { +public record DeserializeResult(String result, io.kafbat.ui.serde.api.DeserializeResult.Type type, + Map additionalProperties) { public enum Type { STRING, JSON } - // nullable - private final String result; - private final Type type; - private final Map additionalProperties; - /** - * @param result string representation of deserialized binary data - * @param type type of string - can it be converted to json or not + * @param result string representation of deserialized binary data + * @param type type of string - can it be converted to json or not * @param additionalProperties additional information about deserialized value (will be shown in UI) */ public DeserializeResult(String result, Type type, Map additionalProperties) { @@ -32,7 +30,8 @@ public DeserializeResult(String result, Type type, Map additiona /** * @return string representation of deserialized binary data, can be null */ - public String getResult() { + @Override + public String result() { return result; } @@ -41,7 +40,8 @@ public String getResult() { * Will be show as json dictionary in UI (serialized with Jackson object mapper). * It is recommended to use primitive types and strings for values. */ - public Map getAdditionalProperties() { + @Override + public Map additionalProperties() { return additionalProperties; } @@ -49,7 +49,8 @@ public Map getAdditionalProperties() { * @return type of deserialized result. Will be used as hint for some internal logic * (ex. if type==STRING smart filters won't try to parse it as json for further usage) */ - public Type getType() { + @Override + public Type type() { return type; } @@ -67,11 +68,6 @@ public boolean equals(Object o) { && additionalProperties.equals(that.additionalProperties); } - @Override - public int hashCode() { - return Objects.hash(result, type, additionalProperties); - } - @Override public String toString() { return "DeserializeResult{" diff --git a/serde-api/src/main/java/io/kafbat/ui/serde/api/SchemaDescription.java b/serde-api/src/main/java/io/kafbat/ui/serde/api/SchemaDescription.java index 60e60a966..98beace13 100644 --- a/serde-api/src/main/java/io/kafbat/ui/serde/api/SchemaDescription.java +++ b/serde-api/src/main/java/io/kafbat/ui/serde/api/SchemaDescription.java @@ -5,33 +5,29 @@ /** * Description of topic's key/value schema. */ -public final class SchemaDescription { - - private final String schema; - private final Map additionalProperties; +public record SchemaDescription(String schema, Map additionalProperties) { /** - * - * @param schema schema descriptions. - * If contains json-schema (preferred) UI will use it for validation and sample data generation. + * @param schema schema descriptions. + * If contains json-schema (preferred) UI will use it for validation and sample data generation. * @param additionalProperties additional properties about schema (may be rendered in UI in the future) */ - public SchemaDescription(String schema, Map additionalProperties) { - this.schema = schema; - this.additionalProperties = additionalProperties; + public SchemaDescription { } /** * @return schema description text. Preferably contains json-schema. Can be null. */ - public String getSchema() { + @Override + public String schema() { return schema; } /** * @return additional properties about schema */ - public Map getAdditionalProperties() { + @Override + public Map additionalProperties() { return additionalProperties; } }