This is an automated email from the ASF dual-hosted git repository.
panjuan 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 a46cc5f Add labels configuration for proxy (#14507)
a46cc5f is described below
commit a46cc5fa59a8ea028ea707229083842b1d629cfb
Author: Haoran Meng <[email protected]>
AuthorDate: Tue Jan 4 16:26:18 2022 +0800
Add labels configuration for proxy (#14507)
Co-authored-by: menghaoran <[email protected]>
---
.../core/datasource/ShardingSphereDataSource.java | 5 +++-
.../mode/manager/ContextManagerBuilder.java | 21 +++------------
.../manager/ContextManagerBuilderParameter.java | 31 +++++++++++++++-------
.../DefaultFixtureContextManagerBuilder.java | 11 ++------
.../fixture/FixtureContextManagerBuilder.java | 11 ++------
.../cluster/ClusterContextManagerBuilder.java | 25 ++++++++---------
.../ClusterContextManagerCoordinatorTest.java | 4 ++-
.../memory/MemoryContextManagerBuilder.java | 18 +++++--------
.../StandaloneContextManagerBuilder.java | 18 ++++++-------
.../StandaloneContextManagerBuilderTextTest.java | 6 +++--
.../proxy/config/ProxyConfiguration.java | 2 ++
.../config/yaml/YamlProxyServerConfiguration.java | 2 ++
.../swapper/YamlProxyConfigurationSwapper.java | 3 +--
.../proxy/initializer/BootstrapInitializer.java | 10 ++++---
14 files changed, 77 insertions(+), 90 deletions(-)
diff --git
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
index a0513ff..3db3041 100644
---
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
+++
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
@@ -27,6 +27,7 @@ import
org.apache.shardingsphere.infra.config.scope.GlobalRuleConfiguration;
import org.apache.shardingsphere.infra.config.scope.SchemaRuleConfiguration;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilderFactory;
+import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -72,7 +73,9 @@ public final class ShardingSphereDataSource extends
AbstractDataSourceAdapter im
Map<String, Collection<RuleConfiguration>> schemaRuleConfigs =
Collections.singletonMap(
schemaName, ruleConfigs.stream().filter(each -> each
instanceof SchemaRuleConfiguration).collect(Collectors.toList()));
Collection<RuleConfiguration> globalRuleConfigs =
ruleConfigs.stream().filter(each -> each instanceof
GlobalRuleConfiguration).collect(Collectors.toList());
- return
ContextManagerBuilderFactory.newInstance(modeConfig).build(modeConfig,
dataSourcesMap, schemaRuleConfigs, globalRuleConfigs, props, isOverwrite, null,
schemaName);
+ ContextManagerBuilderParameter parameter =
ContextManagerBuilderParameter.builder().modeConfig(modeConfig).dataSourcesMap(dataSourcesMap).schemaRuleConfigs(schemaRuleConfigs)
+
.globalRuleConfigs(globalRuleConfigs).props(props).isOverwrite(isOverwrite).schemaName(schemaName).build();
+ return
ContextManagerBuilderFactory.newInstance(modeConfig).build(parameter);
}
@Override
diff --git
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilder.java
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilder.java
index 4b2d716..1e7739a 100644
---
a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilder.java
@@ -17,16 +17,10 @@
package org.apache.shardingsphere.mode.manager;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.spi.required.RequiredSPI;
import org.apache.shardingsphere.spi.typed.TypedSPI;
-import javax.sql.DataSource;
import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Properties;
/**
* Context manager builder.
@@ -35,19 +29,10 @@ public interface ContextManagerBuilder extends TypedSPI,
RequiredSPI {
/**
* Build context manager.
- *
- * @param modeConfig mode configuration
- * @param dataSourcesMap data sources map
- * @param schemaRuleConfigs schema rule configurations
- * @param globalRuleConfigs global rule configurations
- * @param props properties
- * @param isOverwrite whether overwrite to persistence
- * @param port port
- * @param schemaName schema name
+ *
+ * @param parameter context manager builder parameter
* @return context manager
* @throws SQLException SQL exception
*/
- ContextManager build(ModeConfiguration modeConfig, Map<String, Map<String,
DataSource>> dataSourcesMap,
- Map<String, Collection<RuleConfiguration>>
schemaRuleConfigs, Collection<RuleConfiguration> globalRuleConfigs, Properties
props, boolean isOverwrite,
- Integer port, String schemaName) throws SQLException;
+ ContextManager build(ContextManagerBuilderParameter parameter) throws
SQLException;
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfiguration.java
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameter.java
similarity index 59%
copy from
shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfiguration.java
copy to
shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameter.java
index 2b32054..e3ef3cb 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfiguration.java
+++
b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameter.java
@@ -15,29 +15,40 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.config;
+package org.apache.shardingsphere.mode.manager;
+import lombok.Builder;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
+import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import javax.sql.DataSource;
import java.util.Collection;
import java.util.Map;
import java.util.Properties;
/**
- * Proxy configuration.
+ * Context manager builder parameter.
*/
-@RequiredArgsConstructor
+@Builder
@Getter
-public final class ProxyConfiguration {
+public final class ContextManagerBuilderParameter {
- private final Map<String, Map<String, DataSourceParameter>>
schemaDataSources;
+ private ModeConfiguration modeConfig;
- private final Map<String, Collection<RuleConfiguration>> schemaRules;
+ private Map<String, Map<String, DataSource>> dataSourcesMap;
- private final Collection<RuleConfiguration> globalRules;
+ private Map<String, Collection<RuleConfiguration>> schemaRuleConfigs;
- private final Properties props;
+ private Collection<RuleConfiguration> globalRuleConfigs;
+
+ private Properties props;
+
+ private boolean isOverwrite;
+
+ private Integer port;
+
+ private String schemaName;
+
+ private Collection<String> labels;
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/DefaultFixtureContextManagerBuilder.java
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/DefaultFixtureContextManagerBuilder.java
index 568d27f..73c1901 100644
---
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/DefaultFixtureContextManagerBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/DefaultFixtureContextManagerBuilder.java
@@ -17,23 +17,16 @@
package org.apache.shardingsphere.mode.manager.fixture;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilder;
+import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
-import javax.sql.DataSource;
import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Properties;
public final class DefaultFixtureContextManagerBuilder implements
ContextManagerBuilder {
@Override
- public ContextManager build(final ModeConfiguration modeConfig, final
Map<String, Map<String, DataSource>> dataSourcesMap, final Map<String,
Collection<RuleConfiguration>> schemaRuleConfigs,
- final Collection<RuleConfiguration>
globalRuleConfigs, final Properties props,
- final boolean isOverwrite, final Integer port,
final String schemaName) throws SQLException {
+ public ContextManager build(final ContextManagerBuilderParameter
parameter) throws SQLException {
return null;
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/FixtureContextManagerBuilder.java
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/FixtureContextManagerBuilder.java
index 003e1de..4328f6b 100644
---
a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/FixtureContextManagerBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/fixture/FixtureContextManagerBuilder.java
@@ -17,23 +17,16 @@
package org.apache.shardingsphere.mode.manager.fixture;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilder;
+import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
-import javax.sql.DataSource;
import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Properties;
public final class FixtureContextManagerBuilder implements
ContextManagerBuilder {
@Override
- public ContextManager build(final ModeConfiguration modeConfig, final
Map<String, Map<String, DataSource>> dataSourcesMap, final Map<String,
Collection<RuleConfiguration>> schemaRuleConfigs,
- final Collection<RuleConfiguration>
globalRuleConfigs, final Properties props,
- final boolean isOverwrite, final Integer port,
final String schemaName) throws SQLException {
+ public ContextManager build(final ContextManagerBuilderParameter
parameter) throws SQLException {
return null;
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index ab190e2..6b3ab9b 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -22,7 +22,6 @@ import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
import
org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreatorUtil;
-import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.metadata.schema.QualifiedSchema;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.schema.loader.SchemaLoader;
@@ -32,6 +31,7 @@ import
org.apache.shardingsphere.infra.rule.event.impl.DataSourceNameDisabledEve
import
org.apache.shardingsphere.infra.rule.identifier.type.StatusContainedRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilder;
+import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.ClusterContextManagerCoordinator;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.RegistryCenter;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.StorageNodeStatus;
@@ -77,26 +77,23 @@ public final class ClusterContextManagerBuilder implements
ContextManagerBuilder
private ContextManager contextManager;
@Override
- public ContextManager build(final ModeConfiguration modeConfig, final
Map<String, Map<String, DataSource>> dataSourcesMap,
- final Map<String,
Collection<RuleConfiguration>> schemaRuleConfigs, final
Collection<RuleConfiguration> globalRuleConfigs,
- final Properties props, final boolean
isOverwrite, final Integer port, final String schemaName) throws SQLException {
- beforeBuildContextManager(modeConfig, dataSourcesMap,
schemaRuleConfigs, globalRuleConfigs, props, isOverwrite, port, schemaName);
+ public ContextManager build(final ContextManagerBuilderParameter
parameter) throws SQLException {
+ beforeBuildContextManager(parameter);
contextManager = new ContextManager();
contextManager.init(metaDataContexts, transactionContexts, null);
afterBuildContextManager();
return contextManager;
}
- private void beforeBuildContextManager(final ModeConfiguration modeConfig,
final Map<String, Map<String, DataSource>> dataSourcesMap,
- final Map<String,
Collection<RuleConfiguration>> schemaRuleConfigs, final
Collection<RuleConfiguration> globalRuleConfigs,
- final Properties props, final
boolean isOverwrite, final Integer port, final String schemaName) throws
SQLException {
- ClusterPersistRepository repository =
createClusterPersistRepository((ClusterPersistRepositoryConfiguration)
modeConfig.getRepository());
- registryCenter = new RegistryCenter(repository, port);
- ModeScheduleContextFactory.getInstance().init(modeConfig);
+ private void beforeBuildContextManager(final
ContextManagerBuilderParameter parameter) throws SQLException {
+ ClusterPersistRepository repository =
createClusterPersistRepository((ClusterPersistRepositoryConfiguration)
parameter.getModeConfig().getRepository());
+ registryCenter = new RegistryCenter(repository, parameter.getPort());
+
ModeScheduleContextFactory.getInstance().init(parameter.getModeConfig());
metaDataPersistService = new MetaDataPersistService(repository);
- persistConfigurations(metaDataPersistService, dataSourcesMap,
schemaRuleConfigs, globalRuleConfigs, props, isOverwrite);
- Collection<String> schemaNames = Strings.isNullOrEmpty(schemaName) ?
metaDataPersistService.getSchemaMetaDataService().loadAllNames() :
Collections.singletonList(schemaName);
- Map<String, Map<String, DataSource>> clusterDataSources =
loadDataSourcesMap(metaDataPersistService, dataSourcesMap, schemaNames);
+ persistConfigurations(metaDataPersistService,
parameter.getDataSourcesMap(), parameter.getSchemaRuleConfigs(),
parameter.getGlobalRuleConfigs(), parameter.getProps(),
parameter.isOverwrite());
+ Collection<String> schemaNames =
Strings.isNullOrEmpty(parameter.getSchemaName()) ?
metaDataPersistService.getSchemaMetaDataService()
+ .loadAllNames() :
Collections.singletonList(parameter.getSchemaName());
+ Map<String, Map<String, DataSource>> clusterDataSources =
loadDataSourcesMap(metaDataPersistService, parameter.getDataSourcesMap(),
schemaNames);
Map<String, Collection<RuleConfiguration>> clusterSchemaRuleConfigs =
loadSchemaRules(metaDataPersistService, schemaNames);
Properties clusterProps =
metaDataPersistService.getPropsService().load();
Map<String, Collection<ShardingSphereRule>> rules =
SchemaRulesBuilder.buildRules(clusterDataSources, clusterSchemaRuleConfigs,
clusterProps);
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
index 80404a4..eb1d5b7 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
@@ -40,6 +40,7 @@ import
org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
import
org.apache.shardingsphere.mode.manager.cluster.ClusterContextManagerBuilder;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.authority.event.AuthorityChangedEvent;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.datasource.DataSourceChangedEvent;
@@ -108,7 +109,8 @@ public final class ClusterContextManagerCoordinatorTest {
PersistRepositoryConfiguration persistRepositoryConfiguration = new
ClusterPersistRepositoryConfiguration("TEST", "", "", new Properties());
ModeConfiguration configuration = new ModeConfiguration("Cluster",
persistRepositoryConfiguration, false);
ClusterContextManagerBuilder builder = new
ClusterContextManagerBuilder();
- contextManager = builder.build(configuration, new HashMap<>(), new
HashMap<>(), new LinkedList<>(), new Properties(), false, null, null);
+ contextManager =
builder.build(ContextManagerBuilderParameter.builder().modeConfig(configuration).dataSourcesMap(new
HashMap<>()).schemaRuleConfigs(new HashMap<>())
+ .globalRuleConfigs(new LinkedList<>()).props(new
Properties()).isOverwrite(false).build());
contextManager.renewMetaDataContexts(new
MetaDataContexts(contextManager.getMetaDataContexts().getMetaDataPersistService().get(),
createMetaDataMap(), globalRuleMetaData,
mock(ExecutorEngine.class),
new ConfigurationProperties(new Properties()),
createOptimizerContext()));
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
index 016a1ce..cc67576 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
@@ -17,25 +17,22 @@
package org.apache.shardingsphere.mode.manager.memory;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
-import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.schema.loader.SchemaLoader;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilder;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilder;
+import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder;
import org.apache.shardingsphere.schedule.core.api.ModeScheduleContext;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import
org.apache.shardingsphere.transaction.context.TransactionContextsBuilder;
-import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Map;
-import java.util.Properties;
/**
* Memory context manager builder.
@@ -43,15 +40,14 @@ import java.util.Properties;
public final class MemoryContextManagerBuilder implements
ContextManagerBuilder {
@Override
- public ContextManager build(final ModeConfiguration modeConfig, final
Map<String, Map<String, DataSource>> dataSourcesMap,
- final Map<String,
Collection<RuleConfiguration>> schemaRuleConfigs, final
Collection<RuleConfiguration> globalRuleConfigs,
- final Properties props, final boolean
isOverwrite, final Integer port, final String schemaName) throws SQLException {
- Map<String, Collection<ShardingSphereRule>> rules =
SchemaRulesBuilder.buildRules(dataSourcesMap, schemaRuleConfigs, props);
- Map<String, ShardingSphereSchema> schemas = new
SchemaLoader(dataSourcesMap, schemaRuleConfigs, rules, props).load();
- MetaDataContexts metaDataContexts = new
MetaDataContextsBuilder(dataSourcesMap, schemaRuleConfigs, globalRuleConfigs,
schemas, rules, props).build(null);
+ public ContextManager build(final ContextManagerBuilderParameter
parameter) throws SQLException {
+ Map<String, Collection<ShardingSphereRule>> rules =
SchemaRulesBuilder.buildRules(parameter.getDataSourcesMap(),
parameter.getSchemaRuleConfigs(), parameter.getProps());
+ Map<String, ShardingSphereSchema> schemas = new
SchemaLoader(parameter.getDataSourcesMap(), parameter.getSchemaRuleConfigs(),
rules, parameter.getProps()).load();
+ MetaDataContexts metaDataContexts = new
MetaDataContextsBuilder(parameter.getDataSourcesMap(),
parameter.getSchemaRuleConfigs(), parameter.getGlobalRuleConfigs(),
+ schemas, rules, parameter.getProps()).build(null);
TransactionContexts transactionContexts = new
TransactionContextsBuilder(metaDataContexts.getMetaDataMap(),
metaDataContexts.getGlobalRuleMetaData().getRules()).build();
ContextManager result = new ContextManager();
- result.init(metaDataContexts, transactionContexts, new
ModeScheduleContext(modeConfig));
+ result.init(metaDataContexts, transactionContexts, new
ModeScheduleContext(parameter.getModeConfig()));
return result;
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
index 6a0fd90..54f1bd6 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
@@ -21,7 +21,6 @@ import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import
org.apache.shardingsphere.infra.config.datasource.DataSourceConfiguration;
import
org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreatorUtil;
-import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import
org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.schema.loader.SchemaLoader;
@@ -29,6 +28,7 @@ import
org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.builder.schema.SchemaRulesBuilder;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilder;
+import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder;
import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
@@ -61,15 +61,15 @@ public final class StandaloneContextManagerBuilder
implements ContextManagerBuil
}
@Override
- public ContextManager build(final ModeConfiguration modeConfig, final
Map<String, Map<String, DataSource>> dataSourcesMap,
- final Map<String,
Collection<RuleConfiguration>> schemaRuleConfigs, final
Collection<RuleConfiguration> globalRuleConfigs,
- final Properties props, final boolean
isOverwrite, final Integer port, final String schemaName) throws SQLException {
- PersistRepositoryConfiguration repositoryConfig = null ==
modeConfig.getRepository() ? new
StandalonePersistRepositoryConfiguration("File", new Properties()) :
modeConfig.getRepository();
+ public ContextManager build(final ContextManagerBuilderParameter
parameter) throws SQLException {
+ PersistRepositoryConfiguration repositoryConfig = null ==
parameter.getModeConfig().getRepository() ? new
StandalonePersistRepositoryConfiguration("File", new Properties())
+ : parameter.getModeConfig().getRepository();
StandalonePersistRepository repository =
TypedSPIRegistry.getRegisteredService(StandalonePersistRepository.class,
repositoryConfig.getType(), repositoryConfig.getProps());
MetaDataPersistService metaDataPersistService = new
MetaDataPersistService(repository);
- persistConfigurations(metaDataPersistService, dataSourcesMap,
schemaRuleConfigs, globalRuleConfigs, props, isOverwrite);
- Collection<String> schemaNames = Strings.isNullOrEmpty(schemaName) ?
metaDataPersistService.getSchemaMetaDataService().loadAllNames() :
Collections.singletonList(schemaName);
- Map<String, Map<String, DataSource>> standaloneDataSources =
loadDataSourcesMap(metaDataPersistService, dataSourcesMap, schemaNames);
+ persistConfigurations(metaDataPersistService,
parameter.getDataSourcesMap(), parameter.getSchemaRuleConfigs(),
parameter.getGlobalRuleConfigs(), parameter.getProps(),
parameter.isOverwrite());
+ Collection<String> schemaNames =
Strings.isNullOrEmpty(parameter.getSchemaName()) ?
metaDataPersistService.getSchemaMetaDataService().loadAllNames()
+ : Collections.singletonList(parameter.getSchemaName());
+ Map<String, Map<String, DataSource>> standaloneDataSources =
loadDataSourcesMap(metaDataPersistService, parameter.getDataSourcesMap(),
schemaNames);
Map<String, Collection<RuleConfiguration>> standaloneSchemaRules =
loadSchemaRules(metaDataPersistService, schemaNames);
Properties standaloneProps =
metaDataPersistService.getPropsService().load();
Map<String, Collection<ShardingSphereRule>> rules =
SchemaRulesBuilder.buildRules(standaloneDataSources, standaloneSchemaRules,
standaloneProps);
@@ -78,7 +78,7 @@ public final class StandaloneContextManagerBuilder implements
ContextManagerBuil
rules, standaloneProps).build(metaDataPersistService);
TransactionContexts transactionContexts = new
TransactionContextsBuilder(metaDataContexts.getMetaDataMap(),
metaDataContexts.getGlobalRuleMetaData().getRules()).build();
ContextManager result = new ContextManager();
- result.init(metaDataContexts, transactionContexts, new
ModeScheduleContext(modeConfig));
+ result.init(metaDataContexts, transactionContexts, new
ModeScheduleContext(parameter.getModeConfig()));
return result;
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
index acfc587..1470d8b 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.mode.manager.standalone;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.persist.node.GlobalNode;
import org.apache.shardingsphere.mode.metadata.persist.node.SchemaMetaDataNode;
@@ -56,8 +57,9 @@ public final class StandaloneContextManagerBuilderTextTest {
Properties props = new Properties();
ModeConfiguration modeConfiguration = new
ModeConfiguration("testType", null, false);
StandaloneContextManagerBuilder standaloneContextManagerBuilder = new
StandaloneContextManagerBuilder();
- ContextManager actual =
standaloneContextManagerBuilder.build(modeConfiguration, dataSourceMap,
schemaRuleConfigs,
- globalRuleConfigurationCollection, props, false, 1000, null);
+ ContextManager actual =
standaloneContextManagerBuilder.build(ContextManagerBuilderParameter.builder().modeConfig(modeConfiguration)
+
.dataSourcesMap(dataSourceMap).schemaRuleConfigs(schemaRuleConfigs).globalRuleConfigs(globalRuleConfigurationCollection).props(props)
+ .isOverwrite(false).port(1000).build());
MetaDataContexts metaDataContexts = actual.getMetaDataContexts();
assertNotNull(metaDataContexts.getMetaDataMap().get(TEST_DATA_SOURCE_INNER_MAP));
assertNotNull(metaDataContexts.getExecutorEngine());
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfiguration.java
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfiguration.java
index 2b32054..c81d36a 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfiguration.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/ProxyConfiguration.java
@@ -40,4 +40,6 @@ public final class ProxyConfiguration {
private final Collection<RuleConfiguration> globalRules;
private final Properties props;
+
+ private final Collection<String> labels;
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java
index 6ca7b3f..2c1324d 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/yaml/YamlProxyServerConfiguration.java
@@ -39,4 +39,6 @@ public final class YamlProxyServerConfiguration implements
YamlConfiguration {
private Collection<YamlRuleConfiguration> rules = new LinkedList<>();
private Properties props = new Properties();
+
+ private Collection<String> labels;
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapper.java
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapper.java
index 465a747..93d5d1a 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapper.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/config/yaml/swapper/YamlProxyConfigurationSwapper.java
@@ -47,9 +47,8 @@ public final class YamlProxyConfigurationSwapper {
Map<String, Map<String, DataSourceParameter>> schemaDataSources =
getDataSourceParametersMap(yamlConfig.getRuleConfigurations());
Map<String, Collection<RuleConfiguration>> schemaRules =
getRuleConfigurations(yamlConfig.getRuleConfigurations());
Collection<RuleConfiguration> globalRules = new
YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(yamlConfig.getServerConfiguration().getRules());
-
Properties props = yamlConfig.getServerConfiguration().getProps();
- return new ProxyConfiguration(schemaDataSources, schemaRules,
globalRules, props);
+ return new ProxyConfiguration(schemaDataSources, schemaRules,
globalRules, props, yamlConfig.getServerConfiguration().getLabels());
}
private Map<String, Collection<RuleConfiguration>>
getRuleConfigurations(final Map<String, YamlProxyRuleConfiguration>
yamlRuleConfigurations) {
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
index 2f718a0..8ae4825 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
@@ -25,14 +25,15 @@ import
org.apache.shardingsphere.data.pipeline.scenario.rulealtered.RuleAlteredJ
import org.apache.shardingsphere.db.protocol.CommonConstants;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
import
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLServerInfo;
-import
org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreatorUtil;
+import org.apache.shardingsphere.infra.autogen.version.ShardingSphereVersion;
import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
+import
org.apache.shardingsphere.infra.config.datasource.pool.creator.DataSourcePoolCreatorUtil;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.autogen.version.ShardingSphereVersion;
import
org.apache.shardingsphere.infra.yaml.config.swapper.mode.ModeConfigurationYamlSwapper;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.ContextManagerBuilderFactory;
+import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
@@ -74,8 +75,9 @@ public final class BootstrapInitializer {
ProxyConfiguration proxyConfig = new
YamlProxyConfigurationSwapper().swap(yamlConfig);
boolean isOverwrite = null == modeConfig || modeConfig.isOverwrite();
Map<String, Map<String, DataSource>> dataSourcesMap =
getDataSourcesMap(proxyConfig.getSchemaDataSources());
- ContextManager contextManager =
ContextManagerBuilderFactory.newInstance(modeConfig).build(modeConfig,
dataSourcesMap,
- proxyConfig.getSchemaRules(), proxyConfig.getGlobalRules(),
proxyConfig.getProps(), isOverwrite, port, null);
+ ContextManagerBuilderParameter parameter =
ContextManagerBuilderParameter.builder().modeConfig(modeConfig).dataSourcesMap(dataSourcesMap).schemaRuleConfigs(proxyConfig.getSchemaRules())
+
.globalRuleConfigs(proxyConfig.getGlobalRules()).props(proxyConfig.getProps()).isOverwrite(isOverwrite).port(port).labels(proxyConfig.getLabels()).build();
+ ContextManager contextManager =
ContextManagerBuilderFactory.newInstance(modeConfig).build(parameter);
ProxyContext.getInstance().init(contextManager);
}