You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/09/28 13:50:05 UTC

[shardingsphere] branch master updated: Move ResourceSegmentsConverter into shardingsphere-proxy-backend module (#12798)

This is an automated email from the ASF dual-hosted git repository.

menghaoran 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 1a75e7c  Move ResourceSegmentsConverter into shardingsphere-proxy-backend module (#12798)
1a75e7c is described below

commit 1a75e7c26de475871016d8a90475401948fb39be
Author: Liang Zhang <te...@163.com>
AuthorDate: Tue Sep 28 21:49:27 2021 +0800

    Move ResourceSegmentsConverter into shardingsphere-proxy-backend module (#12798)
    
    * Valid DataSourceConfigurationValidator
    
    * Refactor ResourceSegmentsConverter
    
    * Move ResourceSegmentsConverter into shardingsphere-proxy-backend module
---
 .../rdl/resource/AddResourceBackendHandler.java       |  5 ++---
 .../rdl/resource/AlterResourceBackendHandler.java     |  5 ++---
 .../rdl/resource}/ResourceSegmentsConverter.java      | 19 ++++++-------------
 .../rdl/resource}/ResourceSegmentsConverterTest.java  |  6 +++---
 4 files changed, 13 insertions(+), 22 deletions(-)

diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandler.java
index bc2edf8..f62fa4f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandler.java
@@ -30,7 +30,6 @@ import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
 import org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
 import org.apache.shardingsphere.proxy.config.util.DataSourceParameterConverter;
-import org.apache.shardingsphere.proxy.converter.ResourceSegmentsConverter;
 
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -56,8 +55,8 @@ public final class AddResourceBackendHandler extends SchemaRequiredBackendHandle
     @Override
     public ResponseHeader execute(final String schemaName, final AddResourceStatement sqlStatement) throws DistSQLException {
         checkSQLStatement(schemaName, sqlStatement);
-        Map<String, DataSourceConfiguration> dataSourceConfigs = DataSourceParameterConverter.getDataSourceConfigurationMap(
-                DataSourceParameterConverter.getDataSourceParameterMapFromYamlConfiguration(ResourceSegmentsConverter.convert(databaseType, sqlStatement.getDataSources())));
+        Map<String, DataSourceConfiguration> dataSourceConfigs
+                = DataSourceParameterConverter.getDataSourceConfigurationMap(ResourceSegmentsConverter.convert(databaseType, sqlStatement.getDataSources()));
         dataSourceConfigValidator.validate(dataSourceConfigs);
         // TODO update meta data context in memory
         ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataPersistService().ifPresent(optional -> optional.getDataSourceService().append(schemaName, dataSourceConfigs));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandler.java
index 1749e4f..c22aacf 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandler.java
@@ -31,7 +31,6 @@ import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
 import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
 import org.apache.shardingsphere.proxy.backend.text.SchemaRequiredBackendHandler;
 import org.apache.shardingsphere.proxy.config.util.DataSourceParameterConverter;
-import org.apache.shardingsphere.proxy.converter.ResourceSegmentsConverter;
 
 import javax.sql.DataSource;
 import java.util.Collection;
@@ -56,8 +55,8 @@ public final class AlterResourceBackendHandler extends SchemaRequiredBackendHand
     @Override
     public ResponseHeader execute(final String schemaName, final AlterResourceStatement sqlStatement) throws DistSQLException {
         checkSQLStatement(schemaName, sqlStatement);
-        Map<String, DataSourceConfiguration> dataSourceConfigs = DataSourceParameterConverter.getDataSourceConfigurationMap(
-                DataSourceParameterConverter.getDataSourceParameterMapFromYamlConfiguration(ResourceSegmentsConverter.convert(databaseType, sqlStatement.getDataSources())));
+        Map<String, DataSourceConfiguration> dataSourceConfigs
+                = DataSourceParameterConverter.getDataSourceConfigurationMap(ResourceSegmentsConverter.convert(databaseType, sqlStatement.getDataSources()));
         dataSourceConfigValidator.validate(dataSourceConfigs);
         // TODO update meta data context in memory
         ProxyContext.getInstance().getContextManager()
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/converter/ResourceSegmentsConverter.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/ResourceSegmentsConverter.java
similarity index 67%
rename from shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/converter/ResourceSegmentsConverter.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/ResourceSegmentsConverter.java
index 11d53e7..0822b55 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/converter/ResourceSegmentsConverter.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/ResourceSegmentsConverter.java
@@ -15,14 +15,13 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.proxy.converter;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.resource;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
 import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
 
 import java.util.Collection;
 import java.util.LinkedHashMap;
@@ -35,25 +34,19 @@ import java.util.Map;
 public final class ResourceSegmentsConverter {
     
     /**
-     * Convert resource segments to YAML data source parameter map.
+     * Convert resource segments to data source parameter map.
      *
      * @param databaseType database type
      * @param resources data source segments
-     * @return YAML data source parameter map
+     * @return data source parameter map
      */
-    public static Map<String, YamlDataSourceParameter> convert(final DatabaseType databaseType, final Collection<DataSourceSegment> resources) {
-        Map<String, YamlDataSourceParameter> result = new LinkedHashMap<>(resources.size(), 1);
+    public static Map<String, DataSourceParameter> convert(final DatabaseType databaseType, final Collection<DataSourceSegment> resources) {
+        Map<String, DataSourceParameter> result = new LinkedHashMap<>(resources.size(), 1);
         for (DataSourceSegment each : resources) {
-            DataSourceParameter parameter = new DataSourceParameter();
-            YamlDataSourceParameter dataSource = new YamlDataSourceParameter();
+            DataSourceParameter dataSource = new DataSourceParameter();
             dataSource.setUrl(getURL(databaseType, each));
             dataSource.setUsername(each.getUser());
             dataSource.setPassword(each.getPassword());
-            dataSource.setMinPoolSize(parameter.getMinPoolSize());
-            dataSource.setMaxPoolSize(parameter.getMaxPoolSize());
-            dataSource.setConnectionTimeoutMilliseconds(parameter.getConnectionTimeoutMilliseconds());
-            dataSource.setIdleTimeoutMilliseconds(parameter.getIdleTimeoutMilliseconds());
-            dataSource.setMaxLifetimeMilliseconds(parameter.getMaxLifetimeMilliseconds());
             dataSource.setCustomPoolProps(each.getProperties());
             result.put(each.getName(), dataSource);
         }
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/converter/ResourceSegmentsConverterTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/ResourceSegmentsConverterTest.java
similarity index 88%
rename from shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/converter/ResourceSegmentsConverterTest.java
rename to shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/ResourceSegmentsConverterTest.java
index 9f423cd..ba5f44f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/converter/ResourceSegmentsConverterTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/ResourceSegmentsConverterTest.java
@@ -15,11 +15,11 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.proxy.converter;
+package org.apache.shardingsphere.proxy.backend.text.distsql.rdl.resource;
 
 import org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
+import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
 import org.junit.Test;
 
 import java.util.Arrays;
@@ -36,7 +36,7 @@ public final class ResourceSegmentsConverterTest {
     
     @Test
     public void assertConvert() {
-        Map<String, YamlDataSourceParameter> actual = ResourceSegmentsConverter.convert(new MySQLDatabaseType(), createDataSourceSegments());
+        Map<String, DataSourceParameter> actual = ResourceSegmentsConverter.convert(new MySQLDatabaseType(), createDataSourceSegments());
         assertThat(actual.size(), is(2));
         assertTrue(actual.keySet().containsAll(Arrays.asList("ds0", "ds1")));
         assertThat(actual.values().iterator().next().getUsername(), is("root0"));