iliax 2 년 전
부모
커밋
d8f11afd8b

+ 1 - 1
kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/MessagesService.java

@@ -149,7 +149,7 @@ public class MessagesService {
     }
   }
 
-  public KafkaProducer<byte[], byte[]> createProducer(KafkaCluster cluster, Map<String, Object> additionalProps) {
+  public static KafkaProducer<byte[], byte[]> createProducer(KafkaCluster cluster, Map<String, Object> additionalProps) {
     Properties properties = new Properties();
     SslPropertiesUtil.addKafkaSslProperties(cluster.getOriginalProperties().getSsl(), properties);
     properties.putAll(cluster.getProperties());

+ 12 - 10
kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/audit/AuditService.java

@@ -35,24 +35,25 @@ public class AuditService implements Closeable {
   private final Map<String, AuditWriter> auditWriters = new ConcurrentHashMap<>();
 
   public AuditService(ClustersProperties clustersProperties,
-                      MessagesService messagesService,
                       AdminClientService adminClientService,
                       ClustersStorage clustersStorage) {
     if (clustersProperties.getClusters() != null) {
       for (var clusterProps : clustersProperties.getClusters()) {
         var cluster = clustersStorage.getClusterByName(clusterProps.getName()).orElseThrow();
-        initialize(
-            cluster,
-            adminClientService.get(cluster).block(),
-            messagesService
-        );
+        ReactiveAdminClient adminClient = null;
+        try {
+          adminClient = adminClientService.get(cluster).block();
+        } catch (Exception e) {
+          printAuditInitError(cluster, "Error connect to cluster", e);
+          continue;
+        }
+        initialize(cluster, adminClient);
       }
     }
   }
 
   private void initialize(KafkaCluster cluster,
-                          ReactiveAdminClient ac,
-                          MessagesService messagesService) {
+                          ReactiveAdminClient ac) {
     var auditProps = cluster.getOriginalProperties().getAudit();
     if (auditProps == null) {
       return;
@@ -63,11 +64,12 @@ public class AuditService implements Closeable {
       return;
     }
     String auditTopicName = Optional.ofNullable(auditProps.getTopic()).orElse(DEFAULT_AUDIT_TOPIC_NAME);
-    KafkaProducer<byte[], byte[]> producer = null;
+    @Nullable KafkaProducer<byte[], byte[]> producer = null;
     if (topicAudit && createTopicIfNeeded(cluster, ac, auditTopicName, auditProps)) {
-      producer = messagesService.createProducer(cluster, Map.of());
+      producer = MessagesService.createProducer(cluster, Map.of());
     }
     auditWriters.put(cluster.getName(), new AuditWriter(auditTopicName, producer, consoleAudit));
+    log.info("Audit service initialized for cluster '{}'", cluster.getName());
   }
 
   /**

+ 1 - 0
kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/audit/AuditWriter.java

@@ -97,6 +97,7 @@ record AuditWriter(String targetTopic,
                      OperationResult result,
                      @Nullable Object params) {
 
+    //TODO: do not render null
     static final JsonMapper MAPPER = new JsonMapper();
 
     @SneakyThrows