Skip to content

Commit

Permalink
check the required fields of polaris when the config mode starts (#1470)
Browse files Browse the repository at this point in the history
* check the required fields of polaris when the config mode starts

* Modify the format of polaris in BootstrapConfigProperties

* Define static constants of polaris in BeforeCheckConfiguration

* Use configuration and constants exist in  PolarisRefresherHandler

* Just consider the properties of BootstrapPropertiesInterface

* Don't throw exception in if else

* Optimize code format in BeforeCheckConfiguration
  • Loading branch information
mazengrun authored Oct 11, 2023
1 parent cf854b3 commit 26212e4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,11 @@ default Map<String, String> getZookeeper() {
return null;
}

/**
* Get Polaris.
*/
default Map<String, Object> getPolaris() {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public class BootstrapConfigProperties implements BootstrapPropertiesInterface {
*/
private Map<String, String> etcd;

/**
* polaris config
*/
private Map<String, Object> polaris;

/**
* Web config
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ private ConfigKVFile getConfigKVFile() {
return Objects.equals(POLARIS_FILE_TYPE, "yaml") ? configFileService.getConfigYamlFile(namespace, fileGroup, fileName)
: configFileService.getConfigPropertiesFile(namespace, fileGroup, fileName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -144,6 +145,39 @@ public BeforeCheckConfiguration.BeforeCheck dynamicThreadPoolBeforeCheckBean(@Au
}
}

Map<String, Object> 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<String, String> polarisFile = (Map<String, String>) 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:
Expand Down

0 comments on commit 26212e4

Please sign in to comment.