You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2023/06/20 18:04:14 UTC
[shardingsphere] branch master updated: Refactor global rule event (#26463)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 edd92ee89aa Refactor global rule event (#26463)
edd92ee89aa is described below
commit edd92ee89aa4792968e5b47b1211165e78774294
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Wed Jun 21 02:04:07 2023 +0800
Refactor global rule event (#26463)
* Refactor global rule event
* Fix ci
* Fix bug
* Remove unless event
* Fix checkstyle
* Fix package path
* Fix ci
---
.../converter/GlobalRuleNodeConverter.java | 27 ++++++---
.../converter/GlobalRuleNodeConverterTest.java | 16 ++++--
.../AuthorityRuleConfigurationEventBuilder.java | 67 ----------------------
.../NewYamlAuthorityRuleConfigurationSwapper.java | 2 +-
...re.mode.spi.GlobalRuleConfigurationEventBuilder | 19 ------
.../GlobalClockRuleConfigurationEventBuilder.java | 67 ----------------------
...NewYamlGlobalClockRuleConfigurationSwapper.java | 2 +-
...re.mode.spi.GlobalRuleConfigurationEventBuilder | 18 ------
.../LoggingRuleConfigurationEventBuilder.java | 67 ----------------------
.../NewYamlLoggingRuleConfigurationSwapper.java | 2 +-
...re.mode.spi.GlobalRuleConfigurationEventBuilder | 18 ------
.../config/global/GlobalPersistService.java | 11 ++++
.../config/global/NewGlobalRulePersistService.java | 6 ++
...SQLFederationRuleConfigurationEventBuilder.java | 67 ----------------------
...wYamlSQLFederationRuleConfigurationSwapper.java | 2 +-
...re.mode.spi.GlobalRuleConfigurationEventBuilder | 18 ------
.../SQLParserRuleConfigurationEventBuilder.java | 67 ----------------------
.../NewYamlSQLParserRuleConfigurationSwapper.java | 2 +-
...re.mode.spi.GlobalRuleConfigurationEventBuilder | 18 ------
.../SQLTranslatorConfigurationEventBuilder.java | 67 ----------------------
...wYamlSQLTranslatorRuleConfigurationSwapper.java | 2 +-
...re.mode.spi.GlobalRuleConfigurationEventBuilder | 18 ------
.../TrafficRuleConfigurationEventBuilder.java | 67 ----------------------
.../NewYamlTrafficRuleConfigurationSwapper.java | 2 +-
...re.mode.spi.GlobalRuleConfigurationEventBuilder | 18 ------
.../TransactionRuleConfigurationEventBuilder.java | 67 ----------------------
...NewYamlTransactionRuleConfigurationSwapper.java | 2 +-
...re.mode.spi.GlobalRuleConfigurationEventBuilder | 18 ------
.../spi/GlobalRuleConfigurationEventBuilder.java | 37 ------------
.../global}/AlterGlobalRuleConfigurationEvent.java | 5 +-
.../DeleteGlobalRuleConfigurationEvent.java | 6 +-
.../watcher/NewGlobalRuleChangedWatcher.java | 20 ++++---
.../NewConfigurationChangedSubscriber.java | 10 +++-
33 files changed, 75 insertions(+), 760 deletions(-)
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/global/converter/GlobalRuleNodeConverter.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/converter/GlobalRuleNodeConverter.java
similarity index 70%
rename from infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/global/converter/GlobalRuleNodeConverter.java
rename to infra/common/src/main/java/org/apache/shardingsphere/infra/config/converter/GlobalRuleNodeConverter.java
index d7db9c27553..58fa450f2cd 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/global/converter/GlobalRuleNodeConverter.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/converter/GlobalRuleNodeConverter.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.config.rule.global.converter;
+package org.apache.shardingsphere.infra.config.converter;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -52,19 +52,30 @@ public final class GlobalRuleNodeConverter {
}
/**
- * Is expected rule name.
+ * Is active version path.
*
- * @param ruleName rule name
* @param rulePath rule path
- * @return true or false
+ * @return version
*/
- public static boolean isExpectedRuleName(final String ruleName, final String rulePath) {
- Pattern pattern = Pattern.compile(getRootNode(ruleName) + "\\.*", Pattern.CASE_INSENSITIVE);
+ public static boolean isActiveVersionPath(final String rulePath) {
+ Pattern pattern = Pattern.compile(getRuleNameNode() + "/([\\w\\-]+)/active_version$", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(rulePath);
return matcher.find();
}
- private static String getRootNode(final String ruleName) {
- return String.join("/", ruleName);
+ /**
+ * Get rule name.
+ *
+ * @param rulePath rule path
+ * @return rule name
+ */
+ public static Optional<String> getRuleName(final String rulePath) {
+ Pattern pattern = Pattern.compile(getRuleNameNode() + "/([\\w\\-]+)/active_version$", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(rulePath);
+ return matcher.find() ? Optional.of(matcher.group(1)) : Optional.empty();
+ }
+
+ private static String getRuleNameNode() {
+ return String.join("/", "", ROOT_NODE);
}
}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/converter/GlobalRuleNodeConverterTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/converter/GlobalRuleNodeConverterTest.java
similarity index 72%
rename from infra/common/src/test/java/org/apache/shardingsphere/infra/converter/GlobalRuleNodeConverterTest.java
rename to infra/common/src/test/java/org/apache/shardingsphere/infra/config/converter/GlobalRuleNodeConverterTest.java
index 8791913e6c2..d76a934ea3f 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/converter/GlobalRuleNodeConverterTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/converter/GlobalRuleNodeConverterTest.java
@@ -15,15 +15,14 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.converter;
+package org.apache.shardingsphere.infra.config.converter;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
import org.junit.jupiter.api.Test;
import java.util.Optional;
-import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTrue;
class GlobalRuleNodeConverterTest {
@@ -36,7 +35,14 @@ class GlobalRuleNodeConverterTest {
}
@Test
- void assertIsExpectedRuleName() {
- assertTrue(GlobalRuleNodeConverter.isExpectedRuleName("transaction", "/rules/transaction/versions/0"));
+ void assertIsActiveVersionPath() {
+ assertTrue(GlobalRuleNodeConverter.isActiveVersionPath("/rules/transaction/active_version"));
+ }
+
+ @Test
+ void assertGetRuleName() {
+ Optional<String> actual = GlobalRuleNodeConverter.getRuleName("/rules/transaction/active_version");
+ assertTrue(actual.isPresent());
+ assertThat(actual.get(), is("transaction"));
}
}
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/event/AuthorityRuleConfigurationEventBuilder.java b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/event/AuthorityRuleConfigurationEventBuilder.java
deleted file mode 100644
index 1d46a33e041..00000000000
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/event/AuthorityRuleConfigurationEventBuilder.java
+++ /dev/null
@@ -1,67 +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.authority.event;
-
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
-import org.apache.shardingsphere.authority.rule.AuthorityRule;
-import org.apache.shardingsphere.authority.yaml.config.YamlAuthorityRuleConfiguration;
-import org.apache.shardingsphere.authority.yaml.swapper.YamlAuthorityRuleConfigurationSwapper;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
-import org.apache.shardingsphere.infra.config.rule.global.event.AlterGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.config.rule.global.event.DeleteGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
-import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.mode.event.DataChangedEvent;
-import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
-import org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder;
-
-import java.util.Optional;
-
-/**
- * Authority rule configuration event builder.
- */
-public final class AuthorityRuleConfigurationEventBuilder implements GlobalRuleConfigurationEventBuilder {
-
- private static final String AUTHORITY = "authority";
-
- private static final String RULE_TYPE = AuthorityRule.class.getSimpleName();
-
- @Override
- public Optional<GovernanceEvent> build(final DataChangedEvent event) {
- if (!GlobalRuleNodeConverter.isExpectedRuleName(AUTHORITY, event.getKey()) || Strings.isNullOrEmpty(event.getValue())) {
- return Optional.empty();
- }
- Optional<String> version = GlobalRuleNodeConverter.getVersion(AUTHORITY, event.getKey());
- if (version.isPresent() && !Strings.isNullOrEmpty(event.getValue())) {
- return buildEvent(event, version.get());
- }
- return Optional.empty();
- }
-
- private Optional<GovernanceEvent> buildEvent(final DataChangedEvent event, final String version) {
- if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) {
- return Optional.of(new AlterGlobalRuleConfigurationEvent(swapToConfig(event.getValue()), RULE_TYPE, event.getKey(), version));
- }
- return Optional.of(new DeleteGlobalRuleConfigurationEvent(RULE_TYPE, event.getKey(), version));
- }
-
- private AuthorityRuleConfiguration swapToConfig(final String yamlContext) {
- return new YamlAuthorityRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlAuthorityRuleConfiguration.class));
- }
-}
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
index 05a0daa0c81..1ca57cc9585 100644
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
+++ b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
@@ -23,7 +23,7 @@ import org.apache.shardingsphere.authority.converter.YamlUsersConfigurationConve
import org.apache.shardingsphere.authority.rule.builder.DefaultAuthorityRuleConfigurationBuilder;
import org.apache.shardingsphere.authority.yaml.config.YamlAuthorityRuleConfiguration;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
diff --git a/kernel/authority/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder b/kernel/authority/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
deleted file mode 100644
index a0cef66e463..00000000000
--- a/kernel/authority/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
+++ /dev/null
@@ -1,19 +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.
-#
-
-org.apache.shardingsphere.authority.event.AuthorityRuleConfigurationEventBuilder
-
diff --git a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/event/GlobalClockRuleConfigurationEventBuilder.java b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/event/GlobalClockRuleConfigurationEventBuilder.java
deleted file mode 100644
index 3ed057a98c4..00000000000
--- a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/event/GlobalClockRuleConfigurationEventBuilder.java
+++ /dev/null
@@ -1,67 +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.globalclock.core.event;
-
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.globalclock.api.config.GlobalClockRuleConfiguration;
-import org.apache.shardingsphere.globalclock.core.rule.GlobalClockRule;
-import org.apache.shardingsphere.globalclock.core.yaml.config.YamlGlobalClockRuleConfiguration;
-import org.apache.shardingsphere.globalclock.core.yaml.swapper.YamlGlobalClockRuleConfigurationSwapper;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
-import org.apache.shardingsphere.infra.config.rule.global.event.AlterGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.config.rule.global.event.DeleteGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
-import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.mode.event.DataChangedEvent;
-import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
-import org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder;
-
-import java.util.Optional;
-
-/**
- * Global clock rule configuration event builder.
- */
-public final class GlobalClockRuleConfigurationEventBuilder implements GlobalRuleConfigurationEventBuilder {
-
- private static final String GLOBAL_CLOCK = "global_clock";
-
- private static final String RULE_TYPE = GlobalClockRule.class.getSimpleName();
-
- @Override
- public Optional<GovernanceEvent> build(final DataChangedEvent event) {
- if (!GlobalRuleNodeConverter.isExpectedRuleName(GLOBAL_CLOCK, event.getKey()) || Strings.isNullOrEmpty(event.getValue())) {
- return Optional.empty();
- }
- Optional<String> version = GlobalRuleNodeConverter.getVersion(GLOBAL_CLOCK, event.getKey());
- if (version.isPresent() && !Strings.isNullOrEmpty(event.getValue())) {
- return buildEvent(event, version.get());
- }
- return Optional.empty();
- }
-
- private Optional<GovernanceEvent> buildEvent(final DataChangedEvent event, final String version) {
- if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) {
- return Optional.of(new AlterGlobalRuleConfigurationEvent(swapToConfig(event.getValue()), RULE_TYPE, event.getKey(), version));
- }
- return Optional.of(new DeleteGlobalRuleConfigurationEvent(RULE_TYPE, event.getKey(), version));
- }
-
- private GlobalClockRuleConfiguration swapToConfig(final String yamlContext) {
- return new YamlGlobalClockRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlGlobalClockRuleConfiguration.class));
- }
-}
diff --git a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/NewYamlGlobalClockRuleConfigurationSwapper.java b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/NewYamlGlobalClockRuleConfigurationSwapper.java
index 7d8c5fc3066..ff2607cbbd5 100644
--- a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/NewYamlGlobalClockRuleConfigurationSwapper.java
+++ b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/NewYamlGlobalClockRuleConfigurationSwapper.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.globalclock.core.yaml.swapper;
import org.apache.shardingsphere.globalclock.api.config.GlobalClockRuleConfiguration;
import org.apache.shardingsphere.globalclock.core.rule.constant.GlobalClockOrder;
import org.apache.shardingsphere.globalclock.core.yaml.config.YamlGlobalClockRuleConfiguration;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper;
diff --git a/kernel/global-clock/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder b/kernel/global-clock/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
deleted file mode 100644
index 9ee04b75cd0..00000000000
--- a/kernel/global-clock/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.globalclock.core.event.GlobalClockRuleConfigurationEventBuilder
diff --git a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/event/LoggingRuleConfigurationEventBuilder.java b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/event/LoggingRuleConfigurationEventBuilder.java
deleted file mode 100644
index 0f717806e2d..00000000000
--- a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/event/LoggingRuleConfigurationEventBuilder.java
+++ /dev/null
@@ -1,67 +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.logging.event;
-
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
-import org.apache.shardingsphere.infra.config.rule.global.event.AlterGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.config.rule.global.event.DeleteGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
-import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.logging.config.LoggingRuleConfiguration;
-import org.apache.shardingsphere.logging.rule.LoggingRule;
-import org.apache.shardingsphere.logging.yaml.config.YamlLoggingRuleConfiguration;
-import org.apache.shardingsphere.logging.yaml.swapper.YamlLoggingRuleConfigurationSwapper;
-import org.apache.shardingsphere.mode.event.DataChangedEvent;
-import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
-import org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder;
-
-import java.util.Optional;
-
-/**
- * Logging rule configuration event builder.
- */
-public final class LoggingRuleConfigurationEventBuilder implements GlobalRuleConfigurationEventBuilder {
-
- private static final String LOGGING = "logging";
-
- private static final String RULE_TYPE = LoggingRule.class.getSimpleName();
-
- @Override
- public Optional<GovernanceEvent> build(final DataChangedEvent event) {
- if (!GlobalRuleNodeConverter.isExpectedRuleName(LOGGING, event.getKey()) || Strings.isNullOrEmpty(event.getValue())) {
- return Optional.empty();
- }
- Optional<String> version = GlobalRuleNodeConverter.getVersion(LOGGING, event.getKey());
- if (version.isPresent() && !Strings.isNullOrEmpty(event.getValue())) {
- return buildEvent(event, version.get());
- }
- return Optional.empty();
- }
-
- private Optional<GovernanceEvent> buildEvent(final DataChangedEvent event, final String version) {
- if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) {
- return Optional.of(new AlterGlobalRuleConfigurationEvent(swapToConfig(event.getValue()), RULE_TYPE, event.getKey(), version));
- }
- return Optional.of(new DeleteGlobalRuleConfigurationEvent(RULE_TYPE, event.getKey(), version));
- }
-
- private LoggingRuleConfiguration swapToConfig(final String yamlContext) {
- return new YamlLoggingRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlLoggingRuleConfiguration.class));
- }
-}
diff --git a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/NewYamlLoggingRuleConfigurationSwapper.java b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/NewYamlLoggingRuleConfigurationSwapper.java
index 30ef5e5c21d..6fecf838eb7 100644
--- a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/NewYamlLoggingRuleConfigurationSwapper.java
+++ b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/NewYamlLoggingRuleConfigurationSwapper.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.logging.yaml.swapper;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper;
diff --git a/kernel/logging/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder b/kernel/logging/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
deleted file mode 100644
index 4370340f01a..00000000000
--- a/kernel/logging/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.logging.event.LoggingRuleConfigurationEventBuilder
diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalPersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalPersistService.java
index 6f2202d8568..85eab13b6b1 100644
--- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalPersistService.java
+++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/GlobalPersistService.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.metadata.persist.service.config.global;
+import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion;
@@ -52,6 +53,16 @@ public interface GlobalPersistService<T> {
*/
T load();
+ /**
+ * Load single rule configuration.
+ *
+ * @param ruleName rule name
+ * @return single rule configuration
+ */
+ default Collection<RuleConfiguration> load(String ruleName) {
+ return Collections.emptyList();
+ }
+
/**
* TODO remove this after meta data refactor completed
* Load all users.
diff --git a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/NewGlobalRulePersistService.java b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/NewGlobalRulePersistService.java
index d161bf00bc0..2e40107fbcd 100644
--- a/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/NewGlobalRulePersistService.java
+++ b/kernel/metadata/core/src/main/java/org/apache/shardingsphere/metadata/persist/service/config/global/NewGlobalRulePersistService.java
@@ -101,6 +101,12 @@ public final class NewGlobalRulePersistService extends AbstractPersistService im
return dataNodes.isEmpty() ? Collections.emptyList() : new NewYamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(dataNodes);
}
+ @Override
+ public Collection<RuleConfiguration> load(final String ruleName) {
+ Collection<YamlDataNode> dataNodes = getDataNodes(NewGlobalNode.getGlobalRuleVersionsNode(ruleName));
+ return dataNodes.isEmpty() ? Collections.emptyList() : new NewYamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(dataNodes);
+ }
+
/**
* TODO Avoid load all keys.
* Load all users.
diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/event/SQLFederationRuleConfigurationEventBuilder.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/event/SQLFederationRuleConfigurationEventBuilder.java
deleted file mode 100644
index f568d13e924..00000000000
--- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/event/SQLFederationRuleConfigurationEventBuilder.java
+++ /dev/null
@@ -1,67 +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.sqlfederation.event;
-
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
-import org.apache.shardingsphere.infra.config.rule.global.event.AlterGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.config.rule.global.event.DeleteGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
-import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.mode.event.DataChangedEvent;
-import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
-import org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder;
-import org.apache.shardingsphere.sqlfederation.api.config.SQLFederationRuleConfiguration;
-import org.apache.shardingsphere.sqlfederation.rule.SQLFederationRule;
-import org.apache.shardingsphere.sqlfederation.yaml.config.YamlSQLFederationRuleConfiguration;
-import org.apache.shardingsphere.sqlfederation.yaml.swapper.YamlSQLFederationRuleConfigurationSwapper;
-
-import java.util.Optional;
-
-/**
- * SQL federation rule configuration event builder.
- */
-public final class SQLFederationRuleConfigurationEventBuilder implements GlobalRuleConfigurationEventBuilder {
-
- private static final String SQL_FEDERATION = "sql_federation";
-
- private static final String RULE_TYPE = SQLFederationRule.class.getSimpleName();
-
- @Override
- public Optional<GovernanceEvent> build(final DataChangedEvent event) {
- if (!GlobalRuleNodeConverter.isExpectedRuleName(SQL_FEDERATION, event.getKey()) || Strings.isNullOrEmpty(event.getValue())) {
- return Optional.empty();
- }
- Optional<String> version = GlobalRuleNodeConverter.getVersion(SQL_FEDERATION, event.getKey());
- if (version.isPresent() && !Strings.isNullOrEmpty(event.getValue())) {
- return buildEvent(event, version.get());
- }
- return Optional.empty();
- }
-
- private Optional<GovernanceEvent> buildEvent(final DataChangedEvent event, final String version) {
- if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) {
- return Optional.of(new AlterGlobalRuleConfigurationEvent(swapToConfig(event.getValue()), RULE_TYPE, event.getKey(), version));
- }
- return Optional.of(new DeleteGlobalRuleConfigurationEvent(RULE_TYPE, event.getKey(), version));
- }
-
- private SQLFederationRuleConfiguration swapToConfig(final String yamlContext) {
- return new YamlSQLFederationRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlSQLFederationRuleConfiguration.class));
- }
-}
diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapper.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapper.java
index 4e7db32ef02..01c4136db22 100644
--- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapper.java
+++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapper.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sqlfederation.yaml.swapper;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper;
diff --git a/kernel/sql-federation/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder b/kernel/sql-federation/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
deleted file mode 100644
index bd2dfd8a08d..00000000000
--- a/kernel/sql-federation/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.sqlfederation.event.SQLFederationRuleConfigurationEventBuilder
diff --git a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/event/SQLParserRuleConfigurationEventBuilder.java b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/event/SQLParserRuleConfigurationEventBuilder.java
deleted file mode 100644
index 87afe5f5719..00000000000
--- a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/event/SQLParserRuleConfigurationEventBuilder.java
+++ /dev/null
@@ -1,67 +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.parser.event;
-
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
-import org.apache.shardingsphere.infra.config.rule.global.event.AlterGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.config.rule.global.event.DeleteGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
-import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.mode.event.DataChangedEvent;
-import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
-import org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder;
-import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
-import org.apache.shardingsphere.parser.rule.SQLParserRule;
-import org.apache.shardingsphere.parser.yaml.config.YamlSQLParserRuleConfiguration;
-import org.apache.shardingsphere.parser.yaml.swapper.YamlSQLParserRuleConfigurationSwapper;
-
-import java.util.Optional;
-
-/**
- * SQL parser rule configuration event builder.
- */
-public final class SQLParserRuleConfigurationEventBuilder implements GlobalRuleConfigurationEventBuilder {
-
- private static final String SQL_PARSER = "sql_parser";
-
- private static final String RULE_TYPE = SQLParserRule.class.getSimpleName();
-
- @Override
- public Optional<GovernanceEvent> build(final DataChangedEvent event) {
- if (!GlobalRuleNodeConverter.isExpectedRuleName(SQL_PARSER, event.getKey()) || Strings.isNullOrEmpty(event.getValue())) {
- return Optional.empty();
- }
- Optional<String> version = GlobalRuleNodeConverter.getVersion(SQL_PARSER, event.getKey());
- if (version.isPresent() && !Strings.isNullOrEmpty(event.getValue())) {
- return buildEvent(event, version.get());
- }
- return Optional.empty();
- }
-
- private Optional<GovernanceEvent> buildEvent(final DataChangedEvent event, final String version) {
- if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) {
- return Optional.of(new AlterGlobalRuleConfigurationEvent(swapToConfig(event.getValue()), RULE_TYPE, event.getKey(), version));
- }
- return Optional.of(new DeleteGlobalRuleConfigurationEvent(RULE_TYPE, event.getKey(), version));
- }
-
- private SQLParserRuleConfiguration swapToConfig(final String yamlContext) {
- return new YamlSQLParserRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlSQLParserRuleConfiguration.class));
- }
-}
diff --git a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/NewYamlSQLParserRuleConfigurationSwapper.java b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/NewYamlSQLParserRuleConfigurationSwapper.java
index 315cf52b806..8909f1b38a0 100644
--- a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/NewYamlSQLParserRuleConfigurationSwapper.java
+++ b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/NewYamlSQLParserRuleConfigurationSwapper.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.parser.yaml.swapper;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper;
diff --git a/kernel/sql-parser/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder b/kernel/sql-parser/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
deleted file mode 100644
index 058ff9152e4..00000000000
--- a/kernel/sql-parser/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.parser.event.SQLParserRuleConfigurationEventBuilder
diff --git a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/event/SQLTranslatorConfigurationEventBuilder.java b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/event/SQLTranslatorConfigurationEventBuilder.java
deleted file mode 100644
index 9897d20ca7a..00000000000
--- a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/event/SQLTranslatorConfigurationEventBuilder.java
+++ /dev/null
@@ -1,67 +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.sqltranslator.event;
-
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
-import org.apache.shardingsphere.infra.config.rule.global.event.AlterGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.config.rule.global.event.DeleteGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
-import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.mode.event.DataChangedEvent;
-import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
-import org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder;
-import org.apache.shardingsphere.sqltranslator.api.config.SQLTranslatorRuleConfiguration;
-import org.apache.shardingsphere.sqltranslator.rule.SQLTranslatorRule;
-import org.apache.shardingsphere.sqltranslator.yaml.config.YamlSQLTranslatorRuleConfiguration;
-import org.apache.shardingsphere.sqltranslator.yaml.swapper.YamlSQLTranslatorRuleConfigurationSwapper;
-
-import java.util.Optional;
-
-/**
- * SQL parser rule configuration event builder.
- */
-public final class SQLTranslatorConfigurationEventBuilder implements GlobalRuleConfigurationEventBuilder {
-
- private static final String SQL_TRANSLATOR = "sql_translator";
-
- private static final String RULE_TYPE = SQLTranslatorRule.class.getSimpleName();
-
- @Override
- public Optional<GovernanceEvent> build(final DataChangedEvent event) {
- if (!GlobalRuleNodeConverter.isExpectedRuleName(SQL_TRANSLATOR, event.getKey()) || Strings.isNullOrEmpty(event.getValue())) {
- return Optional.empty();
- }
- Optional<String> version = GlobalRuleNodeConverter.getVersion(SQL_TRANSLATOR, event.getKey());
- if (version.isPresent() && !Strings.isNullOrEmpty(event.getValue())) {
- return buildEvent(event, version.get());
- }
- return Optional.empty();
- }
-
- private Optional<GovernanceEvent> buildEvent(final DataChangedEvent event, final String version) {
- if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) {
- return Optional.of(new AlterGlobalRuleConfigurationEvent(swapToConfig(event.getValue()), RULE_TYPE, event.getKey(), version));
- }
- return Optional.of(new DeleteGlobalRuleConfigurationEvent(RULE_TYPE, event.getKey(), version));
- }
-
- private SQLTranslatorRuleConfiguration swapToConfig(final String yamlContext) {
- return new YamlSQLTranslatorRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlSQLTranslatorRuleConfiguration.class));
- }
-}
diff --git a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/NewYamlSQLTranslatorRuleConfigurationSwapper.java b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/NewYamlSQLTranslatorRuleConfigurationSwapper.java
index 57d5c344601..e6c375c10bd 100644
--- a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/NewYamlSQLTranslatorRuleConfigurationSwapper.java
+++ b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/NewYamlSQLTranslatorRuleConfigurationSwapper.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sqltranslator.yaml.swapper;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper;
diff --git a/kernel/sql-translator/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder b/kernel/sql-translator/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
deleted file mode 100644
index c35e2a25846..00000000000
--- a/kernel/sql-translator/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.sqltranslator.event.SQLTranslatorConfigurationEventBuilder
diff --git a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/event/TrafficRuleConfigurationEventBuilder.java b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/event/TrafficRuleConfigurationEventBuilder.java
deleted file mode 100644
index 3a77bc1c3ce..00000000000
--- a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/event/TrafficRuleConfigurationEventBuilder.java
+++ /dev/null
@@ -1,67 +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.traffic.event;
-
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
-import org.apache.shardingsphere.infra.config.rule.global.event.AlterGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.config.rule.global.event.DeleteGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
-import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.mode.event.DataChangedEvent;
-import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
-import org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder;
-import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
-import org.apache.shardingsphere.traffic.rule.TrafficRule;
-import org.apache.shardingsphere.traffic.yaml.config.YamlTrafficRuleConfiguration;
-import org.apache.shardingsphere.traffic.yaml.swapper.YamlTrafficRuleConfigurationSwapper;
-
-import java.util.Optional;
-
-/**
- * Traffic rule configuration event builder.
- */
-public final class TrafficRuleConfigurationEventBuilder implements GlobalRuleConfigurationEventBuilder {
-
- private static final String TRAFFIC = "traffic";
-
- private static final String RULE_TYPE = TrafficRule.class.getSimpleName();
-
- @Override
- public Optional<GovernanceEvent> build(final DataChangedEvent event) {
- if (!GlobalRuleNodeConverter.isExpectedRuleName(TRAFFIC, event.getKey()) || Strings.isNullOrEmpty(event.getValue())) {
- return Optional.empty();
- }
- Optional<String> version = GlobalRuleNodeConverter.getVersion(TRAFFIC, event.getKey());
- if (version.isPresent() && !Strings.isNullOrEmpty(event.getValue())) {
- return buildEvent(event, version.get());
- }
- return Optional.empty();
- }
-
- private Optional<GovernanceEvent> buildEvent(final DataChangedEvent event, final String version) {
- if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) {
- return Optional.of(new AlterGlobalRuleConfigurationEvent(swapToConfig(event.getValue()), RULE_TYPE, event.getKey(), version));
- }
- return Optional.of(new DeleteGlobalRuleConfigurationEvent(RULE_TYPE, event.getKey(), version));
- }
-
- private TrafficRuleConfiguration swapToConfig(final String yamlContext) {
- return new YamlTrafficRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlTrafficRuleConfiguration.class));
- }
-}
diff --git a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapper.java b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapper.java
index 578bb1a00a1..ada13638c32 100644
--- a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapper.java
+++ b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapper.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.traffic.yaml.swapper;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.algorithm.YamlAlgorithmConfigurationSwapper;
diff --git a/kernel/traffic/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder b/kernel/traffic/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
deleted file mode 100644
index a76730d6256..00000000000
--- a/kernel/traffic/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.traffic.event.TrafficRuleConfigurationEventBuilder
diff --git a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/event/TransactionRuleConfigurationEventBuilder.java b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/event/TransactionRuleConfigurationEventBuilder.java
deleted file mode 100644
index 3ed67e264f5..00000000000
--- a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/event/TransactionRuleConfigurationEventBuilder.java
+++ /dev/null
@@ -1,67 +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.transaction.event;
-
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
-import org.apache.shardingsphere.infra.config.rule.global.event.AlterGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.config.rule.global.event.DeleteGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
-import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
-import org.apache.shardingsphere.mode.event.DataChangedEvent;
-import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
-import org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder;
-import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
-import org.apache.shardingsphere.transaction.rule.TransactionRule;
-import org.apache.shardingsphere.transaction.yaml.config.YamlTransactionRuleConfiguration;
-import org.apache.shardingsphere.transaction.yaml.swapper.YamlTransactionRuleConfigurationSwapper;
-
-import java.util.Optional;
-
-/**
- * Transaction rule configuration event builder.
- */
-public final class TransactionRuleConfigurationEventBuilder implements GlobalRuleConfigurationEventBuilder {
-
- private static final String TRANSACTION = "transaction";
-
- private static final String RULE_TYPE = TransactionRule.class.getSimpleName();
-
- @Override
- public Optional<GovernanceEvent> build(final DataChangedEvent event) {
- if (!GlobalRuleNodeConverter.isExpectedRuleName(TRANSACTION, event.getKey()) || Strings.isNullOrEmpty(event.getValue())) {
- return Optional.empty();
- }
- Optional<String> version = GlobalRuleNodeConverter.getVersion(TRANSACTION, event.getKey());
- if (version.isPresent() && !Strings.isNullOrEmpty(event.getValue())) {
- return buildEvent(event, version.get());
- }
- return Optional.empty();
- }
-
- private Optional<GovernanceEvent> buildEvent(final DataChangedEvent event, final String version) {
- if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) {
- return Optional.of(new AlterGlobalRuleConfigurationEvent(swapToConfig(event.getValue()), RULE_TYPE, event.getKey(), version));
- }
- return Optional.of(new DeleteGlobalRuleConfigurationEvent(RULE_TYPE, event.getKey(), version));
- }
-
- private TransactionRuleConfiguration swapToConfig(final String yamlContext) {
- return new YamlTransactionRuleConfigurationSwapper().swapToObject(YamlEngine.unmarshal(yamlContext, YamlTransactionRuleConfiguration.class));
- }
-}
diff --git a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapper.java b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapper.java
index ca5c6f1fac7..7faacd87633 100644
--- a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapper.java
+++ b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapper.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.transaction.yaml.swapper;
-import org.apache.shardingsphere.infra.config.rule.global.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper;
diff --git a/kernel/transaction/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder b/kernel/transaction/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
deleted file mode 100644
index 2b0e3bb244e..00000000000
--- a/kernel/transaction/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.apache.shardingsphere.transaction.event.TransactionRuleConfigurationEventBuilder
diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/GlobalRuleConfigurationEventBuilder.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/GlobalRuleConfigurationEventBuilder.java
deleted file mode 100644
index 24ca0990acb..00000000000
--- a/mode/api/src/main/java/org/apache/shardingsphere/mode/spi/GlobalRuleConfigurationEventBuilder.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.mode.spi;
-
-import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
-import org.apache.shardingsphere.mode.event.DataChangedEvent;
-
-import java.util.Optional;
-
-/**
- * Rule configuration event builder.
- */
-public interface GlobalRuleConfigurationEventBuilder {
-
- /**
- * Build global rule changed event.
- *
- * @param event data changed event
- * @return rule changed event
- */
- Optional<GovernanceEvent> build(DataChangedEvent event);
-}
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/global/event/AlterGlobalRuleConfigurationEvent.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/config/global/AlterGlobalRuleConfigurationEvent.java
similarity index 87%
rename from infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/global/event/AlterGlobalRuleConfigurationEvent.java
rename to mode/core/src/main/java/org/apache/shardingsphere/mode/event/config/global/AlterGlobalRuleConfigurationEvent.java
index a06748a47bb..e93bac00163 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/global/event/AlterGlobalRuleConfigurationEvent.java
+++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/config/global/AlterGlobalRuleConfigurationEvent.java
@@ -15,11 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.config.rule.global.event;
+package org.apache.shardingsphere.mode.event.config.global;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
/**
@@ -29,8 +28,6 @@ import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
@Getter
public final class AlterGlobalRuleConfigurationEvent implements GovernanceEvent {
- private final RuleConfiguration config;
-
private final String ruleSimpleName;
private final String activeVersionKey;
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/global/event/DeleteGlobalRuleConfigurationEvent.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/config/global/DeleteGlobalRuleConfigurationEvent.java
similarity index 88%
rename from infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/global/event/DeleteGlobalRuleConfigurationEvent.java
rename to mode/core/src/main/java/org/apache/shardingsphere/mode/event/config/global/DeleteGlobalRuleConfigurationEvent.java
index a603147d5fb..d3a415f9d31 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/rule/global/event/DeleteGlobalRuleConfigurationEvent.java
+++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/config/global/DeleteGlobalRuleConfigurationEvent.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.config.rule.global.event;
+package org.apache.shardingsphere.mode.event.config.global;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -29,8 +29,4 @@ import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
public final class DeleteGlobalRuleConfigurationEvent implements GovernanceEvent {
private final String ruleSimpleName;
-
- private final String activeVersionKey;
-
- private final String version;
}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/watcher/NewGlobalRuleChangedWatcher.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/watcher/NewGlobalRuleChangedWatcher.java
index 6d9ec4877e3..a36e5ed2c78 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/watcher/NewGlobalRuleChangedWatcher.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/watcher/NewGlobalRuleChangedWatcher.java
@@ -18,12 +18,13 @@
package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.watcher;
import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
-import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
import org.apache.shardingsphere.metadata.persist.node.GlobalNode;
import org.apache.shardingsphere.mode.event.DataChangedEvent;
import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
+import org.apache.shardingsphere.mode.event.config.global.AlterGlobalRuleConfigurationEvent;
+import org.apache.shardingsphere.mode.event.config.global.DeleteGlobalRuleConfigurationEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.NewGovernanceWatcher;
-import org.apache.shardingsphere.mode.spi.GlobalRuleConfigurationEventBuilder;
import java.util.Arrays;
import java.util.Collection;
@@ -36,8 +37,6 @@ import java.util.Optional;
*/
public final class NewGlobalRuleChangedWatcher implements NewGovernanceWatcher<GovernanceEvent> {
- private static final Collection<GlobalRuleConfigurationEventBuilder> EVENT_BUILDERS = ShardingSphereServiceLoader.getServiceInstances(GlobalRuleConfigurationEventBuilder.class);
-
@Override
public Collection<String> getWatchingKeys(final String databaseName) {
return Collections.singleton(GlobalNode.getGlobalRuleNode());
@@ -54,12 +53,15 @@ public final class NewGlobalRuleChangedWatcher implements NewGovernanceWatcher<G
}
private Optional<GovernanceEvent> createGlobalRuleEvent(final DataChangedEvent event) {
- for (GlobalRuleConfigurationEventBuilder each : EVENT_BUILDERS) {
- Optional<GovernanceEvent> result = each.build(event);
- if (!result.isPresent()) {
- continue;
+ if (GlobalRuleNodeConverter.isActiveVersionPath(event.getKey())) {
+ Optional<String> ruleName = GlobalRuleNodeConverter.getRuleName(event.getKey());
+ if (!ruleName.isPresent()) {
+ return Optional.empty();
+ }
+ if (Type.ADDED == event.getType() || Type.UPDATED == event.getType()) {
+ return Optional.of(new AlterGlobalRuleConfigurationEvent(ruleName.get(), event.getKey(), event.getValue()));
}
- return result;
+ return Optional.of(new DeleteGlobalRuleConfigurationEvent(ruleName.get()));
}
return Optional.empty();
}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/NewConfigurationChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/NewConfigurationChangedSubscriber.java
index a8d50514928..e8e6c4837d6 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/NewConfigurationChangedSubscriber.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/NewConfigurationChangedSubscriber.java
@@ -18,9 +18,9 @@
package org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber;
import com.google.common.eventbus.Subscribe;
-import org.apache.shardingsphere.infra.config.rule.global.event.AlterGlobalRuleConfigurationEvent;
-import org.apache.shardingsphere.infra.config.rule.global.event.DeleteGlobalRuleConfigurationEvent;
import org.apache.shardingsphere.mode.event.config.DatabaseRuleConfigurationChangedEvent;
+import org.apache.shardingsphere.mode.event.config.global.AlterGlobalRuleConfigurationEvent;
+import org.apache.shardingsphere.mode.event.config.global.DeleteGlobalRuleConfigurationEvent;
import org.apache.shardingsphere.mode.manager.ContextManager;
/**
@@ -54,7 +54,11 @@ public final class NewConfigurationChangedSubscriber {
*/
@Subscribe
public synchronized void renew(final AlterGlobalRuleConfigurationEvent event) {
- contextManager.alterGlobalRuleConfiguration(event.getRuleSimpleName(), event.getConfig());
+ if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
+ return;
+ }
+ contextManager.alterGlobalRuleConfiguration(event.getRuleSimpleName(),
+ contextManager.getMetaDataContexts().getPersistService().getGlobalRuleService().load(event.getRuleSimpleName()).iterator().next());
}
/**