You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ki...@apache.org on 2020/07/09 06:05:03 UTC
[shardingsphere] branch master updated: Orchestration spi design in
Sharding-proxy (#6298)
This is an automated email from the ASF dual-hosted git repository.
kimmking 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 985de16 Orchestration spi design in Sharding-proxy (#6298)
985de16 is described below
commit 985de166b5223a344103d458b4fbac9e1098ad42
Author: xiaoyu <54...@qq.com>
AuthorDate: Thu Jul 9 14:04:54 2020 +0800
Orchestration spi design in Sharding-proxy (#6298)
* Orchestration spi design in Sharding-proxy
* fix checkstyle
* code optimize
* fix checkstyle
---
...acadeEngine.java => SingletonFacadeEngine.java} | 33 +----
.../panel/spi/SingletonFacadeEngineTest.java | 42 ++++++
.../spi/fixture/FirstMetricsTrackerFacade.java | 46 ++++++
....control.panel.spi.metrics.MetricsHandlerFacade | 18 +++
.../core/schema/OrchestrationSchemaContexts.java | 4 +-
.../spi/singleton/SingletonServiceLoader.java | 84 +++++++++++
shardingsphere-proxy/pom.xml | 1 +
.../shardingsphere-proxy-backend/pom.xml | 7 -
.../jdbc/execute/JDBCExecuteEngine.java | 6 +-
.../proxy/backend/metrics/MetricsUtils.java | 11 +-
.../shardingsphere-proxy-bootstrap/pom.xml | 7 +-
.../org/apache/shardingsphere/proxy/Bootstrap.java | 157 +++------------------
.../shardingsphere-proxy-common/pom.xml | 9 +-
.../proxy/config/ProxyConfiguration.java | 50 +++++++
.../converter/AbstractConfigurationConverter.java | 101 +++++++++++++
.../converter/DefaultConfigurationConverter.java | 68 +++++++++
.../converter/ProxyConfigurationConverter.java | 47 ++++++
.../ProxyConfigurationConverterFactory.java | 50 +++++++
.../proxy/config}/util/DataSourceConverter.java | 2 +-
.../config}/util/DataSourceConverterTest.java | 2 +-
.../frontend/command/CommandExecutorTask.java | 4 +-
.../netty/FrontendChannelInboundHandler.java | 8 +-
.../mysql/MySQLProtocolFrontendEngineTest.java | 55 ++++----
.../mysql/auth/MySQLAuthenticationHandlerTest.java | 70 ++++-----
.../pom.xml | 46 ++----
.../OrchestrationConfigurationConverter.java | 128 +++++++++++++++++
.../schema/ProxyOrchestrationSchemaContexts.java | 4 +-
...xy.config.converter.ProxyConfigurationConverter | 18 +++
.../ProxyOrchestrationSchemaContextsTest.java} | 17 ++-
29 files changed, 785 insertions(+), 310 deletions(-)
diff --git a/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/main/java/org/apache/shardingsphere/control/panel/spi/engine/MetricsHandlerFacadeEngine.java b/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/main/java/org/apache/shardingsphere/control/panel/spi/engine/SingletonFacadeEngine.java
similarity index 55%
rename from shardingsphere-control-panel/shardingsphere-control-panel-spi/src/main/java/org/apache/shardingsphere/control/panel/spi/engine/MetricsHandlerFacadeEngine.java
rename to shardingsphere-control-panel/shardingsphere-control-panel-spi/src/main/java/org/apache/shardingsphere/control/panel/spi/engine/SingletonFacadeEngine.java
index 7ab1571..8fc3951 100644
--- a/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/main/java/org/apache/shardingsphere/control/panel/spi/engine/MetricsHandlerFacadeEngine.java
+++ b/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/main/java/org/apache/shardingsphere/control/panel/spi/engine/SingletonFacadeEngine.java
@@ -17,42 +17,21 @@
package org.apache.shardingsphere.control.panel.spi.engine;
-import java.util.Iterator;
import java.util.Optional;
-import java.util.ServiceLoader;
import org.apache.shardingsphere.control.panel.spi.metrics.MetricsHandlerFacade;
+import org.apache.shardingsphere.infra.spi.singleton.SingletonServiceLoader;
/**
- * Metrics handler facade engine.
+ * Singleton facade engine.
*/
-public final class MetricsHandlerFacadeEngine {
-
- private static MetricsHandlerFacade handlerFacade;
-
- static {
- handlerFacade = loadFirst();
- }
+public final class SingletonFacadeEngine {
/**
- * Build Metrics handler facade.
+ * Build metrics handler facade.
*
* @return Metrics handler facade.
*/
- public static Optional<MetricsHandlerFacade> build() {
- return Optional.ofNullable(handlerFacade);
- }
-
- private static MetricsHandlerFacade loadFirst() {
- final ServiceLoader<MetricsHandlerFacade> loader = loadAll();
- final Iterator<MetricsHandlerFacade> iterator = loader.iterator();
- if (!iterator.hasNext()) {
- return null;
- }
- return iterator.next();
- }
-
- private static ServiceLoader<MetricsHandlerFacade> loadAll() {
- return ServiceLoader.load(MetricsHandlerFacade.class);
+ public static Optional<MetricsHandlerFacade> buildMetrics() {
+ return SingletonServiceLoader.getServiceLoader(MetricsHandlerFacade.class).newServiceInstances();
}
}
-
diff --git a/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/test/java/org/apache/shardingsphere/control/panel/spi/SingletonFacadeEngineTest.java b/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/test/java/org/apache/shardingsphere/control/panel/spi/SingletonFacadeEngineTest.java
new file mode 100644
index 0000000..b6bb923
--- /dev/null
+++ b/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/test/java/org/apache/shardingsphere/control/panel/spi/SingletonFacadeEngineTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.control.panel.spi;
+
+import java.util.Optional;
+import org.apache.shardingsphere.control.panel.spi.engine.SingletonFacadeEngine;
+import org.apache.shardingsphere.control.panel.spi.fixture.FirstMetricsTrackerFacade;
+import org.apache.shardingsphere.control.panel.spi.metrics.MetricsHandlerFacade;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class SingletonFacadeEngineTest {
+
+ @Test
+ public void assertBuild() {
+ Optional<MetricsHandlerFacade> facade = SingletonFacadeEngine.buildMetrics();
+ assertThat(facade.isPresent(), is(true));
+ MetricsHandlerFacade first = facade.get();
+ assertThat(first.getClass().getName(), is(FirstMetricsTrackerFacade.class.getName()));
+ Optional<MetricsHandlerFacade> facadeSecond = SingletonFacadeEngine.buildMetrics();
+ assertThat(facadeSecond.isPresent(), is(true));
+ MetricsHandlerFacade second = facadeSecond.get();
+ assertThat(first, is(second));
+ }
+}
diff --git a/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/test/java/org/apache/shardingsphere/control/panel/spi/fixture/FirstMetricsTrackerFacade.java b/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/test/java/org/apache/shardingsphere/control/panel/spi/fixture/FirstMetricsTrackerFacade.java
new file mode 100644
index 0000000..8408e1b
--- /dev/null
+++ b/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/test/java/org/apache/shardingsphere/control/panel/spi/fixture/FirstMetricsTrackerFacade.java
@@ -0,0 +1,46 @@
+/*
+ * 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.control.panel.spi.fixture;
+
+import java.util.function.Supplier;
+import org.apache.shardingsphere.control.panel.spi.metrics.MetricsHandlerFacade;
+
+public class FirstMetricsTrackerFacade implements MetricsHandlerFacade {
+
+ @Override
+ public void counterInc(final String metricsLabel, final String... labelValues) {
+ }
+
+ @Override
+ public void gaugeInc(final String metricsLabel, final String... labelValues) {
+ }
+
+ @Override
+ public void gaugeDec(final String metricsLabel, final String... labelValues) {
+ }
+
+ @Override
+ public Supplier<Boolean> histogramStartTimer(final String metricsLabel, final String... labelValues) {
+ return null;
+ }
+
+ @Override
+ public Supplier<Boolean> summaryStartTimer(final String metricsLabel, final String... labelValues) {
+ return null;
+ }
+}
diff --git a/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/test/resources/META-INF/services/org.apache.shardingsphere.control.panel.spi.metrics.MetricsHandlerFacade b/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/test/resources/META-INF/services/org.apache.shardingsphere.control.panel.spi.metrics.MetricsHandlerFacade
new file mode 100644
index 0000000..107be7a
--- /dev/null
+++ b/shardingsphere-control-panel/shardingsphere-control-panel-spi/src/test/resources/META-INF/services/org.apache.shardingsphere.control.panel.spi.metrics.MetricsHandlerFacade
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.control.panel.spi.fixture.FirstMetricsTrackerFacade
diff --git a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/src/main/java/org/apache/shardingsphere/orchestration/core/schema/OrchestrationSchemaContexts.java b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/src/main/java/org/apache/shardingsphere/orchestration/core/schema/OrchestrationSchemaContexts.java
index d7f57e1..8b6ae16 100644
--- a/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/src/main/java/org/apache/shardingsphere/orchestration/core/schema/OrchestrationSchemaContexts.java
+++ b/shardingsphere-control-panel/shardingsphere-orchestration/shardingsphere-orchestration-core/shardingsphere-orchestration-core-schema/src/main/java/org/apache/shardingsphere/orchestration/core/schema/OrchestrationSchemaContexts.java
@@ -32,6 +32,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseTypes;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorKernel;
import org.apache.shardingsphere.infra.log.ConfigurationLogger;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.callback.MetaDataCallback;
import org.apache.shardingsphere.infra.metadata.schema.RuleSchemaMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.StatusContainedRule;
@@ -87,8 +88,7 @@ public abstract class OrchestrationSchemaContexts implements SchemaContextsAware
}
private void persistMetaData() {
- schemaContexts.getSchemaContexts().forEach((key, value) -> ShardingOrchestrationFacade.getInstance()
- .getMetaDataCenter().persistMetaDataCenterNode(key, value.getSchema().getMetaData().getSchema()));
+ schemaContexts.getSchemaContexts().forEach((key, value) -> MetaDataCallback.INSTANCE.run(key, value.getSchema().getMetaData().getSchema()));
}
private void disableMasterSlaveRules() {
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoader.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoader.java
new file mode 100644
index 0000000..2b4ff21
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/spi/singleton/SingletonServiceLoader.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.infra.spi.singleton;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Optional;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Singleton service loader.
+ */
+public final class SingletonServiceLoader<T> {
+
+ private static final Map<Class<?>, SingletonServiceLoader<?>> LOADERS = new ConcurrentHashMap<>();
+
+ private final Map<Class<?>, Collection<T>> serviceMap = new ConcurrentHashMap<>();
+
+ private final Class<T> service;
+
+ private SingletonServiceLoader(final Class<T> service) {
+ this.service = service;
+ register(service);
+ }
+
+ /**
+ * Get singleton service loader.
+ *
+ * @param service service type
+ * @param <T> type of service
+ * @return singleton service loader.
+ */
+ @SuppressWarnings("unchecked")
+ public static <T> SingletonServiceLoader<T> getServiceLoader(final Class<T> service) {
+ if (null == service) {
+ throw new NullPointerException("extension clazz is null");
+ }
+ if (!service.isInterface()) {
+ throw new IllegalArgumentException("extension clazz (" + service + "is not interface!");
+ }
+ SingletonServiceLoader<T> serviceLoader = (SingletonServiceLoader<T>) LOADERS.get(service);
+ if (null != serviceLoader) {
+ return serviceLoader;
+ }
+ LOADERS.putIfAbsent(service, new SingletonServiceLoader<>(service));
+ return (SingletonServiceLoader<T>) LOADERS.get(service);
+ }
+
+ /**
+ * New service instances.
+ *
+ * @return service instances
+ */
+ public Optional<T> newServiceInstances() {
+ return serviceMap.get(service).stream().findFirst();
+ }
+
+ private void register(final Class<T> service) {
+ if (serviceMap.containsKey(service)) {
+ return;
+ }
+ serviceMap.put(service, new ArrayList<>());
+ for (T each : ServiceLoader.load(service)) {
+ serviceMap.get(service).add(each);
+ }
+ }
+}
diff --git a/shardingsphere-proxy/pom.xml b/shardingsphere-proxy/pom.xml
index 5e4aca6..381fd49 100644
--- a/shardingsphere-proxy/pom.xml
+++ b/shardingsphere-proxy/pom.xml
@@ -37,5 +37,6 @@
<module>shardingsphere-proxy-frontend</module>
<module>shardingsphere-proxy-backend</module>
<module>shardingsphere-proxy-bootstrap</module>
+ <module>shardingsphere-proxy-orchestration</module>
</modules>
</project>
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
index 51ce337..c59a9d6 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
@@ -118,17 +118,10 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-orchestration-core-schema</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
-
- <dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<scope>compile</scope>
</dependency>
-
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/JDBCExecuteEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/JDBCExecuteEngine.java
index 816801c..ee3df6b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/JDBCExecuteEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/JDBCExecuteEngine.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.proxy.backend.communication.jdbc.execute;
import com.google.common.base.Strings;
import lombok.Getter;
-import org.apache.shardingsphere.control.panel.spi.engine.MetricsHandlerFacadeEngine;
+import org.apache.shardingsphere.control.panel.spi.engine.SingletonFacadeEngine;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.executor.kernel.InputGroup;
import org.apache.shardingsphere.infra.executor.sql.ExecutorConstant;
@@ -102,7 +102,7 @@ public final class JDBCExecuteEngine implements SQLExecuteEngine {
}
ExecuteResult executeResult = executeResults.iterator().next();
if (executeResult instanceof ExecuteQueryResult) {
- MetricsHandlerFacadeEngine.build().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.SQL_STATEMENT_COUNT.getName(), "SELECT"));
+ SingletonFacadeEngine.buildMetrics().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.SQL_STATEMENT_COUNT.getName(), "SELECT"));
return getExecuteQueryResponse(((ExecuteQueryResult) executeResult).getQueryHeaders(), executeResults);
} else {
UpdateResponse updateResponse = new UpdateResponse(executeResults);
@@ -114,7 +114,7 @@ public final class JDBCExecuteEngine implements SQLExecuteEngine {
updateResponse.setType("UPDATE");
}
if (!Strings.isNullOrEmpty(updateResponse.getType())) {
- MetricsHandlerFacadeEngine.build().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.SQL_STATEMENT_COUNT.getName(), updateResponse.getType()));
+ SingletonFacadeEngine.buildMetrics().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.SQL_STATEMENT_COUNT.getName(), updateResponse.getType()));
}
return updateResponse;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/metrics/MetricsUtils.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/metrics/MetricsUtils.java
index 07de852..e08d81c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/metrics/MetricsUtils.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/metrics/MetricsUtils.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.proxy.backend.metrics;
-import org.apache.shardingsphere.control.panel.spi.engine.MetricsHandlerFacadeEngine;
+import org.apache.shardingsphere.control.panel.spi.engine.SingletonFacadeEngine;
import org.apache.shardingsphere.metrics.enums.MetricsLabelEnum;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
@@ -42,9 +42,10 @@ public final class MetricsUtils {
for (RouteUnit each : routeUnits) {
Collection<RouteMapper> tableMappers = each.getTableMappers();
RouteMapper dataSourceMapper = each.getDataSourceMapper();
- MetricsHandlerFacadeEngine.build().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.SHARDING_DATASOURCE.getName(), dataSourceMapper.getActualName()));
+ SingletonFacadeEngine.buildMetrics()
+ .ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.SHARDING_DATASOURCE.getName(), dataSourceMapper.getActualName()));
for (RouteMapper table : tableMappers) {
- MetricsHandlerFacadeEngine.build().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.SHARDING_TABLE.getName(), table.getActualName()));
+ SingletonFacadeEngine.buildMetrics().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.SHARDING_TABLE.getName(), table.getActualName()));
}
}
}
@@ -56,7 +57,7 @@ public final class MetricsUtils {
* @param labelValue label value
*/
public static void buriedTransactionMetric(final String labelValue) {
- MetricsHandlerFacadeEngine.build().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.TRANSACTION.getName(), labelValue));
+ SingletonFacadeEngine.buildMetrics().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.TRANSACTION.getName(), labelValue));
}
/**
@@ -68,7 +69,7 @@ public final class MetricsUtils {
public static void buriedShardingRuleMetrics(final RouteContext routeContext, final Collection<ShardingSphereRule> rules) {
routeContext.getRouteResult().getActualDataSourceNames().forEach(dataSourceName -> rules.forEach(each -> {
if (each instanceof ShadowRule && ((ShadowRule) each).getShadowMappings().containsValue(dataSourceName)) {
- MetricsHandlerFacadeEngine.build().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.SHADOW_HIT_TOTAL.getName()));
+ SingletonFacadeEngine.buildMetrics().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.SHADOW_HIT_TOTAL.getName()));
}
}));
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/pom.xml b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/pom.xml
index f557220..b7f8bde 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/pom.xml
@@ -69,12 +69,7 @@
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-orchestration-core-facade</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-orchestration-center-zookeeper-curator</artifactId>
+ <artifactId>shardingsphere-proxy-orchestration</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
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 6e12d27..4fcfde2 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
@@ -18,21 +18,17 @@
package org.apache.shardingsphere.proxy;
import com.google.common.primitives.Ints;
+import java.util.Objects;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.shardingsphere.cluster.configuration.config.ClusterConfiguration;
-import org.apache.shardingsphere.cluster.configuration.swapper.ClusterConfigurationYamlSwapper;
-import org.apache.shardingsphere.cluster.configuration.yaml.YamlClusterConfiguration;
import org.apache.shardingsphere.control.panel.spi.FacadeConfiguration;
import org.apache.shardingsphere.control.panel.spi.engine.ControlPanelFacadeEngine;
import org.apache.shardingsphere.control.panel.spi.opentracing.OpenTracingConfiguration;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
import org.apache.shardingsphere.infra.auth.Authentication;
-import org.apache.shardingsphere.infra.auth.yaml.config.YamlAuthenticationConfiguration;
-import org.apache.shardingsphere.infra.auth.yaml.swapper.AuthenticationYamlSwapper;
-import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
@@ -41,29 +37,21 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.log.ConfigurationLogger;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
-import org.apache.shardingsphere.kernel.context.SchemaContextsAware;
import org.apache.shardingsphere.kernel.context.SchemaContextsBuilder;
import org.apache.shardingsphere.kernel.context.schema.DataSourceParameter;
import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
-import org.apache.shardingsphere.metrics.configuration.swapper.MetricsConfigurationYamlSwapper;
-import org.apache.shardingsphere.metrics.configuration.yaml.YamlMetricsConfiguration;
-import org.apache.shardingsphere.orchestration.center.yaml.config.YamlOrchestrationConfiguration;
-import org.apache.shardingsphere.orchestration.center.yaml.swapper.OrchestrationConfigurationYamlSwapper;
-import org.apache.shardingsphere.orchestration.core.facade.ShardingOrchestrationFacade;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCRawBackendDataSourceFactory;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.recognizer.JDBCDriverURLRecognizerEngine;
-import org.apache.shardingsphere.proxy.backend.schema.ProxyOrchestrationSchemaContexts;
import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
-import org.apache.shardingsphere.proxy.backend.util.DataSourceConverter;
+import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
+import org.apache.shardingsphere.proxy.config.converter.ProxyConfigurationConverter;
+import org.apache.shardingsphere.proxy.config.converter.ProxyConfigurationConverterFactory;
import org.apache.shardingsphere.proxy.config.ShardingConfiguration;
import org.apache.shardingsphere.proxy.config.ShardingConfigurationLoader;
-import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
import org.apache.shardingsphere.proxy.config.yaml.YamlProxyRuleConfiguration;
-import org.apache.shardingsphere.proxy.config.yaml.YamlProxyServerConfiguration;
import org.apache.shardingsphere.proxy.frontend.bootstrap.ShardingSphereProxy;
import javax.sql.DataSource;
-import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
@@ -73,7 +61,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
@@ -92,18 +79,16 @@ public final class Bootstrap {
* Main entrance.
*
* @param args startup arguments
- * @throws IOException IO exception
- * @throws SQLException SQL exception
+ * @throws Exception exception
*/
- public static void main(final String[] args) throws IOException, SQLException {
+ public static void main(final String[] args) throws Exception {
int port = getPort(args);
ShardingConfiguration shardingConfig = new ShardingConfigurationLoader().load(getConfigPath(args));
logRuleConfigurationMap(getRuleConfigurations(shardingConfig.getRuleConfigurationMap()).values());
- if (null == shardingConfig.getServerConfiguration().getOrchestration()) {
- startWithoutRegistryCenter(shardingConfig.getRuleConfigurationMap(), shardingConfig.getServerConfiguration().getAuthentication(),
- shardingConfig.getServerConfiguration().getMetrics(), shardingConfig.getServerConfiguration().getCluster(), shardingConfig.getServerConfiguration().getProps(), port);
- } else {
- startWithRegistryCenter(shardingConfig.getServerConfiguration(), shardingConfig.getRuleConfigurationMap().keySet(), shardingConfig.getRuleConfigurationMap(), port);
+ boolean isOrchestration = null != shardingConfig.getServerConfiguration().getOrchestration();
+ try (ProxyConfigurationConverter converter = ProxyConfigurationConverterFactory.newInstances(isOrchestration)) {
+ ProxyConfiguration proxyConfiguration = converter.convert(shardingConfig);
+ initialize(proxyConfiguration, port, converter);
}
}
@@ -127,40 +112,14 @@ public final class Bootstrap {
return path.startsWith("/") ? path : ("/" + path);
}
- private static void startWithoutRegistryCenter(final Map<String, YamlProxyRuleConfiguration> ruleConfigs,
- final YamlAuthenticationConfiguration yamlAuthenticationConfig,
- final YamlMetricsConfiguration metricsConfiguration, final YamlClusterConfiguration clusterConfiguration,
- final Properties properties, final int port) throws SQLException {
- Authentication authentication = new AuthenticationYamlSwapper().swapToObject(yamlAuthenticationConfig);
- Map<String, Map<String, DataSourceParameter>> schemaDataSources = getDataSourceParametersMap(ruleConfigs);
- Map<String, Collection<RuleConfiguration>> schemaRules = getRuleConfigurations(ruleConfigs);
- initialize(authentication, properties, schemaDataSources, schemaRules, getMetricsConfiguration(metricsConfiguration),
- getClusterConfiguration(clusterConfiguration), false);
- ShardingSphereProxy.getInstance().start(port);
- }
-
- private static void startWithRegistryCenter(final YamlProxyServerConfiguration serverConfig, final Collection<String> shardingSchemaNames,
- final Map<String, YamlProxyRuleConfiguration> ruleConfigs, final int port) throws SQLException {
- try (ShardingOrchestrationFacade shardingOrchestrationFacade = new ShardingOrchestrationFacade(
- new OrchestrationConfigurationYamlSwapper().swapToObject(new YamlOrchestrationConfiguration(serverConfig.getOrchestration())), shardingSchemaNames)) {
- initShardingOrchestrationFacade(serverConfig, ruleConfigs, shardingOrchestrationFacade);
- Authentication authentication = shardingOrchestrationFacade.getConfigCenter().loadAuthentication();
- Properties properties = shardingOrchestrationFacade.getConfigCenter().loadProperties();
- Map<String, Map<String, DataSourceParameter>> schemaDataSources = getDataSourceParametersMap(shardingOrchestrationFacade);
- Map<String, Collection<RuleConfiguration>> schemaRules = getSchemaRules(shardingOrchestrationFacade);
- ClusterConfiguration clusterConfiguration = shardingOrchestrationFacade.getConfigCenter().loadClusterConfiguration();
- initialize(authentication, properties, schemaDataSources, schemaRules, getMetricsConfiguration(serverConfig.getMetrics()), clusterConfiguration, true);
- ShardingSphereProxy.getInstance().start(port);
- }
- }
-
- private static void initialize(final Authentication authentication, final Properties properties, final Map<String, Map<String, DataSourceParameter>> schemaDataSources,
- final Map<String, Collection<RuleConfiguration>> schemaRules, final MetricsConfiguration metricsConfiguration,
- final ClusterConfiguration clusterConfiguration, final boolean isOrchestration) throws SQLException {
- initProxySchemaContexts(schemaDataSources, schemaRules, authentication, properties, isOrchestration);
- log(authentication, properties);
- initControlPanelFacade(metricsConfiguration, clusterConfiguration);
+ private static void initialize(final ProxyConfiguration proxyConfiguration, final int port, final ProxyConfigurationConverter converter) throws SQLException {
+ Authentication authentication = proxyConfiguration.getAuthentication();
+ Properties props = proxyConfiguration.getProps();
+ log(authentication, props);
+ initProxySchemaContexts(proxyConfiguration.getSchemaDataSources(), proxyConfiguration.getSchemaRules(), authentication, props, converter);
+ initControlPanelFacade(proxyConfiguration.getMetrics(), proxyConfiguration.getCluster());
updateServerInfo();
+ ShardingSphereProxy.getInstance().start(port);
}
private static void updateServerInfo() {
@@ -168,7 +127,7 @@ public final class Bootstrap {
if (CollectionUtils.isEmpty(schemaNames)) {
return;
}
- Map<String, DataSource> dataSources = ProxySchemaContexts.getInstance().getSchema(schemaNames.get(0)).getSchema().getDataSources();
+ Map<String, DataSource> dataSources = Objects.requireNonNull(ProxySchemaContexts.getInstance().getSchema(schemaNames.get(0))).getSchema().getDataSources();
DataSource singleDataSource = dataSources.values().iterator().next();
try (Connection connection = singleDataSource.getConnection()) {
DatabaseMetaData databaseMetaData = connection.getMetaData();
@@ -196,15 +155,14 @@ public final class Bootstrap {
}
private static void initProxySchemaContexts(final Map<String, Map<String, DataSourceParameter>> schemaDataSources, final Map<String, Collection<RuleConfiguration>> schemaRules,
- final Authentication authentication, final Properties properties, final boolean isOrchestration) throws SQLException {
+ final Authentication authentication, final Properties properties, final ProxyConfigurationConverter converter) throws SQLException {
// TODO Consider loading from configuration.
DatabaseType databaseType = schemaDataSources.isEmpty() ? new MySQLDatabaseType()
: DatabaseTypes.getActualDatabaseType(
JDBCDriverURLRecognizerEngine.getJDBCDriverURLRecognizer(schemaDataSources.values().iterator().next().values().iterator().next().getUrl()).getDatabaseType());
SchemaContextsBuilder schemaContextsBuilder =
new SchemaContextsBuilder(createDataSourcesMap(schemaDataSources), schemaDataSources, authentication, databaseType, schemaRules, properties);
- SchemaContextsAware schemaContexts = isOrchestration ? new ProxyOrchestrationSchemaContexts(schemaContextsBuilder.build()) : schemaContextsBuilder.build();
- ProxySchemaContexts.getInstance().init(schemaContexts);
+ ProxySchemaContexts.getInstance().init(converter.contextsAware(schemaContextsBuilder));
}
private static Map<String, Map<String, DataSource>> createDataSourcesMap(final Map<String, Map<String, DataSourceParameter>> schemaDataSources) {
@@ -230,82 +188,11 @@ public final class Bootstrap {
ConfigurationLogger.log(properties);
}
- private static Map<String, Collection<RuleConfiguration>> getSchemaRules(final ShardingOrchestrationFacade shardingOrchestrationFacade) {
- Map<String, Collection<RuleConfiguration>> result = new LinkedHashMap<>();
- for (String each : shardingOrchestrationFacade.getConfigCenter().getAllShardingSchemaNames()) {
- result.put(each, shardingOrchestrationFacade.getConfigCenter().loadRuleConfigurations(each));
- }
- return result;
- }
-
- private static void initShardingOrchestrationFacade(
- final YamlProxyServerConfiguration serverConfig, final Map<String, YamlProxyRuleConfiguration> ruleConfigs, final ShardingOrchestrationFacade shardingOrchestrationFacade) {
- if (isEmptyLocalConfiguration(serverConfig, ruleConfigs)) {
- shardingOrchestrationFacade.init();
- } else {
- shardingOrchestrationFacade.init(getDataSourceConfigurationMap(ruleConfigs),
- getRuleConfigurations(ruleConfigs), new AuthenticationYamlSwapper().swapToObject(serverConfig.getAuthentication()), serverConfig.getProps());
- }
- shardingOrchestrationFacade.initMetricsConfiguration(Optional.ofNullable(serverConfig.getMetrics()).map(new MetricsConfigurationYamlSwapper()::swapToObject).orElse(null));
- shardingOrchestrationFacade.initClusterConfiguration(Optional.ofNullable(serverConfig.getCluster()).map(new ClusterConfigurationYamlSwapper()::swapToObject).orElse(null));
- }
-
- private static boolean isEmptyLocalConfiguration(final YamlProxyServerConfiguration serverConfig, final Map<String, YamlProxyRuleConfiguration> ruleConfigs) {
- return ruleConfigs.isEmpty() && null == serverConfig.getAuthentication() && serverConfig.getProps().isEmpty();
- }
-
- private static Map<String, Map<String, DataSourceConfiguration>> getDataSourceConfigurationMap(final Map<String, YamlProxyRuleConfiguration> ruleConfigs) {
- Map<String, Map<String, DataSourceConfiguration>> result = new LinkedHashMap<>();
- for (Entry<String, YamlProxyRuleConfiguration> entry : ruleConfigs.entrySet()) {
- result.put(entry.getKey(), DataSourceConverter.getDataSourceConfigurationMap(getDataSourceParameters(entry.getValue().getDataSources())));
- }
- return result;
- }
-
private static Map<String, Collection<RuleConfiguration>> getRuleConfigurations(final Map<String, YamlProxyRuleConfiguration> localRuleConfigs) {
YamlRuleConfigurationSwapperEngine swapperEngine = new YamlRuleConfigurationSwapperEngine();
return localRuleConfigs.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> swapperEngine.swapToRuleConfigurations(entry.getValue().getRules())));
}
- private static Map<String, Map<String, DataSourceParameter>> getDataSourceParametersMap(final ShardingOrchestrationFacade shardingOrchestrationFacade) {
- Map<String, Map<String, DataSourceParameter>> result = new LinkedHashMap<>();
- for (String each : shardingOrchestrationFacade.getConfigCenter().getAllShardingSchemaNames()) {
- result.put(each, DataSourceConverter.getDataSourceParameterMap(shardingOrchestrationFacade.getConfigCenter().loadDataSourceConfigurations(each)));
- }
- return result;
- }
-
- private static Map<String, Map<String, DataSourceParameter>> getDataSourceParametersMap(final Map<String, YamlProxyRuleConfiguration> localRuleConfigs) {
- return localRuleConfigs.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> getDataSourceParameters(entry.getValue().getDataSources())));
- }
-
- private static Map<String, DataSourceParameter> getDataSourceParameters(final Map<String, YamlDataSourceParameter> dataSourceParameters) {
- return dataSourceParameters.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> createDataSourceParameter(entry.getValue()), (oldVal, currVal) -> oldVal, LinkedHashMap::new));
- }
-
- private static DataSourceParameter createDataSourceParameter(final YamlDataSourceParameter yamlDataSourceParameter) {
- DataSourceParameter result = new DataSourceParameter();
- result.setConnectionTimeoutMilliseconds(yamlDataSourceParameter.getConnectionTimeoutMilliseconds());
- result.setIdleTimeoutMilliseconds(yamlDataSourceParameter.getIdleTimeoutMilliseconds());
- result.setMaintenanceIntervalMilliseconds(yamlDataSourceParameter.getMaintenanceIntervalMilliseconds());
- result.setMaxLifetimeMilliseconds(yamlDataSourceParameter.getMaxLifetimeMilliseconds());
- result.setMaxPoolSize(yamlDataSourceParameter.getMaxPoolSize());
- result.setMinPoolSize(yamlDataSourceParameter.getMinPoolSize());
- result.setUsername(yamlDataSourceParameter.getUsername());
- result.setPassword(yamlDataSourceParameter.getPassword());
- result.setReadOnly(yamlDataSourceParameter.isReadOnly());
- result.setUrl(yamlDataSourceParameter.getUrl());
- return result;
- }
-
- private static MetricsConfiguration getMetricsConfiguration(final YamlMetricsConfiguration yamlMetricsConfiguration) {
- return Optional.ofNullable(yamlMetricsConfiguration).map(new MetricsConfigurationYamlSwapper()::swapToObject).orElse(null);
- }
-
- private static ClusterConfiguration getClusterConfiguration(final YamlClusterConfiguration yamlClusterConfiguration) {
- return Optional.ofNullable(yamlClusterConfiguration).map(new ClusterConfigurationYamlSwapper()::swapToObject).orElse(null);
- }
-
/**
* Log rule configurations.
*
@@ -313,9 +200,7 @@ public final class Bootstrap {
*/
private static void logRuleConfigurationMap(final Collection<Collection<RuleConfiguration>> ruleConfigurations) {
if (CollectionUtils.isNotEmpty(ruleConfigurations)) {
- for (Collection<RuleConfiguration> each : ruleConfigurations) {
- ConfigurationLogger.log(each);
- }
+ ruleConfigurations.forEach(ConfigurationLogger::log);
}
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml b/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
index 651e575..60e63fc 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
@@ -29,22 +29,23 @@
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-orchestration-core-facade</artifactId>
+ <artifactId>shardingsphere-orchestration-center-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-orchestration-center-api</artifactId>
+ <artifactId>shardingsphere-orchestration-center-configuration</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-orchestration-center-configuration</artifactId>
+ <artifactId>shardingsphere-control-panel-spi</artifactId>
<version>${project.version}</version>
</dependency>
+
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-control-panel-spi</artifactId>
+ <artifactId>shardingsphere-metrics-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfiguration.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfiguration.java
new file mode 100644
index 0000000..fe6775c
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfiguration.java
@@ -0,0 +1,50 @@
+/*
+ * 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.proxy.config;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.cluster.configuration.config.ClusterConfiguration;
+import org.apache.shardingsphere.infra.auth.Authentication;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.kernel.context.schema.DataSourceParameter;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
+
+/**
+ * Proxy configuration.
+ */
+@Getter
+@Setter
+public final class ProxyConfiguration implements Serializable {
+
+ private Authentication authentication;
+
+ private Properties props;
+
+ private Map<String, Map<String, DataSourceParameter>> schemaDataSources;
+
+ private Map<String, Collection<RuleConfiguration>> schemaRules;
+
+ private MetricsConfiguration metrics;
+
+ private ClusterConfiguration cluster;
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/converter/AbstractConfigurationConverter.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/converter/AbstractConfigurationConverter.java
new file mode 100644
index 0000000..50bb35a
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/converter/AbstractConfigurationConverter.java
@@ -0,0 +1,101 @@
+/*
+ * 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.proxy.config.converter;
+
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
+import org.apache.shardingsphere.kernel.context.schema.DataSourceParameter;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
+import org.apache.shardingsphere.metrics.configuration.swapper.MetricsConfigurationYamlSwapper;
+import org.apache.shardingsphere.metrics.configuration.yaml.YamlMetricsConfiguration;
+import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
+import org.apache.shardingsphere.proxy.config.yaml.YamlProxyRuleConfiguration;
+
+/**
+ * Abstract configuration converter.
+ */
+public abstract class AbstractConfigurationConverter implements ProxyConfigurationConverter {
+
+ /**
+ * Get rule configurations.
+ *
+ * @param localRuleConfigs rule configs for YAML
+ * @return rule configurations
+ */
+ protected Map<String, Collection<RuleConfiguration>> getRuleConfigurations(final Map<String, YamlProxyRuleConfiguration> localRuleConfigs) {
+ YamlRuleConfigurationSwapperEngine swapperEngine = new YamlRuleConfigurationSwapperEngine();
+ return localRuleConfigs.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> swapperEngine.swapToRuleConfigurations(entry.getValue().getRules())));
+ }
+
+ /**
+ * Get data source parameters map.
+ *
+ * @param localRuleConfigs rule configs for YAML
+ * @return data source parameters map
+ */
+ protected Map<String, Map<String, DataSourceParameter>> getDataSourceParametersMap(final Map<String, YamlProxyRuleConfiguration> localRuleConfigs) {
+ return localRuleConfigs.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> getDataSourceParameters(entry.getValue().getDataSources())));
+ }
+
+ /**
+ * Get data source parameters.
+ *
+ * @param dataSourceParameters data source parameters for YAML
+ * @return data source parameters
+ */
+ protected Map<String, DataSourceParameter> getDataSourceParameters(final Map<String, YamlDataSourceParameter> dataSourceParameters) {
+ return dataSourceParameters.entrySet().stream()
+ .collect(Collectors.toMap(Map.Entry::getKey, entry -> createDataSourceParameter(entry.getValue()), (oldVal, currVal) -> oldVal, LinkedHashMap::new));
+ }
+
+ /**
+ * Create data source parameter.
+ *
+ * @param yamlDataSourceParameter data source parameter for YAML
+ * @return data source parameter
+ */
+ protected DataSourceParameter createDataSourceParameter(final YamlDataSourceParameter yamlDataSourceParameter) {
+ DataSourceParameter result = new DataSourceParameter();
+ result.setConnectionTimeoutMilliseconds(yamlDataSourceParameter.getConnectionTimeoutMilliseconds());
+ result.setIdleTimeoutMilliseconds(yamlDataSourceParameter.getIdleTimeoutMilliseconds());
+ result.setMaintenanceIntervalMilliseconds(yamlDataSourceParameter.getMaintenanceIntervalMilliseconds());
+ result.setMaxLifetimeMilliseconds(yamlDataSourceParameter.getMaxLifetimeMilliseconds());
+ result.setMaxPoolSize(yamlDataSourceParameter.getMaxPoolSize());
+ result.setMinPoolSize(yamlDataSourceParameter.getMinPoolSize());
+ result.setUsername(yamlDataSourceParameter.getUsername());
+ result.setPassword(yamlDataSourceParameter.getPassword());
+ result.setReadOnly(yamlDataSourceParameter.isReadOnly());
+ result.setUrl(yamlDataSourceParameter.getUrl());
+ return result;
+ }
+
+ /**
+ * Get metrics configuration.
+ *
+ * @param yamlMetricsConfiguration metrics configuration for YAML
+ * @return metrics configuration
+ */
+ protected MetricsConfiguration getMetricsConfiguration(final YamlMetricsConfiguration yamlMetricsConfiguration) {
+ return Optional.ofNullable(yamlMetricsConfiguration).map(new MetricsConfigurationYamlSwapper()::swapToObject).orElse(null);
+ }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/converter/DefaultConfigurationConverter.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/converter/DefaultConfigurationConverter.java
new file mode 100644
index 0000000..085659b
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/converter/DefaultConfigurationConverter.java
@@ -0,0 +1,68 @@
+/*
+ * 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.proxy.config.converter;
+
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.shardingsphere.cluster.configuration.config.ClusterConfiguration;
+import org.apache.shardingsphere.cluster.configuration.swapper.ClusterConfigurationYamlSwapper;
+import org.apache.shardingsphere.cluster.configuration.yaml.YamlClusterConfiguration;
+import org.apache.shardingsphere.infra.auth.Authentication;
+import org.apache.shardingsphere.infra.auth.yaml.swapper.AuthenticationYamlSwapper;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.kernel.context.SchemaContextsAware;
+import org.apache.shardingsphere.kernel.context.SchemaContextsBuilder;
+import org.apache.shardingsphere.kernel.context.schema.DataSourceParameter;
+import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
+import org.apache.shardingsphere.proxy.config.ShardingConfiguration;
+
+/**
+ * Default configuration converter.
+ */
+public final class DefaultConfigurationConverter extends AbstractConfigurationConverter {
+
+ @Override
+ public ProxyConfiguration convert(final ShardingConfiguration shardingConfiguration) {
+ ProxyConfiguration proxyConfiguration = new ProxyConfiguration();
+ Authentication authentication = new AuthenticationYamlSwapper().swapToObject(shardingConfiguration.getServerConfiguration().getAuthentication());
+ Map<String, Map<String, DataSourceParameter>> schemaDataSources = getDataSourceParametersMap(shardingConfiguration.getRuleConfigurationMap());
+ Map<String, Collection<RuleConfiguration>> schemaRules = getRuleConfigurations(shardingConfiguration.getRuleConfigurationMap());
+ proxyConfiguration.setAuthentication(authentication);
+ proxyConfiguration.setProps(shardingConfiguration.getServerConfiguration().getProps());
+ proxyConfiguration.setSchemaDataSources(schemaDataSources);
+ proxyConfiguration.setSchemaRules(schemaRules);
+ proxyConfiguration.setCluster(getClusterConfiguration(shardingConfiguration.getServerConfiguration().getCluster()));
+ proxyConfiguration.setMetrics(getMetricsConfiguration(shardingConfiguration.getServerConfiguration().getMetrics()));
+ return proxyConfiguration;
+ }
+
+ @Override
+ public SchemaContextsAware contextsAware(final SchemaContextsBuilder builder) throws SQLException {
+ return builder.build();
+ }
+
+ private ClusterConfiguration getClusterConfiguration(final YamlClusterConfiguration yamlClusterConfiguration) {
+ return Optional.ofNullable(yamlClusterConfiguration).map(new ClusterConfigurationYamlSwapper()::swapToObject).orElse(null);
+ }
+
+ @Override
+ public void close() {
+ }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/converter/ProxyConfigurationConverter.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/converter/ProxyConfigurationConverter.java
new file mode 100644
index 0000000..65327cb
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/converter/ProxyConfigurationConverter.java
@@ -0,0 +1,47 @@
+/*
+ * 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.proxy.config.converter;
+
+import java.sql.SQLException;
+import org.apache.shardingsphere.kernel.context.SchemaContextsAware;
+import org.apache.shardingsphere.kernel.context.SchemaContextsBuilder;
+import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
+import org.apache.shardingsphere.proxy.config.ShardingConfiguration;
+
+/**
+ * Proxy configuration converter.
+ */
+public interface ProxyConfigurationConverter extends AutoCloseable {
+
+ /**
+ * Convert proxy configuration.
+ *
+ * @param shardingConfiguration sharding configuration
+ * @return proxy configuration
+ */
+ ProxyConfiguration convert(ShardingConfiguration shardingConfiguration);
+
+ /**
+ * Build contexts aware.
+ *
+ * @param builder schema contexts builder
+ * @return schema contexts aware
+ * @throws SQLException sql exception
+ */
+ SchemaContextsAware contextsAware(SchemaContextsBuilder builder) throws SQLException;
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/converter/ProxyConfigurationConverterFactory.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/converter/ProxyConfigurationConverterFactory.java
new file mode 100644
index 0000000..015a345
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/converter/ProxyConfigurationConverterFactory.java
@@ -0,0 +1,50 @@
+/*
+ * 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.proxy.config.converter;
+
+import java.util.Optional;
+import org.apache.shardingsphere.infra.spi.exception.ServiceProviderNotFoundException;
+import org.apache.shardingsphere.infra.spi.singleton.SingletonServiceLoader;
+
+/**
+ * Proxy configuration converter factory.
+ */
+public final class ProxyConfigurationConverterFactory {
+
+ /**
+ * New proxy configuration converter instances.
+ *
+ * @param isOrchestration is orchestration
+ * @return proxy configuration converter
+ */
+ public static ProxyConfigurationConverter newInstances(final boolean isOrchestration) {
+ if (isOrchestration) {
+ return loadConverter();
+ } else {
+ return new DefaultConfigurationConverter();
+ }
+ }
+
+ private static ProxyConfigurationConverter loadConverter() {
+ Optional<ProxyConfigurationConverter> configurationConverter = SingletonServiceLoader.getServiceLoader(ProxyConfigurationConverter.class).newServiceInstances();
+ if (!configurationConverter.isPresent()) {
+ throw new ServiceProviderNotFoundException(ProxyConfigurationConverter.class);
+ }
+ return configurationConverter.get();
+ }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/util/DataSourceConverter.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/util/DataSourceConverter.java
similarity index 98%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/util/DataSourceConverter.java
rename to shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/util/DataSourceConverter.java
index df854c2..7cb2145 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/util/DataSourceConverter.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/main/java/org/apache/shardingsphere/proxy/config/util/DataSourceConverter.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.util;
+package org.apache.shardingsphere.proxy.config.util;
import com.zaxxer.hikari.HikariDataSource;
import lombok.AccessLevel;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/util/DataSourceConverterTest.java b/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/config/util/DataSourceConverterTest.java
similarity index 98%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/util/DataSourceConverterTest.java
rename to shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/config/util/DataSourceConverterTest.java
index 06d4ea3..f8f6cef 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/util/DataSourceConverterTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-common/src/test/java/org/apache/shardingsphere/proxy/config/util/DataSourceConverterTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.util;
+package org.apache.shardingsphere.proxy.config.util;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
index 4ad2527..4f9d441 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/command/CommandExecutorTask.java
@@ -22,7 +22,7 @@ import io.netty.channel.ChannelHandlerContext;
import java.util.function.Supplier;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.control.panel.spi.engine.MetricsHandlerFacadeEngine;
+import org.apache.shardingsphere.control.panel.spi.engine.SingletonFacadeEngine;
import org.apache.shardingsphere.control.panel.spi.metrics.MetricsHandlerFacade;
import org.apache.shardingsphere.db.protocol.packet.CommandPacket;
import org.apache.shardingsphere.db.protocol.packet.CommandPacketType;
@@ -67,7 +67,7 @@ public final class CommandExecutorTask implements Runnable {
RootInvokeHook rootInvokeHook = new SPIRootInvokeHook();
rootInvokeHook.start();
Supplier<Boolean> histogramSupplier = null;
- Optional<MetricsHandlerFacade> handlerFacade = MetricsHandlerFacadeEngine.build();
+ Optional<MetricsHandlerFacade> handlerFacade = SingletonFacadeEngine.buildMetrics();
if (handlerFacade.isPresent()) {
histogramSupplier = handlerFacade.get().histogramStartTimer(MetricsLabelEnum.REQUEST_LATENCY.getName());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
index 214fe1d..f8c8aef 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
@@ -22,7 +22,7 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.control.panel.spi.engine.MetricsHandlerFacadeEngine;
+import org.apache.shardingsphere.control.panel.spi.engine.SingletonFacadeEngine;
import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
import org.apache.shardingsphere.metrics.enums.MetricsLabelEnum;
@@ -55,7 +55,7 @@ public final class FrontendChannelInboundHandler extends ChannelInboundHandlerAd
public void channelActive(final ChannelHandlerContext context) {
ChannelThreadExecutorGroup.getInstance().register(context.channel().id());
databaseProtocolFrontendEngine.getAuthEngine().handshake(context, backendConnection);
- MetricsHandlerFacadeEngine.build().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.gaugeInc(MetricsLabelEnum.CHANNEL_COUNT.getName()));
+ SingletonFacadeEngine.buildMetrics().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.gaugeInc(MetricsLabelEnum.CHANNEL_COUNT.getName()));
}
@Override
@@ -64,7 +64,7 @@ public final class FrontendChannelInboundHandler extends ChannelInboundHandlerAd
authorized = auth(context, (ByteBuf) message);
return;
}
- MetricsHandlerFacadeEngine.build().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.REQUEST_TOTAL.getName()));
+ SingletonFacadeEngine.buildMetrics().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.counterInc(MetricsLabelEnum.REQUEST_TOTAL.getName()));
CommandExecutorSelector.getExecutor(databaseProtocolFrontendEngine.getFrontendContext().isOccupyThreadForPerConnection(), backendConnection.isSupportHint(),
backendConnection.getTransactionType(), context.channel().id()).execute(new CommandExecutorTask(databaseProtocolFrontendEngine, backendConnection, context, message));
}
@@ -87,7 +87,7 @@ public final class FrontendChannelInboundHandler extends ChannelInboundHandlerAd
databaseProtocolFrontendEngine.release(backendConnection);
backendConnection.close(true);
ChannelThreadExecutorGroup.getInstance().unregister(context.channel().id());
- MetricsHandlerFacadeEngine.build().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.gaugeDec(MetricsLabelEnum.CHANNEL_COUNT.getName()));
+ SingletonFacadeEngine.buildMetrics().ifPresent(metricsHandlerFacade -> metricsHandlerFacade.gaugeDec(MetricsLabelEnum.CHANNEL_COUNT.getName()));
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLProtocolFrontendEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLProtocolFrontendEngineTest.java
index cff95ec..d0f9c2a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLProtocolFrontendEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLProtocolFrontendEngineTest.java
@@ -32,10 +32,7 @@ import org.apache.shardingsphere.kernel.context.SchemaContext;
import org.apache.shardingsphere.kernel.context.SchemaContexts;
import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.orchestration.core.common.event.AuthenticationChangedEvent;
-import org.apache.shardingsphere.orchestration.core.common.eventbus.ShardingOrchestrationEventBus;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.schema.ProxyOrchestrationSchemaContexts;
import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
import org.apache.shardingsphere.proxy.frontend.ConnectionIdGenerator;
import org.apache.shardingsphere.proxy.frontend.mysql.auth.MySQLAuthenticationEngine;
@@ -64,6 +61,8 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public final class MySQLProtocolFrontendEngineTest {
+ private static final String SCHEMA = "schema_";
+
private MySQLProtocolFrontendEngine mysqlProtocolFrontendEngine;
@Mock
@@ -77,7 +76,6 @@ public final class MySQLProtocolFrontendEngineTest {
@Before
public void setUp() {
- initProxySchemaContexts();
resetConnectionIdGenerator();
}
@@ -89,31 +87,6 @@ public final class MySQLProtocolFrontendEngineTest {
mysqlProtocolFrontendEngine = new MySQLProtocolFrontendEngine();
}
- @SneakyThrows
- private void initProxySchemaContexts() {
- Field field = ProxySchemaContexts.getInstance().getClass().getDeclaredField("schemaContexts");
- field.setAccessible(true);
- field.set(ProxySchemaContexts.getInstance(), getProxyOrchestrationSchemaContexts());
- }
-
- private ProxyOrchestrationSchemaContexts getProxyOrchestrationSchemaContexts() {
- ProxyOrchestrationSchemaContexts result = new ProxyOrchestrationSchemaContexts(new SchemaContexts());
- SchemaContexts schemaContexts = new SchemaContexts(getSchemaContextMap(), new ConfigurationProperties(new Properties()), new Authentication());
- result.getSchemaContexts().putAll(schemaContexts.getSchemaContexts());
- return result;
- }
-
- private Map<String, SchemaContext> getSchemaContextMap() {
- Map<String, SchemaContext> result = new HashMap<>(10);
- for (int i = 0; i < 10; i++) {
- String name = "schema_" + i;
- ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
- RuntimeContext runtimeContext = mock(RuntimeContext.class);
- result.put(name, new SchemaContext(name, schema, runtimeContext));
- }
- return result;
- }
-
@Test
public void assertHandshake() {
mysqlProtocolFrontendEngine.getAuthEngine().handshake(context, mock(BackendConnection.class));
@@ -162,7 +135,7 @@ public final class MySQLProtocolFrontendEngineTest {
private void setAuthentication(final ProxyUser proxyUser) {
Authentication authentication = new Authentication();
authentication.getUsers().put("root", proxyUser);
- ShardingOrchestrationEventBus.getInstance().post(new AuthenticationChangedEvent(authentication));
+ initProxySchemaContexts(authentication);
}
@SneakyThrows
@@ -171,4 +144,26 @@ public final class MySQLProtocolFrontendEngineTest {
field.setAccessible(true);
field.set(mysqlProtocolFrontendEngine.getAuthEngine(), connectionPhase);
}
+
+ @SneakyThrows
+ private void initProxySchemaContexts(final Authentication authentication) {
+ Field field = ProxySchemaContexts.getInstance().getClass().getDeclaredField("schemaContexts");
+ field.setAccessible(true);
+ field.set(ProxySchemaContexts.getInstance(), getSchemaContexts(authentication));
+ }
+
+ private SchemaContexts getSchemaContexts(final Authentication authentication) {
+ return new SchemaContexts(getSchemaContextMap(), new ConfigurationProperties(new Properties()), authentication);
+ }
+
+ private Map<String, SchemaContext> getSchemaContextMap() {
+ Map<String, SchemaContext> result = new HashMap<>();
+ for (int i = 0; i < 10; i++) {
+ String name = SCHEMA + i;
+ ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
+ RuntimeContext runtimeContext = mock(RuntimeContext.class);
+ result.put(name, new SchemaContext(name, schema, runtimeContext));
+ }
+ return result;
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
index 02a2dfc..f7248bf 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
@@ -18,6 +18,11 @@
package org.apache.shardingsphere.proxy.frontend.mysql.auth;
import com.google.common.primitives.Bytes;
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
import lombok.SneakyThrows;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerErrorCode;
import org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLAuthPluginData;
@@ -28,19 +33,10 @@ import org.apache.shardingsphere.kernel.context.SchemaContext;
import org.apache.shardingsphere.kernel.context.SchemaContexts;
import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.orchestration.core.common.event.AuthenticationChangedEvent;
-import org.apache.shardingsphere.orchestration.core.common.eventbus.ShardingOrchestrationEventBus;
-import org.apache.shardingsphere.proxy.backend.schema.ProxyOrchestrationSchemaContexts;
import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
import org.junit.Before;
import org.junit.Test;
-import java.lang.reflect.Field;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
@@ -57,7 +53,6 @@ public final class MySQLAuthenticationHandlerTest {
@Before
public void setUp() {
initAuthPluginDataForAuthenticationHandler();
- initProxySchemaContexts();
}
@SneakyThrows
@@ -68,31 +63,6 @@ public final class MySQLAuthenticationHandlerTest {
field.set(authenticationHandler, authPluginData);
}
- @SneakyThrows
- private void initProxySchemaContexts() {
- Field field = ProxySchemaContexts.getInstance().getClass().getDeclaredField("schemaContexts");
- field.setAccessible(true);
- field.set(ProxySchemaContexts.getInstance(), getProxyOrchestrationSchemaContexts());
- }
-
- private ProxyOrchestrationSchemaContexts getProxyOrchestrationSchemaContexts() {
- ProxyOrchestrationSchemaContexts result = new ProxyOrchestrationSchemaContexts(new SchemaContexts());
- SchemaContexts schemaContexts = new SchemaContexts(getSchemaContextMap(), new ConfigurationProperties(new Properties()), new Authentication());
- result.getSchemaContexts().putAll(schemaContexts.getSchemaContexts());
- return result;
- }
-
- private Map<String, SchemaContext> getSchemaContextMap() {
- Map<String, SchemaContext> result = new HashMap<>(10);
- for (int i = 0; i < 10; i++) {
- String name = "schema_" + i;
- ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
- RuntimeContext runtimeContext = mock(RuntimeContext.class);
- result.put(name, new SchemaContext(name, schema, runtimeContext));
- }
- return result;
- }
-
@Test
public void assertLoginWithPassword() {
setAuthentication(new ProxyUser("root", Collections.singleton("db1")));
@@ -128,15 +98,37 @@ public final class MySQLAuthenticationHandlerTest {
assertThat(authenticationHandler.login("root", authResponse, "db2").orElse(null), is(MySQLServerErrorCode.ER_DBACCESS_DENIED_ERROR));
}
+ @Test
+ public void assertGetAuthPluginData() {
+ assertThat(authenticationHandler.getAuthPluginData().getAuthPluginData(), is(Bytes.concat(part1, part2)));
+ }
+
@SneakyThrows
private void setAuthentication(final ProxyUser proxyUser) {
Authentication authentication = new Authentication();
authentication.getUsers().put("root", proxyUser);
- ShardingOrchestrationEventBus.getInstance().post(new AuthenticationChangedEvent(authentication));
+ initProxySchemaContexts(authentication);
}
- @Test
- public void assertGetAuthPluginData() {
- assertThat(authenticationHandler.getAuthPluginData().getAuthPluginData(), is(Bytes.concat(part1, part2)));
+ @SneakyThrows
+ private void initProxySchemaContexts(final Authentication authentication) {
+ Field field = ProxySchemaContexts.getInstance().getClass().getDeclaredField("schemaContexts");
+ field.setAccessible(true);
+ field.set(ProxySchemaContexts.getInstance(), getSchemaContexts(authentication));
+ }
+
+ private SchemaContexts getSchemaContexts(final Authentication authentication) {
+ return new SchemaContexts(getSchemaContextMap(), new ConfigurationProperties(new Properties()), authentication);
+ }
+
+ private Map<String, SchemaContext> getSchemaContextMap() {
+ Map<String, SchemaContext> result = new HashMap<>(10);
+ for (int i = 0; i < 10; i++) {
+ String name = "schema_" + i;
+ ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
+ RuntimeContext runtimeContext = mock(RuntimeContext.class);
+ result.put(name, new SchemaContext(name, schema, runtimeContext));
+ }
+ return result;
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml b/shardingsphere-proxy/shardingsphere-proxy-orchestration/pom.xml
similarity index 55%
copy from shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
copy to shardingsphere-proxy/shardingsphere-proxy-orchestration/pom.xml
index 651e575..74f644c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-common/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-orchestration/pom.xml
@@ -16,61 +16,43 @@
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-proxy</artifactId>
<version>5.0.0-RC1-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-proxy-common</artifactId>
- <name>${project.artifactId}</name>
-
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>shardingsphere-proxy-orchestration</artifactId>
+
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-orchestration-core-facade</artifactId>
+ <artifactId>shardingsphere-proxy-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-orchestration-center-api</artifactId>
+ <artifactId>shardingsphere-proxy-backend</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-orchestration-center-configuration</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-control-panel-spi</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-metrics-configuration</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-cluster-configuration</artifactId>
+ <artifactId>shardingsphere-orchestration-core-facade</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-cluster-facade</artifactId>
+ <artifactId>shardingsphere-orchestration-center-zookeeper-curator</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-cluster-heartbeat</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>com.zaxxer</groupId>
- <artifactId>HikariCP</artifactId>
- <scope>compile</scope>
+ <artifactId>shardingsphere-orchestration-core-schema</artifactId>
+ <version>${project.parent.version}</version>
</dependency>
</dependencies>
-</project>
+</project>
\ No newline at end of file
diff --git a/shardingsphere-proxy/shardingsphere-proxy-orchestration/src/main/java/org/apache/shardingsphere/proxy/orchestration/OrchestrationConfigurationConverter.java b/shardingsphere-proxy/shardingsphere-proxy-orchestration/src/main/java/org/apache/shardingsphere/proxy/orchestration/OrchestrationConfigurationConverter.java
new file mode 100644
index 0000000..b324426
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-orchestration/src/main/java/org/apache/shardingsphere/proxy/orchestration/OrchestrationConfigurationConverter.java
@@ -0,0 +1,128 @@
+/*
+ * 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.proxy.orchestration;
+
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+import java.util.Set;
+import org.apache.shardingsphere.cluster.configuration.config.ClusterConfiguration;
+import org.apache.shardingsphere.cluster.configuration.swapper.ClusterConfigurationYamlSwapper;
+import org.apache.shardingsphere.infra.auth.Authentication;
+import org.apache.shardingsphere.infra.auth.yaml.swapper.AuthenticationYamlSwapper;
+import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.kernel.context.SchemaContextsAware;
+import org.apache.shardingsphere.kernel.context.SchemaContextsBuilder;
+import org.apache.shardingsphere.kernel.context.schema.DataSourceParameter;
+import org.apache.shardingsphere.metrics.configuration.swapper.MetricsConfigurationYamlSwapper;
+import org.apache.shardingsphere.orchestration.center.yaml.config.YamlCenterRepositoryConfiguration;
+import org.apache.shardingsphere.orchestration.center.yaml.config.YamlOrchestrationConfiguration;
+import org.apache.shardingsphere.orchestration.center.yaml.swapper.OrchestrationConfigurationYamlSwapper;
+import org.apache.shardingsphere.orchestration.core.facade.ShardingOrchestrationFacade;
+import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
+import org.apache.shardingsphere.proxy.config.ShardingConfiguration;
+import org.apache.shardingsphere.proxy.config.converter.AbstractConfigurationConverter;
+import org.apache.shardingsphere.proxy.config.util.DataSourceConverter;
+import org.apache.shardingsphere.proxy.config.yaml.YamlProxyRuleConfiguration;
+import org.apache.shardingsphere.proxy.config.yaml.YamlProxyServerConfiguration;
+import org.apache.shardingsphere.proxy.orchestration.schema.ProxyOrchestrationSchemaContexts;
+
+/**
+ * Orchestration configuration converter.
+ */
+public class OrchestrationConfigurationConverter extends AbstractConfigurationConverter {
+
+ private ShardingOrchestrationFacade shardingOrchestrationFacade;
+
+ @Override
+ public ProxyConfiguration convert(final ShardingConfiguration shardingConfiguration) {
+ Map<String, YamlCenterRepositoryConfiguration> orchestration = shardingConfiguration.getServerConfiguration().getOrchestration();
+ Set<String> schemaNames = shardingConfiguration.getRuleConfigurationMap().keySet();
+ ProxyConfiguration proxyConfiguration = new ProxyConfiguration();
+ shardingOrchestrationFacade = new ShardingOrchestrationFacade(new OrchestrationConfigurationYamlSwapper().swapToObject(new YamlOrchestrationConfiguration(orchestration)), schemaNames);
+ initShardingOrchestrationFacade(shardingConfiguration.getServerConfiguration(), shardingConfiguration.getRuleConfigurationMap(), shardingOrchestrationFacade);
+ Authentication authentication = shardingOrchestrationFacade.getConfigCenter().loadAuthentication();
+ Properties properties = shardingOrchestrationFacade.getConfigCenter().loadProperties();
+ Map<String, Map<String, DataSourceParameter>> schemaDataSources = getDataSourceParametersMap(shardingOrchestrationFacade);
+ Map<String, Collection<RuleConfiguration>> schemaRules = getSchemaRules(shardingOrchestrationFacade);
+ ClusterConfiguration clusterConfiguration = shardingOrchestrationFacade.getConfigCenter().loadClusterConfiguration();
+ proxyConfiguration.setAuthentication(authentication);
+ proxyConfiguration.setProps(properties);
+ proxyConfiguration.setSchemaDataSources(schemaDataSources);
+ proxyConfiguration.setSchemaRules(schemaRules);
+ proxyConfiguration.setCluster(clusterConfiguration);
+ proxyConfiguration.setMetrics(getMetricsConfiguration(shardingConfiguration.getServerConfiguration().getMetrics()));
+ return proxyConfiguration;
+ }
+
+ @Override
+ public SchemaContextsAware contextsAware(final SchemaContextsBuilder builder) throws SQLException {
+ return new ProxyOrchestrationSchemaContexts(builder.build());
+ }
+
+ private void initShardingOrchestrationFacade(
+ final YamlProxyServerConfiguration serverConfig, final Map<String, YamlProxyRuleConfiguration> ruleConfigs, final ShardingOrchestrationFacade shardingOrchestrationFacade) {
+ if (isEmptyLocalConfiguration(serverConfig, ruleConfigs)) {
+ shardingOrchestrationFacade.init();
+ } else {
+ shardingOrchestrationFacade.init(getDataSourceConfigurationMap(ruleConfigs),
+ getRuleConfigurations(ruleConfigs), new AuthenticationYamlSwapper().swapToObject(serverConfig.getAuthentication()), serverConfig.getProps());
+ }
+ shardingOrchestrationFacade.initMetricsConfiguration(Optional.ofNullable(serverConfig.getMetrics()).map(new MetricsConfigurationYamlSwapper()::swapToObject).orElse(null));
+ shardingOrchestrationFacade.initClusterConfiguration(Optional.ofNullable(serverConfig.getCluster()).map(new ClusterConfigurationYamlSwapper()::swapToObject).orElse(null));
+ }
+
+ private boolean isEmptyLocalConfiguration(final YamlProxyServerConfiguration serverConfig, final Map<String, YamlProxyRuleConfiguration> ruleConfigs) {
+ return ruleConfigs.isEmpty() && null == serverConfig.getAuthentication() && serverConfig.getProps().isEmpty();
+ }
+
+ private Map<String, Map<String, DataSourceConfiguration>> getDataSourceConfigurationMap(final Map<String, YamlProxyRuleConfiguration> ruleConfigs) {
+ Map<String, Map<String, DataSourceConfiguration>> result = new LinkedHashMap<>();
+ for (Map.Entry<String, YamlProxyRuleConfiguration> entry : ruleConfigs.entrySet()) {
+ result.put(entry.getKey(), DataSourceConverter.getDataSourceConfigurationMap(getDataSourceParameters(entry.getValue().getDataSources())));
+ }
+ return result;
+ }
+
+ private Map<String, Map<String, DataSourceParameter>> getDataSourceParametersMap(final ShardingOrchestrationFacade shardingOrchestrationFacade) {
+ Map<String, Map<String, DataSourceParameter>> result = new LinkedHashMap<>();
+ for (String each : shardingOrchestrationFacade.getConfigCenter().getAllShardingSchemaNames()) {
+ result.put(each, DataSourceConverter.getDataSourceParameterMap(shardingOrchestrationFacade.getConfigCenter().loadDataSourceConfigurations(each)));
+ }
+ return result;
+ }
+
+ private Map<String, Collection<RuleConfiguration>> getSchemaRules(final ShardingOrchestrationFacade shardingOrchestrationFacade) {
+ Map<String, Collection<RuleConfiguration>> result = new LinkedHashMap<>();
+ for (String each : shardingOrchestrationFacade.getConfigCenter().getAllShardingSchemaNames()) {
+ result.put(each, shardingOrchestrationFacade.getConfigCenter().loadRuleConfigurations(each));
+ }
+ return result;
+ }
+
+ @Override
+ public void close() {
+ if (null != shardingOrchestrationFacade) {
+ shardingOrchestrationFacade.close();
+ }
+ }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/schema/ProxyOrchestrationSchemaContexts.java b/shardingsphere-proxy/shardingsphere-proxy-orchestration/src/main/java/org/apache/shardingsphere/proxy/orchestration/schema/ProxyOrchestrationSchemaContexts.java
similarity index 97%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/schema/ProxyOrchestrationSchemaContexts.java
rename to shardingsphere-proxy/shardingsphere-proxy-orchestration/src/main/java/org/apache/shardingsphere/proxy/orchestration/schema/ProxyOrchestrationSchemaContexts.java
index 8a87cf9..55a5036 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/schema/ProxyOrchestrationSchemaContexts.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-orchestration/src/main/java/org/apache/shardingsphere/proxy/orchestration/schema/ProxyOrchestrationSchemaContexts.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.schema;
+package org.apache.shardingsphere.proxy.orchestration.schema;
import com.google.common.collect.Maps;
import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.kernel.context.schema.DataSourceParameter;
import org.apache.shardingsphere.orchestration.core.schema.OrchestrationSchemaContexts;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSourceFactory;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCRawBackendDataSourceFactory;
-import org.apache.shardingsphere.proxy.backend.util.DataSourceConverter;
+import org.apache.shardingsphere.proxy.config.util.DataSourceConverter;
import javax.sql.DataSource;
import java.util.LinkedHashMap;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-orchestration/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.config.converter.ProxyConfigurationConverter b/shardingsphere-proxy/shardingsphere-proxy-orchestration/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.config.converter.ProxyConfigurationConverter
new file mode 100644
index 0000000..d10cd19
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-orchestration/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.config.converter.ProxyConfigurationConverter
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.proxy.orchestration.OrchestrationConfigurationConverter
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ShardingSphereProxyContextTest.java b/shardingsphere-proxy/shardingsphere-proxy-orchestration/src/test/java/org/apache/shardingsphere/proxy/orchestration/ProxyOrchestrationSchemaContextsTest.java
similarity index 96%
rename from shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ShardingSphereProxyContextTest.java
rename to shardingsphere-proxy/shardingsphere-proxy-orchestration/src/test/java/org/apache/shardingsphere/proxy/orchestration/ProxyOrchestrationSchemaContextsTest.java
index 975d310..550b328 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/context/ShardingSphereProxyContextTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-orchestration/src/test/java/org/apache/shardingsphere/proxy/orchestration/ProxyOrchestrationSchemaContextsTest.java
@@ -15,8 +15,13 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.context;
+package org.apache.shardingsphere.proxy.orchestration;
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.auth.Authentication;
import org.apache.shardingsphere.infra.auth.ProxyUser;
@@ -30,24 +35,18 @@ import org.apache.shardingsphere.orchestration.core.common.event.AuthenticationC
import org.apache.shardingsphere.orchestration.core.common.event.PropertiesChangedEvent;
import org.apache.shardingsphere.orchestration.core.common.eventbus.ShardingOrchestrationEventBus;
import org.apache.shardingsphere.orchestration.core.registrycenter.event.CircuitStateChangedEvent;
-import org.apache.shardingsphere.proxy.backend.schema.ProxyOrchestrationSchemaContexts;
import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
+import org.apache.shardingsphere.proxy.orchestration.schema.ProxyOrchestrationSchemaContexts;
import org.junit.Before;
import org.junit.Test;
-import java.lang.reflect.Field;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
-public final class ShardingSphereProxyContextTest {
+public final class ProxyOrchestrationSchemaContextsTest {
@Before
@SneakyThrows(ReflectiveOperationException.class)