use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration in project elastic-job by dangdangdotcom.
the class ExecutionContextService method getJobShardingContext.
/**
* 获取当前作业服务器分片上下文.
*
* @param shardingItems 分片项
* @return 分片上下文
*/
public ShardingContexts getJobShardingContext(final List<Integer> shardingItems) {
LiteJobConfiguration liteJobConfig = configService.load(false);
removeRunningIfMonitorExecution(liteJobConfig.isMonitorExecution(), shardingItems);
if (shardingItems.isEmpty()) {
return new ShardingContexts(buildTaskId(liteJobConfig, shardingItems), liteJobConfig.getJobName(), liteJobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount(), liteJobConfig.getTypeConfig().getCoreConfig().getJobParameter(), Collections.<Integer, String>emptyMap());
}
Map<Integer, String> shardingItemParameterMap = new ShardingItemParameters(liteJobConfig.getTypeConfig().getCoreConfig().getShardingItemParameters()).getMap();
return new ShardingContexts(buildTaskId(liteJobConfig, shardingItems), liteJobConfig.getJobName(), liteJobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount(), liteJobConfig.getTypeConfig().getCoreConfig().getJobParameter(), getAssignedShardingItemParameterMap(shardingItems, shardingItemParameterMap));
}
use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration in project elastic-job by dangdangdotcom.
the class LiteJobFacadeTest method assertLoad.
@Test
public void assertLoad() {
LiteJobConfiguration expected = LiteJobConfiguration.newBuilder(null).build();
when(configService.load(true)).thenReturn(expected);
assertThat(liteJobFacade.loadJobRootConfiguration(true), is(expected));
}
use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration in project elastic-job by dangdangdotcom.
the class LiteJobConfigurationGsonFactoryTest method assertToJsonForScriptJob.
@Test
public void assertToJsonForScriptJob() {
LiteJobConfiguration actual = LiteJobConfiguration.newBuilder(new ScriptJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), "test.sh")).build();
assertThat(LiteJobConfigurationGsonFactory.toJson(actual), is(scriptJobJson));
}
use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration in project elastic-job by dangdangdotcom.
the class LiteJobConfigurationGsonFactoryTest method assertFromJsonForSimpleJob.
@Test
public void assertFromJsonForSimpleJob() {
LiteJobConfiguration actual = LiteJobConfigurationGsonFactory.fromJson(simpleJobJson);
assertThat(actual.getJobName(), is("test_job"));
assertThat(actual.getTypeConfig().getJobClass(), is(TestSimpleJob.class.getCanonicalName()));
assertThat(actual.getTypeConfig().getJobType(), is(JobType.SIMPLE));
assertThat(actual.getTypeConfig().getCoreConfig().getCron(), is("0/1 * * * * ?"));
assertThat(actual.getTypeConfig().getCoreConfig().getShardingTotalCount(), is(3));
assertThat(actual.getTypeConfig().getCoreConfig().getShardingItemParameters(), is(""));
assertThat(actual.getTypeConfig().getCoreConfig().getJobParameter(), is(""));
assertTrue(actual.getTypeConfig().getCoreConfig().isFailover());
assertFalse(actual.getTypeConfig().getCoreConfig().isMisfire());
assertThat(actual.getTypeConfig().getCoreConfig().getDescription(), is(""));
assertThat(actual.getTypeConfig().getCoreConfig().getJobProperties().get(JobProperties.JobPropertiesEnum.JOB_EXCEPTION_HANDLER), is(DefaultJobExceptionHandler.class.getCanonicalName()));
assertThat(actual.getTypeConfig().getCoreConfig().getJobProperties().get(JobProperties.JobPropertiesEnum.EXECUTOR_SERVICE_HANDLER), is(DefaultExecutorServiceHandler.class.getCanonicalName()));
assertFalse(actual.isMonitorExecution());
assertThat(actual.getMaxTimeDiffSeconds(), is(1000));
assertThat(actual.getMonitorPort(), is(8888));
assertThat(actual.getJobShardingStrategyClass(), is("testClass"));
assertThat(actual.getReconcileIntervalMinutes(), is(15));
assertTrue(actual.isDisabled());
assertTrue(actual.isOverwrite());
}
use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration in project elastic-job by dangdangdotcom.
the class LiteJobConfigurationGsonFactoryTest method assertFromJsonForScriptJob.
@Test
public void assertFromJsonForScriptJob() {
LiteJobConfiguration actual = LiteJobConfigurationGsonFactory.fromJson(scriptJobJson);
assertThat(actual.getJobName(), is("test_job"));
assertThat(actual.getTypeConfig().getJobClass(), is(ScriptJob.class.getCanonicalName()));
assertThat(actual.getTypeConfig().getJobType(), is(JobType.SCRIPT));
assertThat(actual.getTypeConfig().getCoreConfig().getCron(), is("0/1 * * * * ?"));
assertThat(actual.getTypeConfig().getCoreConfig().getShardingTotalCount(), is(3));
assertThat(actual.getTypeConfig().getCoreConfig().getShardingItemParameters(), is(""));
assertThat(actual.getTypeConfig().getCoreConfig().getJobParameter(), is(""));
assertFalse(actual.getTypeConfig().getCoreConfig().isFailover());
assertTrue(actual.getTypeConfig().getCoreConfig().isMisfire());
assertThat(actual.getTypeConfig().getCoreConfig().getDescription(), is(""));
assertThat(actual.getTypeConfig().getCoreConfig().getJobProperties().get(JobProperties.JobPropertiesEnum.JOB_EXCEPTION_HANDLER), is(DefaultJobExceptionHandler.class.getCanonicalName()));
assertThat(actual.getTypeConfig().getCoreConfig().getJobProperties().get(JobProperties.JobPropertiesEnum.EXECUTOR_SERVICE_HANDLER), is(DefaultExecutorServiceHandler.class.getCanonicalName()));
assertTrue(actual.isMonitorExecution());
assertThat(actual.getMaxTimeDiffSeconds(), is(-1));
assertThat(actual.getMonitorPort(), is(-1));
assertThat(actual.getJobShardingStrategyClass(), is(""));
assertFalse(actual.isDisabled());
assertFalse(actual.isOverwrite());
assertThat(actual.getReconcileIntervalMinutes(), is(-1));
assertThat(((ScriptJobConfiguration) actual.getTypeConfig()).getScriptCommandLine(), is("test.sh"));
}
Aggregations