You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2022/12/15 16:44:32 UTC
[shardingsphere] branch master updated: Remove AgentPathBuilder.configPath (#22896)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 f0c21873c8d Remove AgentPathBuilder.configPath (#22896)
f0c21873c8d is described below
commit f0c21873c8d60353ccb74ce7d1259c0c9a542632
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Dec 16 00:44:23 2022 +0800
Remove AgentPathBuilder.configPath (#22896)
* Move package of YamlAgentConfiguration
* Remove AgentPathBuilder.configPath
* Rename RemotePluginConfigurationValidator
* Fix checkstyle
* Rename YamlPluginsConfiguration
---
.../agent/core/config/loader/PluginConfigurationLoader.java | 10 +++++-----
.../agent/core/config/path/AgentPathBuilder.java | 8 --------
...alidator.java => RemotePluginConfigurationValidator.java} | 6 +++---
.../yaml/{ => entity}/YamlPluginCategoryConfiguration.java | 2 +-
.../config/yaml/{ => entity}/YamlPluginConfiguration.java | 5 +++--
.../YamlPluginsConfiguration.java} | 6 +++---
...tionSwapper.java => YamlPluginsConfigurationSwapper.java} | 12 ++++++------
...Test.java => RemotePluginConfigurationValidatorTest.java} | 12 +++++++-----
.../jaeger/service/JaegerTracingPluginBootService.java | 4 ++--
.../zipkin/service/ZipkinTracingPluginBootService.java | 4 ++--
10 files changed, 32 insertions(+), 37 deletions(-)
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/loader/PluginConfigurationLoader.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/loader/PluginConfigurationLoader.java
index bb5272567a9..bc10c6ca44a 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/loader/PluginConfigurationLoader.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/loader/PluginConfigurationLoader.java
@@ -22,8 +22,8 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
import org.apache.shardingsphere.agent.core.config.path.AgentPathBuilder;
-import org.apache.shardingsphere.agent.core.config.yaml.YamlAgentConfiguration;
-import org.apache.shardingsphere.agent.core.config.yaml.swapper.YamlAgentConfigurationSwapper;
+import org.apache.shardingsphere.agent.core.config.yaml.entity.YamlPluginsConfiguration;
+import org.apache.shardingsphere.agent.core.config.yaml.swapper.YamlPluginsConfigurationSwapper;
import org.apache.shardingsphere.agent.core.yaml.YamlEngine;
import java.io.File;
@@ -46,11 +46,11 @@ public final class PluginConfigurationLoader {
*/
public static Map<String, PluginConfiguration> load() throws IOException {
File configFile = new File(AgentPathBuilder.getAgentPath(), DEFAULT_CONFIG_PATH);
- return YamlAgentConfigurationSwapper.swap(load(configFile));
+ return YamlPluginsConfigurationSwapper.swap(load(configFile));
}
- private static YamlAgentConfiguration load(final File yamlFile) throws IOException {
- YamlAgentConfiguration result = YamlEngine.unmarshal(yamlFile, YamlAgentConfiguration.class);
+ private static YamlPluginsConfiguration load(final File yamlFile) throws IOException {
+ YamlPluginsConfiguration result = YamlEngine.unmarshal(yamlFile, YamlPluginsConfiguration.class);
Preconditions.checkNotNull(result, "Agent configuration file `%s` is invalid.", yamlFile.getName());
return result;
}
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/path/AgentPathBuilder.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/path/AgentPathBuilder.java
index 3ba6355827a..f89989285a6 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/path/AgentPathBuilder.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/path/AgentPathBuilder.java
@@ -40,13 +40,9 @@ public final class AgentPathBuilder {
@Getter
private static File pluginPath;
- @Getter
- private static File configPath;
-
static {
agentPath = buildAgentPath();
pluginPath = buildAgentPluginPath();
- configPath = buildAgentConfigPath();
}
private static File buildAgentPath() {
@@ -78,8 +74,4 @@ public final class AgentPathBuilder {
private static File buildAgentPluginPath() {
return new File(String.join("/", agentPath.getPath(), "plugins"));
}
-
- private static File buildAgentConfigPath() {
- return new File(String.join("/", agentPath.getPath(), "conf"));
- }
}
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/validator/PluginConfigurationValidator.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/validator/RemotePluginConfigurationValidator.java
similarity index 91%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/validator/PluginConfigurationValidator.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/validator/RemotePluginConfigurationValidator.java
index ab320f40936..d4575f76a41 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/validator/PluginConfigurationValidator.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/validator/RemotePluginConfigurationValidator.java
@@ -24,13 +24,13 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
/**
- * Plugin configuration validator.
+ * Remote plugin configuration validator.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class PluginConfigurationValidator {
+public final class RemotePluginConfigurationValidator {
/**
- * Validate plugin configuration.
+ * Validate remote plugin configuration.
*
* @param type plugin type
* @param pluginConfig to be validated plugin configuration
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginCategoryConfiguration.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/entity/YamlPluginCategoryConfiguration.java
similarity index 95%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginCategoryConfiguration.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/entity/YamlPluginCategoryConfiguration.java
index eab341f1bc2..be0253729b9 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginCategoryConfiguration.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/entity/YamlPluginCategoryConfiguration.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.config.yaml;
+package org.apache.shardingsphere.agent.core.config.yaml.entity;
import lombok.Getter;
import lombok.Setter;
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginConfiguration.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/entity/YamlPluginConfiguration.java
similarity index 94%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginConfiguration.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/entity/YamlPluginConfiguration.java
index 550b37b6cbe..9701152f217 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginConfiguration.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/entity/YamlPluginConfiguration.java
@@ -15,12 +15,13 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.config.yaml;
+package org.apache.shardingsphere.agent.core.config.yaml.entity;
-import java.util.Properties;
import lombok.Getter;
import lombok.Setter;
+import java.util.Properties;
+
/**
* YAML plugin configuration.
*/
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/entity/YamlPluginsConfiguration.java
similarity index 86%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/entity/YamlPluginsConfiguration.java
index 7e2cca941df..24f10644057 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/entity/YamlPluginsConfiguration.java
@@ -15,17 +15,17 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.config.yaml;
+package org.apache.shardingsphere.agent.core.config.yaml.entity;
import lombok.Getter;
import lombok.Setter;
/**
- * YAML agent configuration.
+ * YAML plugins configuration.
*/
@Getter
@Setter
-public final class YamlAgentConfiguration {
+public final class YamlPluginsConfiguration {
private YamlPluginCategoryConfiguration plugins;
}
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlPluginsConfigurationSwapper.java
similarity index 86%
rename from agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
rename to agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlPluginsConfigurationSwapper.java
index d04c82680a8..71ccb87c8b1 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlPluginsConfigurationSwapper.java
@@ -20,19 +20,19 @@ package org.apache.shardingsphere.agent.core.config.yaml.swapper;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
-import org.apache.shardingsphere.agent.core.config.yaml.YamlAgentConfiguration;
-import org.apache.shardingsphere.agent.core.config.yaml.YamlPluginCategoryConfiguration;
-import org.apache.shardingsphere.agent.core.config.yaml.YamlPluginConfiguration;
+import org.apache.shardingsphere.agent.core.config.yaml.entity.YamlPluginsConfiguration;
+import org.apache.shardingsphere.agent.core.config.yaml.entity.YamlPluginCategoryConfiguration;
+import org.apache.shardingsphere.agent.core.config.yaml.entity.YamlPluginConfiguration;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
- * YAML agent configuration swapper.
+ * YAML plugins configuration swapper.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class YamlAgentConfigurationSwapper {
+public final class YamlPluginsConfigurationSwapper {
/**
* Swap YAML agent configuration to plugin configurations.
@@ -40,7 +40,7 @@ public final class YamlAgentConfigurationSwapper {
* @param yamlConfig YAML agent configuration
* @return plugin configurations
*/
- public static Map<String, PluginConfiguration> swap(final YamlAgentConfiguration yamlConfig) {
+ public static Map<String, PluginConfiguration> swap(final YamlPluginsConfiguration yamlConfig) {
Map<String, PluginConfiguration> result = new LinkedHashMap<>();
YamlPluginCategoryConfiguration plugins = yamlConfig.getPlugins();
if (null != plugins) {
diff --git a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/config/validator/PluginConfigurationValidatorTest.java b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/config/validator/RemotePluginConfigurationValidatorTest.java
similarity index 70%
rename from agent/core/src/test/java/org/apache/shardingsphere/agent/core/config/validator/PluginConfigurationValidatorTest.java
rename to agent/core/src/test/java/org/apache/shardingsphere/agent/core/config/validator/RemotePluginConfigurationValidatorTest.java
index 3ddf5ae05f8..f417fdbe8f5 100644
--- a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/config/validator/PluginConfigurationValidatorTest.java
+++ b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/config/validator/RemotePluginConfigurationValidatorTest.java
@@ -22,26 +22,28 @@ import org.junit.Test;
import static org.junit.Assert.assertThrows;
-public final class PluginConfigurationValidatorTest {
+public final class RemotePluginConfigurationValidatorTest {
@Test
public void assertValidateSuccess() {
- PluginConfigurationValidator.validate("foo_type", new PluginConfiguration("localhost", 8080, "pwd", null));
+ RemotePluginConfigurationValidator.validate("foo_type", new PluginConfiguration("localhost", 8080, "pwd", null));
}
@Test
public void assertValidateWhenHostIsEmpty() {
- assertThrows("Hostname of foo_type is required", IllegalArgumentException.class, () -> PluginConfigurationValidator.validate("foo_type", new PluginConfiguration("", 8080, "pwd", null)));
+ assertThrows("Hostname of foo_type is required", IllegalArgumentException.class,
+ () -> RemotePluginConfigurationValidator.validate("foo_type", new PluginConfiguration("", 8080, "pwd", null)));
}
@Test
public void assertValidateWhenHostIsNull() {
- assertThrows("Hostname of foo_type is required", IllegalArgumentException.class, () -> PluginConfigurationValidator.validate("foo_type", new PluginConfiguration(null, 8080, "pwd", null)));
+ assertThrows("Hostname of foo_type is required", IllegalArgumentException.class,
+ () -> RemotePluginConfigurationValidator.validate("foo_type", new PluginConfiguration(null, 8080, "pwd", null)));
}
@Test
public void assertValidateWhenPortLessThanOne() {
assertThrows("Port `0` of foo_host must be a positive number", IllegalArgumentException.class,
- () -> PluginConfigurationValidator.validate("foo_type", new PluginConfiguration("localhost", 0, "pwd", null)));
+ () -> RemotePluginConfigurationValidator.validate("foo_type", new PluginConfiguration("localhost", 0, "pwd", null)));
}
}
diff --git a/agent/plugins/tracing/type/jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java b/agent/plugins/tracing/type/jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java
index f34392c50b3..7db5c645520 100644
--- a/agent/plugins/tracing/type/jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java
+++ b/agent/plugins/tracing/type/jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.agent.plugin.tracing.jaeger.service;
import io.jaegertracing.Configuration;
import io.opentracing.util.GlobalTracer;
import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
-import org.apache.shardingsphere.agent.core.config.validator.PluginConfigurationValidator;
+import org.apache.shardingsphere.agent.core.config.validator.RemotePluginConfigurationValidator;
import org.apache.shardingsphere.agent.spi.plugin.PluginBootService;
import java.util.Optional;
@@ -39,7 +39,7 @@ public final class JaegerTracingPluginBootService implements PluginBootService {
@SuppressWarnings("AccessOfSystemProperties")
@Override
public void start(final PluginConfiguration pluginConfig, final boolean isEnhancedForProxy) {
- PluginConfigurationValidator.validate(getType(), pluginConfig);
+ RemotePluginConfigurationValidator.validate(getType(), pluginConfig);
pluginConfig.getProps().forEach((key, value) -> setSystemProperty(String.valueOf(key), String.valueOf(value)));
Configuration.SamplerConfiguration samplerConfig = Configuration.SamplerConfiguration.fromEnv();
Configuration.ReporterConfiguration reporterConfig = Configuration.ReporterConfiguration.fromEnv()
diff --git a/agent/plugins/tracing/type/zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java b/agent/plugins/tracing/type/zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java
index 3dae48ddffa..70089538732 100644
--- a/agent/plugins/tracing/type/zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java
+++ b/agent/plugins/tracing/type/zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java
@@ -22,7 +22,7 @@ import brave.sampler.BoundarySampler;
import brave.sampler.RateLimitingSampler;
import brave.sampler.Sampler;
import org.apache.shardingsphere.agent.config.plugin.PluginConfiguration;
-import org.apache.shardingsphere.agent.core.config.validator.PluginConfigurationValidator;
+import org.apache.shardingsphere.agent.core.config.validator.RemotePluginConfigurationValidator;
import org.apache.shardingsphere.agent.spi.plugin.PluginBootService;
import zipkin2.reporter.brave.AsyncZipkinSpanHandler;
import zipkin2.reporter.okhttp3.OkHttpSender;
@@ -59,7 +59,7 @@ public final class ZipkinTracingPluginBootService implements PluginBootService {
@Override
public void start(final PluginConfiguration pluginConfig, final boolean isEnhancedForProxy) {
- PluginConfigurationValidator.validate(getType(), pluginConfig);
+ RemotePluginConfigurationValidator.validate(getType(), pluginConfig);
Properties props = pluginConfig.getProps();
String urlVersion = Optional.ofNullable(props.getProperty(KEY_URL_VERSION)).orElse(DEFAULT_URL_VERSION);
String serviceName = Optional.ofNullable(props.getProperty(KEY_SERVICE_NAME)).orElse(DEFAULT_SERVICE_NAME);