You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/12/24 16:16:30 UTC
[shardingsphere] branch master updated: refactor agent code. (#8763)
This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 5fb4d5b refactor agent code. (#8763)
5fb4d5b is described below
commit 5fb4d5b4e360b3b0f5ea16cc3c9150d10b6c7a3d
Author: xiaoyu <54...@qq.com>
AuthorDate: Fri Dec 25 00:16:11 2020 +0800
refactor agent code. (#8763)
---
.../agent/bootstrap/ShardingSphereAgent.java | 22 +++---
.../agent/core/config/AgentConfiguration.java | 11 ++-
.../core/config/JaegerPluginConfiguration.java | 44 ------------
.../agent/core/config/PluginConfiguration.java | 19 ++++--
.../RemotePluginConfiguration.java} | 13 +++-
.../core/config/ZipkinPluginConfiguration.java | 42 ------------
.../config/loader/AgentConfigurationLoader.java | 2 +-
.../core/config/yaml/YamlAgentConfiguration.java | 7 +-
.../config/yaml/YamlJaegerPluginConfiguration.java | 43 ------------
.../YamlPluginConfiguration.java} | 16 ++---
.../yaml/YamlPrometheusPluginConfiguration.java | 41 -----------
.../yaml/YamlRemotePluginConfiguration.java} | 18 ++---
.../config/yaml/YamlZipkinPluginConfiguration.java | 43 ------------
.../JaegerPluginConfigurationYamlSwapper.java | 47 -------------
.../PrometheusPluginConfigurationYamlSwapper.java | 47 -------------
.../swapper/YamlAgentConfigurationSwapper.java | 20 ++++--
.../ZipkinPluginConfigurationYamlSwapper.java | 47 -------------
.../core/plugin/service/PluginBootService.java | 22 +-----
.../core/plugin/service/PluginServiceManager.java | 60 ++++------------
.../agent/core/spi/AgentTypedSPIRegistry.java | 12 ++++
.../shardingsphere/agent/core/yaml/YamlEngine.java | 56 +--------------
.../yaml/constructor/AgentYamlConstructor.java | 33 ---------
.../swapper/YamlPluginConfigurationSwapper.java | 38 -----------
.../YamlPluginConfigurationSwapperEngine.java | 79 ----------------------
.../agent/core/yaml/swapper/YamlSwapper.java | 37 ----------
.../src/test/resources/conf/agent.yaml | 22 +++---
.../src/main/resources/conf/agent.yaml | 25 +++----
.../service/PrometheusPluginBootService.java | 20 +++---
.../service/JaegerTracingPluginBootService.java | 18 +++--
.../service/ZipkinTracingPluginBootService.java | 14 ++--
30 files changed, 152 insertions(+), 766 deletions(-)
diff --git a/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java b/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
index a609c42..9fa5d04 100644
--- a/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
+++ b/shardingsphere-agent/shardingsphere-agent-bootstrap/src/main/java/org/apache/shardingsphere/agent/bootstrap/ShardingSphereAgent.java
@@ -17,24 +17,23 @@
package org.apache.shardingsphere.agent.bootstrap;
-import java.util.Collection;
+import java.io.IOException;
+import java.lang.instrument.Instrumentation;
+import java.util.Map;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.dynamic.scaffold.TypeValidation;
import net.bytebuddy.matcher.ElementMatchers;
+import org.apache.shardingsphere.agent.core.cache.AgentObjectPool;
import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
-import org.apache.shardingsphere.agent.core.listener.LoggingListener;
-import org.apache.shardingsphere.agent.core.transformer.ShardingSphereTransformer;
import org.apache.shardingsphere.agent.core.config.loader.AgentConfigurationLoader;
+import org.apache.shardingsphere.agent.core.listener.LoggingListener;
import org.apache.shardingsphere.agent.core.plugin.loader.PluginLoader;
import org.apache.shardingsphere.agent.core.plugin.service.PluginServiceManager;
-import org.apache.shardingsphere.agent.core.cache.AgentObjectPool;
-
-import java.io.IOException;
-import java.lang.instrument.Instrumentation;
+import org.apache.shardingsphere.agent.core.transformer.ShardingSphereTransformer;
/**
* ShardingSphere agent.
@@ -54,7 +53,7 @@ public final class ShardingSphereAgent {
AgentObjectPool.INSTANCE.put(agentConfiguration);
PluginLoader pluginLoader = createPluginLoader();
setUpAgentBuilder(instrumentation, pluginLoader);
- setupPluginBootService(agentConfiguration.getPluginConfigurations());
+ setupPluginBootService(agentConfiguration.getPlugins());
}
private static PluginLoader createPluginLoader() throws IOException {
@@ -63,10 +62,9 @@ public final class ShardingSphereAgent {
return result;
}
- private static void setupPluginBootService(final Collection<PluginConfiguration> pluginConfigurations) {
- PluginServiceManager.setUpAllService(pluginConfigurations);
- PluginServiceManager.startAllService(pluginConfigurations);
- Runtime.getRuntime().addShutdownHook(new Thread(PluginServiceManager::cleanUpAllService));
+ private static void setupPluginBootService(final Map<String, PluginConfiguration> pluginConfigurationMap) {
+ PluginServiceManager.startAllService(pluginConfigurationMap);
+ Runtime.getRuntime().addShutdownHook(new Thread(PluginServiceManager::closeAllService));
}
private static void setUpAgentBuilder(final Instrumentation instrumentation, final PluginLoader pluginLoader) {
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfiguration.java
index 1928244..5b68eb2 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/AgentConfiguration.java
@@ -17,13 +17,12 @@
package org.apache.shardingsphere.agent.core.config;
-import lombok.Getter;
-import lombok.Setter;
-
-import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
-import java.util.LinkedList;
+import java.util.Map;
import java.util.Set;
+import lombok.Getter;
+import lombok.Setter;
/**
* Agent configuration.
@@ -38,5 +37,5 @@ public final class AgentConfiguration {
private Set<String> ignorePlugins = new HashSet<>();
- private Collection<PluginConfiguration> pluginConfigurations = new LinkedList<>();
+ private Map<String, PluginConfiguration> plugins = new HashMap<>();
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/JaegerPluginConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/JaegerPluginConfiguration.java
deleted file mode 100644
index e4c139c..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/JaegerPluginConfiguration.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.config;
-
-import java.util.HashMap;
-import java.util.Map;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * Jaeger plugin configuration.
- */
-@Getter
-@Setter
-public final class JaegerPluginConfiguration implements PluginConfiguration {
-
- private String applicationName = "shardingsphere-jaeger";
-
- private String host = "localhost";
-
- private int port = 5775;
-
- private Map<String, String> extra = new HashMap<>();
-
- @Override
- public String getPluginName() {
- return "Jaeger";
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/PluginConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/PluginConfiguration.java
index 8c88145..7dfa26f 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/PluginConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/PluginConfiguration.java
@@ -17,15 +17,20 @@
package org.apache.shardingsphere.agent.core.config;
+import java.util.Properties;
+import lombok.Getter;
+import lombok.Setter;
+
/**
* Plugin configuration.
*/
-public interface PluginConfiguration {
+@Getter
+@Setter
+public class PluginConfiguration extends RemotePluginConfiguration {
+
+ private String host = "localhost";
+
+ private int port = 5775;
- /**
- * Get plugin name.
- *
- * @return plugin name
- */
- String getPluginName();
+ private Properties props = new Properties();
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/config/YamlConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/RemotePluginConfiguration.java
similarity index 78%
rename from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/config/YamlConfiguration.java
rename to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/RemotePluginConfiguration.java
index 3c1303e..68d3c6c 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/config/YamlConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/RemotePluginConfiguration.java
@@ -15,10 +15,17 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.yaml.config;
+package org.apache.shardingsphere.agent.core.config;
+
+import lombok.Getter;
+import lombok.Setter;
/**
- * YAML configuration.
+ * Remote plugin configuration.
*/
-public interface YamlConfiguration {
+@Getter
+@Setter
+public class RemotePluginConfiguration {
+
+ private String password;
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/ZipkinPluginConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/ZipkinPluginConfiguration.java
deleted file mode 100644
index 5fbc684..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/ZipkinPluginConfiguration.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.config;
-
-import java.util.HashMap;
-import java.util.Map;
-import lombok.Getter;
-import lombok.Setter;
-
-/**
- * Zipkin plugin configuration.
- */
-@Getter
-@Setter
-public final class ZipkinPluginConfiguration implements PluginConfiguration {
-
- private String host = "localhost";
-
- private int port = 15775;
-
- private Map<String, String> extra = new HashMap<>();
-
- @Override
- public String getPluginName() {
- return "Zipkin";
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/loader/AgentConfigurationLoader.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/loader/AgentConfigurationLoader.java
index d44b673..236e73f 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/loader/AgentConfigurationLoader.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/loader/AgentConfigurationLoader.java
@@ -45,7 +45,7 @@ public final class AgentConfigurationLoader {
public static AgentConfiguration load() throws IOException {
File configFile = new File(AgentPathBuilder.getAgentPath(), DEFAULT_CONFIG_PATH);
YamlAgentConfiguration yamlAgentConfiguration = loadAgentConfiguration(configFile);
- return new YamlAgentConfigurationSwapper().swap(yamlAgentConfiguration);
+ return YamlAgentConfigurationSwapper.swap(yamlAgentConfiguration);
}
private static YamlAgentConfiguration loadAgentConfiguration(final File yamlFile) throws IOException {
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
index e4366e9..21bc20f 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlAgentConfiguration.java
@@ -17,13 +17,12 @@
package org.apache.shardingsphere.agent.core.config.yaml;
-import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
-import java.util.LinkedList;
+import java.util.Map;
import java.util.Set;
import lombok.Getter;
import lombok.Setter;
-import org.apache.shardingsphere.agent.core.yaml.config.YamlPluginConfiguration;
/**
* YAML agent configuration.
@@ -38,5 +37,5 @@ public final class YamlAgentConfiguration {
private Set<String> ignorePlugins = new HashSet<>();
- private Collection<YamlPluginConfiguration> plugins = new LinkedList<>();
+ private Map<String, YamlPluginConfiguration> plugins = new HashMap<>();
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlJaegerPluginConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlJaegerPluginConfiguration.java
deleted file mode 100644
index 29c883d..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlJaegerPluginConfiguration.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.config.yaml;
-
-import java.util.HashMap;
-import java.util.Map;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.agent.core.yaml.config.YamlPluginConfiguration;
-
-/**
- * Jaeger plugin configuration for YAML.
- */
-@Getter
-@Setter
-public final class YamlJaegerPluginConfiguration implements YamlPluginConfiguration {
-
- private String host = "localhost";
-
- private int port = 5775;
-
- private Map<String, String> extra = new HashMap<>();
-
- @Override
- public String getPluginName() {
- return "Jaeger";
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/PrometheusPluginConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginConfiguration.java
similarity index 73%
rename from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/PrometheusPluginConfiguration.java
rename to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginConfiguration.java
index 2799969..e34286a 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/PrometheusPluginConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPluginConfiguration.java
@@ -15,26 +15,22 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.config;
+package org.apache.shardingsphere.agent.core.config.yaml;
+import java.util.Properties;
import lombok.Getter;
import lombok.Setter;
/**
- * Prometheus plugin configuration.
+ * YAML plugin configuration.
*/
@Getter
@Setter
-public final class PrometheusPluginConfiguration implements PluginConfiguration {
+public class YamlPluginConfiguration extends YamlRemotePluginConfiguration {
private String host = "localhost";
- private int port = 9090;
+ private int port = 5775;
- private boolean jvmInformationCollectorEnabled;
-
- @Override
- public String getPluginName() {
- return "Prometheus";
- }
+ private Properties props = new Properties();
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPrometheusPluginConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPrometheusPluginConfiguration.java
deleted file mode 100644
index 2f1930f..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlPrometheusPluginConfiguration.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.config.yaml;
-
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.agent.core.yaml.config.YamlPluginConfiguration;
-
-/**
- * Prometheus plugin configuration for YAML.
- */
-@Getter
-@Setter
-public class YamlPrometheusPluginConfiguration implements YamlPluginConfiguration {
-
- private String host = "localhost";
-
- private int port = 9090;
-
- private boolean jvmInformationCollectorEnabled;
-
- @Override
- public String getPluginName() {
- return "Prometheus";
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/config/YamlPluginConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlRemotePluginConfiguration.java
similarity index 75%
rename from shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/config/YamlPluginConfiguration.java
rename to shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlRemotePluginConfiguration.java
index 7a4d47a..700ac0d 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/config/YamlPluginConfiguration.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlRemotePluginConfiguration.java
@@ -15,17 +15,17 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.agent.core.yaml.config;
+package org.apache.shardingsphere.agent.core.config.yaml;
+
+import lombok.Getter;
+import lombok.Setter;
/**
- * YAML plugin configuration.
+ * YAML Remote plugin configuration.
*/
-public interface YamlPluginConfiguration extends YamlConfiguration {
+@Getter
+@Setter
+public class YamlRemotePluginConfiguration {
- /**
- * Get plugin name.
- *
- * @return plugin name
- */
- String getPluginName();
+ private String password;
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlZipkinPluginConfiguration.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlZipkinPluginConfiguration.java
deleted file mode 100644
index aa2f7e4..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/YamlZipkinPluginConfiguration.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.config.yaml;
-
-import java.util.HashMap;
-import java.util.Map;
-import lombok.Getter;
-import lombok.Setter;
-import org.apache.shardingsphere.agent.core.yaml.config.YamlPluginConfiguration;
-
-/**
- * Jaeger plugin configuration for YAML.
- */
-@Getter
-@Setter
-public class YamlZipkinPluginConfiguration implements YamlPluginConfiguration {
-
- private String host = "localhost";
-
- private int port = 15775;
-
- private Map<String, String> extra = new HashMap<>();
-
- @Override
- public String getPluginName() {
- return "Zipkin";
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/JaegerPluginConfigurationYamlSwapper.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/JaegerPluginConfigurationYamlSwapper.java
deleted file mode 100644
index 10080ec..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/JaegerPluginConfigurationYamlSwapper.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.config.yaml.swapper;
-
-import org.apache.shardingsphere.agent.core.config.JaegerPluginConfiguration;
-import org.apache.shardingsphere.agent.core.config.yaml.YamlJaegerPluginConfiguration;
-import org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapper;
-
-/**
- * Jaeger plugin configuration YAML swapper.
- */
-public final class JaegerPluginConfigurationYamlSwapper implements YamlPluginConfigurationSwapper<YamlJaegerPluginConfiguration, JaegerPluginConfiguration> {
-
- @Override
- public JaegerPluginConfiguration swapToObject(final YamlJaegerPluginConfiguration yamlConfig) {
- JaegerPluginConfiguration result = new JaegerPluginConfiguration();
- result.setHost(yamlConfig.getHost());
- result.setPort(yamlConfig.getPort());
- result.setExtra(yamlConfig.getExtra());
- return result;
- }
-
- @Override
- public String getPluginTagName() {
- return "JAEGER";
- }
-
- @Override
- public String getType() {
- return "Jaeger";
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/PrometheusPluginConfigurationYamlSwapper.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/PrometheusPluginConfigurationYamlSwapper.java
deleted file mode 100644
index e8b3d2d..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/PrometheusPluginConfigurationYamlSwapper.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.config.yaml.swapper;
-
-import org.apache.shardingsphere.agent.core.config.PrometheusPluginConfiguration;
-import org.apache.shardingsphere.agent.core.config.yaml.YamlPrometheusPluginConfiguration;
-import org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapper;
-
-/**
- * Prometheus plugin configuration YAML swapper.
- */
-public final class PrometheusPluginConfigurationYamlSwapper implements YamlPluginConfigurationSwapper<YamlPrometheusPluginConfiguration, PrometheusPluginConfiguration> {
-
- @Override
- public PrometheusPluginConfiguration swapToObject(final YamlPrometheusPluginConfiguration yamlConfig) {
- PrometheusPluginConfiguration result = new PrometheusPluginConfiguration();
- result.setHost(yamlConfig.getHost());
- result.setPort(yamlConfig.getPort());
- result.setJvmInformationCollectorEnabled(yamlConfig.isJvmInformationCollectorEnabled());
- return result;
- }
-
- @Override
- public String getPluginTagName() {
- return "PROMETHEUS";
- }
-
- @Override
- public String getType() {
- return "Prometheus";
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
index 0436a48..384658c 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/YamlAgentConfigurationSwapper.java
@@ -17,11 +17,12 @@
package org.apache.shardingsphere.agent.core.config.yaml.swapper;
-import java.util.Collection;
+import java.util.Map;
+import java.util.stream.Collectors;
import org.apache.shardingsphere.agent.core.config.AgentConfiguration;
import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
import org.apache.shardingsphere.agent.core.config.yaml.YamlAgentConfiguration;
-import org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapperEngine;
+import org.apache.shardingsphere.agent.core.config.yaml.YamlPluginConfiguration;
/**
* YAML agent configuration swapper.
@@ -34,13 +35,22 @@ public final class YamlAgentConfigurationSwapper {
* @param yamlConfig YAML agent configuration
* @return agent configuration
*/
- public AgentConfiguration swap(final YamlAgentConfiguration yamlConfig) {
+ public static AgentConfiguration swap(final YamlAgentConfiguration yamlConfig) {
AgentConfiguration result = new AgentConfiguration();
result.setApplicationName(yamlConfig.getApplicationName());
result.setMetricsType(yamlConfig.getMetricsType());
result.setIgnorePlugins(yamlConfig.getIgnorePlugins());
- Collection<PluginConfiguration> pluginConfigurations = YamlPluginConfigurationSwapperEngine.swapToPluginConfigurations(yamlConfig.getPlugins());
- result.setPluginConfigurations(pluginConfigurations);
+ Map<String, PluginConfiguration> configurationMap = yamlConfig.getPlugins().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> transform(entry.getValue())));
+ result.setPlugins(configurationMap);
+ return result;
+ }
+
+ private static PluginConfiguration transform(final YamlPluginConfiguration yamlConfig) {
+ PluginConfiguration result = new PluginConfiguration();
+ result.setHost(yamlConfig.getHost());
+ result.setPort(yamlConfig.getPort());
+ result.setProps(yamlConfig.getProps());
+ result.setPassword(yamlConfig.getPassword());
return result;
}
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/ZipkinPluginConfigurationYamlSwapper.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/ZipkinPluginConfigurationYamlSwapper.java
deleted file mode 100644
index a7d2d02..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/config/yaml/swapper/ZipkinPluginConfigurationYamlSwapper.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.config.yaml.swapper;
-
-import org.apache.shardingsphere.agent.core.config.ZipkinPluginConfiguration;
-import org.apache.shardingsphere.agent.core.config.yaml.YamlZipkinPluginConfiguration;
-import org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapper;
-
-/**
- * Zipkin plugin configuration YAML swapper.
- */
-public final class ZipkinPluginConfigurationYamlSwapper implements YamlPluginConfigurationSwapper<YamlZipkinPluginConfiguration, ZipkinPluginConfiguration> {
-
- @Override
- public ZipkinPluginConfiguration swapToObject(final YamlZipkinPluginConfiguration yamlConfig) {
- ZipkinPluginConfiguration result = new ZipkinPluginConfiguration();
- result.setHost(yamlConfig.getHost());
- result.setPort(yamlConfig.getPort());
- result.setExtra(yamlConfig.getExtra());
- return result;
- }
-
- @Override
- public String getPluginTagName() {
- return "ZIPKIN";
- }
-
- @Override
- public String getType() {
- return "Zipkin";
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/PluginBootService.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/PluginBootService.java
index 3fe0c93..02831a7 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/PluginBootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/PluginBootService.java
@@ -22,29 +22,13 @@ import org.apache.shardingsphere.agent.core.spi.AgentTypedSPI;
/**
* Plugin boot service that the lifecycle is from the agent startup to shutdown.
- *
- * @param <T> type of plugin configuration
*/
-public interface PluginBootService<T extends PluginConfiguration> extends AgentTypedSPI {
+public interface PluginBootService extends AgentTypedSPI, AutoCloseable {
/**
* Setup plugin boot service, like to configure or to initial.
*
- * @param configuration type of plugin configuration
- */
- void setup(T configuration);
-
- /**
- * Start plugin boot service.
- *
- * @param configuration type of plugin configuration
- */
- default void start(T configuration) {
- }
-
- /**
- * Cleanup plugin boot service.
+ * @param pluginConfiguration plugin configuration
*/
- default void cleanup() {
- }
+ void start(PluginConfiguration pluginConfiguration);
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/PluginServiceManager.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/PluginServiceManager.java
index 813d18e..89c3357 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/PluginServiceManager.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/plugin/service/PluginServiceManager.java
@@ -17,9 +17,7 @@
package org.apache.shardingsphere.agent.core.plugin.service;
-import java.util.Collection;
import java.util.Map;
-import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
import org.apache.shardingsphere.agent.core.spi.AgentTypedSPIRegistry;
@@ -29,64 +27,36 @@ import org.apache.shardingsphere.agent.core.spi.AgentTypedSPIRegistry;
*/
@Slf4j
public final class PluginServiceManager {
-
- /**
- * Set up all service.
- *
- * @param pluginConfigurations plugin configurations
- */
- @SuppressWarnings(value = {"unchecked", "rawtypes"})
- public static void setUpAllService(final Collection<PluginConfiguration> pluginConfigurations) {
- Collection<String> pluginNames = pluginConfigurations.stream().map(PluginConfiguration::getPluginName).collect(Collectors.toList());
- for (Map.Entry<String, PluginBootService> entry : AgentTypedSPIRegistry.getRegisteredServices(pluginNames, PluginBootService.class).entrySet()) {
- for (PluginConfiguration each : pluginConfigurations) {
- if (each.getPluginName().equals(entry.getKey())) {
- try {
- entry.getValue().setup(each);
- // CHECKSTYLE:OFF
- } catch (final Throwable ex) {
- // CHECKSTYLE:ON
- log.error("Failed to setup service.", ex);
- }
- }
- }
- }
- }
-
/**
* Start all service.
*
- * @param pluginConfigurations plugin configurations
+ * @param pluginConfigurationMap plugin configurations
*/
- @SuppressWarnings(value = {"unchecked", "rawtypes"})
- public static void startAllService(final Collection<PluginConfiguration> pluginConfigurations) {
- Collection<String> pluginNames = pluginConfigurations.stream().map(PluginConfiguration::getPluginName).collect(Collectors.toList());
- for (Map.Entry<String, PluginBootService> entry : AgentTypedSPIRegistry.getRegisteredServices(pluginNames, PluginBootService.class).entrySet()) {
- for (PluginConfiguration each : pluginConfigurations) {
- if (each.getPluginName().equals(entry.getKey())) {
- try {
- entry.getValue().start(each);
- // CHECKSTYLE:OFF
- } catch (final Throwable ex) {
- // CHECKSTYLE:ON
- log.error("Failed to start service.", ex);
- }
+ public static void startAllService(final Map<String, PluginConfiguration> pluginConfigurationMap) {
+ for (Map.Entry<String, PluginConfiguration> entry: pluginConfigurationMap.entrySet()) {
+ AgentTypedSPIRegistry.getRegisteredServiceOptional(PluginBootService.class, entry.getKey()).ifPresent(pluginBootService -> {
+ try {
+ pluginBootService.start(entry.getValue());
+ // CHECKSTYLE:OFF
+ } catch (final Throwable ex) {
+ // CHECKSTYLE:ON
+ log.error("Failed to start service.", ex);
}
- }
+ });
}
}
/**
- * Clean up all service.
+ * Close all service.
*/
- public static void cleanUpAllService() {
+ public static void closeAllService() {
AgentTypedSPIRegistry.getAllRegisteredService(PluginBootService.class).forEach(each -> {
try {
- each.cleanup();
+ each.close();
// CHECKSTYLE:OFF
} catch (final Throwable ex) {
// CHECKSTYLE:ON
- log.error("Failed to shutdown service.", ex);
+ log.error("Failed to close service.", ex);
}
});
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentTypedSPIRegistry.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentTypedSPIRegistry.java
index 6cd60e2..e821f50 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentTypedSPIRegistry.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/spi/AgentTypedSPIRegistry.java
@@ -49,6 +49,18 @@ public final class AgentTypedSPIRegistry {
}
/**
+ * Get registered service.
+ *
+ * @param typedSPIClass typed SPI class
+ * @param type type
+ * @param <T> type
+ * @return registered service
+ */
+ public static <T extends AgentTypedSPI> Optional<T> getRegisteredServiceOptional(final Class<T> typedSPIClass, final String type) {
+ return AgentServiceLoader.getServiceLoader(typedSPIClass).newServiceInstances().stream().filter(each -> each.getType().equalsIgnoreCase(type)).findFirst();
+ }
+
+ /**
* Get all registered service.
*
* @param typedSPIClass typed SPI class
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/YamlEngine.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/YamlEngine.java
index dc3e358..3563354 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/YamlEngine.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/YamlEngine.java
@@ -17,19 +17,12 @@
package org.apache.shardingsphere.agent.core.yaml;
-import com.google.common.base.Strings;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InputStreamReader;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Properties;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.agent.core.yaml.constructor.AgentYamlConstructor;
import org.yaml.snakeyaml.Yaml;
/**
@@ -52,54 +45,7 @@ public final class YamlEngine {
FileInputStream fileInputStream = new FileInputStream(yamlFile);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream)
) {
- return new Yaml(new AgentYamlConstructor(classType)).loadAs(inputStreamReader, classType);
+ return new Yaml().loadAs(inputStreamReader, classType);
}
}
-
- /**
- * Unmarshal YAML.
- *
- * @param yamlBytes YAML bytes
- * @param classType class type
- * @param <T> type of class
- * @return object from YAML
- * @throws IOException IO Exception
- */
- public static <T> T unmarshal(final byte[] yamlBytes, final Class<T> classType) throws IOException {
- try (InputStream inputStream = new ByteArrayInputStream(yamlBytes)) {
- return new Yaml(new AgentYamlConstructor(classType)).loadAs(inputStream, classType);
- }
- }
-
- /**
- * Unmarshal YAML.
- *
- * @param yamlContent YAML content
- * @param classType class type
- * @param <T> type of class
- * @return object from YAML
- */
- public static <T> T unmarshal(final String yamlContent, final Class<T> classType) {
- return new Yaml(new AgentYamlConstructor(classType)).loadAs(yamlContent, classType);
- }
-
- /**
- * Unmarshal YAML.
- *
- * @param yamlContent YAML content
- * @return map from YAML
- */
- public static Map<?, ?> unmarshal(final String yamlContent) {
- return Strings.isNullOrEmpty(yamlContent) ? new LinkedHashMap<>() : (Map) new Yaml().load(yamlContent);
- }
-
- /**
- * Unmarshal properties YAML.
- *
- * @param yamlContent YAML content
- * @return properties from YAML
- */
- public static Properties unmarshalProperties(final String yamlContent) {
- return Strings.isNullOrEmpty(yamlContent) ? new Properties() : new Yaml().loadAs(yamlContent, Properties.class);
- }
}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/constructor/AgentYamlConstructor.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/constructor/AgentYamlConstructor.java
deleted file mode 100644
index fbf921e..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/constructor/AgentYamlConstructor.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.yaml.constructor;
-
-import org.apache.shardingsphere.agent.core.yaml.swapper.YamlPluginConfigurationSwapperEngine;
-import org.yaml.snakeyaml.TypeDescription;
-import org.yaml.snakeyaml.constructor.Constructor;
-
-/**
- * Agent YAML constructor.
- */
-public final class AgentYamlConstructor extends Constructor {
-
- public AgentYamlConstructor(final Class<?> rootClass) {
- super(rootClass);
- YamlPluginConfigurationSwapperEngine.getYamlShortcuts().forEach((key, value) -> addTypeDescription(new TypeDescription(value, key)));
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlPluginConfigurationSwapper.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlPluginConfigurationSwapper.java
deleted file mode 100644
index 297b1ce..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlPluginConfigurationSwapper.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.yaml.swapper;
-
-import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
-import org.apache.shardingsphere.agent.core.spi.AgentTypedSPI;
-import org.apache.shardingsphere.agent.core.yaml.config.YamlPluginConfiguration;
-
-/**
- * YAML plugin configuration swapper.
- *
- * @param <Y> type of YAML plugin configuration
- * @param <T> type of plugin configuration
- */
-public interface YamlPluginConfigurationSwapper<Y extends YamlPluginConfiguration, T extends PluginConfiguration> extends YamlSwapper<Y, T>, AgentTypedSPI {
-
- /**
- * Get YAML plugin tag name.
- *
- * @return YAML plugin tag name
- */
- String getPluginTagName();
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlPluginConfigurationSwapperEngine.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlPluginConfigurationSwapperEngine.java
deleted file mode 100644
index dd8889c..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlPluginConfigurationSwapperEngine.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.yaml.swapper;
-
-import java.lang.reflect.ParameterizedType;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
-import lombok.SneakyThrows;
-import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
-import org.apache.shardingsphere.agent.core.spi.AgentServiceLoader;
-import org.apache.shardingsphere.agent.core.spi.AgentTypedSPIRegistry;
-import org.apache.shardingsphere.agent.core.yaml.config.YamlPluginConfiguration;
-
-/**
- * YAML plugin configuration swapper engine.
- */
-@SuppressWarnings("ALL")
-public final class YamlPluginConfigurationSwapperEngine {
-
- /**
- * Swap from YAML plugin configurations to plugin configurations.
- *
- * @param yamlPluginConfigurations YAML plugin configurations
- * @return plugin configurations
- */
- public static Collection<PluginConfiguration> swapToPluginConfigurations(final Collection<YamlPluginConfiguration> yamlPluginConfigurations) {
- Collection<PluginConfiguration> result = new LinkedList<>();
- Collection<String> ruleConfigurationTypes = yamlPluginConfigurations.stream().map(YamlPluginConfiguration::getPluginName).collect(Collectors.toList());
- for (Entry<String, YamlPluginConfigurationSwapper> entry : AgentTypedSPIRegistry.getRegisteredServices(ruleConfigurationTypes, YamlPluginConfigurationSwapper.class).entrySet()) {
- result.addAll(swapToRuleConfigurations(yamlPluginConfigurations, entry.getKey(), entry.getValue()));
- }
- return result;
- }
-
- private static Collection<PluginConfiguration> swapToRuleConfigurations(final Collection<YamlPluginConfiguration> yamlPluginConfigurations,
- final String type, final YamlPluginConfigurationSwapper swapper) {
- Collection<PluginConfiguration> result = new LinkedList<>();
- for (YamlPluginConfiguration each : yamlPluginConfigurations) {
- if (each.getPluginName().equals(type)) {
- result.add((PluginConfiguration) swapper.swapToObject(each));
- }
- }
- return result;
- }
-
- /**
- * Get YAML shortcuts.
- *
- * @return YAML shortcuts
- */
- @SneakyThrows(ReflectiveOperationException.class)
- public static Map<String, Class<?>> getYamlShortcuts() {
- Map<String, Class<?>> result = new HashMap<>();
- for (YamlPluginConfigurationSwapper each : AgentServiceLoader.getServiceLoader(YamlPluginConfigurationSwapper.class).newServiceInstances()) {
- Class<?> yamlRuleConfigurationClass = Class.forName(((ParameterizedType) each.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[0].getTypeName());
- result.put("!" + each.getPluginTagName(), yamlRuleConfigurationClass);
- }
- return result;
- }
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlSwapper.java b/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlSwapper.java
deleted file mode 100644
index c877ad0..0000000
--- a/shardingsphere-agent/shardingsphere-agent-core/src/main/java/org/apache/shardingsphere/agent/core/yaml/swapper/YamlSwapper.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.agent.core.yaml.swapper;
-
-import org.apache.shardingsphere.agent.core.yaml.config.YamlConfiguration;
-
-/**
- * YAML configuration swapper.
- *
- * @param <Y> type of YAML configuration
- * @param <T> type of swapped object
- */
-public interface YamlSwapper<Y extends YamlConfiguration, T> {
-
- /**
- * Swap from YAML configuration to object.
- *
- * @param yamlConfig YAML configuration
- * @return swapped object
- */
- T swapToObject(Y yamlConfig);
-}
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml b/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
index 23722ea..f83a13c 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/test/resources/conf/agent.yaml
@@ -21,17 +21,21 @@ ignorePlugins:
- test
plugins:
- - !PROMETHEUS
- host: "localhost"
+ prometheus:
+ host: "localhost"
port: 9090
- jvmInformationCollectorEnabled : true
- - !JAEGER
+ props:
+ jvmInformationCollectorEnabled : "true"
+ Jaeger:
host: "localhost"
port: 5775
- extra:
- name: Jaeger
- - !ZIPKIN
+ props:
+ JAEGER_SAMPLER_TYPE: "const"
+ JAEGER_SAMPLER_PARAM: "1"
+ JAEGER_REPORTER_LOG_SPANS: "true"
+ JAEGER_REPORTER_FLUSH_INTERVAL: "1"
+ Zipkin:
host: "localhost"
port: 15775
- extra:
- name: Zipkin
+ props:
+ name: "Zipkin"
diff --git a/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml b/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml
index fe44121..100a4df 100644
--- a/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml
+++ b/shardingsphere-agent/shardingsphere-agent-distribution/src/main/resources/conf/agent.yaml
@@ -21,21 +21,22 @@ ignorePlugins:
- test
plugins:
- - !PROMETHEUS
- host: "localhost"
+ prometheus:
+ host: "localhost"
port: 9090
- jvmInformationCollectorEnabled : true
- - !JAEGER
+ props:
+ jvmInformationCollectorEnabled : "true"
+ Jaeger:
host: "localhost"
port: 5775
- extra:
- JAEGER_SAMPLER_TYPE: const
- JAEGER_SAMPLER_PARAM: 1
- JAEGER_REPORTER_LOG_SPANS: true
- JAEGER_REPORTER_FLUSH_INTERVAL: 1
- - !ZIPKIN
+ props:
+ JAEGER_SAMPLER_TYPE: "const"
+ JAEGER_SAMPLER_PARAM: "1"
+ JAEGER_REPORTER_LOG_SPANS: "true"
+ JAEGER_REPORTER_FLUSH_INTERVAL: "1"
+ Zipkin:
host: "localhost"
port: 15775
- extra:
- name: Zipkin
+ props:
+ name: "Zipkin"
\ No newline at end of file
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootService.java
index c72983f..e4c5de0 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootService.java
@@ -23,7 +23,7 @@ import io.prometheus.client.hotspot.DefaultExports;
import java.io.IOException;
import java.net.InetSocketAddress;
import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.agent.core.config.PrometheusPluginConfiguration;
+import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
import org.apache.shardingsphere.agent.core.plugin.service.PluginBootService;
import org.apache.shardingsphere.agent.metrics.prometheus.collector.BuildInfoCollector;
@@ -31,22 +31,19 @@ import org.apache.shardingsphere.agent.metrics.prometheus.collector.BuildInfoCol
* Prometheus plugin boot service.
*/
@Slf4j
-public class PrometheusPluginBootService implements PluginBootService<PrometheusPluginConfiguration> {
+public class PrometheusPluginBootService implements PluginBootService {
private HTTPServer httpServer;
@Override
- public void setup(final PrometheusPluginConfiguration configuration) {
- registerJvm(configuration);
- }
-
- @Override
- public void start(final PrometheusPluginConfiguration configuration) {
+ public void start(final PluginConfiguration configuration) {
+ boolean enabled = Boolean.parseBoolean(configuration.getProps().getProperty("jvmInformationCollectorEnabled"));
+ registerJvm(enabled);
startServer(configuration);
}
@Override
- public void cleanup() {
+ public void close() {
if (null != httpServer) {
httpServer.stop();
}
@@ -57,15 +54,14 @@ public class PrometheusPluginBootService implements PluginBootService<Prometheus
return "Prometheus";
}
- private void registerJvm(final PrometheusPluginConfiguration configuration) {
- boolean enabled = configuration.isJvmInformationCollectorEnabled();
+ private void registerJvm(final boolean enabled) {
if (enabled) {
new BuildInfoCollector().register();
DefaultExports.initialize();
}
}
- private void startServer(final PrometheusPluginConfiguration configuration) {
+ private void startServer(final PluginConfiguration configuration) {
int port = configuration.getPort();
String host = configuration.getHost();
InetSocketAddress inetSocketAddress;
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java
index af4332f..7cd4bbd 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-jaeger/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/jaeger/service/JaegerTracingPluginBootService.java
@@ -19,25 +19,25 @@ package org.apache.shardingsphere.agent.plugin.tracing.jaeger.service;
import io.jaegertracing.Configuration;
import io.opentracing.util.GlobalTracer;
-import org.apache.shardingsphere.agent.core.config.JaegerPluginConfiguration;
+import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
import org.apache.shardingsphere.agent.core.plugin.service.PluginBootService;
/**
* Jaeger tracing plugin boot service.
*/
-public final class JaegerTracingPluginBootService implements PluginBootService<JaegerPluginConfiguration> {
+public final class JaegerTracingPluginBootService implements PluginBootService {
@Override
- public void setup(final JaegerPluginConfiguration configuration) {
- configuration.getExtra().forEach(System::setProperty);
+ public void start(final PluginConfiguration pluginConfiguration) {
+ pluginConfiguration.getProps().forEach((key, value) -> System.setProperty(String.valueOf(key), String.valueOf(value)));
Configuration.SamplerConfiguration samplerConfig = Configuration.SamplerConfiguration.fromEnv();
Configuration.ReporterConfiguration reporterConfig = Configuration.ReporterConfiguration.fromEnv()
.withSender(
Configuration.SenderConfiguration.fromEnv()
- .withAgentHost(configuration.getHost())
- .withAgentPort(configuration.getPort())
+ .withAgentHost(pluginConfiguration.getHost())
+ .withAgentPort(pluginConfiguration.getPort())
);
- Configuration config = new Configuration(configuration.getApplicationName())
+ Configuration config = new Configuration("ShardingSphere-Jaeger")
.withSampler(samplerConfig)
.withReporter(reporterConfig);
GlobalTracer.register(config.getTracer());
@@ -47,4 +47,8 @@ public final class JaegerTracingPluginBootService implements PluginBootService<J
public String getType() {
return "Jaeger";
}
+
+ @Override
+ public void close() {
+ }
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java
index b683269..f70d7f8 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-zipkin/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/zipkin/service/ZipkinTracingPluginBootService.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.agent.plugin.tracing.zipkin.service;
import brave.Tracing;
-import org.apache.shardingsphere.agent.core.config.ZipkinPluginConfiguration;
+import org.apache.shardingsphere.agent.core.config.PluginConfiguration;
import org.apache.shardingsphere.agent.core.plugin.service.PluginBootService;
import zipkin2.reporter.brave.AsyncZipkinSpanHandler;
import zipkin2.reporter.okhttp3.OkHttpSender;
@@ -26,7 +26,7 @@ import zipkin2.reporter.okhttp3.OkHttpSender;
/**
* Zipkin tracing plugin boot service.
*/
-public final class ZipkinTracingPluginBootService implements PluginBootService<ZipkinPluginConfiguration> {
+public final class ZipkinTracingPluginBootService implements PluginBootService {
private AsyncZipkinSpanHandler zipkinSpanHandler;
@@ -35,18 +35,14 @@ public final class ZipkinTracingPluginBootService implements PluginBootService<Z
private Tracing tracing;
@Override
- public void setup(final ZipkinPluginConfiguration configuration) {
+ public void start(final PluginConfiguration configuration) {
sender = OkHttpSender.create(buildHttpPath(configuration));
zipkinSpanHandler = AsyncZipkinSpanHandler.create(sender);
- }
-
- @Override
- public void start(final ZipkinPluginConfiguration configuration) {
tracing = Tracing.newBuilder().localServiceName("shardingsphere-agent").addSpanHandler(zipkinSpanHandler).build();
}
@Override
- public void cleanup() {
+ public void close() {
tracing.close();
zipkinSpanHandler.close();
sender.close();
@@ -57,7 +53,7 @@ public final class ZipkinTracingPluginBootService implements PluginBootService<Z
return "Zipkin";
}
- private String buildHttpPath(final ZipkinPluginConfiguration configuration) {
+ private String buildHttpPath(final PluginConfiguration configuration) {
return String.format("http://%s:%s", configuration.getHost(), configuration.getPort());
}
}