This is an automated email from the ASF dual-hosted git repository. menghaoran pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push: new ce7432f Adjust DatabaseDiscoveryDataSourceRuleConfiguration, change name to groupName (#14416) ce7432f is described below commit ce7432fb7eb085f35d8f42256490a0c47c8c4a1b Author: zhaojinchao <33742097+zj...@users.noreply.github.com> AuthorDate: Wed Dec 29 19:49:56 2021 +0800 Adjust DatabaseDiscoveryDataSourceRuleConfiguration, change name to groupName (#14416) * Adjust DatabaseDiscoveryDataSourceRuleConfiguration, change name to groupName. * update log --- .../user-manual/shardingsphere-jdbc/java-api/rules/ha.cn.md | 2 +- .../user-manual/shardingsphere-jdbc/java-api/rules/ha.en.md | 4 ++-- .../rule/DatabaseDiscoveryDataSourceRuleConfiguration.java | 2 +- .../dbdiscovery/route/DatabaseDiscoverySQLRouter.java | 2 +- .../dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java | 6 +++--- .../shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java | 10 +++++----- ...DiscoveryRuleAlgorithmProviderConfigurationYamlSwapper.java | 2 +- .../swapper/DatabaseDiscoveryRuleConfigurationYamlSwapper.java | 2 +- .../dbdiscovery/rule/DatabaseDiscoveryRuleTest.java | 2 +- ...overyRuleAlgorithmProviderConfigurationYamlSwapperTest.java | 2 +- .../DatabaseDiscoveryRuleConfigurationYamlSwapperTest.java | 2 +- .../handler/query/DatabaseDiscoveryRuleQueryResultSet.java | 8 ++++---- .../update/AlterDatabaseDiscoveryRuleStatementUpdater.java | 6 +++--- .../update/CreateDatabaseDiscoveryRuleStatementUpdater.java | 2 +- .../update/DropDatabaseDiscoveryRuleStatementUpdater.java | 5 +++-- .../converter/DatabaseDiscoveryRuleStatementConverterTest.java | 4 ++-- .../handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java | 6 +++--- .../update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java | 8 ++++---- .../CreateDatabaseDiscoveryRuleStatementUpdaterTest.java | 8 ++++---- .../spring/boot/DatabaseDiscoverySpringBootStarterTest.java | 2 +- 20 files changed, 43 insertions(+), 42 deletions(-) diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/ha.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/ha.cn.md index eb50944..0779cd1 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/ha.cn.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/ha.cn.md @@ -23,7 +23,7 @@ weight = 3 | *名称* | *数据类型* | *说明* | *默认值* | | -------------------------- | -------------------- | ------------------------------------------------- | ------------- | -| name (+) | String | 数据源名称 | - | +| groupName (+) | String | 数据库发现组名称 | - | | dataSourceNames (+) | Collection\<String\> | 数据源名称,多个数据源用逗号分隔 如:ds_0, ds_1 | - | | discoveryHeartbeatName (+) | String | 监听心跳名称 | - | | discoveryTypeName (+) | String | 数据库发现类型名称 | - | diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/ha.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/ha.en.md index 7714f84..8336c80 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/ha.en.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/java-api/rules/ha.en.md @@ -21,9 +21,9 @@ Class name:org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDisco Attributes: -| *Name* | *DataType* | *Description* | *Default Value* | +| *Name* | *DataType* | *Description* | *Default Value* | | -------------------------- | -------------------- | ---------------------------------------------------------------------------------------- | ------------- | -| name (+) | String | Data source name | - | +| groupName (+) | String | Database discovery group name | - | | dataSourceNames (+) | Collection\<String\> | Data source names, multiple data source names separated with comma. Such as: ds_0, ds_1 | - | | discoveryHeartbeatName (+) | String | Detect heartbeat name | - | | discoveryTypeName (+) | String | Database discovery type name | - | diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/dbdiscovery/api/config/rule/DatabaseDiscoveryDataSourceRuleConfiguration.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/dbdiscovery/api/config/rule/DatabaseDiscoveryDataSourceRuleConfiguration.java index 544ff11..edf21d8 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/dbdiscovery/api/config/rule/DatabaseDiscoveryDataSourceRuleConfiguration.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-api/src/main/java/org/apache/shardingsphere/dbdiscovery/api/config/rule/DatabaseDiscoveryDataSourceRuleConfiguration.java @@ -29,7 +29,7 @@ import java.util.List; @Getter public final class DatabaseDiscoveryDataSourceRuleConfiguration { - private final String name; + private final String groupName; private final List<String> dataSourceNames; diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java index f343cd5..87dfc9e 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java @@ -56,7 +56,7 @@ public final class DatabaseDiscoverySQLRouter implements SQLRouter<DatabaseDisco for (RouteUnit each : routeContext.getRouteUnits()) { String dataSourceName = each.getDataSourceMapper().getLogicName(); Optional<DatabaseDiscoveryDataSourceRule> dataSourceRule = rule.findDataSourceRule(dataSourceName); - if (dataSourceRule.isPresent() && dataSourceRule.get().getName().equalsIgnoreCase(each.getDataSourceMapper().getActualName())) { + if (dataSourceRule.isPresent() && dataSourceRule.get().getGroupName().equalsIgnoreCase(each.getDataSourceMapper().getActualName())) { toBeRemoved.add(each); String actualDataSourceName = new DatabaseDiscoveryDataSourceRouter(dataSourceRule.get()).route(); toBeAdded.add(new RouteUnit(new RouteMapper(each.getDataSourceMapper().getLogicName(), actualDataSourceName), each.getTableMappers())); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java index 340a4862..30d0cf2 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java @@ -38,7 +38,7 @@ import java.util.stream.Collectors; @Getter public final class DatabaseDiscoveryDataSourceRule { - private final String name; + private final String groupName; private final List<String> dataSourceNames; @@ -52,14 +52,14 @@ public final class DatabaseDiscoveryDataSourceRule { public DatabaseDiscoveryDataSourceRule(final DatabaseDiscoveryDataSourceRuleConfiguration config, final Properties props, final DatabaseDiscoveryType databaseDiscoveryType) { checkConfiguration(config); - name = config.getName(); + groupName = config.getGroupName(); dataSourceNames = config.getDataSourceNames(); this.heartbeatProps = props; this.databaseDiscoveryType = databaseDiscoveryType; } private void checkConfiguration(final DatabaseDiscoveryDataSourceRuleConfiguration config) { - Preconditions.checkArgument(!Strings.isNullOrEmpty(config.getName()), "Name is required."); + Preconditions.checkArgument(!Strings.isNullOrEmpty(config.getGroupName()), "Group name is required."); Preconditions.checkArgument(null != config.getDataSourceNames() && !config.getDataSourceNames().isEmpty(), "Data source names are required."); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java index 2dd3736..ca09db3 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java @@ -98,7 +98,7 @@ public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContai final Map<String, DatabaseDiscoveryHeartBeatConfiguration> heartbeatConfig) { Map<String, DatabaseDiscoveryDataSourceRule> result = new HashMap<>(dataSources.size(), 1); for (DatabaseDiscoveryDataSourceRuleConfiguration each : dataSources) { - result.put(each.getName(), new DatabaseDiscoveryDataSourceRule(each, Strings.isNullOrEmpty(each.getDiscoveryHeartbeatName()) ? new Properties() + result.put(each.getGroupName(), new DatabaseDiscoveryDataSourceRule(each, Strings.isNullOrEmpty(each.getDiscoveryHeartbeatName()) ? new Properties() : heartbeatConfig.get(each.getDiscoveryHeartbeatName()).getProps(), discoveryTypes.get(each.getDiscoveryTypeName()))); } return result; @@ -166,7 +166,7 @@ public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContai } } else if (event instanceof PrimaryDataSourceChangedEvent) { for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : dataSourceRules.entrySet()) { - if (entry.getValue().getName().equals(((PrimaryDataSourceChangedEvent) event).getGroupName())) { + if (entry.getValue().getGroupName().equals(((PrimaryDataSourceChangedEvent) event).getGroupName())) { entry.getValue().updatePrimaryDataSourceName(((PrimaryDataSourceChangedEvent) event).getDataSourceName()); } } @@ -182,7 +182,7 @@ public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContai private Map<String, String> exportPrimaryDataSourceMap() { Map<String, String> result = new HashMap<>(dataSourceRules.size(), 1); - dataSourceRules.forEach((name, dataSourceRule) -> result.put(dataSourceRule.getName(), dataSourceRule.getPrimaryDataSourceName())); + dataSourceRules.forEach((name, dataSourceRule) -> result.put(dataSourceRule.getGroupName(), dataSourceRule.getPrimaryDataSourceName())); return result; } @@ -192,8 +192,8 @@ public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContai for (Entry<String, DatabaseDiscoveryDataSourceRule> entry : dataSourceRules.entrySet()) { Map<String, DataSource> dataSources = dataSourceMap.entrySet().stream().filter(dataSource -> !entry.getValue().getDisabledDataSourceNames().contains(dataSource.getKey())) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); - CronJob job = new CronJob(entry.getValue().getDatabaseDiscoveryType().getType() + "-" + entry.getValue().getName(), - each -> new HeartbeatJob(schemaName, dataSources, entry.getValue().getName(), entry.getValue().getDatabaseDiscoveryType(), entry.getValue().getDisabledDataSourceNames()) + CronJob job = new CronJob(entry.getValue().getDatabaseDiscoveryType().getType() + "-" + entry.getValue().getGroupName(), + each -> new HeartbeatJob(schemaName, dataSources, entry.getValue().getGroupName(), entry.getValue().getDatabaseDiscoveryType(), entry.getValue().getDisabledDataSourceNames()) .execute(null), entry.getValue().getHeartbeatProps().getProperty("keep-alive-cron")); modeScheduleContext.get().startCronJob(job); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper.java index 20358b8..184af51 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapper.java @@ -44,7 +44,7 @@ public final class DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwappe public YamlDatabaseDiscoveryRuleConfiguration swapToYamlConfiguration(final AlgorithmProvidedDatabaseDiscoveryRuleConfiguration data) { YamlDatabaseDiscoveryRuleConfiguration result = new YamlDatabaseDiscoveryRuleConfiguration(); result.setDataSources(data.getDataSources().stream().collect( - Collectors.toMap(DatabaseDiscoveryDataSourceRuleConfiguration::getName, this::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); + Collectors.toMap(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName, this::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); if (null != data.getDiscoveryHeartbeats()) { data.getDiscoveryHeartbeats().forEach((key, value) -> result.getDiscoveryHeartbeats().put(key, swapToYamlConfiguration(value))); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapper.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapper.java index a3cd23d..3c63494 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapper.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapper.java @@ -48,7 +48,7 @@ public final class DatabaseDiscoveryRuleConfigurationYamlSwapper public YamlDatabaseDiscoveryRuleConfiguration swapToYamlConfiguration(final DatabaseDiscoveryRuleConfiguration data) { YamlDatabaseDiscoveryRuleConfiguration result = new YamlDatabaseDiscoveryRuleConfiguration(); result.setDataSources(data.getDataSources().stream().collect( - Collectors.toMap(DatabaseDiscoveryDataSourceRuleConfiguration::getName, this::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); + Collectors.toMap(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName, this::swapToYamlConfiguration, (oldValue, currentValue) -> oldValue, LinkedHashMap::new))); if (null != data.getDiscoveryHeartbeats()) { data.getDiscoveryHeartbeats().forEach((key, value) -> result.getDiscoveryHeartbeats().put(key, swapToYamlConfiguration(value))); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java index da866ca..621e62d 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java @@ -60,7 +60,7 @@ public final class DatabaseDiscoveryRuleTest { } private void assertDataSourceRule(final DatabaseDiscoveryDataSourceRule actual) { - assertThat(actual.getName(), is("test_pr")); + assertThat(actual.getGroupName(), is("test_pr")); assertThat(actual.getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1"))); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapperTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapperTest.java index b32a398..30c702f 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapperTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwapperTest.java @@ -59,7 +59,7 @@ public final class DatabaseDiscoveryRuleAlgorithmProviderConfigurationYamlSwappe assertTrue(actual.getDataSources().iterator().hasNext()); DatabaseDiscoveryDataSourceRuleConfiguration ruleConfig = actual.getDataSources().iterator().next(); assertNotNull(ruleConfig); - assertThat(ruleConfig.getName(), is("name")); + assertThat(ruleConfig.getGroupName(), is("name")); assertNotNull(actual.getDiscoveryHeartbeats()); assertThat(actual.getDiscoveryHeartbeats().keySet(), is(Collections.singleton("mgr_heartbeat"))); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapperTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapperTest.java index 6dae120..d11d996 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapperTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/test/java/org/apache/shardingsphere/dbdiscovery/yaml/swapper/DatabaseDiscoveryRuleConfigurationYamlSwapperTest.java @@ -88,7 +88,7 @@ public final class DatabaseDiscoveryRuleConfigurationYamlSwapperTest { private void assertHARuleConfiguration(final DatabaseDiscoveryRuleConfiguration actual) { DatabaseDiscoveryDataSourceRuleConfiguration group = actual.getDataSources().iterator().next(); - assertThat(group.getName(), is("ha_ds")); + assertThat(group.getGroupName(), is("ha_ds")); assertThat(group.getDataSourceNames(), is(Arrays.asList("ds_0", "ds_1"))); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQuer [...] index 1950b5b..4502e5d 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java @@ -42,7 +42,7 @@ import java.util.Optional; */ public final class DatabaseDiscoveryRuleQueryResultSet implements DistSQLResultSet { - private static final String NAME = "name"; + private static final String NAME = "group_name"; private static final String DATA_SOURCE_NAMES = "data_source_names"; @@ -91,9 +91,9 @@ public final class DatabaseDiscoveryRuleQueryResultSet implements DistSQLResultS Map<String, String> heartbeatMap = new LinkedHashMap<>(); heartbeatMap.put(NAME, dataSourceRuleConfig.getDiscoveryHeartbeatName()); heartbeatMap.putAll(convertToMap(discoveryHeartbeats.get(dataSourceRuleConfig.getDiscoveryHeartbeatName()))); - String name = dataSourceRuleConfig.getName(); - String primaryDataSourceName = null == primaryDataSources.get(name) ? "" : primaryDataSources.get(name); - return Arrays.asList(name, String.join(",", dataSourceRuleConfig.getDataSourceNames()), primaryDataSourceName, typeMap, heartbeatMap); + String groupName = dataSourceRuleConfig.getGroupName(); + String primaryDataSourceName = null == primaryDataSources.get(groupName) ? "" : primaryDataSources.get(groupName); + return Arrays.asList(groupName, String.join(",", dataSourceRuleConfig.getDataSourceNames()), primaryDataSourceName, typeMap, heartbeatMap); } private Map<String, String> convertToMap(final Object obj) { diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDis [...] index ef141df..794e59e 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java @@ -73,7 +73,7 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RuleDef private void checkToBeAlteredRules(final String schemaName, final AlterDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { - Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toSet()); + Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName).collect(Collectors.toSet()); Collection<String> notExistedRuleNames = getToBeAlteredRuleNames(sqlStatement).stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toList()); DistSQLException.predictionThrow(notExistedRuleNames.isEmpty(), new RequiredRuleMissedException("database discovery", schemaName, notExistedRuleNames)); } @@ -125,13 +125,13 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RuleDef private void dropRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final DatabaseDiscoveryRuleConfiguration toBeAlteredRuleConfig) { for (DatabaseDiscoveryDataSourceRuleConfiguration each : toBeAlteredRuleConfig.getDataSources()) { - dropDataSourceRuleConfiguration(currentRuleConfig, each.getName()); + dropDataSourceRuleConfiguration(currentRuleConfig, each.getGroupName()); } } private void dropDataSourceRuleConfiguration(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final String toBeDroppedRuleNames) { Optional<DatabaseDiscoveryDataSourceRuleConfiguration> toBeDroppedDataSourceRuleConfig = currentRuleConfig.getDataSources().stream() - .filter(each -> each.getName().equals(toBeDroppedRuleNames)).findAny(); + .filter(each -> each.getGroupName().equals(toBeDroppedRuleNames)).findAny(); Preconditions.checkState(toBeDroppedDataSourceRuleConfig.isPresent()); currentRuleConfig.getDataSources().remove(toBeDroppedDataSourceRuleConfig.get()); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseD [...] index 20200f7..cc3dc26 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java @@ -71,7 +71,7 @@ public final class CreateDatabaseDiscoveryRuleStatementUpdater implements RuleDe if (null == currentRuleConfig) { return; } - Collection<String> existRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toList()); + Collection<String> existRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName).collect(Collectors.toList()); Collection<String> duplicateRuleNames = sqlStatement.getRules().stream().map(AbstractDatabaseDiscoverySegment::getName).filter(existRuleNames::contains).collect(Collectors.toSet()); duplicateRuleNames.addAll(getToBeCreatedDuplicateRuleNames(sqlStatement)); DistSQLException.predictionThrow(duplicateRuleNames.isEmpty(), new DuplicateRuleException(RULE_TYPE, schemaName, duplicateRuleNames)); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDisco [...] index 82f4d08..e0da70e 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java @@ -56,7 +56,7 @@ public final class DropDatabaseDiscoveryRuleStatementUpdater implements RuleDefi private void checkIsExist(final String schemaName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException { - Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName).collect(Collectors.toList()); + Collection<String> currentRuleNames = currentRuleConfig.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName).collect(Collectors.toList()); Collection<String> notExistedRuleNames = sqlStatement.getRuleNames().stream().filter(each -> !currentRuleNames.contains(each)).collect(Collectors.toList()); DistSQLException.predictionThrow(notExistedRuleNames.isEmpty(), new RequiredRuleMissedException(RULE_TYPE, schemaName)); } @@ -78,7 +78,8 @@ public final class DropDatabaseDiscoveryRuleStatementUpdater implements RuleDefi } private void dropRule(final DatabaseDiscoveryRuleConfiguration currentRuleConfig, final String ruleName) { - Optional<DatabaseDiscoveryDataSourceRuleConfiguration> dataSourceRuleConfig = currentRuleConfig.getDataSources().stream().filter(dataSource -> dataSource.getName().equals(ruleName)).findAny(); + Optional<DatabaseDiscoveryDataSourceRuleConfiguration> dataSourceRuleConfig = currentRuleConfig.getDataSources().stream().filter(dataSource -> + dataSource.getGroupName().equals(ruleName)).findAny(); Preconditions.checkState(dataSourceRuleConfig.isPresent()); currentRuleConfig.getDataSources().remove(dataSourceRuleConfig.get()); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseDiscoveryRuleStatementConverterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseD [...] index 8f3b597..e45d8e1 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseDiscoveryRuleStatementConverterTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/converter/DatabaseDiscoveryRuleStatementConverterTest.java @@ -47,12 +47,12 @@ public final class DatabaseDiscoveryRuleStatementConverterTest { Iterator<DatabaseDiscoveryDataSourceRuleConfiguration> iterator = ruleConfiguration.getDataSources().iterator(); DatabaseDiscoveryDataSourceRuleConfiguration configuration = iterator.next(); assertThat(configuration.getDataSourceNames(), is(Arrays.asList("resource0", "resource1"))); - assertThat(configuration.getName(), is("definition")); + assertThat(configuration.getGroupName(), is("definition")); assertThat(configuration.getDiscoveryTypeName(), is("definition_mgr")); assertThat(configuration.getDiscoveryHeartbeatName(), is("definition_heartbeat")); configuration = iterator.next(); assertThat(configuration.getDataSourceNames(), is(Arrays.asList("resource0", "resource1"))); - assertThat(configuration.getName(), is("construction")); + assertThat(configuration.getGroupName(), is("construction")); assertThat(configuration.getDiscoveryTypeName(), is("type")); assertThat(configuration.getDiscoveryHeartbeatName(), is("heartbeat")); } diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRule [...] index 8043f38..9364672 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSetTest.java @@ -56,13 +56,13 @@ public final class DatabaseDiscoveryRuleQueryResultSetTest { Collection<String> columnNames = resultSet.getColumnNames(); ArrayList<Object> actual = new ArrayList<>(resultSet.getRowData()); assertThat(columnNames.size(), is(5)); - columnNames.containsAll(Arrays.asList("name", "data_source_names", "primary_data_source_name", "discover_type", "heartbeat")); + columnNames.containsAll(Arrays.asList("group_name", "data_source_names", "primary_data_source_name", "discover_type", "heartbeat")); assertThat(actual.size(), is(5)); assertThat(actual.get(0), is("ms_group")); assertThat(actual.get(1), is("ds_0,ds_1")); assertThat(actual.get(2), is("")); - assertThat(actual.get(3).toString(), is("{name=type_test, type=MGR, props={}}")); - assertThat(actual.get(4).toString(), is("{name=heartbeat_test, props={}}")); + assertThat(actual.get(3).toString(), is("{group_name=type_test, type=MGR, props={}}")); + assertThat(actual.get(4).toString(), is("{group_name=heartbeat_test, props={}}")); } private RuleConfiguration createRuleConfiguration() { diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabas [...] index 22f71fa..10504fe 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdaterTest.java @@ -124,9 +124,9 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdaterTest { DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfiguration = (DatabaseDiscoveryRuleConfiguration) updater.buildToBeAlteredRuleConfiguration(new AlterDatabaseDiscoveryRuleStatement(Arrays.asList(constructionSegment, definitionSegment))); assertThat(databaseDiscoveryRuleConfiguration.getDataSources().size(), is(2)); - assertTrue(databaseDiscoveryRuleConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName) + assertTrue(databaseDiscoveryRuleConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName) .collect(Collectors.toList()).removeAll(Collections.singletonList("pr_ds_1"))); - assertTrue(databaseDiscoveryRuleConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName) + assertTrue(databaseDiscoveryRuleConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName) .collect(Collectors.toList()).removeAll(Collections.singletonList("pr_ds_2"))); assertTrue(databaseDiscoveryRuleConfiguration.getDiscoveryTypes().containsKey("pr_ds_2_mgr")); assertTrue(databaseDiscoveryRuleConfiguration.getDiscoveryHeartbeats().containsKey("pr_ds_2_heartbeat")); @@ -145,9 +145,9 @@ public final class AlterDatabaseDiscoveryRuleStatementUpdaterTest { new HashMap<>(Collections.singletonMap("discovery_type_name", null)), new HashMap<>(Collections.singletonMap("heartbeat_name", null))); updater.updateCurrentRuleConfiguration(currentConfiguration, toBeCreatedRuleConfig); assertThat(currentConfiguration.getDataSources().size(), is(2)); - assertTrue(currentConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName) + assertTrue(currentConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName) .collect(Collectors.toList()).removeAll(Collections.singletonList("pr_ds_1"))); - assertTrue(currentConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName) + assertTrue(currentConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName) .collect(Collectors.toList()).removeAll(Collections.singletonList("pr_ds_2"))); assertTrue(currentConfiguration.getDiscoveryTypes().containsKey("pr_ds_2_mgr")); assertTrue(currentConfiguration.getDiscoveryHeartbeats().containsKey("pr_ds_2_heartbeat")); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatab [...] index 514e3e7..e541fcc 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdaterTest.java @@ -111,9 +111,9 @@ public final class CreateDatabaseDiscoveryRuleStatementUpdaterTest { DatabaseDiscoveryRuleConfiguration databaseDiscoveryRuleConfiguration = updater.buildToBeCreatedRuleConfiguration(new CreateDatabaseDiscoveryRuleStatement(Arrays.asList(constructionSegment, definitionSegment))); assertThat(databaseDiscoveryRuleConfiguration.getDataSources().size(), is(2)); - assertTrue(databaseDiscoveryRuleConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName) + assertTrue(databaseDiscoveryRuleConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName) .collect(Collectors.toList()).removeAll(Collections.singletonList("pr_ds_1"))); - assertTrue(databaseDiscoveryRuleConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName) + assertTrue(databaseDiscoveryRuleConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName) .collect(Collectors.toList()).removeAll(Collections.singletonList("pr_ds_2"))); assertTrue(databaseDiscoveryRuleConfiguration.getDiscoveryTypes().containsKey("pr_ds_2_mgr")); assertTrue(databaseDiscoveryRuleConfiguration.getDiscoveryHeartbeats().containsKey("pr_ds_2_heartbeat")); @@ -130,9 +130,9 @@ public final class CreateDatabaseDiscoveryRuleStatementUpdaterTest { DatabaseDiscoveryRuleConfiguration currentConfiguration = new DatabaseDiscoveryRuleConfiguration(new LinkedList<>(), new LinkedHashMap<>(), new LinkedHashMap<>()); updater.updateCurrentRuleConfiguration(currentConfiguration, toBeCreatedRuleConfig); assertThat(currentConfiguration.getDataSources().size(), is(2)); - assertTrue(currentConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName) + assertTrue(currentConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName) .collect(Collectors.toList()).removeAll(Collections.singletonList("pr_ds_1"))); - assertTrue(currentConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getName) + assertTrue(currentConfiguration.getDataSources().stream().map(DatabaseDiscoveryDataSourceRuleConfiguration::getGroupName) .collect(Collectors.toList()).removeAll(Collections.singletonList("pr_ds_2"))); assertTrue(currentConfiguration.getDiscoveryTypes().containsKey("pr_ds_2_mgr")); assertTrue(currentConfiguration.getDiscoveryHeartbeats().containsKey("pr_ds_2_heartbeat")); diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/java/org/apache/shardingsphere/dbdiscovery/spring/boot/DatabaseDiscoverySpringBootStarterTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/java/org/apache/shardingsphere/dbdiscovery/spring/boot/DatabaseDiscoverySpringBootStarterTest.java index 573bfca..2b4129b 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/java/org/apache/shardingsphere/dbdiscovery/spring/boot/DatabaseDiscoverySpringBootStarterTest.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-spring/shardingsphere-db-discovery-spring-boot-starter/src/test/java/org/apache/shardingsphere/dbdiscovery/spring/boot/DatabaseDiscoverySpringBootStarterTest.java @@ -47,7 +47,7 @@ public class DatabaseDiscoverySpringBootStarterTest { assertThat(config.getDataSources().size(), is(1)); assertTrue(config.getDataSources().stream().findFirst().isPresent()); DatabaseDiscoveryDataSourceRuleConfiguration dataSourceRuleConfig = config.getDataSources().stream().findFirst().get(); - assertThat(dataSourceRuleConfig.getName(), is("primary_replica_ds")); + assertThat(dataSourceRuleConfig.getGroupName(), is("primary_replica_ds")); assertThat(dataSourceRuleConfig.getDataSourceNames().size(), is(2)); assertTrue(config.getDataSources().contains(dataSourceRuleConfig)); assertThat(config.getDiscoveryHeartbeats().size(), is(1));