Just consider the properties of BootstrapPropertiesInterface

pull/1470/head
MZR 2 years ago
parent f9ca95d225
commit a5d01f8ea8

@ -101,4 +101,11 @@ public interface BootstrapPropertiesInterface {
return null; return null;
} }
/**
* Get Polaris.
*/
default Map<String, Object> getPolaris() {
return null;
}
} }

@ -76,6 +76,11 @@ public class BootstrapConfigProperties implements BootstrapPropertiesInterface {
*/ */
private Map<String, String> etcd; private Map<String, String> etcd;
/**
* polaris config
*/
private Map<String, Object> polaris;
/** /**
* Web config * Web config
* *

@ -36,13 +36,13 @@ public class PolarisRefresherHandler extends AbstractConfigThreadPoolDynamicRefr
private final ConfigFileService configFileService; private final ConfigFileService configFileService;
private static final String POLARIS_NAMESPACE = "${spring.dynamic.thread-pool.polaris.namespace}"; private static final String POLARIS_NAMESPACE = "${spring.dynamic.thread-pool.polaris.namespace:dev}";
private static final String POLARIS_FILE_GROUP = "${spring.dynamic.thread-pool.polaris.file.group}"; private static final String POLARIS_FILE_GROUP = "${spring.dynamic.thread-pool.polaris.file.group:dynamic}";
private static final String POLARIS_FILE_NAME = "${spring.dynamic.thread-pool.polaris.file.name}"; private static final String POLARIS_FILE_NAME = "${spring.dynamic.thread-pool.polaris.file.name:root/bootstrap.yaml}";
private static final String POLARIS_FILE_TYPE = "${spring.dynamic.thread-pool.polaris.file.type}"; private static final String POLARIS_FILE_TYPE = "${spring.dynamic.thread-pool.polaris.file.type:properties}";
@Value(POLARIS_NAMESPACE) @Value(POLARIS_NAMESPACE)
private String namespace; private String namespace;
@ -72,19 +72,4 @@ public class PolarisRefresherHandler extends AbstractConfigThreadPoolDynamicRefr
: configFileService.getConfigPropertiesFile(namespace, fileGroup, fileName); : configFileService.getConfigPropertiesFile(namespace, fileGroup, fileName);
} }
public static String getPolarisNamespace() {
return POLARIS_NAMESPACE;
}
public static String getPolarisFileGroup() {
return POLARIS_FILE_GROUP;
}
public static String getPolarisFileName() {
return POLARIS_FILE_NAME;
}
public static String getPolarisFileType() {
return POLARIS_FILE_TYPE;
}
} }

@ -34,11 +34,6 @@
<artifactId>hippo4j-threadpool-kernel-monitor</artifactId> <artifactId>hippo4j-threadpool-kernel-monitor</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-threadpool-config-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>

@ -40,18 +40,6 @@ public class BeforeCheckConfiguration {
private final String bootstrapPropertiesClassName = "cn.hippo4j.springboot.starter.config.BootstrapProperties"; private final String bootstrapPropertiesClassName = "cn.hippo4j.springboot.starter.config.BootstrapProperties";
private final String bootstrapConfigPropertiesClassName = "cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties"; private final String bootstrapConfigPropertiesClassName = "cn.hippo4j.threadpool.dynamic.mode.config.properties.BootstrapConfigProperties";
@Value("#{T(cn.hippo4j.config.springboot.starter.refresher.PolarisRefresherHandler).getPolarisNamespace()}")
private String polarisNamespace;
@Value("#{T(cn.hippo4j.config.springboot.starter.refresher.PolarisRefresherHandler).getPolarisFileGroup()}")
private String polarisFileGroup;
@Value("#{T(cn.hippo4j.config.springboot.starter.refresher.PolarisRefresherHandler).getPolarisFileName()}")
private String polarisFileName;
@Value("#{T(cn.hippo4j.config.springboot.starter.refresher.PolarisRefresherHandler).getPolarisFileType()}")
private String polarisFileType;
@Bean @Bean
public BeforeCheckConfiguration.BeforeCheck dynamicThreadPoolBeforeCheckBean(@Autowired(required = false) BootstrapPropertiesInterface properties, public BeforeCheckConfiguration.BeforeCheck dynamicThreadPoolBeforeCheckBean(@Autowired(required = false) BootstrapPropertiesInterface properties,
ConfigurableEnvironment environment) { ConfigurableEnvironment environment) {
@ -157,25 +145,39 @@ public class BeforeCheckConfiguration {
} }
} }
if (StringUtil.isBlank(polarisNamespace)) { Map<String, Object> polaris = properties.getPolaris();
throw new ConfigEmptyException( if (MapUtil.isNotEmpty(polaris)) {
"Web server failed to start. The dynamic thread pool polaris namespace is empty.", String namespace = polaris.get("namespace").toString();
"Please check whether the [spring.dynamic.thread-pool.polaris.namespace] configuration is empty or an empty string."); if (StringUtil.isBlank(namespace)) {
} throw new ConfigEmptyException(
if (StringUtil.isBlank(polarisFileGroup)) { "Web server maybe fail to start. The dynamic thread pool polaris namespace is empty.",
throw new ConfigEmptyException( "Please check whether the [spring.dynamic.thread-pool.polaris.namespace] configuration is empty or an empty string.");
"Web server failed 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."); if (polaris.get("file") instanceof Map) {
} Map<String, String> polarisFile = (Map<String, String>)polaris.get("file");
if (StringUtil.isBlank(polarisFileName)) { String fileGroup = polarisFile.get("group");
throw new ConfigEmptyException( if (StringUtil.isBlank(fileGroup)) {
"Web server failed to start. The dynamic thread pool polaris file name is empty.", throw new ConfigEmptyException(
"Please check whether the [spring.dynamic.thread-pool.polaris.file.name] configuration is empty or an empty string."); "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.");
if (StringUtil.isBlank(polarisFileType)) { }
throw new ConfigEmptyException( String fileName = polarisFile.get("name");
"Web server failed to start. The dynamic thread pool polaris file type is empty.", if (StringUtil.isBlank(fileName)) {
"Please check whether the [spring.dynamic.thread-pool.polaris.file.type] configuration is empty or an empty string."); 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.");
}
} else {
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.");
}
} }
break; break;
} }

Loading…
Cancel
Save