Search in sources :

Example 6 with LiteJobConfiguration

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));
}
Also used : LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) ShardingItemParameters(com.dangdang.ddframe.job.util.config.ShardingItemParameters) ShardingContexts(com.dangdang.ddframe.job.executor.ShardingContexts)

Example 7 with LiteJobConfiguration

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));
}
Also used : LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) Test(org.junit.Test)

Example 8 with LiteJobConfiguration

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));
}
Also used : LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) ScriptJobConfiguration(com.dangdang.ddframe.job.config.script.ScriptJobConfiguration) Test(org.junit.Test)

Example 9 with LiteJobConfiguration

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());
}
Also used : LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) Test(org.junit.Test)

Example 10 with LiteJobConfiguration

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"));
}
Also used : LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) Test(org.junit.Test)

Aggregations

LiteJobConfiguration (com.dangdang.ddframe.job.lite.config.LiteJobConfiguration)20 Test (org.junit.Test)14 ScriptJobConfiguration (com.dangdang.ddframe.job.config.script.ScriptJobConfiguration)2 JobNodePath (com.dangdang.ddframe.job.lite.internal.storage.JobNodePath)2 DataflowJobConfiguration (com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration)1 SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)1 ShardingContexts (com.dangdang.ddframe.job.executor.ShardingContexts)1 JobShardingStrategy (com.dangdang.ddframe.job.lite.api.strategy.JobShardingStrategy)1 JobShardingStrategyOption (com.dangdang.ddframe.job.lite.api.strategy.JobShardingStrategyOption)1 TestDataflowJob (com.dangdang.ddframe.job.lite.fixture.TestDataflowJob)1 AbstractBaseStdJobAutoInitTest (com.dangdang.ddframe.job.lite.integrate.AbstractBaseStdJobAutoInitTest)1 JobBriefInfo (com.dangdang.ddframe.job.lite.lifecycle.domain.JobBriefInfo)1 JobSettings (com.dangdang.ddframe.job.lite.lifecycle.domain.JobSettings)1 ShardingItemParameters (com.dangdang.ddframe.job.util.config.ShardingItemParameters)1