Skip to content

Commit

Permalink
Remove useless ContextManagerBuilderParameter.force (#34302)
Browse files Browse the repository at this point in the history
* Refactor ClusterProcessPersistService

* Remove ContextManagerAware

* Remove useless ContextManagerBuilderParameter.force
  • Loading branch information
terrymanu authored Jan 10, 2025
1 parent 8b85edb commit fc47768
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private ContextManager createContextManager(final ModeConfiguration modeConfig,
Collection<RuleConfiguration> databaseRuleConfigs = new LinkedList<>(ruleConfigs);
databaseRuleConfigs.removeAll(globalRuleConfigs);
ContextManagerBuilderParameter param = new ContextManagerBuilderParameter(modeConfig, Collections.singletonMap(databaseName,
new DataSourceProvidedDatabaseConfiguration(dataSourceMap, databaseRuleConfigs)), Collections.emptyMap(), globalRuleConfigs, props, Collections.emptyList(), instanceMetaData, false);
new DataSourceProvidedDatabaseConfiguration(dataSourceMap, databaseRuleConfigs)), Collections.emptyMap(), globalRuleConfigs, props, Collections.emptyList(), instanceMetaData);
return TypedSPILoader.getService(ContextManagerBuilder.class, null == modeConfig ? null : modeConfig.getType()).build(param, new EventBusContext());
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public final class ContextManagerBuilderParameter {

private final InstanceMetaData instanceMetaData;

private final boolean force;

/**
* Get mode configuration.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ContextManagerBuilderParameterTest {

@Test
void assertGetDefaultModeConfiguration() {
ContextManagerBuilderParameter param = new ContextManagerBuilderParameter(null, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), new Properties(), null, null, false);
ContextManagerBuilderParameter param = new ContextManagerBuilderParameter(null, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), new Properties(), null, null);
assertThat(param.getModeConfiguration().getType(), is("Standalone"));
assertNull(param.getModeConfiguration().getRepository());
}
Expand All @@ -43,7 +43,7 @@ void assertGetDefaultModeConfiguration() {
void assertGetModeConfiguration() {
ModeConfiguration modeConfig = new ModeConfiguration("Cluster", mock(PersistRepositoryConfiguration.class));
ContextManagerBuilderParameter param =
new ContextManagerBuilderParameter(modeConfig, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), new Properties(), null, null, false);
new ContextManagerBuilderParameter(modeConfig, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), new Properties(), null, null);
assertThat(param.getModeConfiguration().getType(), is("Cluster"));
assertNotNull(param.getModeConfiguration().getRepository());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ void assertCreateWithProxyInstanceMetaData() throws SQLException {
private ContextManagerBuilderParameter createContextManagerBuilderParameter() {
DatabaseConfiguration databaseConfig = new DataSourceProvidedDatabaseConfiguration(Collections.singletonMap("foo", new MockedDataSource()), Collections.emptyList());
return new ContextManagerBuilderParameter(null, Collections.singletonMap("foo_db", databaseConfig), Collections.emptyMap(),
Collections.emptyList(), new Properties(), Collections.emptyList(), null, false);
Collections.emptyList(), new Properties(), Collections.emptyList(), null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public Collection<Process> getProcessList() {
}
}

private Collection<String> getShowProcessListTriggerPaths(final String taskId) {
return Stream.of(InstanceType.values())
.flatMap(each -> repository.getChildrenKeys(ComputeNodePath.getOnlinePath(each)).stream().map(instanceId -> ComputeNodePath.getShowProcessListTriggerPath(instanceId, taskId)))
.collect(Collectors.toList());
}

private Collection<Process> getShowProcessListData(final String taskId) {
YamlProcessList yamlProcessList = new YamlProcessList();
for (String each : repository.getChildrenKeys(ProcessNodePath.getRootPath(taskId)).stream()
Expand All @@ -69,12 +75,6 @@ private Collection<Process> getShowProcessListData(final String taskId) {
return new YamlProcessListSwapper().swapToObject(yamlProcessList);
}

private Collection<String> getShowProcessListTriggerPaths(final String taskId) {
return Stream.of(InstanceType.values())
.flatMap(each -> repository.getChildrenKeys(ComputeNodePath.getOnlinePath(each)).stream().map(instanceId -> ComputeNodePath.getShowProcessListTriggerPath(instanceId, taskId)))
.collect(Collectors.toList());
}

@Override
public void killProcess(final String processId) {
Collection<String> triggerPaths = getKillProcessTriggerPaths(processId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void assertBuildForProxy() throws SQLException {

private void assertBuild(final InstanceMetaData instanceMetaData) throws SQLException {
ContextManager actual = builder.build(new ContextManagerBuilderParameter(createModeConfiguration(),
Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), new Properties(), Collections.emptyList(), instanceMetaData, false), mock(EventBusContext.class));
Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), new Properties(), Collections.emptyList(), instanceMetaData), mock(EventBusContext.class));
assertThat(actual.getComputeNodeInstanceContext().getInstance().getMetaData(), is(instanceMetaData));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void assertBuildWithDefault() throws SQLException {
void assertBuild(final ContextManagerBuilder builder) throws SQLException {
InstanceMetaData instanceMetaData = new JDBCInstanceMetaData("foo", "foo_db");
ContextManager actual = builder.build(new ContextManagerBuilderParameter(createModeConfiguration(),
Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), new Properties(), Collections.emptyList(), instanceMetaData, false), mock(EventBusContext.class));
Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), new Properties(), Collections.emptyList(), instanceMetaData), mock(EventBusContext.class));
assertThat(actual.getComputeNodeInstanceContext().getInstance().getMetaData(), is(instanceMetaData));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void main(final String[] args) throws IOException, SQLException {
int port = bootstrapArgs.getPort().orElseGet(() -> new ConfigurationProperties(yamlConfig.getServerConfiguration().getProps()).getValue(ConfigurationPropertyKey.PROXY_DEFAULT_PORT));
List<String> addresses = bootstrapArgs.getAddresses();
checkPort(addresses, port);
new BootstrapInitializer().init(yamlConfig, port, bootstrapArgs.isForce());
new BootstrapInitializer().init(yamlConfig, port);
Optional.ofNullable((Integer) yamlConfig.getServerConfiguration().getProps().get(ConfigurationPropertyKey.CDC_SERVER_PORT.getKey()))
.ifPresent(optional -> new Thread(new CDCServer(addresses, optional)).start());
ProxySSLContext.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,6 @@ public Optional<String> getSocketPath() {
return addresses.stream().filter(address -> !InetAddresses.isInetAddress(address)).filter(this::isValidPath).findFirst();
}

/**
* Get force startup parameter.
*
* @return force parameter
*/
public boolean isForce() {
return args.length >= 4 && parseForceParameter(args[3]);
}

private boolean parseForceParameter(final String forceParam) {
return Boolean.TRUE.toString().equalsIgnoreCase(forceParam.trim());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,20 @@ public final class BootstrapInitializer {
*
* @param yamlConfig YAML proxy configuration
* @param port proxy port
* @param force force start
* @throws SQLException SQL exception
*/
public void init(final YamlProxyConfiguration yamlConfig, final int port, final boolean force) throws SQLException {
public void init(final YamlProxyConfiguration yamlConfig, final int port) throws SQLException {
ModeConfiguration modeConfig = null == yamlConfig.getServerConfiguration().getMode() ? null : new YamlModeConfigurationSwapper().swapToObject(yamlConfig.getServerConfiguration().getMode());
ProxyConfiguration proxyConfig = new YamlProxyConfigurationSwapper().swap(yamlConfig);
ContextManager contextManager = createContextManager(proxyConfig, modeConfig, port, force);
ContextManager contextManager = createContextManager(proxyConfig, modeConfig, port);
ProxyContext.init(contextManager);
ShardingSphereProxyVersion.setVersion(contextManager);
}

private ContextManager createContextManager(final ProxyConfiguration proxyConfig, final ModeConfiguration modeConfig, final int port, final boolean force) throws SQLException {
private ContextManager createContextManager(final ProxyConfiguration proxyConfig, final ModeConfiguration modeConfig, final int port) throws SQLException {
InstanceMetaData instanceMetaData = TypedSPILoader.getService(InstanceMetaDataBuilder.class, "Proxy").build(port, "");
ContextManagerBuilderParameter param = new ContextManagerBuilderParameter(modeConfig, proxyConfig.getDatabaseConfigurations(), proxyConfig.getGlobalConfiguration().getDataSources(),
proxyConfig.getGlobalConfiguration().getRules(), proxyConfig.getGlobalConfiguration().getProperties(), proxyConfig.getGlobalConfiguration().getLabels(), instanceMetaData, force);
proxyConfig.getGlobalConfiguration().getRules(), proxyConfig.getGlobalConfiguration().getProperties(), proxyConfig.getGlobalConfiguration().getLabels(), instanceMetaData);
return TypedSPILoader.getService(ContextManagerBuilder.class, null == modeConfig ? null : modeConfig.getType()).build(param, new EventBusContext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,6 @@ void assertGetAddressesWithThreeArguments() {
assertThat(new BootstrapArguments(new String[]{"3306", "test_conf", "1.1.1.1,127.0.0.1"}).getAddresses(), is(Arrays.asList("1.1.1.1", "127.0.0.1")));
}

@Test
void assertGetForce() {
assertFalse(new BootstrapArguments(new String[]{"3306", "test_conf", "127.0.0.1"}).isForce());
assertFalse(new BootstrapArguments(new String[]{"3306", "test_conf", "127.0.0.1", "false"}).isForce());
assertTrue(new BootstrapArguments(new String[]{"3306", "test_conf", "127.0.0.1", "true "}).isForce());
assertTrue(new BootstrapArguments(new String[]{"3306", "test_conf", "127.0.0.1", "true"}).isForce());
assertTrue(new BootstrapArguments(new String[]{"3306", "test_conf", "127.0.0.1", "TrUe"}).isForce());
}

@Test
void assertGetSocketPath() {
assertThat(new BootstrapArguments(new String[]{"3306", "test_conf", "127.0.0.1,/tmp/shardingsphere.sock"}).getSocketPath(), is(Optional.of("/tmp/shardingsphere.sock")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void start() {
private void startInternalProxy() {
YamlProxyConfiguration yamlConfig = ProxyConfigurationLoader.load(getTempConfigDirectory().toString());
int port = Integer.parseInt(ConfigurationPropertyKey.PROXY_DEFAULT_PORT.getDefaultValue());
new BootstrapInitializer().init(yamlConfig, port, false);
new BootstrapInitializer().init(yamlConfig, port);
ProxySSLContext.init();
proxy = new ShardingSphereProxy();
proxy.startInternal(port, Collections.singletonList("0.0.0.0"));
Expand Down

0 comments on commit fc47768

Please sign in to comment.