Skip to content

Commit

Permalink
Simplify variable name from configuration to config
Browse files Browse the repository at this point in the history
Simplify variable name from  configuration to config
  • Loading branch information
taojintianxia authored Oct 25, 2023
2 parents f9825c7 + aa4bd31 commit ed420cf
Show file tree
Hide file tree
Showing 27 changed files with 160 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class WechatJobErrorHandlerTest {
@SuppressWarnings({"unchecked", "rawtypes"})
@BeforeAll
static void init() {
NettyRestfulServiceConfiguration configuration = new NettyRestfulServiceConfiguration(PORT);
configuration.setHost(HOST);
configuration.addControllerInstances(new WechatInternalController());
restfulService = new NettyRestfulService(configuration);
NettyRestfulServiceConfiguration config = new NettyRestfulServiceConfiguration(PORT);
config.setHost(HOST);
config.addControllerInstances(new WechatInternalController());
restfulService = new NettyRestfulService(config);
restfulService.startup();
ch.qos.logback.classic.Logger log = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(WechatJobErrorHandler.class);
ListAppender<LoggingEvent> appender = (ListAppender) log.getAppender("WechatJobErrorHandlerTestAppender");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public ExecutorContext(final JobConfiguration jobConfig) {
/**
* Reload all reloadable item if necessary.
*
* @param jobConfiguration job configuration
* @param jobConfig job configuration
*/
public void reloadIfNecessary(final JobConfiguration jobConfiguration) {
ShardingSphereServiceLoader.getServiceInstances(Reloadable.class).forEach(each -> each.reloadIfNecessary(jobConfiguration));
public void reloadIfNecessary(final JobConfiguration jobConfig) {
ShardingSphereServiceLoader.getServiceInstances(Reloadable.class).forEach(each -> each.reloadIfNecessary(jobConfig));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class HttpJobExecutorTest {

@BeforeAll
static void init() {
NettyRestfulServiceConfiguration configuration = new NettyRestfulServiceConfiguration(PORT);
configuration.setHost(HOST);
configuration.addControllerInstances(new InternalController());
restfulService = new NettyRestfulService(configuration);
NettyRestfulServiceConfiguration config = new NettyRestfulServiceConfiguration(PORT);
config.setHost(HOST);
config.addControllerInstances(new InternalController());
restfulService = new NettyRestfulService(config);
restfulService.startup();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
*
* @param <T> type of tracing storage
*/
@Getter
@RequiredArgsConstructor
@Getter
public final class TracingConfiguration<T> implements JobExtraConfiguration {

private final String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
*
* @param <T> type of storage
*/
@NoArgsConstructor
@Getter
@Setter
@NoArgsConstructor
public final class YamlTracingConfiguration<T> implements YamlConfiguration<TracingConfiguration<T>> {

private static final long serialVersionUID = -6625535892000287729L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class YamlTracingConfigurationConverterTest {
void assertConvertTracingConfiguration() {
JobEventCaller expectedStorage = () -> {
};
TracingConfiguration<JobEventCaller> tracingConfiguration = new TracingConfiguration<>("TEST", expectedStorage);
TracingConfiguration<JobEventCaller> tracingConfig = new TracingConfiguration<>("TEST", expectedStorage);
YamlTracingConfigurationConverter<JobEventCaller> converter = new YamlTracingConfigurationConverter<>();
YamlTracingConfiguration<JobEventCaller> actual = converter.convertToYamlConfiguration(tracingConfiguration);
YamlTracingConfiguration<JobEventCaller> actual = converter.convertToYamlConfiguration(tracingConfig);
assertThat(actual.getType(), is("TEST"));
assertNotNull(actual.getTracingStorageConfiguration());
assertTrue(actual.getTracingStorageConfiguration() instanceof YamlJobEventCallerConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ public static DataSourceRegistry getInstance() {
return instance;
}

void registerDataSource(final DataSourceConfiguration configuration, final DataSource dataSource) {
dataSources.putIfAbsent(configuration, dataSource);
void registerDataSource(final DataSourceConfiguration dataSourceConfig, final DataSource dataSource) {
dataSources.putIfAbsent(dataSourceConfig, dataSource);
}

/**
* Get {@link DataSource} by {@link TracingStorageConfiguration}.
* Get {@link DataSource} by {@link DataSourceConfiguration}.
*
* @param configuration {@link TracingStorageConfiguration}
* @param dataSourceConfig data source configuration
* @return instance of {@link DataSource}
*/
public DataSource getDataSource(final DataSourceConfiguration configuration) {
return dataSources.computeIfAbsent(configuration, DataSourceConfiguration::createDataSource);
public DataSource getDataSource(final DataSourceConfiguration dataSourceConfig) {
return dataSources.computeIfAbsent(dataSourceConfig, DataSourceConfiguration::createDataSource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.Map;

/**
* YAML DataSourceConfiguration.
* YAML Data source configuration.
*/
@Setter
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public final class YamlDataSourceConfigurationConverter implements YamlConfigura

@Override
public YamlTracingStorageConfiguration<DataSource> convertToYamlConfiguration(final TracingStorageConfiguration<DataSource> data) {
DataSourceConfiguration dataSourceConfiguration = (DataSourceConfiguration) data;
DataSourceConfiguration dataSourceConfig = (DataSourceConfiguration) data;
YamlDataSourceConfiguration result = new YamlDataSourceConfiguration();
result.setDataSourceClassName(dataSourceConfiguration.getDataSourceClassName());
result.setProps(dataSourceConfiguration.getProps());
result.setDataSourceClassName(dataSourceConfig.getDataSourceClassName());
result.setProps(dataSourceConfig.getProps());
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,26 @@
class DataSourceRegistryTest {

@Mock
private DataSourceConfiguration dataSourceConfiguration;
private DataSourceConfiguration dataSourceConfig;

@Test
void assertGetDataSourceBySameConfiguration() {
when(dataSourceConfiguration.createDataSource()).then(invocation -> mock(DataSource.class));
DataSource expected = DataSourceRegistry.getInstance().getDataSource(dataSourceConfiguration);
DataSource actual = DataSourceRegistry.getInstance().getDataSource(dataSourceConfiguration);
verify(dataSourceConfiguration).createDataSource();
when(dataSourceConfig.createDataSource()).then(invocation -> mock(DataSource.class));
DataSource expected = DataSourceRegistry.getInstance().getDataSource(dataSourceConfig);
DataSource actual = DataSourceRegistry.getInstance().getDataSource(dataSourceConfig);
verify(dataSourceConfig).createDataSource();
assertThat(actual, is(expected));
}

@Test
void assertGetDataSourceWithDifferentConfiguration() {
when(dataSourceConfiguration.createDataSource()).then(invocation -> mock(DataSource.class));
DataSourceConfiguration anotherDataSourceConfiguration = mock(DataSourceConfiguration.class);
when(anotherDataSourceConfiguration.createDataSource()).then(invocation -> mock(DataSource.class));
DataSource one = DataSourceRegistry.getInstance().getDataSource(dataSourceConfiguration);
DataSource another = DataSourceRegistry.getInstance().getDataSource(anotherDataSourceConfiguration);
verify(dataSourceConfiguration).createDataSource();
verify(anotherDataSourceConfiguration).createDataSource();
when(dataSourceConfig.createDataSource()).then(invocation -> mock(DataSource.class));
DataSourceConfiguration anotherDataSourceConfig = mock(DataSourceConfiguration.class);
when(anotherDataSourceConfig.createDataSource()).then(invocation -> mock(DataSource.class));
DataSource one = DataSourceRegistry.getInstance().getDataSource(dataSourceConfig);
DataSource another = DataSourceRegistry.getInstance().getDataSource(anotherDataSourceConfig);
verify(dataSourceConfig).createDataSource();
verify(anotherDataSourceConfig).createDataSource();
assertThat(another, not(one));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.shardingsphere.elasticjob.tracing.rdb.datasource;

import com.zaxxer.hikari.HikariDataSource;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingStorageConfiguration;
import org.apache.shardingsphere.elasticjob.tracing.exception.TracingStorageUnavailableException;
import org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConverter;
import org.apache.shardingsphere.elasticjob.tracing.storage.TracingStorageConverterFactory;
Expand Down Expand Up @@ -57,8 +56,7 @@ void assertConvert() throws SQLException {
when(connection.getMetaData()).thenReturn(databaseMetaData);
when(databaseMetaData.getURL()).thenReturn("jdbc:url");
DataSourceTracingStorageConverter converter = new DataSourceTracingStorageConverter();
TracingStorageConfiguration<DataSource> configuration = converter.convertObjectToConfiguration(dataSource);
assertNotNull(configuration);
assertNotNull(converter.convertObjectToConfiguration(dataSource));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class YamlDataSourceConfigurationConverterTest {

@Test
void assertConvertDataSourceConfiguration() {
DataSourceConfiguration dataSourceConfiguration = new DataSourceConfiguration("org.h2.Driver");
dataSourceConfiguration.getProps().put("foo", "bar");
DataSourceConfiguration dataSourceConfig = new DataSourceConfiguration("org.h2.Driver");
dataSourceConfig.getProps().put("foo", "bar");
YamlDataSourceConfigurationConverter converter = new YamlDataSourceConfigurationConverter();
YamlTracingStorageConfiguration<DataSource> actual = converter.convertToYamlConfiguration(dataSourceConfiguration);
YamlTracingStorageConfiguration<DataSource> actual = converter.convertToYamlConfiguration(dataSourceConfig);
assertTrue(actual instanceof YamlDataSourceConfiguration);
YamlDataSourceConfiguration result = (YamlDataSourceConfiguration) actual;
assertThat(result.getDataSourceClassName(), is("org.h2.Driver"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,35 +104,35 @@ public JobConfiguration toJobConfiguration() {
/**
* Convert from job configuration.
*
* @param jobConfiguration job configuration
* @param jobConfig job configuration
* @return job configuration POJO
*/
@SuppressWarnings("unchecked")
public static JobConfigurationPOJO fromJobConfiguration(final JobConfiguration jobConfiguration) {
public static JobConfigurationPOJO fromJobConfiguration(final JobConfiguration jobConfig) {
JobConfigurationPOJO result = new JobConfigurationPOJO();
result.setJobName(jobConfiguration.getJobName());
result.setCron(jobConfiguration.getCron());
result.setTimeZone(jobConfiguration.getTimeZone());
result.setShardingTotalCount(jobConfiguration.getShardingTotalCount());
result.setShardingItemParameters(jobConfiguration.getShardingItemParameters());
result.setJobParameter(jobConfiguration.getJobParameter());
result.setMonitorExecution(jobConfiguration.isMonitorExecution());
result.setFailover(jobConfiguration.isFailover());
result.setMisfire(jobConfiguration.isMisfire());
result.setMaxTimeDiffSeconds(jobConfiguration.getMaxTimeDiffSeconds());
result.setReconcileIntervalMinutes(jobConfiguration.getReconcileIntervalMinutes());
result.setJobShardingStrategyType(jobConfiguration.getJobShardingStrategyType());
result.setJobExecutorServiceHandlerType(jobConfiguration.getJobExecutorServiceHandlerType());
result.setJobErrorHandlerType(jobConfiguration.getJobErrorHandlerType());
result.setJobListenerTypes(jobConfiguration.getJobListenerTypes());
jobConfiguration.getExtraConfigurations().stream()
result.setJobName(jobConfig.getJobName());
result.setCron(jobConfig.getCron());
result.setTimeZone(jobConfig.getTimeZone());
result.setShardingTotalCount(jobConfig.getShardingTotalCount());
result.setShardingItemParameters(jobConfig.getShardingItemParameters());
result.setJobParameter(jobConfig.getJobParameter());
result.setMonitorExecution(jobConfig.isMonitorExecution());
result.setFailover(jobConfig.isFailover());
result.setMisfire(jobConfig.isMisfire());
result.setMaxTimeDiffSeconds(jobConfig.getMaxTimeDiffSeconds());
result.setReconcileIntervalMinutes(jobConfig.getReconcileIntervalMinutes());
result.setJobShardingStrategyType(jobConfig.getJobShardingStrategyType());
result.setJobExecutorServiceHandlerType(jobConfig.getJobExecutorServiceHandlerType());
result.setJobErrorHandlerType(jobConfig.getJobErrorHandlerType());
result.setJobListenerTypes(jobConfig.getJobListenerTypes());
jobConfig.getExtraConfigurations().stream()
.map(each -> TypedSPILoader.getService(YamlConfigurationConverter.class, each.getClass()).convertToYamlConfiguration(each)).forEach(result.getJobExtraConfigurations()::add);
result.setDescription(jobConfiguration.getDescription());
result.setProps(jobConfiguration.getProps());
result.setDisabled(jobConfiguration.isDisabled());
result.setOverwrite(jobConfiguration.isOverwrite());
result.setLabel(jobConfiguration.getLabel());
result.setStaticSharding(jobConfiguration.isStaticSharding());
result.setDescription(jobConfig.getDescription());
result.setProps(jobConfig.getProps());
result.setDisabled(jobConfig.isDisabled());
result.setOverwrite(jobConfig.isOverwrite());
result.setLabel(jobConfig.getLabel());
result.setStaticSharding(jobConfig.isStaticSharding());
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ void assertToJobConfiguration() {

@Test
void assertFromJobConfiguration() {
JobConfiguration jobConfiguration = JobConfiguration.newBuilder("test_job", 3)
JobConfiguration jobConfig = JobConfiguration.newBuilder("test_job", 3)
.cron("0/1 * * * * ?")
.shardingItemParameters("0=A,1=B,2=C").jobParameter("param")
.monitorExecution(true).failover(true).misfire(true)
.jobShardingStrategyType("AVG_ALLOCATION").jobExecutorServiceHandlerType("CPU").jobErrorHandlerType("IGNORE")
.jobListenerTypes("LOG").description("Job description").setProperty("key", "value")
.disabled(true).overwrite(true).build();
JobConfigurationPOJO actual = JobConfigurationPOJO.fromJobConfiguration(jobConfiguration);
JobConfigurationPOJO actual = JobConfigurationPOJO.fromJobConfiguration(jobConfig);
assertThat(actual.getJobName(), is("test_job"));
assertThat(actual.getCron(), is("0/1 * * * * ?"));
assertThat(actual.getShardingTotalCount(), is(3));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import java.util.Optional;
import org.apache.shardingsphere.elasticjob.annotation.ElasticJobConfiguration;
import org.apache.shardingsphere.elasticjob.annotation.ElasticJobProp;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.api.JobExtraConfiguration;
import org.apache.shardingsphere.elasticjob.api.JobExtraConfigurationFactory;
import org.apache.shardingsphere.elasticjob.infra.exception.JobConfigurationException;

import java.util.Optional;

/**
* Job Builder from @ElasticJobConfiguration.
*/
public final class JobAnnotationBuilder {

/**
* generate JobConfiguration from @ElasticJobConfiguration.
* Generate job configuration from @ElasticJobConfiguration.
*
* @param type The job of @ElasticJobConfiguration annotation class
* @return JobConfiguration
* @return job configuration
*/
public static JobConfiguration generateJobConfiguration(final Class<?> type) {
ElasticJobConfiguration annotation = type.getAnnotation(ElasticJobConfiguration.class);
Expand All @@ -60,8 +62,8 @@ public static JobConfiguration generateJobConfiguration(final Class<?> type) {
.overwrite(annotation.overwrite());
for (Class<? extends JobExtraConfigurationFactory> clazz : annotation.extraConfigurations()) {
try {
Optional<JobExtraConfiguration> jobExtraConfiguration = clazz.newInstance().getJobExtraConfiguration();
jobExtraConfiguration.ifPresent(jobConfigurationBuilder::addExtraConfigurations);
Optional<JobExtraConfiguration> jobExtraConfig = clazz.newInstance().getJobExtraConfiguration();
jobExtraConfig.ifPresent(jobConfigurationBuilder::addExtraConfigurations);
} catch (IllegalAccessException | InstantiationException exception) {
throw (JobConfigurationException) new JobConfigurationException("new JobExtraConfigurationFactory instance by class '%s' failure", clazz).initCause(exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class CronSettingAndJobEventChangedJobListener implements DataChangedEventListen
@Override
public void onChange(final DataChangedEvent event) {
if (configNode.isConfigPath(event.getKey()) && Type.UPDATED == event.getType() && !JobRegistry.getInstance().isShutdown(jobName)) {
JobConfiguration jobConfiguration = YamlEngine.unmarshal(event.getValue(), JobConfigurationPOJO.class).toJobConfiguration();
if (StringUtils.isEmpty(jobConfiguration.getCron())) {
JobConfiguration jobConfig = YamlEngine.unmarshal(event.getValue(), JobConfigurationPOJO.class).toJobConfiguration();
if (StringUtils.isEmpty(jobConfig.getCron())) {
JobRegistry.getInstance().getJobScheduleController(jobName).rescheduleJob();
} else {
JobRegistry.getInstance().getJobScheduleController(jobName).rescheduleJob(jobConfiguration.getCron(), jobConfiguration.getTimeZone());
JobRegistry.getInstance().getJobScheduleController(jobName).rescheduleJob(jobConfig.getCron(), jobConfig.getTimeZone());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public ExecutionService(final CoordinatorRegistryCenter regCenter, final String
*/
public void registerJobBegin(final ShardingContexts shardingContexts) {
JobRegistry.getInstance().setJobRunning(jobName, true);
JobConfiguration jobConfiguration = configService.load(true);
if (!jobConfiguration.isMonitorExecution()) {
JobConfiguration jobConfig = configService.load(true);
if (!jobConfig.isMonitorExecution()) {
return;
}
String jobInstanceId = JobRegistry.getInstance().getJobInstance(jobName).getJobInstanceId();
for (int each : shardingContexts.getShardingItemParameters().keySet()) {
if (jobConfiguration.isFailover()) {
if (jobConfig.isFailover()) {
jobNodeStorage.fillJobNode(ShardingNode.getRunningNode(each), jobInstanceId);
} else {
jobNodeStorage.fillEphemeralJobNode(ShardingNode.getRunningNode(each), jobInstanceId);
Expand Down
Loading

0 comments on commit ed420cf

Please sign in to comment.