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 dc2618de17c Simplify advisor creation process (#23431)
dc2618de17c is described below
commit dc2618de17cb1dea08feab99197c7c6ba47d2080
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jan 9 15:29:08 2023 +0800
Simplify advisor creation process (#23431)
---
.../advisor/config/AdvisorConfigurationLoader.java | 2 +-
.../config/AdvisorConfigurationRegistry.java | 39 --------------------
.../AdvisorConfigurationRegistryFactory.java | 43 ----------------------
.../swapper/YamlAdvisorConfigurationSwapper.java | 6 +--
.../swapper/YamlAdvisorsConfigurationSwapper.java | 5 +--
.../AdvisorConfigurationRegistryFactoryTest.java | 31 ----------------
.../config/AdvisorConfigurationRegistryTest.java | 31 ----------------
.../YamlAdvisorsConfigurationSwapperTest.java | 2 +-
8 files changed, 6 insertions(+), 153 deletions(-)
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationLoader.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationLoader.java
index 05f62b7219e..c17ff11cbd4 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationLoader.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationLoader.java
@@ -56,7 +56,7 @@ public final class AdvisorConfigurationLoader {
if (null == advisorsResourceStream) {
LOGGER.info("No configuration of advisor for type `{}`.",
each);
} else {
- mergeConfigurations(result,
YamlAdvisorsConfigurationSwapper.swap(YamlAdvisorsConfigurationLoader.load(advisorsResourceStream),
each));
+ mergeConfigurations(result,
YamlAdvisorsConfigurationSwapper.swap(YamlAdvisorsConfigurationLoader.load(advisorsResourceStream)));
}
}
return result;
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationRegistry.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationRegistry.java
deleted file mode 100644
index 765d4fafc93..00000000000
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationRegistry.java
+++ /dev/null
@@ -1,39 +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.advisor.config;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Advisor configuration registry.
- */
-public final class AdvisorConfigurationRegistry {
-
- private final Map<String, AdvisorConfiguration> advisors = new
ConcurrentHashMap<>();
-
- /**
- * Get advisor configuration.
- *
- * @param targetClassName to be advised class name
- * @return advisor configuration
- */
- public AdvisorConfiguration getAdvisorConfiguration(final String
targetClassName) {
- return advisors.computeIfAbsent(targetClassName,
AdvisorConfiguration::new);
- }
-}
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationRegistryFactory.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationRegistryFactory.java
deleted file mode 100644
index 92bab3958cd..00000000000
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationRegistryFactory.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.advisor.config;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Advisor configuration registry factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class AdvisorConfigurationRegistryFactory {
-
- private static final Map<String, AdvisorConfigurationRegistry> REGISTRIES
= new ConcurrentHashMap<>();
-
- /**
- * Get advisor configuration registry.
- *
- * @param type registry type
- * @return advisor configuration registry
- */
- public static AdvisorConfigurationRegistry getRegistry(final String type) {
- return REGISTRIES.computeIfAbsent(type, each -> new
AdvisorConfigurationRegistry());
- }
-}
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorConfigurationSwapper.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorConfigurationSwapper.java
index 496083d8467..7465ca8d389 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorConfigurationSwapper.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorConfigurationSwapper.java
@@ -21,7 +21,6 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import
org.apache.shardingsphere.agent.core.advisor.config.AdvisorConfiguration;
import
org.apache.shardingsphere.agent.core.advisor.config.MethodAdvisorConfiguration;
-import
org.apache.shardingsphere.agent.core.advisor.config.AdvisorConfigurationRegistryFactory;
import
org.apache.shardingsphere.agent.core.advisor.config.yaml.entity.YamlAdvisorConfiguration;
import
org.apache.shardingsphere.agent.core.advisor.config.yaml.entity.YamlPointcutConfiguration;
@@ -35,11 +34,10 @@ public final class YamlAdvisorConfigurationSwapper {
* Swap from YAML advisor configuration to advisors configuration.
*
* @param yamlConfig YAML advisor configuration
- * @param type type
* @return advisor configuration
*/
- public static AdvisorConfiguration swap(final YamlAdvisorConfiguration
yamlConfig, final String type) {
- AdvisorConfiguration result =
AdvisorConfigurationRegistryFactory.getRegistry(type).getAdvisorConfiguration(yamlConfig.getTarget());
+ public static AdvisorConfiguration swap(final YamlAdvisorConfiguration
yamlConfig) {
+ AdvisorConfiguration result = new
AdvisorConfiguration(yamlConfig.getTarget());
for (YamlPointcutConfiguration each : yamlConfig.getPointcuts()) {
YamlPointcutConfigurationSwapper.swap(each).ifPresent(elementMatcher ->
result.getAdvisors().add(new MethodAdvisorConfiguration(elementMatcher,
yamlConfig.getAdvice())));
}
diff --git
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorsConfigurationSwapper.java
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorsConfigurationSwapper.java
index 393864cedcc..0ac766fd0db 100644
---
a/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorsConfigurationSwapper.java
+++
b/agent/core/src/main/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorsConfigurationSwapper.java
@@ -36,14 +36,13 @@ public final class YamlAdvisorsConfigurationSwapper {
* Swap from YAML advisors configuration to advisor configurations.
*
* @param yamlAdvisorsConfig YAML advisors configuration
- * @param type plugin type
* @return advisor configurations
*/
- public static Collection<AdvisorConfiguration> swap(final
YamlAdvisorsConfiguration yamlAdvisorsConfig, final String type) {
+ public static Collection<AdvisorConfiguration> swap(final
YamlAdvisorsConfiguration yamlAdvisorsConfig) {
Collection<AdvisorConfiguration> result = new LinkedList<>();
for (YamlAdvisorConfiguration each : yamlAdvisorsConfig.getAdvisors())
{
if (null != each.getTarget()) {
- result.add(YamlAdvisorConfigurationSwapper.swap(each, type));
+ result.add(YamlAdvisorConfigurationSwapper.swap(each));
}
}
return result;
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationRegistryFactoryTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationRegistryFactoryTest.java
deleted file mode 100644
index f1be6b98c09..00000000000
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationRegistryFactoryTest.java
+++ /dev/null
@@ -1,31 +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.advisor.config;
-
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class AdvisorConfigurationRegistryFactoryTest {
-
- @Test
- public void assertGetRegistryWithType() {
- assertThat(AdvisorConfigurationRegistryFactory.getRegistry("test"),
instanceOf(AdvisorConfigurationRegistry.class));
- }
-}
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationRegistryTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationRegistryTest.java
deleted file mode 100644
index 9cb2eaf8052..00000000000
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/AdvisorConfigurationRegistryTest.java
+++ /dev/null
@@ -1,31 +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.advisor.config;
-
-import org.junit.Test;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-public final class AdvisorConfigurationRegistryTest {
-
- @Test
- public void assertGetAdvisorConfiguration() {
- assertThat(new
AdvisorConfigurationRegistry().getAdvisorConfiguration("test"),
instanceOf(AdvisorConfiguration.class));
- }
-}
diff --git
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java
index 1fa63102372..94454429d49 100644
---
a/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java
+++
b/agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/config/yaml/swapper/YamlAdvisorsConfigurationSwapperTest.java
@@ -38,7 +38,7 @@ public final class YamlAdvisorsConfigurationSwapperTest {
@Test
public void assertSwapToObject() {
Collection<AdvisorConfiguration> actual =
YamlAdvisorsConfigurationSwapper.swap(
- new
Yaml().loadAs(getClass().getResourceAsStream("/META-INF/conf/advisors.yaml"),
YamlAdvisorsConfiguration.class), "YAML_FIXTURE");
+ new
Yaml().loadAs(getClass().getResourceAsStream("/META-INF/conf/advisors.yaml"),
YamlAdvisorsConfiguration.class));
assertThat(actual.size(), is(1));
assertAdvisorConfiguration(actual.iterator().next());
}