Skip to content

Commit

Permalink
Fixes NPE when proxy starts without cluster or metrics configuration (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
menghaoranss authored and cmonkey committed Jun 22, 2020
1 parent 2fe29f8 commit d0e1697
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public MetricsTrackerManager findMetricsTrackerManager(final String metricsName)
* @param metricsConfiguration metrics configuration
*/
public void init(final MetricsConfiguration metricsConfiguration) {
Preconditions.checkNotNull(metricsConfiguration, "metrics configuration can not be null.");
metricsTrackerManager = findMetricsTrackerManager(metricsConfiguration.getMetricsName());
Preconditions.checkNotNull(metricsTrackerManager, "Can not find metrics tracker manager with metrics name in metrics configuration.");
metricsTrackerManager.start(metricsConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -134,8 +135,8 @@ private static void startWithoutRegistryCenter(final Map<String, YamlProxyRuleCo
Authentication authentication = new AuthenticationYamlSwapper().swapToObject(yamlAuthenticationConfig);
Map<String, Map<String, DataSourceParameter>> schemaDataSources = getDataSourceParametersMap(ruleConfigs);
Map<String, Collection<RuleConfiguration>> schemaRules = getRuleConfigurations(ruleConfigs);
initialize(authentication, properties, schemaDataSources, schemaRules, new MetricsConfigurationYamlSwapper().swapToObject(metricsConfiguration),
new ClusterConfigurationYamlSwapper().swapToObject(clusterConfiguration), false);
initialize(authentication, properties, schemaDataSources, schemaRules, getMetricsConfiguration(metricsConfiguration),
getClusterConfiguration(clusterConfiguration), false);
ShardingSphereProxy.getInstance().start(port);
}

Expand Down Expand Up @@ -289,6 +290,14 @@ private static DataSourceParameter createDataSourceParameter(final YamlDataSourc
return result;
}

private static MetricsConfiguration getMetricsConfiguration(final YamlMetricsConfiguration yamlMetricsConfiguration) {
return Optional.ofNullable(yamlMetricsConfiguration).map(new MetricsConfigurationYamlSwapper()::swapToObject).orElse(null);
}

private static ClusterConfiguration getClusterConfiguration(final YamlClusterConfiguration yamlClusterConfiguration) {
return Optional.ofNullable(yamlClusterConfiguration).map(new ClusterConfigurationYamlSwapper()::swapToObject).orElse(null);
}

/**
* Log rule configurations.
*
Expand Down

0 comments on commit d0e1697

Please sign in to comment.