Skip to content

Commit

Permalink
Refactor Bootstrap's log (apache#6559)
Browse files Browse the repository at this point in the history
* Refactor Bootstrap

* Refactor Bootstrap's log
  • Loading branch information
terrymanu authored and qiulu3 committed Aug 3, 2020
1 parent b38c537 commit aeed057
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
/**
* ShardingSphere of constants.
*/
@Deprecated
// TODO remove the class, ref #6546
public final class Constants {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.infra.log.ConfigurationLogger;
import org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.apache.shardingsphere.kernel.context.SchemaContextsBuilder;
import org.apache.shardingsphere.kernel.context.schema.DataSourceParameter;
import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
Expand All @@ -48,7 +47,6 @@
import org.apache.shardingsphere.proxy.config.YamlProxyConfiguration;
import org.apache.shardingsphere.proxy.config.converter.ProxyConfigurationConverter;
import org.apache.shardingsphere.proxy.config.converter.ProxyConfigurationConverterFactory;
import org.apache.shardingsphere.proxy.config.yaml.YamlProxyRuleConfiguration;
import org.apache.shardingsphere.proxy.frontend.bootstrap.ShardingSphereProxy;

import javax.sql.DataSource;
Expand Down Expand Up @@ -83,37 +81,30 @@ public static void main(final String[] args) throws Exception {
int port = bootstrapArgs.getPort();
System.setProperty(Constants.PORT_KEY, String.valueOf(port));
YamlProxyConfiguration yamlConfig = ProxyConfigurationLoader.load(bootstrapArgs.getConfigurationPath());
logRuleConfigurations(getRuleConfigurations(yamlConfig.getRuleConfigurations()).values());
try (ProxyConfigurationConverter converter = ProxyConfigurationConverterFactory.newInstances(null != yamlConfig.getServerConfiguration().getOrchestration())) {
ProxyConfiguration proxyConfiguration = converter.convert(yamlConfig);
log(proxyConfiguration);
initialize(proxyConfiguration, port, converter);
}
}

private static void logRuleConfigurations(final Collection<Collection<RuleConfiguration>> ruleConfigurations) {
private static void log(final ProxyConfiguration proxyConfiguration) {
Collection<Collection<RuleConfiguration>> ruleConfigurations = proxyConfiguration.getSchemaRules().values();
if (CollectionUtils.isNotEmpty(ruleConfigurations)) {
ruleConfigurations.forEach(ConfigurationLogger::log);
}
}

private static Map<String, Collection<RuleConfiguration>> getRuleConfigurations(final Map<String, YamlProxyRuleConfiguration> localRuleConfigs) {
YamlRuleConfigurationSwapperEngine swapperEngine = new YamlRuleConfigurationSwapperEngine();
return localRuleConfigs.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> swapperEngine.swapToRuleConfigurations(entry.getValue().getRules())));
ConfigurationLogger.log(proxyConfiguration.getAuthentication());
ConfigurationLogger.log(proxyConfiguration.getProps());
}

private static void initialize(final ProxyConfiguration proxyConfiguration, final int port, final ProxyConfigurationConverter converter) throws SQLException {
Authentication authentication = proxyConfiguration.getAuthentication();
Properties props = proxyConfiguration.getProps();
log(authentication, props);
initProxySchemaContexts(proxyConfiguration.getSchemaDataSources(), proxyConfiguration.getSchemaRules(), authentication, props, converter);
initControlPanelFacade(proxyConfiguration.getMetrics(), proxyConfiguration.getCluster());
updateServerInfo();
ShardingSphereProxy.getInstance().start(port);
}
private static void log(final Authentication authentication, final Properties properties) {
ConfigurationLogger.log(authentication);
ConfigurationLogger.log(properties);
}

private static void initProxySchemaContexts(final Map<String, Map<String, DataSourceParameter>> schemaDataSources, final Map<String, Collection<RuleConfiguration>> schemaRules,
final Authentication authentication, final Properties properties, final ProxyConfigurationConverter converter) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static YamlProxyConfiguration load(final String path) throws IOException
YamlProxyServerConfiguration serverConfig = loadServerConfiguration(getResourceFile(path + "/" + SERVER_CONFIG_FILE));
File configPath = getResourceFile(path);
Collection<YamlProxyRuleConfiguration> ruleConfigurations = loadRuleConfigurations(schemaNames, configPath);
Preconditions.checkState(!ruleConfigurations.isEmpty() || null != serverConfig.getOrchestration(), "Can not find any sharding rule configuration file in path `%s`.", configPath.getPath());
Preconditions.checkState(!ruleConfigurations.isEmpty() || null != serverConfig.getOrchestration(), "Can not find any rule configurations file in path `%s`.", configPath.getPath());
return new YamlProxyConfiguration(serverConfig, ruleConfigurations.stream().collect(Collectors.toMap(YamlProxyRuleConfiguration::getSchemaName, each -> each)));
}

Expand Down

0 comments on commit aeed057

Please sign in to comment.