use of org.apache.shardingsphere.elasticjob.api.JobConfiguration in project elastic-job by dangdangdotcom.
the class CloudJobFacade method loadJobConfiguration.
@Override
public JobConfiguration loadJobConfiguration(final boolean fromCache) {
JobConfiguration result = JobConfiguration.newBuilder(jobConfig.getJobName(), jobConfig.getShardingTotalCount()).cron(jobConfig.getCron()).shardingItemParameters(jobConfig.getShardingItemParameters()).jobParameter(jobConfig.getJobParameter()).failover(jobConfig.isFailover()).misfire(jobConfig.isMisfire()).description(jobConfig.getDescription()).jobExecutorServiceHandlerType(jobConfig.getJobExecutorServiceHandlerType()).jobErrorHandlerType(jobConfig.getJobErrorHandlerType()).build();
result.getProps().putAll(jobConfig.getProps());
return result;
}
use of org.apache.shardingsphere.elasticjob.api.JobConfiguration in project elastic-job by dangdangdotcom.
the class ExecutorServiceReloadableTest method assertReload.
@Test
public void assertReload() {
ExecutorServiceReloadable executorServiceReloadable = new ExecutorServiceReloadable();
setField(executorServiceReloadable, "jobExecutorServiceHandlerType", "mock");
setField(executorServiceReloadable, "executorService", mockExecutorService);
JobConfiguration jobConfig = JobConfiguration.newBuilder("job", 1).build();
executorServiceReloadable.reloadIfNecessary(jobConfig);
verify(mockExecutorService).shutdown();
ExecutorService actual = executorServiceReloadable.getInstance();
assertFalse(actual.isShutdown());
assertFalse(actual.isTerminated());
actual.shutdown();
}
use of org.apache.shardingsphere.elasticjob.api.JobConfiguration in project elastic-job by dangdangdotcom.
the class ExecutorServiceReloadableTest method assertInitialize.
@Test
public void assertInitialize() {
ExecutorServiceReloadable executorServiceReloadable = new ExecutorServiceReloadable();
String jobExecutorServiceHandlerType = "SINGLE_THREAD";
JobConfiguration jobConfig = JobConfiguration.newBuilder("job", 1).jobExecutorServiceHandlerType(jobExecutorServiceHandlerType).build();
assertNull(executorServiceReloadable.getInstance());
executorServiceReloadable.init(jobConfig);
ExecutorService actual = executorServiceReloadable.getInstance();
assertNotNull(actual);
assertFalse(actual.isShutdown());
assertFalse(actual.isTerminated());
actual.shutdown();
}
use of org.apache.shardingsphere.elasticjob.api.JobConfiguration in project elastic-job by dangdangdotcom.
the class JobConfigurationPOJOTest method assertFromJobConfiguration.
@Test
public void assertFromJobConfiguration() {
JobConfiguration jobConfiguration = 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);
assertThat(actual.getJobName(), is("test_job"));
assertThat(actual.getCron(), is("0/1 * * * * ?"));
assertThat(actual.getShardingTotalCount(), is(3));
assertThat(actual.getShardingItemParameters(), is("0=A,1=B,2=C"));
assertThat(actual.getJobParameter(), is("param"));
assertTrue(actual.isMonitorExecution());
assertTrue(actual.isFailover());
assertTrue(actual.isMisfire());
assertThat(actual.getJobShardingStrategyType(), is("AVG_ALLOCATION"));
assertThat(actual.getJobExecutorServiceHandlerType(), is("CPU"));
assertThat(actual.getJobErrorHandlerType(), is("IGNORE"));
assertThat(actual.getJobListenerTypes(), hasItem("LOG"));
assertThat(actual.getDescription(), is("Job description"));
assertThat(actual.getProps().getProperty("key"), is("value"));
assertTrue(actual.isDisabled());
assertTrue(actual.isOverwrite());
}
use of org.apache.shardingsphere.elasticjob.api.JobConfiguration in project elastic-job by dangdangdotcom.
the class JobConfigurationPOJO method toJobConfiguration.
/**
* Convert to job configuration.
*
* @return job configuration
*/
public JobConfiguration toJobConfiguration() {
JobConfiguration result = JobConfiguration.newBuilder(jobName, shardingTotalCount).cron(cron).timeZone(timeZone).shardingItemParameters(shardingItemParameters).jobParameter(jobParameter).monitorExecution(monitorExecution).failover(failover).misfire(misfire).maxTimeDiffSeconds(maxTimeDiffSeconds).reconcileIntervalMinutes(reconcileIntervalMinutes).jobShardingStrategyType(jobShardingStrategyType).jobExecutorServiceHandlerType(jobExecutorServiceHandlerType).jobErrorHandlerType(jobErrorHandlerType).jobListenerTypes(jobListenerTypes.toArray(new String[] {})).description(description).disabled(disabled).overwrite(overwrite).label(label).staticSharding(staticSharding).build();
jobExtraConfigurations.stream().map(YamlConfiguration::toConfiguration).forEach(result.getExtraConfigurations()::add);
for (Object each : props.keySet()) {
result.getProps().setProperty(each.toString(), props.get(each.toString()).toString());
}
return result;
}
Aggregations