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

duanzhengqiang 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 5504580  Add ConfigCenterRepositoryFactory (#11497)
5504580 is described below

commit 5504580be2e8503567d42d33b3a170385baee69d
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jul 25 17:36:46 2021 +0800

    Add ConfigCenterRepositoryFactory (#11497)
    
    * Refactor AbstractBootstrapInitializer
    
    * Add ConfigCenterRepositoryFactory
    
    * Add ConfigCenterRepositoryFactory
    
    * Revise TODO comment
    
    * Revise TODO comment
---
 .../registry/RegistryCenterRepositoryFactory.java  |  4 +--
 ...ory.java => ConfigCenterRepositoryFactory.java} | 40 +++++++---------------
 .../repository/LocalConfigCenterRepository.java    |  1 +
 .../core/datasource/ShardingSphereDataSource.java  |  5 ++-
 .../org/apache/shardingsphere/proxy/Bootstrap.java | 11 ++----
 .../impl/AbstractBootstrapInitializer.java         |  4 +--
 .../impl/StandardBootstrapInitializer.java         |  1 +
 7 files changed, 23 insertions(+), 43 deletions(-)

diff --git 
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterRepositoryFactory.java
 
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterRepositoryFactory.java
index 900ee95..ea43be4 100644
--- 
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterRepositoryFactory.java
+++ 
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/RegistryCenterRepositoryFactory.java
@@ -37,10 +37,10 @@ public final class RegistryCenterRepositoryFactory {
     }
     
     /**
-     * Create new instance of Registry center repository.
+     * Create new instance of registry center repository.
      * 
      * @param config governance configuration
-     * @return new instance of Registry center repository
+     * @return new instance of registry center repository
      */
     public static RegistryCenterRepository newInstance(final 
GovernanceConfiguration config) {
         RegistryCenterConfiguration registryCenterConfig = 
config.getRegistryCenterConfiguration();
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/LocalConfigCenterRepository.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/ConfigCenterRepositoryFactory.java
similarity index 58%
copy from 
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/LocalConfigCenterRepository.java
copy to 
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/ConfigCenterRepositoryFactory.java
index 1326682..f4f7e00 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/LocalConfigCenterRepository.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/ConfigCenterRepositoryFactory.java
@@ -17,38 +17,24 @@
 
 package org.apache.shardingsphere.infra.config.persist.repository;
 
-import java.util.Collections;
-import java.util.List;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
 
 /**
- * Local config center repository.
+ * Config center repository factory.
  */
-public final class LocalConfigCenterRepository implements 
ConfigCenterRepository {
+public final class ConfigCenterRepositoryFactory {
     
-    @Override
-    public String get(final String key) {
-        return "";
+    static {
+        ShardingSphereServiceLoader.register(ConfigCenterRepository.class);
     }
     
-    @Override
-    public List<String> getChildrenKeys(final String key) {
-        return Collections.emptyList();
-    }
-    
-    @Override
-    public void persist(final String key, final String value) {
-    }
-    
-    @Override
-    public void delete(final String key) {
-    }
-    
-    @Override
-    public void close() {
-    }
-    
-    @Override
-    public String getType() {
-        return "Local";
+    /**
+     * Create new instance of config center repository.
+     *
+     * @return new instance of config center repository
+     */
+    public static ConfigCenterRepository newInstance() {
+        // TODO load from SPI and make LocalConfigCenterRepository as default 
one. We can add more ConfigCenterRepository type such as: Database, Ceph etc...
+        return new LocalConfigCenterRepository();
     }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/LocalConfigCenterRepository.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/LocalConfigCenterRepository.java
index 1326682..454ab2d 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/LocalConfigCenterRepository.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/persist/repository/LocalConfigCenterRepository.java
@@ -23,6 +23,7 @@ import java.util.List;
 /**
  * Local config center repository.
  */
+// TODO finished me
 public final class LocalConfigCenterRepository implements 
ConfigCenterRepository {
     
     @Override
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
index ed1ded7..d69b34d 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
@@ -24,7 +24,7 @@ import 
org.apache.shardingsphere.driver.jdbc.unsupported.AbstractUnsupportedOper
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.config.persist.ConfigCenter;
 import 
org.apache.shardingsphere.infra.config.persist.repository.ConfigCenterRepository;
-import 
org.apache.shardingsphere.infra.config.persist.repository.LocalConfigCenterRepository;
+import 
org.apache.shardingsphere.infra.config.persist.repository.ConfigCenterRepositoryFactory;
 import 
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
 import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
 import 
org.apache.shardingsphere.infra.context.metadata.MetaDataContextsBuilder;
@@ -54,8 +54,7 @@ public final class ShardingSphereDataSource extends 
AbstractUnsupportedOperation
     private final TransactionContexts transactionContexts;
     
     public ShardingSphereDataSource(final Map<String, DataSource> 
dataSourceMap, final Collection<RuleConfiguration> configurations, final 
Properties props) throws SQLException {
-        // TODO load from SPI
-        ConfigCenterRepository repository = new LocalConfigCenterRepository();
+        ConfigCenterRepository repository = 
ConfigCenterRepositoryFactory.newInstance();
         metaDataContexts = new MetaDataContextsBuilder(
                 Collections.singletonMap(DefaultSchema.LOGIC_NAME, 
dataSourceMap), Collections.singletonMap(DefaultSchema.LOGIC_NAME, 
configurations), props).build(new ConfigCenter(repository));
         String xaTransactionMangerType = 
metaDataContexts.getProps().getValue(ConfigurationPropertyKey.XA_TRANSACTION_MANAGER_TYPE);
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
index b961123..f95485c 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
@@ -22,9 +22,7 @@ import lombok.NoArgsConstructor;
 import 
org.apache.shardingsphere.governance.core.registry.RegistryCenterRepositoryFactory;
 import 
org.apache.shardingsphere.governance.core.yaml.swapper.GovernanceConfigurationYamlSwapper;
 import 
org.apache.shardingsphere.governance.repository.api.config.GovernanceConfiguration;
-import 
org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
-import 
org.apache.shardingsphere.infra.config.persist.repository.ConfigCenterRepository;
-import 
org.apache.shardingsphere.infra.config.persist.repository.LocalConfigCenterRepository;
+import 
org.apache.shardingsphere.infra.config.persist.repository.ConfigCenterRepositoryFactory;
 import org.apache.shardingsphere.proxy.arguments.BootstrapArguments;
 import org.apache.shardingsphere.proxy.config.ProxyConfigurationLoader;
 import org.apache.shardingsphere.proxy.config.YamlProxyConfiguration;
@@ -56,12 +54,9 @@ public final class Bootstrap {
     
     private static BootstrapInitializer createBootstrapInitializer(final 
YamlProxyConfiguration yamlConfig) {
         if (null == yamlConfig.getServerConfiguration().getGovernance()) {
-            // TODO load from SPI
-            ConfigCenterRepository repository = new 
LocalConfigCenterRepository();
-            return new StandardBootstrapInitializer(repository);
+            return new 
StandardBootstrapInitializer(ConfigCenterRepositoryFactory.newInstance());
         }
         GovernanceConfiguration governanceConfig = new 
GovernanceConfigurationYamlSwapper().swapToObject(yamlConfig.getServerConfiguration().getGovernance());
-        RegistryCenterRepository repository = 
RegistryCenterRepositoryFactory.newInstance(governanceConfig);
-        return new GovernanceBootstrapInitializer(repository);
+        return new 
GovernanceBootstrapInitializer(RegistryCenterRepositoryFactory.newInstance(governanceConfig));
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
index ec61d58..f59995e 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/AbstractBootstrapInitializer.java
@@ -87,9 +87,7 @@ public abstract class AbstractBootstrapInitializer implements 
BootstrapInitializ
     
     private MetaDataContexts createMetaDataContexts(final ProxyConfiguration 
proxyConfig) throws SQLException {
         Map<String, Map<String, DataSource>> dataSourcesMap = 
createDataSourcesMap(proxyConfig.getSchemaDataSources());
-        MetaDataContextsBuilder metaDataContextsBuilder = new 
MetaDataContextsBuilder(
-                dataSourcesMap, proxyConfig.getSchemaRules(), 
proxyConfig.getGlobalRules(), proxyConfig.getProps());
-        return metaDataContextsBuilder.build(configCenter);
+        return new MetaDataContextsBuilder(dataSourcesMap, 
proxyConfig.getSchemaRules(), proxyConfig.getGlobalRules(), 
proxyConfig.getProps()).build(configCenter);
     }
     
     private static Map<String, Map<String, DataSource>> 
createDataSourcesMap(final Map<String, Map<String, DataSourceParameter>> 
schemaDataSources) {
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
index 0d01170..f92afd9 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/impl/StandardBootstrapInitializer.java
@@ -45,6 +45,7 @@ public final class StandardBootstrapInitializer extends 
AbstractBootstrapInitial
     protected ProxyConfiguration getProxyConfiguration(final 
YamlProxyConfiguration yamlConfig) {
         persistConfigurations(yamlConfig, false);
         ProxyConfiguration result = loadProxyConfiguration();
+        // TODO remove isEmpty judge after LocalConfigCenterRepository finished
         return (result.getSchemaDataSources().isEmpty()) ? new 
YamlProxyConfigurationSwapper().swap(yamlConfig) : result;
     }
     

Reply via email to