You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2023/01/05 12:53:43 UTC
[shardingsphere] branch master updated: Refactor YamlPluginsConfigurationSwapper (#23359)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 f5596521a96 Refactor YamlPluginsConfigurationSwapper (#23359)
f5596521a96 is described below
commit f5596521a965adc33c0391666dbe8a6da8df1fc8
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Jan 5 20:53:36 2023 +0800
Refactor YamlPluginsConfigurationSwapper (#23359)
---
.../swapper/YamlPluginsConfigurationSwapper.java | 31 +++++++++++-----------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlPluginsConfigurationSwapper.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlPluginsConfigurationSwapper.java
index 3b68e70cf96..470e0b6a246 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlPluginsConfigurationSwapper.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlPluginsConfigurationSwapper.java
@@ -19,14 +19,16 @@ package org.apache.shardingsphere.agent.core.config.yaml.swapper;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.agent.api.PluginConfiguration;
+import org.apache.shardingsphere.agent.core.config.yaml.entity.YamlAgentConfiguration;
import org.apache.shardingsphere.agent.core.config.yaml.entity.YamlPluginCategoryConfiguration;
import org.apache.shardingsphere.agent.core.config.yaml.entity.YamlPluginConfiguration;
-import org.apache.shardingsphere.agent.core.config.yaml.entity.YamlAgentConfiguration;
-import org.apache.shardingsphere.agent.api.PluginConfiguration;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.stream.Collectors;
/**
* YAML plugins configuration swapper.
@@ -41,27 +43,24 @@ public final class YamlPluginsConfigurationSwapper {
* @return plugin configurations
*/
public static Map<String, PluginConfiguration> swap(final YamlAgentConfiguration yamlConfig) {
- Map<String, PluginConfiguration> result = new LinkedHashMap<>();
YamlPluginCategoryConfiguration plugins = yamlConfig.getPlugins();
- if (null != plugins) {
- result.putAll(transformPluginConfigurationMap(plugins.getLogging()));
- result.putAll(transformPluginConfigurationMap(plugins.getMetrics()));
- result.putAll(transformPluginConfigurationMap(plugins.getTracing()));
+ if (null == plugins) {
+ return Collections.emptyMap();
}
+ Map<String, PluginConfiguration> result = new LinkedHashMap<>();
+ result.putAll(swap(plugins.getLogging()));
+ result.putAll(swap(plugins.getMetrics()));
+ result.putAll(swap(plugins.getTracing()));
return result;
}
- private static Map<String, PluginConfiguration> transformPluginConfigurationMap(final Map<String, YamlPluginConfiguration> yamlConfigurationMap) {
- Map<String, PluginConfiguration> result = new LinkedHashMap<>();
- if (null != yamlConfigurationMap) {
- for (Entry<String, YamlPluginConfiguration> entry : yamlConfigurationMap.entrySet()) {
- result.put(entry.getKey(), transform(entry.getValue()));
- }
- }
- return result;
+ private static Map<String, PluginConfiguration> swap(final Map<String, YamlPluginConfiguration> yamlConfigs) {
+ return null == yamlConfigs
+ ? Collections.emptyMap()
+ : yamlConfigs.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> swap(entry.getValue()), (key, value) -> value, LinkedHashMap::new));
}
- private static PluginConfiguration transform(final YamlPluginConfiguration yamlConfig) {
+ private static PluginConfiguration swap(final YamlPluginConfiguration yamlConfig) {
return new PluginConfiguration(yamlConfig.getHost(), yamlConfig.getPort(), yamlConfig.getPassword(), yamlConfig.getProps());
}
}