Search in sources :

Example 1 with ScriptJobConfiguration

use of com.dangdang.ddframe.job.config.script.ScriptJobConfiguration in project elastic-job by dangdangdotcom.

the class AbstractJobConfigurationGsonTypeAdapter method write.

@Override
public void write(final JsonWriter out, final T value) throws IOException {
    out.beginObject();
    out.name("jobName").value(value.getTypeConfig().getCoreConfig().getJobName());
    out.name("jobClass").value(value.getTypeConfig().getJobClass());
    out.name("jobType").value(value.getTypeConfig().getJobType().name());
    out.name("cron").value(value.getTypeConfig().getCoreConfig().getCron());
    out.name("shardingTotalCount").value(value.getTypeConfig().getCoreConfig().getShardingTotalCount());
    out.name("shardingItemParameters").value(value.getTypeConfig().getCoreConfig().getShardingItemParameters());
    out.name("jobParameter").value(value.getTypeConfig().getCoreConfig().getJobParameter());
    out.name("failover").value(value.getTypeConfig().getCoreConfig().isFailover());
    out.name("misfire").value(value.getTypeConfig().getCoreConfig().isMisfire());
    out.name("description").value(value.getTypeConfig().getCoreConfig().getDescription());
    out.name("jobProperties").jsonValue(value.getTypeConfig().getCoreConfig().getJobProperties().json());
    if (value.getTypeConfig().getJobType() == JobType.DATAFLOW) {
        DataflowJobConfiguration dataflowJobConfig = (DataflowJobConfiguration) value.getTypeConfig();
        out.name("streamingProcess").value(dataflowJobConfig.isStreamingProcess());
    } else if (value.getTypeConfig().getJobType() == JobType.SCRIPT) {
        ScriptJobConfiguration scriptJobConfig = (ScriptJobConfiguration) value.getTypeConfig();
        out.name("scriptCommandLine").value(scriptJobConfig.getScriptCommandLine());
    }
    writeCustomized(out, value);
    out.endObject();
}
Also used : DataflowJobConfiguration(com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration) ScriptJobConfiguration(com.dangdang.ddframe.job.config.script.ScriptJobConfiguration)

Example 2 with ScriptJobConfiguration

use of com.dangdang.ddframe.job.config.script.ScriptJobConfiguration in project elastic-job by dangdangdotcom.

the class AbstractBaseStdJobTest method initJobConfig.

private LiteJobConfiguration initJobConfig(final Class<? extends ElasticJob> elasticJobClass) {
    String cron = "0/1 * * * * ?";
    int totalShardingCount = 3;
    String shardingParameters = "0=A,1=B,2=C";
    JobCoreConfiguration jobCoreConfig = JobCoreConfiguration.newBuilder(jobName, cron, totalShardingCount).shardingItemParameters(shardingParameters).jobProperties(JobProperties.JobPropertiesEnum.JOB_EXCEPTION_HANDLER.getKey(), IgnoreJobExceptionHandler.class.getCanonicalName()).build();
    JobTypeConfiguration jobTypeConfig;
    if (DataflowJob.class.isAssignableFrom(elasticJobClass)) {
        jobTypeConfig = new DataflowJobConfiguration(jobCoreConfig, elasticJobClass.getCanonicalName(), false);
    } else if (ScriptJob.class.isAssignableFrom(elasticJobClass)) {
        jobTypeConfig = new ScriptJobConfiguration(jobCoreConfig, AbstractBaseStdJobTest.class.getResource("/script/test.sh").getPath());
    } else {
        jobTypeConfig = new SimpleJobConfiguration(jobCoreConfig, elasticJobClass.getCanonicalName());
    }
    return LiteJobConfiguration.newBuilder(jobTypeConfig).monitorPort(monitorPort).disabled(disabled).overwrite(true).build();
}
Also used : ScriptJob(com.dangdang.ddframe.job.api.script.ScriptJob) JobCoreConfiguration(com.dangdang.ddframe.job.config.JobCoreConfiguration) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) DataflowJobConfiguration(com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration) ScriptJobConfiguration(com.dangdang.ddframe.job.config.script.ScriptJobConfiguration) JobTypeConfiguration(com.dangdang.ddframe.job.config.JobTypeConfiguration)

Example 3 with ScriptJobConfiguration

use of com.dangdang.ddframe.job.config.script.ScriptJobConfiguration 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 4 with ScriptJobConfiguration

use of com.dangdang.ddframe.job.config.script.ScriptJobConfiguration in project elastic-job by dangdangdotcom.

the class ScriptElasticJobTest method assertJobInit.

@Test
public void assertJobInit() throws IOException {
    ScriptElasticJobUtil.buildScriptCommandLine();
    WaitingUtils.waitingShortTime();
    String scriptCommandLine = ((ScriptJobConfiguration) getLiteJobConfig().getTypeConfig()).getScriptCommandLine();
    LiteJobConfiguration liteJobConfig = LiteJobConfigurationGsonFactory.fromJson(getRegCenter().get("/" + getJobName() + "/config"));
    assertThat(((ScriptJobConfiguration) liteJobConfig.getTypeConfig()).getScriptCommandLine(), is(scriptCommandLine));
}
Also used : LiteJobConfiguration(com.dangdang.ddframe.job.lite.config.LiteJobConfiguration) ScriptJobConfiguration(com.dangdang.ddframe.job.config.script.ScriptJobConfiguration) AbstractBaseStdJobAutoInitTest(com.dangdang.ddframe.job.lite.integrate.AbstractBaseStdJobAutoInitTest) Test(org.junit.Test)

Example 5 with ScriptJobConfiguration

use of com.dangdang.ddframe.job.config.script.ScriptJobConfiguration in project elastic-job by dangdangdotcom.

the class JavaMain method setUpScriptJob.

private static void setUpScriptJob(final CoordinatorRegistryCenter regCenter, final JobEventConfiguration jobEventConfig) throws IOException {
    JobCoreConfiguration coreConfig = JobCoreConfiguration.newBuilder("scriptElasticJob", "0/5 * * * * ?", 3).build();
    ScriptJobConfiguration scriptJobConfig = new ScriptJobConfiguration(coreConfig, buildScriptCommandLine());
    new JobScheduler(regCenter, LiteJobConfiguration.newBuilder(scriptJobConfig).build(), jobEventConfig).init();
}
Also used : JobScheduler(com.dangdang.ddframe.job.lite.api.JobScheduler) JobCoreConfiguration(com.dangdang.ddframe.job.config.JobCoreConfiguration) ScriptJobConfiguration(com.dangdang.ddframe.job.config.script.ScriptJobConfiguration)

Aggregations

ScriptJobConfiguration (com.dangdang.ddframe.job.config.script.ScriptJobConfiguration)6 DataflowJobConfiguration (com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration)3 JobCoreConfiguration (com.dangdang.ddframe.job.config.JobCoreConfiguration)2 JobTypeConfiguration (com.dangdang.ddframe.job.config.JobTypeConfiguration)2 SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)2 LiteJobConfiguration (com.dangdang.ddframe.job.lite.config.LiteJobConfiguration)2 Test (org.junit.Test)2 ScriptJob (com.dangdang.ddframe.job.api.script.ScriptJob)1 JobScheduler (com.dangdang.ddframe.job.lite.api.JobScheduler)1 AbstractBaseStdJobAutoInitTest (com.dangdang.ddframe.job.lite.integrate.AbstractBaseStdJobAutoInitTest)1