You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ch...@apache.org on 2023/06/10 05:27:40 UTC
[shardingsphere] branch master updated: Completed global rule new structure swapper (#26249)
This is an automated email from the ASF dual-hosted git repository.
chengzhang 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 45cdcbf3a5d Completed global rule new structure swapper (#26249)
45cdcbf3a5d is described below
commit 45cdcbf3a5d0e94bb1e24ad00cd347f4a3625f4c
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Sat Jun 10 13:27:30 2023 +0800
Completed global rule new structure swapper (#26249)
* Completed global rule swapper
* Fix checkstyle
---
.../NewYamlLoggingRuleConfigurationSwapper.java | 92 ++++++++++++++++++++++
...ewYamlLoggingRuleConfigurationSwapperTest.java} | 11 +--
.../YamlLoggingRuleConfigurationSwapperTest.java | 5 +-
.../NewYamlSingleRuleConfigurationSwapper.java | 83 +++++++++++++++++++
...NewYamlSingleRuleConfigurationSwapperTest.java} | 11 +--
.../YamlSingleRuleConfigurationSwapperTest.java | 3 +-
...wYamlSQLFederationRuleConfigurationSwapper.java | 84 ++++++++++++++++++++
...SQLFederationRuleConfigurationSwapperTest.java} | 12 +--
.../NewYamlSQLParserRuleConfigurationSwapper.java | 92 ++++++++++++++++++++++
...YamlSQLParserRuleConfigurationSwapperTest.java} | 13 +--
...wYamlSQLTranslatorRuleConfigurationSwapper.java | 81 +++++++++++++++++++
...SQLTranslatorRuleConfigurationSwapperTest.java} | 11 +--
.../NewYamlTrafficRuleConfigurationSwapper.java | 3 +-
...NewYamlTrafficRuleConfigurationSwapperTest.java | 1 +
14 files changed, 469 insertions(+), 33 deletions(-)
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
new file mode 100644
index 00000000000..9607725e68e
--- /dev/null
+++ b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/NewYamlLoggingRuleConfigurationSwapper.java
@@ -0,0 +1,92 @@
+/*
+ * 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.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.rule.NewYamlRuleConfigurationSwapper;
+import org.apache.shardingsphere.logging.config.LoggingRuleConfiguration;
+import org.apache.shardingsphere.logging.constant.LoggingOrder;
+import org.apache.shardingsphere.logging.rule.builder.DefaultLoggingRuleConfigurationBuilder;
+import org.apache.shardingsphere.logging.yaml.config.YamlAppendersConfigurationConverter;
+import org.apache.shardingsphere.logging.yaml.config.YamlLoggersConfigurationConverter;
+import org.apache.shardingsphere.logging.yaml.config.YamlLoggingRuleConfiguration;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+
+/**
+ * TODO Rename YamlLoggingRuleConfigurationSwapper when metadata structure adjustment completed. #25485
+ * YAML logging rule configuration swapper.
+ */
+public final class NewYamlLoggingRuleConfigurationSwapper implements NewYamlRuleConfigurationSwapper<LoggingRuleConfiguration> {
+
+ @Override
+ public Collection<YamlDataNode> swapToDataNodes(final LoggingRuleConfiguration data) {
+ return Collections.singletonList(new YamlDataNode(GlobalRuleNodeConverter.getRootNode(getRuleTagName().toLowerCase()), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ }
+
+ private YamlLoggingRuleConfiguration swapToYamlConfiguration(final LoggingRuleConfiguration data) {
+ YamlLoggingRuleConfiguration result = new YamlLoggingRuleConfiguration();
+ result.setLoggers(YamlLoggersConfigurationConverter.convertYamlLoggerConfigurations(data.getLoggers()));
+ result.setAppenders(YamlAppendersConfigurationConverter.convertYamlAppenderConfigurations(data.getAppenders()));
+ return result;
+ }
+
+ @Override
+ public LoggingRuleConfiguration 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(), YamlLoggingRuleConfiguration.class));
+ }
+ return getDefaultLoggingRuleConfiguration();
+ }
+
+ private LoggingRuleConfiguration swapToObject(final YamlLoggingRuleConfiguration yamlConfig) {
+ LoggingRuleConfiguration result = new LoggingRuleConfiguration(YamlLoggersConfigurationConverter.convertShardingSphereLogger(yamlConfig.getLoggers()),
+ YamlAppendersConfigurationConverter.convertShardingSphereAppender(yamlConfig.getAppenders()));
+ if (null == result.getLoggers()) {
+ result = getDefaultLoggingRuleConfiguration();
+ }
+ return result;
+ }
+
+ private LoggingRuleConfiguration getDefaultLoggingRuleConfiguration() {
+ return new DefaultLoggingRuleConfigurationBuilder().build();
+ }
+
+ @Override
+ public Class<LoggingRuleConfiguration> getTypeClass() {
+ return LoggingRuleConfiguration.class;
+ }
+
+ @Override
+ public String getRuleTagName() {
+ return "LOGGING";
+ }
+
+ @Override
+ public int getOrder() {
+ return LoggingOrder.ORDER;
+ }
+}
diff --git a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java b/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/yaml/swapper/NewYamlLoggingRuleConfigurationSwapperTest.java
similarity index 63%
copy from kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java
copy to kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/yaml/swapper/NewYamlLoggingRuleConfigurationSwapperTest.java
index 9c5df109c6a..549257b5319 100644
--- a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java
+++ b/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/yaml/swapper/NewYamlLoggingRuleConfigurationSwapperTest.java
@@ -15,20 +15,21 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.traffic.yaml.swapper;
+package org.apache.shardingsphere.logging.yaml.swapper;
-import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
+import org.apache.shardingsphere.logging.rule.builder.DefaultLoggingRuleConfigurationBuilder;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class NewYamlTrafficRuleConfigurationSwapperTest {
+// TODO Rename YamlLoggingRuleConfigurationSwapperTest when metadata structure adjustment completed. #25485
+class NewYamlLoggingRuleConfigurationSwapperTest {
- private final NewYamlTrafficRuleConfigurationSwapper swapper = new NewYamlTrafficRuleConfigurationSwapper();
+ private final NewYamlLoggingRuleConfigurationSwapper swapper = new NewYamlLoggingRuleConfigurationSwapper();
@Test
void assertSwapToDataNodes() {
- assertThat(swapper.swapToDataNodes(new TrafficRuleConfiguration()).iterator().next().getKey(), is("/rules/traffic"));
+ assertThat(swapper.swapToDataNodes(new DefaultLoggingRuleConfigurationBuilder().build()).iterator().next().getKey(), is("/rules/logging"));
}
}
diff --git a/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/yaml/YamlLoggingRuleConfigurationSwapperTest.java b/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingRuleConfigurationSwapperTest.java
similarity index 91%
rename from kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/yaml/YamlLoggingRuleConfigurationSwapperTest.java
rename to kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingRuleConfigurationSwapperTest.java
index 832af913d55..f69cc5433c3 100644
--- a/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/yaml/YamlLoggingRuleConfigurationSwapperTest.java
+++ b/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/yaml/swapper/YamlLoggingRuleConfigurationSwapperTest.java
@@ -15,15 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.logging.yaml;
+package org.apache.shardingsphere.logging.yaml.swapper;
import org.apache.shardingsphere.logging.config.LoggingRuleConfiguration;
import org.apache.shardingsphere.logging.logger.ShardingSphereAppender;
import org.apache.shardingsphere.logging.logger.ShardingSphereLogger;
import org.apache.shardingsphere.logging.yaml.config.YamlLoggingRuleConfiguration;
-import org.apache.shardingsphere.logging.yaml.swapper.YamlAppenderSwapper;
-import org.apache.shardingsphere.logging.yaml.swapper.YamlLoggerSwapper;
-import org.apache.shardingsphere.logging.yaml.swapper.YamlLoggingRuleConfigurationSwapper;
import org.junit.jupiter.api.Test;
import java.util.Collections;
diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/NewYamlSingleRuleConfigurationSwapper.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/NewYamlSingleRuleConfigurationSwapper.java
new file mode 100644
index 00000000000..599f4e88fec
--- /dev/null
+++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/yaml/config/swapper/NewYamlSingleRuleConfigurationSwapper.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.single.yaml.config.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.rule.NewYamlRuleConfigurationSwapper;
+import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
+import org.apache.shardingsphere.single.constant.SingleOrder;
+import org.apache.shardingsphere.single.yaml.config.pojo.YamlSingleRuleConfiguration;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+
+/**
+ * TODO Rename YamlSingleRuleConfigurationSwapper when metadata structure adjustment completed. #25485
+ * YAML single rule configuration swapper.
+ */
+public final class NewYamlSingleRuleConfigurationSwapper implements NewYamlRuleConfigurationSwapper<SingleRuleConfiguration> {
+
+ @Override
+ public Collection<YamlDataNode> swapToDataNodes(final SingleRuleConfiguration data) {
+ return Collections.singletonList(new YamlDataNode(GlobalRuleNodeConverter.getRootNode(getRuleTagName().toLowerCase()), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ }
+
+ private YamlSingleRuleConfiguration swapToYamlConfiguration(final SingleRuleConfiguration data) {
+ YamlSingleRuleConfiguration result = new YamlSingleRuleConfiguration();
+ result.getTables().addAll(data.getTables());
+ data.getDefaultDataSource().ifPresent(result::setDefaultDataSource);
+ return result;
+ }
+
+ @Override
+ public SingleRuleConfiguration 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(), YamlSingleRuleConfiguration.class));
+ }
+ return new SingleRuleConfiguration();
+ }
+
+ private SingleRuleConfiguration swapToObject(final YamlSingleRuleConfiguration yamlConfig) {
+ SingleRuleConfiguration result = new SingleRuleConfiguration();
+ result.getTables().addAll(yamlConfig.getTables());
+ result.setDefaultDataSource(yamlConfig.getDefaultDataSource());
+ return result;
+ }
+
+ @Override
+ public Class<SingleRuleConfiguration> getTypeClass() {
+ return SingleRuleConfiguration.class;
+ }
+
+ @Override
+ public String getRuleTagName() {
+ return "SINGLE";
+ }
+
+ @Override
+ public int getOrder() {
+ return SingleOrder.ORDER;
+ }
+}
diff --git a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/yaml/config/swapper/NewYamlSingleRuleConfigurationSwapperTest.java
similarity index 65%
copy from kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java
copy to kernel/single/core/src/test/java/org/apache/shardingsphere/single/yaml/config/swapper/NewYamlSingleRuleConfigurationSwapperTest.java
index 9c5df109c6a..a741cefb12f 100644
--- a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java
+++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/yaml/config/swapper/NewYamlSingleRuleConfigurationSwapperTest.java
@@ -15,20 +15,21 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.traffic.yaml.swapper;
+package org.apache.shardingsphere.single.yaml.config.swapper;
-import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
+import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class NewYamlTrafficRuleConfigurationSwapperTest {
+// TODO Rename YamlSingleRuleConfigurationSwapperTest when metadata structure adjustment completed. #25485
+class NewYamlSingleRuleConfigurationSwapperTest {
- private final NewYamlTrafficRuleConfigurationSwapper swapper = new NewYamlTrafficRuleConfigurationSwapper();
+ private final NewYamlSingleRuleConfigurationSwapper swapper = new NewYamlSingleRuleConfigurationSwapper();
@Test
void assertSwapToDataNodes() {
- assertThat(swapper.swapToDataNodes(new TrafficRuleConfiguration()).iterator().next().getKey(), is("/rules/traffic"));
+ assertThat(swapper.swapToDataNodes(new SingleRuleConfiguration()).iterator().next().getKey(), is("/rules/single"));
}
}
diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/swapper/YamlSingleRuleConfigurationSwapperTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/yaml/config/swapper/YamlSingleRuleConfigurationSwapperTest.java
similarity index 94%
rename from kernel/single/core/src/test/java/org/apache/shardingsphere/single/swapper/YamlSingleRuleConfigurationSwapperTest.java
rename to kernel/single/core/src/test/java/org/apache/shardingsphere/single/yaml/config/swapper/YamlSingleRuleConfigurationSwapperTest.java
index a2fd8855c7c..2f8678a3763 100644
--- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/swapper/YamlSingleRuleConfigurationSwapperTest.java
+++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/yaml/config/swapper/YamlSingleRuleConfigurationSwapperTest.java
@@ -15,11 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.single.swapper;
+package org.apache.shardingsphere.single.yaml.config.swapper;
import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration;
import org.apache.shardingsphere.single.yaml.config.pojo.YamlSingleRuleConfiguration;
-import org.apache.shardingsphere.single.yaml.config.swapper.YamlSingleRuleConfigurationSwapper;
import org.junit.jupiter.api.Test;
import java.util.Collections;
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
new file mode 100644
index 00000000000..b218f8e3082
--- /dev/null
+++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapper.java
@@ -0,0 +1,84 @@
+/*
+ * 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.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.rule.NewYamlRuleConfigurationSwapper;
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
+import org.apache.shardingsphere.sqlfederation.api.config.SQLFederationRuleConfiguration;
+import org.apache.shardingsphere.sqlfederation.constant.SQLFederationOrder;
+import org.apache.shardingsphere.sqlfederation.yaml.config.YamlSQLFederationRuleConfiguration;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+
+/**
+ * TODO Rename YamlSQLTranslatorRuleConfigurationSwapper when metadata structure adjustment completed. #25485
+ * YAML SQL federation rule configuration swapper.
+ */
+public final class NewYamlSQLFederationRuleConfigurationSwapper implements NewYamlRuleConfigurationSwapper<SQLFederationRuleConfiguration> {
+
+ private final YamlSQLFederationExecutionPlanCacheConfigurationSwapper executionPlanCacheConfigSwapper = new YamlSQLFederationExecutionPlanCacheConfigurationSwapper();
+
+ @Override
+ public Collection<YamlDataNode> swapToDataNodes(final SQLFederationRuleConfiguration data) {
+ return Collections.singletonList(new YamlDataNode(GlobalRuleNodeConverter.getRootNode(getRuleTagName().toLowerCase()), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ }
+
+ private YamlSQLFederationRuleConfiguration swapToYamlConfiguration(final SQLFederationRuleConfiguration data) {
+ YamlSQLFederationRuleConfiguration result = new YamlSQLFederationRuleConfiguration();
+ result.setSqlFederationEnabled(data.isSqlFederationEnabled());
+ result.setExecutionPlanCache(executionPlanCacheConfigSwapper.swapToYamlConfiguration(data.getExecutionPlanCache()));
+ return result;
+ }
+
+ @Override
+ public SQLFederationRuleConfiguration 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(), YamlSQLFederationRuleConfiguration.class));
+ }
+ return new SQLFederationRuleConfiguration(false, new CacheOption(0, 0));
+ }
+
+ private SQLFederationRuleConfiguration swapToObject(final YamlSQLFederationRuleConfiguration yamlConfig) {
+ CacheOption executionPlanCacheConfig = executionPlanCacheConfigSwapper.swapToObject(yamlConfig.getExecutionPlanCache());
+ return new SQLFederationRuleConfiguration(yamlConfig.isSqlFederationEnabled(), executionPlanCacheConfig);
+ }
+
+ @Override
+ public Class<SQLFederationRuleConfiguration> getTypeClass() {
+ return SQLFederationRuleConfiguration.class;
+ }
+
+ @Override
+ public String getRuleTagName() {
+ return "SQL_FEDERATION";
+ }
+
+ @Override
+ public int getOrder() {
+ return SQLFederationOrder.ORDER;
+ }
+}
diff --git a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapperTest.java
similarity index 59%
copy from kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java
copy to kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapperTest.java
index 9c5df109c6a..a82d5f355bf 100644
--- a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java
+++ b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapperTest.java
@@ -15,20 +15,22 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.traffic.yaml.swapper;
+package org.apache.shardingsphere.sqlfederation.yaml.swapper;
-import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
+import org.apache.shardingsphere.sqlfederation.api.config.SQLFederationRuleConfiguration;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class NewYamlTrafficRuleConfigurationSwapperTest {
+// TODO Rename YamlSQLFederationRuleConfigurationSwapperTest when metadata structure adjustment completed. #25485
+class NewYamlSQLFederationRuleConfigurationSwapperTest {
- private final NewYamlTrafficRuleConfigurationSwapper swapper = new NewYamlTrafficRuleConfigurationSwapper();
+ private final NewYamlSQLFederationRuleConfigurationSwapper swapper = new NewYamlSQLFederationRuleConfigurationSwapper();
@Test
void assertSwapToDataNodes() {
- assertThat(swapper.swapToDataNodes(new TrafficRuleConfiguration()).iterator().next().getKey(), is("/rules/traffic"));
+ assertThat(swapper.swapToDataNodes(new SQLFederationRuleConfiguration(false, new CacheOption(0, 0))).iterator().next().getKey(), is("/rules/sql_federation"));
}
}
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
new file mode 100644
index 00000000000..6dfb860f161
--- /dev/null
+++ b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/NewYamlSQLParserRuleConfigurationSwapper.java
@@ -0,0 +1,92 @@
+/*
+ * 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.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.rule.NewYamlRuleConfigurationSwapper;
+import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
+import org.apache.shardingsphere.parser.constant.SQLParserOrder;
+import org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
+import org.apache.shardingsphere.parser.yaml.config.YamlSQLParserRuleConfiguration;
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+
+/**
+ * TODO Rename YamlSQLTranslatorRuleConfigurationSwapper when metadata structure adjustment completed. #25485
+ * YAML SQL parser rule configuration swapper.
+ */
+public final class NewYamlSQLParserRuleConfigurationSwapper implements NewYamlRuleConfigurationSwapper<SQLParserRuleConfiguration> {
+
+ private final YamlSQLParserCacheOptionConfigurationSwapper cacheOptionSwapper = new YamlSQLParserCacheOptionConfigurationSwapper();
+
+ @Override
+ public Collection<YamlDataNode> swapToDataNodes(final SQLParserRuleConfiguration data) {
+ return Collections.singletonList(new YamlDataNode(GlobalRuleNodeConverter.getRootNode(getRuleTagName().toLowerCase()), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ }
+
+ private YamlSQLParserRuleConfiguration swapToYamlConfiguration(final SQLParserRuleConfiguration data) {
+ YamlSQLParserRuleConfiguration result = new YamlSQLParserRuleConfiguration();
+ result.setSqlCommentParseEnabled(data.isSqlCommentParseEnabled());
+ result.setParseTreeCache(cacheOptionSwapper.swapToYamlConfiguration(data.getParseTreeCache()));
+ result.setSqlStatementCache(cacheOptionSwapper.swapToYamlConfiguration(data.getSqlStatementCache()));
+ return result;
+ }
+
+ @Override
+ public SQLParserRuleConfiguration 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(), YamlSQLParserRuleConfiguration.class));
+ }
+ return new SQLParserRuleConfiguration(false, DefaultSQLParserRuleConfigurationBuilder.PARSE_TREE_CACHE_OPTION,
+ DefaultSQLParserRuleConfigurationBuilder.SQL_STATEMENT_CACHE_OPTION);
+ }
+
+ private SQLParserRuleConfiguration swapToObject(final YamlSQLParserRuleConfiguration yamlConfig) {
+ CacheOption parseTreeCacheOption = null == yamlConfig.getParseTreeCache()
+ ? DefaultSQLParserRuleConfigurationBuilder.PARSE_TREE_CACHE_OPTION
+ : cacheOptionSwapper.swapToObject(yamlConfig.getParseTreeCache());
+ CacheOption sqlStatementCacheOption = null == yamlConfig.getSqlStatementCache()
+ ? DefaultSQLParserRuleConfigurationBuilder.SQL_STATEMENT_CACHE_OPTION
+ : cacheOptionSwapper.swapToObject(yamlConfig.getSqlStatementCache());
+ return new SQLParserRuleConfiguration(yamlConfig.isSqlCommentParseEnabled(), parseTreeCacheOption, sqlStatementCacheOption);
+ }
+
+ @Override
+ public Class<SQLParserRuleConfiguration> getTypeClass() {
+ return SQLParserRuleConfiguration.class;
+ }
+
+ @Override
+ public String getRuleTagName() {
+ return "SQL_PARSER";
+ }
+
+ @Override
+ public int getOrder() {
+ return SQLParserOrder.ORDER;
+ }
+}
diff --git a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java b/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/yaml/swapper/NewYamlSQLParserRuleConfigurationSwapperTest.java
similarity index 55%
copy from kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java
copy to kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/yaml/swapper/NewYamlSQLParserRuleConfigurationSwapperTest.java
index 9c5df109c6a..a252e10a491 100644
--- a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java
+++ b/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/yaml/swapper/NewYamlSQLParserRuleConfigurationSwapperTest.java
@@ -15,20 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.traffic.yaml.swapper;
+package org.apache.shardingsphere.parser.yaml.swapper;
-import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
+import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
+import org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class NewYamlTrafficRuleConfigurationSwapperTest {
+// TODO Rename YamlSQLParserRuleConfigurationSwapperTest when metadata structure adjustment completed. #25485
+class NewYamlSQLParserRuleConfigurationSwapperTest {
- private final NewYamlTrafficRuleConfigurationSwapper swapper = new NewYamlTrafficRuleConfigurationSwapper();
+ private final NewYamlSQLParserRuleConfigurationSwapper swapper = new NewYamlSQLParserRuleConfigurationSwapper();
@Test
void assertSwapToDataNodes() {
- assertThat(swapper.swapToDataNodes(new TrafficRuleConfiguration()).iterator().next().getKey(), is("/rules/traffic"));
+ assertThat(swapper.swapToDataNodes(new SQLParserRuleConfiguration(false, DefaultSQLParserRuleConfigurationBuilder.PARSE_TREE_CACHE_OPTION,
+ DefaultSQLParserRuleConfigurationBuilder.SQL_STATEMENT_CACHE_OPTION)).iterator().next().getKey(), is("/rules/sql_parser"));
}
}
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
new file mode 100644
index 00000000000..49f7f377ddd
--- /dev/null
+++ b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/NewYamlSQLTranslatorRuleConfigurationSwapper.java
@@ -0,0 +1,81 @@
+/*
+ * 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.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.rule.NewYamlRuleConfigurationSwapper;
+import org.apache.shardingsphere.sqltranslator.api.config.SQLTranslatorRuleConfiguration;
+import org.apache.shardingsphere.sqltranslator.constant.SQLTranslatorOrder;
+import org.apache.shardingsphere.sqltranslator.yaml.config.YamlSQLTranslatorRuleConfiguration;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+
+/**
+ * TODO Rename YamlSQLTranslatorRuleConfigurationSwapper when metadata structure adjustment completed. #25485
+ * YAML SQL translator rule configuration swapper.
+ */
+public final class NewYamlSQLTranslatorRuleConfigurationSwapper implements NewYamlRuleConfigurationSwapper<SQLTranslatorRuleConfiguration> {
+
+ @Override
+ public Collection<YamlDataNode> swapToDataNodes(final SQLTranslatorRuleConfiguration data) {
+ return Collections.singletonList(new YamlDataNode(GlobalRuleNodeConverter.getRootNode(getRuleTagName().toLowerCase()), YamlEngine.marshal(swapToYamlConfiguration(data))));
+ }
+
+ private YamlSQLTranslatorRuleConfiguration swapToYamlConfiguration(final SQLTranslatorRuleConfiguration data) {
+ YamlSQLTranslatorRuleConfiguration result = new YamlSQLTranslatorRuleConfiguration();
+ result.setType(data.getType());
+ result.setUseOriginalSQLWhenTranslatingFailed(data.isUseOriginalSQLWhenTranslatingFailed());
+ return result;
+ }
+
+ @Override
+ public SQLTranslatorRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
+ SQLTranslatorRuleConfiguration result = new SQLTranslatorRuleConfiguration();
+ for (YamlDataNode each : dataNodes) {
+ Optional<String> version = GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
+ if (!version.isPresent()) {
+ continue;
+ }
+ return swapToObject(YamlEngine.unmarshal(each.getValue(), YamlSQLTranslatorRuleConfiguration.class));
+ }
+ return result;
+ }
+
+ private SQLTranslatorRuleConfiguration swapToObject(final YamlSQLTranslatorRuleConfiguration yamlConfig) {
+ return new SQLTranslatorRuleConfiguration(yamlConfig.getType(), yamlConfig.isUseOriginalSQLWhenTranslatingFailed());
+ }
+
+ @Override
+ public Class<SQLTranslatorRuleConfiguration> getTypeClass() {
+ return SQLTranslatorRuleConfiguration.class;
+ }
+
+ @Override
+ public String getRuleTagName() {
+ return "SQL_TRANSLATOR";
+ }
+
+ @Override
+ public int getOrder() {
+ return SQLTranslatorOrder.ORDER;
+ }
+}
diff --git a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java b/kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/NewYamlSQLTranslatorRuleConfigurationSwapperTest.java
similarity index 63%
copy from kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java
copy to kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/NewYamlSQLTranslatorRuleConfigurationSwapperTest.java
index 9c5df109c6a..6bf5355047f 100644
--- a/kernel/traffic/core/src/test/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapperTest.java
+++ b/kernel/sql-translator/core/src/test/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/NewYamlSQLTranslatorRuleConfigurationSwapperTest.java
@@ -15,20 +15,21 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.traffic.yaml.swapper;
+package org.apache.shardingsphere.sqltranslator.yaml.swapper;
-import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
+import org.apache.shardingsphere.sqltranslator.api.config.SQLTranslatorRuleConfiguration;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-class NewYamlTrafficRuleConfigurationSwapperTest {
+// TODO Rename YamlSQLTranslatorRuleConfigurationSwapperTest when metadata structure adjustment completed. #25485
+class NewYamlSQLTranslatorRuleConfigurationSwapperTest {
- private final NewYamlTrafficRuleConfigurationSwapper swapper = new NewYamlTrafficRuleConfigurationSwapper();
+ private final NewYamlSQLTranslatorRuleConfigurationSwapper swapper = new NewYamlSQLTranslatorRuleConfigurationSwapper();
@Test
void assertSwapToDataNodes() {
- assertThat(swapper.swapToDataNodes(new TrafficRuleConfiguration()).iterator().next().getKey(), is("/rules/traffic"));
+ assertThat(swapper.swapToDataNodes(new SQLTranslatorRuleConfiguration()).iterator().next().getKey(), is("/rules/sql_translator"));
}
}
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 ceb0c8e4d4d..43df38dfd21 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
@@ -65,7 +65,6 @@ public final class NewYamlTrafficRuleConfigurationSwapper implements NewYamlRule
@Override
public TrafficRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
- TrafficRuleConfiguration result = new TrafficRuleConfiguration();
for (YamlDataNode each : dataNodes) {
Optional<String> version = GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
if (!version.isPresent()) {
@@ -73,7 +72,7 @@ public final class NewYamlTrafficRuleConfigurationSwapper implements NewYamlRule
}
return swapToObject(YamlEngine.unmarshal(each.getValue(), YamlTrafficRuleConfiguration.class));
}
- return result;
+ return new TrafficRuleConfiguration();
}
private TrafficRuleConfiguration swapToObject(final YamlTrafficRuleConfiguration yamlConfig) {
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 9c5df109c6a..8e85102b192 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
@@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+// TODO Rename YamlTrafficRuleConfigurationSwapperTest when metadata structure adjustment completed. #25485
class NewYamlTrafficRuleConfigurationSwapperTest {
private final NewYamlTrafficRuleConfigurationSwapper swapper = new NewYamlTrafficRuleConfigurationSwapper();