You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by xi...@apache.org on 2020/07/13 12:01:46 UTC

[shardingsphere] branch master updated: Use registry center to run SQL for proxy

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

xiaoyu 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 68094ec  Use registry center to run SQL for proxy
     new 21a6780  Merge pull request #6341 from tristaZero/new
68094ec is described below

commit 68094ec3a6e3a3a07593985aa5c4adcae294621a
Author: tristaZero <ha...@163.com>
AuthorDate: Mon Jul 13 19:36:17 2020 +0800

    Use registry center to run SQL for proxy
---
 .../jdbc/execute/RegistryCenterExecuteEngine.java  | 24 ++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/RegistryCenterExecuteEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/RegistryCenterExecuteEngine.java
index e0705a7..8ebb6b4 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/RegistryCenterExecuteEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/RegistryCenterExecuteEngine.java
@@ -18,14 +18,19 @@
 package org.apache.shardingsphere.proxy.backend.communication.jdbc.execute;
 
 import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.callback.orchestration.DataSourceCallback;
+import org.apache.shardingsphere.infra.callback.orchestration.RuleCallback;
 import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
 import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
+import org.apache.shardingsphere.kernel.context.SchemaContexts;
 import org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.generator.YamlDataSourceConfigurationGenerator;
 import org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.generator.YamlShardingRuleConfigurationGenerator;
 import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
+import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
 import org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse;
+import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
 import org.apache.shardingsphere.proxy.config.util.DataSourceConverter;
 import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
 import org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
@@ -34,6 +39,7 @@ import org.apache.shardingsphere.sql.parser.binder.statement.ddl.CreateDataSourc
 import org.apache.shardingsphere.sql.parser.binder.statement.ddl.CreateShardingRuleStatementContext;
 import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
 
+import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedList;
@@ -63,22 +69,32 @@ public class RegistryCenterExecuteEngine implements SQLExecuteEngine {
     }
     
     private BackendResponse execute(final CreateDataSourcesStatementContext context) {
+        if (!isRegistryCenterExisted()) {
+            return new ErrorResponse(new SQLException("No Registry center to execute `%s` SQL", context.getClass().getSimpleName()));
+        }
         Map<String, YamlDataSourceParameter> parameters = new YamlDataSourceConfigurationGenerator().generate(context);
         Map<String, DataSourceConfiguration> dataSources = DataSourceConverter.getDataSourceConfigurationMap(DataSourceConverter.getDataSourceParameterMap2(parameters));
-        // TODO Check whether registry center exists.
-        // TODO Load dataSources from registry center, merge them and persist them.
+        // TODO Need to get the executed feedback from registry center for returning.
+        DataSourceCallback.getInstance().run(schemaName, dataSources);
         UpdateResponse result = new UpdateResponse();
         result.setType("CREATE");
         return result;
     }
     
     private BackendResponse execute(final CreateShardingRuleStatementContext context) {
+        if (!isRegistryCenterExisted()) {
+            return new ErrorResponse(new SQLException("No Registry center to execute `%s` SQL", context.getClass().getSimpleName()));
+        }
         YamlShardingRuleConfiguration configurations = new YamlShardingRuleConfigurationGenerator().generate(context);
         Collection<RuleConfiguration> rules = new YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(Collections.singleton(configurations));
-        // TODO Check whether registry center exists.
-        // TODO Persist it.
+        // TODO Need to get the executed feedback from registry center for returning.
+        RuleCallback.getInstance().run(schemaName, rules);
         UpdateResponse result = new UpdateResponse();
         result.setType("CREATE");
         return result;
     }
+    
+    private boolean isRegistryCenterExisted() {
+        return !(ProxySchemaContexts.getInstance().getSchemaContexts() instanceof SchemaContexts);
+    }
 }