提交 1ce382c1 编写于 作者: 马晓光

增加缺失配置判断

上级 d4d629ab
......@@ -68,7 +68,9 @@ public class OrchestrationSpringBootConfiguration implements EnvironmentAware {
*/
@Bean
public DataSource dataSource() throws SQLException {
return OrchestrationConfiguration.SHARDING.equals(orchestrationProperties.getType())
String type = orchestrationProperties.getType();
Preconditions.checkState(null != type, "Missing the type of datasource configuration in orchestration configuration");
return OrchestrationConfiguration.SHARDING.equals(type)
? OrchestrationShardingDataSourceFactory.createDataSource(dataSourceMap,
shardingProperties.getShardingRuleConfiguration(), shardingProperties.getConfigMap(), shardingProperties.getProps(), orchestrationProperties.getOrchestrationConfiguration())
: OrchestrationMasterSlaveDataSourceFactory.createDataSource(dataSourceMap,
......
......@@ -17,6 +17,7 @@
package io.shardingjdbc.orchestration.api;
import com.google.common.base.Preconditions;
import io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration;
import io.shardingjdbc.core.yaml.masterslave.YamlMasterSlaveRuleConfiguration;
import io.shardingjdbc.orchestration.api.config.OrchestrationConfiguration;
......@@ -30,11 +31,7 @@ import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import javax.sql.DataSource;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.sql.SQLException;
import java.util.Map;
......@@ -52,7 +49,7 @@ public final class OrchestrationMasterSlaveDataSourceFactory {
*
* @param dataSourceMap data source map
* @param masterSlaveRuleConfig master-slave rule configuration
* @param orchestrationConfig orchestration master-slave configuration
* @param orchestrationConfig orchestration configuration
* @param configMap config map
* @return master-slave data source
* @throws SQLException SQL exception
......@@ -61,9 +58,11 @@ public final class OrchestrationMasterSlaveDataSourceFactory {
final Map<String, DataSource> dataSourceMap, final MasterSlaveRuleConfiguration masterSlaveRuleConfig,
final Map<String, Object> configMap, final OrchestrationConfiguration orchestrationConfig) throws SQLException {
OrchestrationFacade orchestrationFacade = new OrchestrationFacade(orchestrationConfig);
if (null == masterSlaveRuleConfig) {
if (null == masterSlaveRuleConfig || null == masterSlaveRuleConfig.getMasterDataSourceName()) {
ConfigurationService configService = orchestrationFacade.getConfigService();
return createDataSource(configService.loadDataSourceMap(), configService.loadMasterSlaveRuleConfiguration(), configService.loadMasterSlaveConfigMap(), orchestrationFacade);
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, masterSlaveRuleConfig, configMap, orchestrationFacade);
}
......@@ -74,7 +73,7 @@ public final class OrchestrationMasterSlaveDataSourceFactory {
*
* @param dataSourceMap data source map
* @param yamlMasterSlaveRuleConfig yaml master-slave rule configuration
* @param orchestrationConfig orchestration master-slave configuration
* @param orchestrationConfig orchestration configuration
* @return master-slave data source
* @throws SQLException SQL exception
*/
......@@ -83,7 +82,9 @@ public final class OrchestrationMasterSlaveDataSourceFactory {
OrchestrationFacade orchestrationFacade = new OrchestrationFacade(orchestrationConfig);
if (null == yamlMasterSlaveRuleConfig) {
ConfigurationService configService = orchestrationFacade.getConfigService();
return createDataSource(configService.loadDataSourceMap(), configService.loadMasterSlaveRuleConfiguration(), configService.loadMasterSlaveConfigMap(), orchestrationFacade);
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);
}
......
......@@ -17,6 +17,7 @@
package io.shardingjdbc.orchestration.api;
import com.google.common.base.Preconditions;
import io.shardingjdbc.core.api.MasterSlaveDataSourceFactory;
import io.shardingjdbc.core.api.config.MasterSlaveRuleConfiguration;
import io.shardingjdbc.core.api.config.ShardingRuleConfiguration;
......@@ -57,7 +58,7 @@ public final class OrchestrationShardingDataSourceFactory {
*
* @param dataSourceMap data source map
* @param shardingRuleConfig sharding rule configuration
* @param orchestrationConfig orchestration master-slave configuration
* @param orchestrationConfig orchestration configuration
* @param configMap config map
* @param props properties for data source
* @return sharding data source
......@@ -67,9 +68,11 @@ public final class OrchestrationShardingDataSourceFactory {
final Map<String, DataSource> dataSourceMap, final ShardingRuleConfiguration shardingRuleConfig,
final Map<String, Object> configMap, final Properties props, final OrchestrationConfiguration orchestrationConfig) throws SQLException {
OrchestrationFacade orchestrationFacade = new OrchestrationFacade(orchestrationConfig);
if (null == shardingRuleConfig) {
if (null == shardingRuleConfig || shardingRuleConfig.getTableRuleConfigs().isEmpty()) {
ConfigurationService configService = orchestrationFacade.getConfigService();
return createDataSource(configService.loadDataSourceMap(), configService.loadShardingRuleConfiguration(), configService.loadShardingConfigMap(), configService.loadShardingProperties(), orchestrationFacade);
final ShardingRuleConfiguration cloudShardingRuleConfig = configService.loadShardingRuleConfiguration();
Preconditions.checkState(null != cloudShardingRuleConfig, "Missing the sharding rule configuration on register center");
return createDataSource(configService.loadDataSourceMap(), cloudShardingRuleConfig, configService.loadShardingConfigMap(), configService.loadShardingProperties(), orchestrationFacade);
} else {
return createDataSource(dataSourceMap, shardingRuleConfig, configMap, props, orchestrationFacade);
}
......@@ -80,7 +83,7 @@ public final class OrchestrationShardingDataSourceFactory {
*
* @param dataSourceMap data source map
* @param yamlShardingRuleConfig yaml sharding rule configuration
* @param orchestrationConfig orchestration master-slave configuration
* @param orchestrationConfig orchestration configuration
* @return sharding data source
* @throws SQLException SQL exception
*/
......@@ -89,7 +92,9 @@ public final class OrchestrationShardingDataSourceFactory {
OrchestrationFacade orchestrationFacade = new OrchestrationFacade(orchestrationConfig);
if (null == yamlShardingRuleConfig) {
ConfigurationService configService = orchestrationFacade.getConfigService();
return createDataSource(configService.loadDataSourceMap(), configService.loadShardingRuleConfiguration(), configService.loadShardingConfigMap(), configService.loadShardingProperties(), orchestrationFacade);
final ShardingRuleConfiguration cloudShardingRuleConfig = configService.loadShardingRuleConfiguration();
Preconditions.checkState(null != cloudShardingRuleConfig, "Missing the sharding rule configuration on register center");
return createDataSource(configService.loadDataSourceMap(), cloudShardingRuleConfig, configService.loadShardingConfigMap(), configService.loadShardingProperties(), orchestrationFacade);
} else {
return createDataSource(dataSourceMap, yamlShardingRuleConfig.getShardingRuleConfiguration(), yamlShardingRuleConfig.getConfigMap(), yamlShardingRuleConfig.getProps(), orchestrationFacade);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册