use of io.shardingjdbc.core.yaml.masterslave.YamlMasterSlaveRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class OrchestrationMasterSlaveDataSourceFactory method createDataSource.
/**
* Create master-slave data source.
*
* @param dataSourceMap data source map
* @param yamlMasterSlaveRuleConfig yaml master-slave rule configuration
* @param orchestrationConfig orchestration configuration
* @return master-slave data source
* @throws SQLException SQL exception
*/
public static DataSource createDataSource(final Map<String, DataSource> dataSourceMap, final YamlMasterSlaveRuleConfiguration yamlMasterSlaveRuleConfig, final OrchestrationConfiguration orchestrationConfig) throws SQLException {
OrchestrationFacade orchestrationFacade = new OrchestrationFacade(orchestrationConfig);
if (null == yamlMasterSlaveRuleConfig) {
ConfigurationService configService = orchestrationFacade.getConfigService();
final MasterSlaveRuleConfiguration cloudMasterSlaveRuleConfig = configService.loadMasterSlaveRuleConfiguration();
Preconditions.checkState(null != cloudMasterSlaveRuleConfig, "Missing the master-slave rule configuration on register center");
return createDataSource(configService.loadDataSourceMap(), cloudMasterSlaveRuleConfig, configService.loadMasterSlaveConfigMap(), orchestrationFacade);
} else {
return createDataSource(dataSourceMap, yamlMasterSlaveRuleConfig.getMasterSlaveRuleConfiguration(), yamlMasterSlaveRuleConfig.getConfigMap(), orchestrationFacade);
}
}
use of io.shardingjdbc.core.yaml.masterslave.YamlMasterSlaveRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class YamlShardingRuleConfiguration method getShardingRuleConfiguration.
/**
* Get sharding rule configuration.
*
* @return sharding rule configuration
*/
public ShardingRuleConfiguration getShardingRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.setDefaultDataSourceName(defaultDataSourceName);
for (Entry<String, YamlTableRuleConfiguration> entry : tables.entrySet()) {
YamlTableRuleConfiguration tableRuleConfig = entry.getValue();
tableRuleConfig.setLogicTable(entry.getKey());
result.getTableRuleConfigs().add(tableRuleConfig.build());
}
result.getBindingTableGroups().addAll(bindingTables);
if (null != defaultDatabaseStrategy) {
result.setDefaultDatabaseShardingStrategyConfig(defaultDatabaseStrategy.build());
}
if (null != defaultTableStrategy) {
result.setDefaultTableShardingStrategyConfig(defaultTableStrategy.build());
}
if (null != defaultKeyGeneratorClass) {
result.setDefaultKeyGenerator(KeyGeneratorFactory.newInstance(defaultKeyGeneratorClass));
}
Collection<MasterSlaveRuleConfiguration> masterSlaveRuleConfigs = new LinkedList<>();
for (Entry<String, YamlMasterSlaveRuleConfiguration> entry : masterSlaveRules.entrySet()) {
YamlMasterSlaveRuleConfiguration each = entry.getValue();
each.setName(entry.getKey());
masterSlaveRuleConfigs.add(entry.getValue().getMasterSlaveRuleConfiguration());
}
result.setMasterSlaveRuleConfigs(masterSlaveRuleConfigs);
return result;
}
use of io.shardingjdbc.core.yaml.masterslave.YamlMasterSlaveRuleConfiguration in project sharding-jdbc by shardingjdbc.
the class YamlShardingRuleConfigurationTest method createYamlMasterSlaveRuleConfig.
private YamlMasterSlaveRuleConfiguration createYamlMasterSlaveRuleConfig() {
YamlMasterSlaveRuleConfiguration result = new YamlMasterSlaveRuleConfiguration();
result.setName("master_slave_ds");
result.setMasterDataSourceName("master_ds");
result.setSlaveDataSourceNames(Arrays.asList("slave_ds_0", "slave_ds_1"));
result.setLoadBalanceAlgorithmType(MasterSlaveLoadBalanceAlgorithmType.ROUND_ROBIN);
result.setLoadBalanceAlgorithmClassName("TestLoadBalanceAlgorithmClassName");
return result;
}
Aggregations