You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/02/07 04:50:13 UTC
[shardingsphere] branch master updated: Clearify exception info if
missing valid config files during proxy startup (#9364)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 075c8f0 Clearify exception info if missing valid config files during proxy startup (#9364)
075c8f0 is described below
commit 075c8f01812adb39cbdd39f5cc24da8a323434c4
Author: Liang Zhang <te...@163.com>
AuthorDate: Sun Feb 7 12:49:55 2021 +0800
Clearify exception info if missing valid config files during proxy startup (#9364)
* Clearify exception info if missing valid config files during proxy startup
* refactor
* refactor
---
.../proxy/config/ProxyConfigurationLoader.java | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfigurationLoader.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfigurationLoader.java
index ba54508..e817329 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfigurationLoader.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfigurationLoader.java
@@ -56,21 +56,17 @@ public final class ProxyConfigurationLoader {
* @throws IOException IO exception
*/
public static YamlProxyConfiguration load(final String path) throws IOException {
- Collection<String> schemaNames = new HashSet<>();
- YamlProxyServerConfiguration serverConfig = loadServerConfiguration(getResourceFile(path + "/" + SERVER_CONFIG_FILE));
+ YamlProxyServerConfiguration serverConfig = loadServerConfiguration(getResourceFile(String.join("/", path, SERVER_CONFIG_FILE)));
File configPath = getResourceFile(path);
- Collection<YamlProxyRuleConfiguration> ruleConfigurations = loadRuleConfigurations(schemaNames, configPath);
- Preconditions.checkState(!ruleConfigurations.isEmpty() || null != serverConfig.getGovernance(), "Can not find any rule configurations file in path `%s`.", configPath.getPath());
+ Collection<YamlProxyRuleConfiguration> ruleConfigurations = loadRuleConfigurations(configPath);
+ Preconditions.checkState(!ruleConfigurations.isEmpty() || null != serverConfig.getGovernance(), "Can not find any valid rule configurations file in path `%s`.", configPath.getPath());
return new YamlProxyConfiguration(serverConfig, ruleConfigurations.stream().collect(Collectors.toMap(
YamlProxyRuleConfiguration::getSchemaName, each -> each, (oldValue, currentValue) -> oldValue, LinkedHashMap::new)));
}
private static File getResourceFile(final String path) {
URL url = ProxyConfigurationLoader.class.getResource(path);
- if (null != url) {
- return new File(url.getFile());
- }
- return new File(path);
+ return null == url ? new File(path) : new File(url.getFile());
}
private static YamlProxyServerConfiguration loadServerConfiguration(final File yamlFile) throws IOException {
@@ -81,11 +77,12 @@ public final class ProxyConfigurationLoader {
return result;
}
- private static Collection<YamlProxyRuleConfiguration> loadRuleConfigurations(final Collection<String> schemaNames, final File configPath) throws IOException {
+ private static Collection<YamlProxyRuleConfiguration> loadRuleConfigurations(final File configPath) throws IOException {
+ Collection<String> loadedSchemaNames = new HashSet<>();
Collection<YamlProxyRuleConfiguration> result = new LinkedList<>();
for (File each : findRuleConfigurationFiles(configPath)) {
loadRuleConfiguration(each).ifPresent(yamlProxyRuleConfig -> {
- Preconditions.checkState(schemaNames.add(yamlProxyRuleConfig.getSchemaName()), "Schema name `%s` must unique at all rule configurations.", yamlProxyRuleConfig.getSchemaName());
+ Preconditions.checkState(loadedSchemaNames.add(yamlProxyRuleConfig.getSchemaName()), "Schema name `%s` must unique at all rule configurations.", yamlProxyRuleConfig.getSchemaName());
result.add(yamlProxyRuleConfig);
});
}
@@ -106,6 +103,6 @@ public final class ProxyConfigurationLoader {
}
private static File[] findRuleConfigurationFiles(final File path) {
- return path.listFiles(pathname -> RULE_CONFIG_FILE_PATTERN.matcher(pathname.getName()).matches());
+ return path.listFiles(each -> RULE_CONFIG_FILE_PATTERN.matcher(each.getName()).matches());
}
}