From e98b106cb1220d92f99307992934a7adab3d5c22 Mon Sep 17 00:00:00 2001 From: Jingliu Xiong Date: Mon, 18 Sep 2023 15:48:39 +0800 Subject: [PATCH] feature: hippo4j config model in zookeeper config before check (#1457) --- .../api/BootstrapPropertiesInterface.java | 7 +++++ .../core/enable/BeforeCheckConfiguration.java | 29 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/kernel/dynamic/api/src/main/java/cn/hippo4j/threadpool/dynamic/api/BootstrapPropertiesInterface.java b/kernel/dynamic/api/src/main/java/cn/hippo4j/threadpool/dynamic/api/BootstrapPropertiesInterface.java index 110c3f5e..ab743fd2 100644 --- a/kernel/dynamic/api/src/main/java/cn/hippo4j/threadpool/dynamic/api/BootstrapPropertiesInterface.java +++ b/kernel/dynamic/api/src/main/java/cn/hippo4j/threadpool/dynamic/api/BootstrapPropertiesInterface.java @@ -94,4 +94,11 @@ public interface BootstrapPropertiesInterface { return null; } + /** + * Get Zookeeper. + */ + default Map getZookeeper() { + return null; + } + } diff --git a/threadpool/core/src/main/java/cn/hippo4j/core/enable/BeforeCheckConfiguration.java b/threadpool/core/src/main/java/cn/hippo4j/core/enable/BeforeCheckConfiguration.java index e1f6fed1..5265faf6 100644 --- a/threadpool/core/src/main/java/cn/hippo4j/core/enable/BeforeCheckConfiguration.java +++ b/threadpool/core/src/main/java/cn/hippo4j/core/enable/BeforeCheckConfiguration.java @@ -115,6 +115,35 @@ public class BeforeCheckConfiguration { "Please check whether the [spring.dynamic.thread-pool.apollo.namespace] configuration is empty or an empty string."); } } + + Map zookeeper = properties.getZookeeper(); + if (MapUtil.isNotEmpty(zookeeper)) { + String zkConnectStr = zookeeper.get("zk-connect-str"); + if ((StringUtil.isBlank(zkConnectStr))) { + throw new ConfigEmptyException( + "Web server failed to start. The dynamic thread pool zookeeper zk-connect-str is empty.", + "Please check whether the [spring.dynamic.thread-pool.zookeeper.zk-connect-str] configuration is empty or an empty string."); + } + String configVersion = zookeeper.get("config-version"); + if ((StringUtil.isBlank(configVersion))) { + throw new ConfigEmptyException( + "Web server failed to start. The dynamic thread pool zookeeper config-version is empty.", + "Please check whether the [spring.dynamic.thread-pool.zookeeper.config-version] configuration is empty or an empty string."); + } + String rootNode = zookeeper.get("root-node"); + if ((StringUtil.isBlank(rootNode))) { + throw new ConfigEmptyException( + "Web server failed to start. The dynamic thread pool zookeeper root-node is empty.", + "Please check whether the [spring.dynamic.thread-pool.zookeeper.root-node] configuration is empty or an empty string."); + } + String node = zookeeper.get("node"); + if ((StringUtil.isBlank(node))) { + throw new ConfigEmptyException( + "Web server failed to start. The dynamic thread pool zookeeper node is empty.", + "Please check whether the [spring.dynamic.thread-pool.zookeeper.node] configuration is empty or an empty string."); + } + } + break; } default: