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 2022/12/20 13:17:08 UTC
[shardingsphere] branch master updated: Refactor AdvisorConfigurationLoader (#22998)
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 c514769825e Refactor AdvisorConfigurationLoader (#22998)
c514769825e is described below
commit c514769825ef101ba718a95af35b9588885dd32d
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Dec 20 21:17:01 2022 +0800
Refactor AdvisorConfigurationLoader (#22998)
---
.../plugin/loader/AdvisorConfigurationLoader.java | 15 ++++++++++---
.../{jdbc-advisors.yaml => advisors.yaml} | 0
.../main/resources/baselogging/proxy-advisors.yaml | 26 ----------------------
3 files changed, 12 insertions(+), 29 deletions(-)
diff --git a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AdvisorConfigurationLoader.java b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AdvisorConfigurationLoader.java
index decd30b2d92..6017a9bd5cf 100644
--- a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AdvisorConfigurationLoader.java
+++ b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/plugin/loader/AdvisorConfigurationLoader.java
@@ -28,6 +28,7 @@ import org.apache.shardingsphere.agent.core.plugin.yaml.swapper.YamlAdvisorsConf
import org.apache.shardingsphere.agent.core.spi.PluginServiceLoader;
import org.apache.shardingsphere.agent.spi.plugin.PluginBootService;
+import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@@ -53,12 +54,20 @@ public final class AdvisorConfigurationLoader {
AgentClassLoader.init(pluginJars);
for (PluginBootService each : PluginServiceLoader.newServiceInstances(PluginBootService.class, AgentClassLoader.getClassLoader())) {
if (pluginTypes.contains(each.getType())) {
- String resourceFile = String.join("/", "", each.getType().toLowerCase(), (isEnhancedForProxy ? "proxy" : "jdbc") + "-advisors.yaml");
- Collection<AdvisorConfiguration> advisorConfigs = YamlAdvisorsConfigurationSwapper.swapToObject(
- YamlAdvisorsConfigurationLoader.load(each.getClass().getResourceAsStream(resourceFile)), each.getType());
+ Collection<AdvisorConfiguration> advisorConfigs = YamlAdvisorsConfigurationSwapper
+ .swapToObject(YamlAdvisorsConfigurationLoader.load(getAdvisorsResourceStream(each, isEnhancedForProxy)), each.getType());
result.putAll(advisorConfigs.stream().collect(Collectors.toMap(AdvisorConfiguration::getTargetClassName, Function.identity())));
}
}
return ImmutableMap.<String, AdvisorConfiguration>builder().putAll(result).build();
}
+
+ private static InputStream getAdvisorsResourceStream(final PluginBootService pluginBootService, final boolean isEnhancedForProxy) {
+ InputStream result = pluginBootService.getClass().getResourceAsStream(getAdvisorsResourceFile(pluginBootService, (isEnhancedForProxy ? "proxy" : "jdbc") + "-advisors.yaml"));
+ return null == result ? pluginBootService.getClass().getResourceAsStream(getAdvisorsResourceFile(pluginBootService, "advisors.yaml")) : result;
+ }
+
+ private static String getAdvisorsResourceFile(final PluginBootService pluginBootService, final String fileName) {
+ return String.join("/", "", pluginBootService.getType().toLowerCase(), fileName);
+ }
}
diff --git a/agent/plugins/logging/base/src/main/resources/baselogging/jdbc-advisors.yaml b/agent/plugins/logging/base/src/main/resources/baselogging/advisors.yaml
similarity index 100%
rename from agent/plugins/logging/base/src/main/resources/baselogging/jdbc-advisors.yaml
rename to agent/plugins/logging/base/src/main/resources/baselogging/advisors.yaml
diff --git a/agent/plugins/logging/base/src/main/resources/baselogging/proxy-advisors.yaml b/agent/plugins/logging/base/src/main/resources/baselogging/proxy-advisors.yaml
deleted file mode 100644
index 3fe1b6be3d6..00000000000
--- a/agent/plugins/logging/base/src/main/resources/baselogging/proxy-advisors.yaml
+++ /dev/null
@@ -1,26 +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.
-#
-
-advisors:
- - target: org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory
- advice: org.apache.shardingsphere.agent.plugin.logging.base.advice.MetaDataContextsFactoryAdvice
- pointcuts:
- - name: create
- type: method
- params:
- - index: 3
- name: storageNodes
\ No newline at end of file