You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/06/10 03:50:16 UTC
[shardingsphere] branch master updated: Add NewYamlGlobalClockRuleConfigurationSwapper and GlobalRuleNodeConverter (#26248)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 944305ac64f Add NewYamlGlobalClockRuleConfigurationSwapper and GlobalRuleNodeConverter (#26248)
944305ac64f is described below
commit 944305ac64f9c26a9cfad82416cc7bf5e759f640
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Sat Jun 10 11:50:06 2023 +0800
Add NewYamlGlobalClockRuleConfigurationSwapper and GlobalRuleNodeConverter (#26248)
* Add NewYamlGlobalClockRuleConfigurationSwapper and GlobalRuleNodeConverter
* Update
---
.../infra/converter/GlobalRuleNodeConverter.java | 28 +++++---
.../converter/GlobalRuleNodeConverterTest.java | 11 ++-
.../NewYamlAuthorityRuleConfigurationSwapper.java | 6 +-
...wYamlAuthorityRuleConfigurationSwapperTest.java | 2 +-
.../exception/GlobalClockNotEnabledException.java | 32 ---------
...NewYamlGlobalClockRuleConfigurationSwapper.java | 83 ++++++++++++++++++++++
...mlGlobalClockRuleConfigurationSwapperTest.java} | 18 ++---
.../metadata/converter/TrafficNodeConverter.java | 57 ---------------
.../NewYamlTrafficRuleConfigurationSwapper.java | 6 +-
...NewYamlTrafficRuleConfigurationSwapperTest.java | 2 +-
10 files changed, 120 insertions(+), 125 deletions(-)
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/metadata/converter/AuthorityNodeConverter.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/converter/GlobalRuleNodeConverter.java
similarity index 61%
rename from kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/metadata/converter/AuthorityNodeConverter.java
rename to infra/common/src/main/java/org/apache/shardingsphere/infra/converter/GlobalRuleNodeConverter.java
index 6c72868b607..6f3284f124b 100644
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/metadata/converter/AuthorityNodeConverter.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/converter/GlobalRuleNodeConverter.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.metadata.converter;
+package org.apache.shardingsphere.infra.converter;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -25,33 +25,39 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
- * Authority node converter.
+ * Global rule node converter.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class AuthorityNodeConverter {
+public final class GlobalRuleNodeConverter {
- private static final String ROOT_NODE = "authority/";
+ private static final String ROOT_NODE = "rules";
- private static final String VERSION_NODE_PREFIX = "/rules/" + ROOT_NODE;
+ private static final String VERSIONS = "versions";
/**
- * Get group name path.
+ * Get root node.
*
- * @return group name path
+ * @param ruleName rule name
+ * @return root node
*/
- public static String getRootNode() {
- return ROOT_NODE;
+ public static String getRootNode(final String ruleName) {
+ return String.join("/", "", ROOT_NODE, ruleName);
}
/**
* Get version.
*
+ * @param ruleName rule name
* @param rulePath rule path
* @return version
*/
- public static Optional<String> getVersion(final String rulePath) {
- Pattern pattern = Pattern.compile(VERSION_NODE_PREFIX + "versions" + "/([\\w\\-]+)$", Pattern.CASE_INSENSITIVE);
+ public static Optional<String> getVersion(final String ruleName, final String rulePath) {
+ Pattern pattern = Pattern.compile(getVersionsNode(ruleName) + "/([\\w\\-]+)$", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(rulePath);
return matcher.find() ? Optional.of(matcher.group(1)) : Optional.empty();
}
+
+ private static String getVersionsNode(final String ruleName) {
+ return String.join(getRootNode(ruleName), VERSIONS);
+ }
}
diff --git a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/metadata/AuthorityNodeConverterTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/converter/GlobalRuleNodeConverterTest.java
similarity index 75%
rename from kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/metadata/AuthorityNodeConverterTest.java
rename to infra/common/src/test/java/org/apache/shardingsphere/infra/converter/GlobalRuleNodeConverterTest.java
index 6b861643f33..2354b10e4f0 100644
--- a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/metadata/AuthorityNodeConverterTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/converter/GlobalRuleNodeConverterTest.java
@@ -15,9 +15,8 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.metadata;
+package org.apache.shardingsphere.infra.converter;
-import org.apache.shardingsphere.authority.metadata.converter.AuthorityNodeConverter;
import org.junit.jupiter.api.Test;
import java.util.Optional;
@@ -26,16 +25,16 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
-class AuthorityNodeConverterTest {
+class GlobalRuleNodeConverterTest {
@Test
- void assetGetRootNode() {
- assertThat(AuthorityNodeConverter.getRootNode(), is("authority/"));
+ void assertGetRootNode() {
+ assertThat(GlobalRuleNodeConverter.getRootNode("transaction"), is("/rules/transaction"));
}
@Test
void assertGetVersion() {
- Optional<String> actual = AuthorityNodeConverter.getVersion("/rules/authority/versions/0");
+ Optional<String> actual = GlobalRuleNodeConverter.getVersion("transaction", "/rules/transaction/versions/0");
assertTrue(actual.isPresent());
assertThat(actual.get(), is("0"));
}
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 ec477c08eeb..c95cfd2ab82 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
@@ -20,10 +20,10 @@ package org.apache.shardingsphere.authority.yaml.swapper;
import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
import org.apache.shardingsphere.authority.constant.AuthorityOrder;
import org.apache.shardingsphere.authority.converter.YamlUsersConfigurationConverter;
-import org.apache.shardingsphere.authority.metadata.converter.AuthorityNodeConverter;
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.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;
@@ -44,7 +44,7 @@ public final class NewYamlAuthorityRuleConfigurationSwapper implements NewYamlRu
@Override
public Collection<YamlDataNode> swapToDataNodes(final AuthorityRuleConfiguration data) {
- return Collections.singletonList(new YamlDataNode(AuthorityNodeConverter.getRootNode(), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ return Collections.singletonList(new YamlDataNode(GlobalRuleNodeConverter.getRootNode(getRuleTagName().toLowerCase()), YamlEngine.marshal(swapToYamlConfiguration(data))));
}
@@ -62,7 +62,7 @@ public final class NewYamlAuthorityRuleConfigurationSwapper implements NewYamlRu
@Override
public AuthorityRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
for (YamlDataNode each : dataNodes) {
- Optional<String> version = AuthorityNodeConverter.getVersion(each.getKey());
+ Optional<String> version = GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
if (!version.isPresent()) {
continue;
}
diff --git a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapperTest.java b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapperTest.java
index e4ced41489d..8afa8a964da 100644
--- a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapperTest.java
+++ b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapperTest.java
@@ -39,6 +39,6 @@ class NewYamlAuthorityRuleConfigurationSwapperTest {
void assertSwapToDataNodes() {
Collection<ShardingSphereUser> users = Collections.singleton(new ShardingSphereUser("root", "", "localhost"));
Collection<YamlDataNode> actual = swapper.swapToDataNodes(new AuthorityRuleConfiguration(users, new AlgorithmConfiguration("ALL_PERMITTED", new Properties()), null));
- assertThat(actual.iterator().next().getKey(), is("authority/"));
+ assertThat(actual.iterator().next().getKey(), is("/rules/authority"));
}
}
diff --git a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/exception/GlobalClockNotEnabledException.java b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/exception/GlobalClockNotEnabledException.java
deleted file mode 100644
index 0202f2356f3..00000000000
--- a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/exception/GlobalClockNotEnabledException.java
+++ /dev/null
@@ -1,32 +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.exception;
-
-import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
-
-/**
- * Global clock not enabled exception.
- */
-public final class GlobalClockNotEnabledException extends GlobalClockSQLException {
-
- private static final long serialVersionUID = 2499130145956182704L;
-
- public GlobalClockNotEnabledException() {
- super(XOpenSQLState.CHECK_OPTION_VIOLATION, 1, "The global clock rule has not been enabled");
- }
-}
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
new file mode 100644
index 00000000000..59ee11a7af5
--- /dev/null
+++ b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/NewYamlGlobalClockRuleConfigurationSwapper.java
@@ -0,0 +1,83 @@
+/*
+ * 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.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.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;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+import java.util.Properties;
+
+/**
+ * TODO Rename YamlGlobalClockRuleConfigurationSwapper when metadata structure adjustment completed. #25485
+ * YAML global clock rule configuration swapper.
+ */
+public final class NewYamlGlobalClockRuleConfigurationSwapper implements NewYamlRuleConfigurationSwapper<GlobalClockRuleConfiguration> {
+
+ @Override
+ public Collection<YamlDataNode> swapToDataNodes(final GlobalClockRuleConfiguration data) {
+ return Collections.singletonList(new YamlDataNode(GlobalRuleNodeConverter.getRootNode(getRuleTagName().toLowerCase()), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ }
+
+ private YamlGlobalClockRuleConfiguration swapToYamlConfiguration(final GlobalClockRuleConfiguration data) {
+ YamlGlobalClockRuleConfiguration result = new YamlGlobalClockRuleConfiguration();
+ result.setType(data.getType());
+ result.setProvider(data.getProvider());
+ result.setEnabled(data.isEnabled());
+ result.setProps(data.getProps());
+ return result;
+ }
+
+ @Override
+ public GlobalClockRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
+ for (YamlDataNode each : dataNodes) {
+ Optional<String> version = GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
+ if (!version.isPresent()) {
+ continue;
+ }
+ return swapToObject(YamlEngine.unmarshal(each.getValue(), YamlGlobalClockRuleConfiguration.class));
+ }
+ return new GlobalClockRuleConfiguration("", "", false, new Properties());
+ }
+
+ private GlobalClockRuleConfiguration swapToObject(final YamlGlobalClockRuleConfiguration yamlConfig) {
+ return new GlobalClockRuleConfiguration(yamlConfig.getType(), yamlConfig.getProvider(), yamlConfig.isEnabled(), null == yamlConfig.getProps() ? new Properties() : yamlConfig.getProps());
+ }
+
+ @Override
+ public String getRuleTagName() {
+ return "GLOBAL_CLOCK";
+ }
+
+ @Override
+ public int getOrder() {
+ return GlobalClockOrder.ORDER;
+ }
+
+ @Override
+ public Class<GlobalClockRuleConfiguration> getTypeClass() {
+ return GlobalClockRuleConfiguration.class;
+ }
+}
diff --git a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapperTest.java b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/NewYamlGlobalClockRuleConfigurationSwapperTest.java
similarity index 57%
copy from kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapperTest.java
copy to kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/NewYamlGlobalClockRuleConfigurationSwapperTest.java
index e4ced41489d..25791db2fcc 100644
--- a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapperTest.java
+++ b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/NewYamlGlobalClockRuleConfigurationSwapperTest.java
@@ -15,30 +15,26 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.authority.yaml.swapper;
+package org.apache.shardingsphere.globalclock.core.yaml.swapper;
-import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
-import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.apache.shardingsphere.globalclock.api.config.GlobalClockRuleConfiguration;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.junit.jupiter.api.Test;
import java.util.Collection;
-import java.util.Collections;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-// TODO Rename YamlAuthorityRuleConfigurationSwapperTest when metadata structure adjustment completed. #25485
-class NewYamlAuthorityRuleConfigurationSwapperTest {
+// TODO Rename YamlGlobalClockRuleConfigurationSwapperTest when metadata structure adjustment completed. #25485
+class NewYamlGlobalClockRuleConfigurationSwapperTest {
- private final NewYamlAuthorityRuleConfigurationSwapper swapper = new NewYamlAuthorityRuleConfigurationSwapper();
+ private final NewYamlGlobalClockRuleConfigurationSwapper swapper = new NewYamlGlobalClockRuleConfigurationSwapper();
@Test
void assertSwapToDataNodes() {
- Collection<ShardingSphereUser> users = Collections.singleton(new ShardingSphereUser("root", "", "localhost"));
- Collection<YamlDataNode> actual = swapper.swapToDataNodes(new AuthorityRuleConfiguration(users, new AlgorithmConfiguration("ALL_PERMITTED", new Properties()), null));
- assertThat(actual.iterator().next().getKey(), is("authority/"));
+ Collection<YamlDataNode> actual = swapper.swapToDataNodes(new GlobalClockRuleConfiguration("", "", false, new Properties()));
+ assertThat(actual.iterator().next().getKey(), is("/rules/global_clock"));
}
}
diff --git a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/metadata/converter/TrafficNodeConverter.java b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/metadata/converter/TrafficNodeConverter.java
deleted file mode 100644
index d2a3bdc1b3e..00000000000
--- a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/metadata/converter/TrafficNodeConverter.java
+++ /dev/null
@@ -1,57 +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.metadata.converter;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.util.Optional;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Traffic node converter.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class TrafficNodeConverter {
-
- private static final String ROOT_NODE = "traffic/";
-
- private static final String VERSION_NODE_PREFIX = "/rules/" + ROOT_NODE;
-
- /**
- * Get group name path.
- *
- * @return group name path
- */
- public static String getRootNode() {
- return ROOT_NODE;
- }
-
- /**
- * Get version.
- *
- * @param rulePath rule path
- * @return version
- */
- public static Optional<String> getVersion(final String rulePath) {
- Pattern pattern = Pattern.compile(VERSION_NODE_PREFIX + "versions" + "/([\\w\\-]+)$", Pattern.CASE_INSENSITIVE);
- Matcher matcher = pattern.matcher(rulePath);
- return matcher.find() ? Optional.of(matcher.group(1)) : Optional.empty();
- }
-}
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 4503d10881a..ceb0c8e4d4d 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,13 +17,13 @@
package org.apache.shardingsphere.traffic.yaml.swapper;
+import org.apache.shardingsphere.infra.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;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper;
import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
import org.apache.shardingsphere.traffic.constant.TrafficOrder;
-import org.apache.shardingsphere.traffic.metadata.converter.TrafficNodeConverter;
import org.apache.shardingsphere.traffic.yaml.config.YamlTrafficRuleConfiguration;
import org.apache.shardingsphere.traffic.yaml.config.YamlTrafficStrategyConfiguration;
@@ -44,7 +44,7 @@ public final class NewYamlTrafficRuleConfigurationSwapper implements NewYamlRule
@Override
public Collection<YamlDataNode> swapToDataNodes(final TrafficRuleConfiguration data) {
- return Collections.singletonList(new YamlDataNode(TrafficNodeConverter.getRootNode(), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ return Collections.singletonList(new YamlDataNode(GlobalRuleNodeConverter.getRootNode(getRuleTagName().toLowerCase()), YamlEngine.marshal(swapToYamlConfiguration(data))));
}
private YamlTrafficRuleConfiguration swapToYamlConfiguration(final TrafficRuleConfiguration data) {
@@ -67,7 +67,7 @@ public final class NewYamlTrafficRuleConfigurationSwapper implements NewYamlRule
public TrafficRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
TrafficRuleConfiguration result = new TrafficRuleConfiguration();
for (YamlDataNode each : dataNodes) {
- Optional<String> version = TrafficNodeConverter.getVersion(each.getKey());
+ Optional<String> version = GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
if (!version.isPresent()) {
continue;
}
diff --git a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java
index 9c2ddd48cfe..9c5df109c6a 100644
--- a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java
+++ b/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java
@@ -29,6 +29,6 @@ class NewYamlTrafficRuleConfigurationSwapperTest {
@Test
void assertSwapToDataNodes() {
- assertThat(swapper.swapToDataNodes(new TrafficRuleConfiguration()).iterator().next().getKey(), is("traffic/"));
+ assertThat(swapper.swapToDataNodes(new TrafficRuleConfiguration()).iterator().next().getKey(), is("/rules/traffic"));
}
}