瀏覽代碼

Add a failover recovery for empty cluster versions (#2473)

* Add a failover recovery for empty cluster versions

* Review suggestions
Roman Zabaluev 2 年之前
父節點
當前提交
9e1f8d773f

+ 9 - 4
kafka-ui-api/src/main/java/com/provectus/kafka/ui/service/ReactiveAdminClient.java

@@ -90,10 +90,15 @@ public class ReactiveAdminClient implements Closeable {
   }
 
   private static SupportedFeature getSupportedUpdateFeatureForVersion(String versionStr) {
-    float version = NumberUtil.parserClusterVersion(versionStr);
-    return version <= 2.3f
-        ? SupportedFeature.ALTER_CONFIGS
-        : SupportedFeature.INCREMENTAL_ALTER_CONFIGS;
+    try {
+      float version = NumberUtil.parserClusterVersion(versionStr);
+      return version <= 2.3f
+          ? SupportedFeature.ALTER_CONFIGS
+          : SupportedFeature.INCREMENTAL_ALTER_CONFIGS;
+    } catch (NumberFormatException e) {
+      log.info("Assuming non-incremental alter configs due to version parsing error");
+      return SupportedFeature.ALTER_CONFIGS;
+    }
   }
 
   //TODO: discuss - maybe we should map kafka-library's exceptions to our exceptions here

+ 3 - 2
kafka-ui-api/src/main/java/com/provectus/kafka/ui/util/NumberUtil.java

@@ -13,7 +13,8 @@ public class NumberUtil {
     return value != null && NumberUtils.isCreatable(value.toString());
   }
 
-  public static float parserClusterVersion(String version) {
+  public static float parserClusterVersion(String version) throws NumberFormatException {
+    log.trace("Parsing cluster version [{}]", version);
     try {
       final String[] parts = version.split("\\.");
       if (parts.length > 2) {
@@ -21,7 +22,7 @@ public class NumberUtil {
       }
       return Float.parseFloat(version.split("-")[0]);
     } catch (Exception e) {
-      log.error("Conversion clusterVersion {} to float value failed", version);
+      log.error("Conversion clusterVersion [{}] to float value failed", version, e);
       throw e;
     }
   }