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 ab743fd2..4f7316da 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 @@ -101,4 +101,11 @@ public interface BootstrapPropertiesInterface { return null; } + /** + * Get Polaris. + */ + default Map getPolaris() { + return null; + } + } diff --git a/kernel/dynamic/mode/config/src/main/java/cn/hippo4j/threadpool/dynamic/mode/config/properties/BootstrapConfigProperties.java b/kernel/dynamic/mode/config/src/main/java/cn/hippo4j/threadpool/dynamic/mode/config/properties/BootstrapConfigProperties.java index ea1dc322..1bc87dc0 100644 --- a/kernel/dynamic/mode/config/src/main/java/cn/hippo4j/threadpool/dynamic/mode/config/properties/BootstrapConfigProperties.java +++ b/kernel/dynamic/mode/config/src/main/java/cn/hippo4j/threadpool/dynamic/mode/config/properties/BootstrapConfigProperties.java @@ -76,6 +76,11 @@ public class BootstrapConfigProperties implements BootstrapPropertiesInterface { */ private Map etcd; + /** + * polaris config + */ + private Map polaris; + /** * Web config * diff --git a/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/refresher/PolarisRefresherHandler.java b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/refresher/PolarisRefresherHandler.java index 3f2a3f8b..b06b4ebf 100644 --- a/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/refresher/PolarisRefresherHandler.java +++ b/starters/threadpool/config/src/main/java/cn/hippo4j/config/springboot/starter/refresher/PolarisRefresherHandler.java @@ -71,4 +71,5 @@ public class PolarisRefresherHandler extends AbstractConfigThreadPoolDynamicRefr return Objects.equals(POLARIS_FILE_TYPE, "yaml") ? configFileService.getConfigYamlFile(namespace, fileGroup, fileName) : configFileService.getConfigPropertiesFile(namespace, fileGroup, fileName); } + } 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 5265faf6..20c2df30 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 @@ -23,6 +23,7 @@ import cn.hippo4j.core.config.ConfigEmptyException; import cn.hippo4j.threadpool.dynamic.api.BootstrapPropertiesInterface; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.ConfigurableEnvironment; @@ -144,6 +145,39 @@ public class BeforeCheckConfiguration { } } + Map polaris = properties.getPolaris(); + if (MapUtil.isNotEmpty(polaris)) { + String namespace = polaris.get("namespace").toString(); + if (StringUtil.isBlank(namespace)) { + throw new ConfigEmptyException( + "Web server maybe fail to start. The dynamic thread pool polaris namespace is empty.", + "Please check whether the [spring.dynamic.thread-pool.polaris.namespace] configuration is empty or an empty string."); + } + if (!(polaris.get("file") instanceof Map)) { + throw new ConfigEmptyException( + "Web server maybe fail to start. Lack of the dynamic thread pool polaris file configuration.", + "Please check whether the [spring.dynamic.thread-pool.polaris.file.*] configuration is complete."); + } + Map polarisFile = (Map) polaris.get("file"); + String fileGroup = polarisFile.get("group"); + if (StringUtil.isBlank(fileGroup)) { + throw new ConfigEmptyException( + "Web server maybe fail to start. The dynamic thread pool polaris file group is empty.", + "Please check whether the [spring.dynamic.thread-pool.polaris.file.group] configuration is empty or an empty string."); + } + String fileName = polarisFile.get("name"); + if (StringUtil.isBlank(fileName)) { + throw new ConfigEmptyException( + "Web server maybe fail to start. The dynamic thread pool polaris file name is empty.", + "Please check whether the [spring.dynamic.thread-pool.polaris.file.name] configuration is empty or an empty string."); + } + String fileType = polarisFile.get("type"); + if (StringUtil.isBlank(fileType)) { + throw new ConfigEmptyException( + "Web server maybe fail to start. The dynamic thread pool polaris file type is empty.", + "Please check whether the [spring.dynamic.thread-pool.polaris.file.type] configuration is empty or an empty string."); + } + } break; } default: