Browse Source

Fixed some problems

Roman Nedzvetskiy 5 years ago
parent
commit
d98179fa28

+ 1 - 2
kafka-ui-api/src/main/java/com/provectus/kafka/ui/cluster/service/ClusterService.java

@@ -159,7 +159,6 @@ public class ClusterService {
 
 
     public Mono<Map<String, BigDecimal>> getOffsets(String clusterName) {
     public Mono<Map<String, BigDecimal>> getOffsets(String clusterName) {
         return clustersStorage.getClusterByName(clusterName)
         return clustersStorage.getClusterByName(clusterName)
-                .map(c -> kafkaService.getOrCreateAdminClient(c)
-                        .flatMap(a -> kafkaService.getOffsets(a.getAdminClient(), c))).orElseThrow();
+                .map(c -> kafkaService.getOffsets( c))).orElseThrow();
     }
     }
 }
 }

+ 6 - 3
kafka-ui-api/src/main/java/com/provectus/kafka/ui/kafka/KafkaService.java

@@ -352,8 +352,9 @@ public class KafkaService {
             );
             );
     }
     }
 
 
-    public Mono<Map<String, BigDecimal>> getOffsets (AdminClient ac, KafkaCluster c) {
-        return getTopicPartitionList(ac)
+    public Mono<Map<String, BigDecimal>> getOffsets (KafkaCluster c) {
+        return getOrCreateAdminClient(c).flatMap(ac ->
+                getTopicPartitionList(ac.getAdminClient())
                 .map(s -> {
                 .map(s -> {
                     var tps = s.stream()
                     var tps = s.stream()
                             .map(tp ->
                             .map(tp ->
@@ -366,7 +367,7 @@ public class KafkaService {
                             .stream().flatMap(List::stream).collect(Collectors.toList())
                             .stream().flatMap(List::stream).collect(Collectors.toList())
                             .stream().flatMap(List::stream).collect(Collectors.toList());
                             .stream().flatMap(List::stream).collect(Collectors.toList());
                     return getTopicPartitionOffset(c, tps);
                     return getTopicPartitionOffset(c, tps);
-                });
+                }));
     }
     }
 
 
     private Mono<List<Map<String, List<Integer>>>> getTopicPartitionList(AdminClient ac) {
     private Mono<List<Map<String, List<Integer>>>> getTopicPartitionList(AdminClient ac) {
@@ -386,6 +387,8 @@ public class KafkaService {
             offset.putAll(ClusterUtil.toSingleMap(consumer.endOffsets(topicPartitions).entrySet().stream()
             offset.putAll(ClusterUtil.toSingleMap(consumer.endOffsets(topicPartitions).entrySet().stream()
                     .map(e -> Map.of(e.getKey().topic() + '-' + e.getKey().partition() + '-' + "min", new BigDecimal(e.getValue())))));
                     .map(e -> Map.of(e.getKey().topic() + '-' + e.getKey().partition() + '-' + "min", new BigDecimal(e.getValue())))));
             return offset;
             return offset;
+        } catch (Exception e) {
+            return Collections.emptyMap();
         }
         }
     }
     }
 }
 }