Search in sources :

Example 1 with JobCoreConfiguration

use of com.dangdang.ddframe.job.config.JobCoreConfiguration 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 2 with JobCoreConfiguration

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

the class JavaMain method setUpDataflowJob.

private static void setUpDataflowJob(final CoordinatorRegistryCenter regCenter, final JobEventConfiguration jobEventConfig) {
    JobCoreConfiguration coreConfig = JobCoreConfiguration.newBuilder("javaDataflowElasticJob", "0/5 * * * * ?", 3).shardingItemParameters("0=Beijing,1=Shanghai,2=Guangzhou").build();
    DataflowJobConfiguration dataflowJobConfig = new DataflowJobConfiguration(coreConfig, JavaDataflowJob.class.getCanonicalName(), true);
    new JobScheduler(regCenter, LiteJobConfiguration.newBuilder(dataflowJobConfig).build(), jobEventConfig).init();
}
Also used : JobScheduler(com.dangdang.ddframe.job.lite.api.JobScheduler) JobCoreConfiguration(com.dangdang.ddframe.job.config.JobCoreConfiguration) DataflowJobConfiguration(com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration) JavaDataflowJob(com.dangdang.ddframe.job.example.job.dataflow.JavaDataflowJob)

Example 3 with JobCoreConfiguration

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

the class JavaMain method setUpSimpleJob.

private static void setUpSimpleJob(final CoordinatorRegistryCenter regCenter, final JobEventConfiguration jobEventConfig) {
    JobCoreConfiguration coreConfig = JobCoreConfiguration.newBuilder("javaSimpleJob", "0/5 * * * * ?", 3).shardingItemParameters("0=Beijing,1=Shanghai,2=Guangzhou").build();
    SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(coreConfig, JavaSimpleJob.class.getCanonicalName());
    new JobScheduler(regCenter, LiteJobConfiguration.newBuilder(simpleJobConfig).build(), jobEventConfig, new JavaSimpleListener(), new JavaSimpleDistributeListener(1000L, 2000L)).init();
}
Also used : JobScheduler(com.dangdang.ddframe.job.lite.api.JobScheduler) JobCoreConfiguration(com.dangdang.ddframe.job.config.JobCoreConfiguration) SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) JavaSimpleJob(com.dangdang.ddframe.job.example.job.simple.JavaSimpleJob) JavaSimpleListener(com.dangdang.ddframe.job.example.listener.JavaSimpleListener) JavaSimpleDistributeListener(com.dangdang.ddframe.job.example.listener.JavaSimpleDistributeListener)

Example 4 with JobCoreConfiguration

use of com.dangdang.ddframe.job.config.JobCoreConfiguration 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)

Example 5 with JobCoreConfiguration

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

the class AbstractJobConfigurationGsonTypeAdapter method read.

@Override
public T read(final JsonReader in) throws IOException {
    String jobName = "";
    String cron = "";
    int shardingTotalCount = 0;
    String shardingItemParameters = "";
    String jobParameter = "";
    boolean failover = false;
    boolean misfire = failover;
    String description = "";
    JobProperties jobProperties = new JobProperties();
    JobType jobType = null;
    String jobClass = "";
    boolean streamingProcess = false;
    String scriptCommandLine = "";
    Map<String, Object> customizedValueMap = new HashMap<>(32, 1);
    in.beginObject();
    while (in.hasNext()) {
        String jsonName = in.nextName();
        switch(jsonName) {
            case "jobName":
                jobName = in.nextString();
                break;
            case "cron":
                cron = in.nextString();
                break;
            case "shardingTotalCount":
                shardingTotalCount = in.nextInt();
                break;
            case "shardingItemParameters":
                shardingItemParameters = in.nextString();
                break;
            case "jobParameter":
                jobParameter = in.nextString();
                break;
            case "failover":
                failover = in.nextBoolean();
                break;
            case "misfire":
                misfire = in.nextBoolean();
                break;
            case "description":
                description = in.nextString();
                break;
            case "jobProperties":
                jobProperties = getJobProperties(in);
                break;
            case "jobType":
                jobType = JobType.valueOf(in.nextString());
                break;
            case "jobClass":
                jobClass = in.nextString();
                break;
            case "streamingProcess":
                streamingProcess = in.nextBoolean();
                break;
            case "scriptCommandLine":
                scriptCommandLine = in.nextString();
                break;
            default:
                addToCustomizedValueMap(jsonName, in, customizedValueMap);
                break;
        }
    }
    in.endObject();
    JobCoreConfiguration coreConfig = getJobCoreConfiguration(jobName, cron, shardingTotalCount, shardingItemParameters, jobParameter, failover, misfire, description, jobProperties);
    JobTypeConfiguration typeConfig = getJobTypeConfiguration(coreConfig, jobType, jobClass, streamingProcess, scriptCommandLine);
    return getJobRootConfiguration(typeConfig, customizedValueMap);
}
Also used : JobProperties(com.dangdang.ddframe.job.executor.handler.JobProperties) JobType(com.dangdang.ddframe.job.api.JobType) HashMap(java.util.HashMap) JobCoreConfiguration(com.dangdang.ddframe.job.config.JobCoreConfiguration) JobTypeConfiguration(com.dangdang.ddframe.job.config.JobTypeConfiguration)

Aggregations

JobCoreConfiguration (com.dangdang.ddframe.job.config.JobCoreConfiguration)5 JobScheduler (com.dangdang.ddframe.job.lite.api.JobScheduler)3 JobTypeConfiguration (com.dangdang.ddframe.job.config.JobTypeConfiguration)2 DataflowJobConfiguration (com.dangdang.ddframe.job.config.dataflow.DataflowJobConfiguration)2 ScriptJobConfiguration (com.dangdang.ddframe.job.config.script.ScriptJobConfiguration)2 SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)2 JobType (com.dangdang.ddframe.job.api.JobType)1 ScriptJob (com.dangdang.ddframe.job.api.script.ScriptJob)1 JavaDataflowJob (com.dangdang.ddframe.job.example.job.dataflow.JavaDataflowJob)1 JavaSimpleJob (com.dangdang.ddframe.job.example.job.simple.JavaSimpleJob)1 JavaSimpleDistributeListener (com.dangdang.ddframe.job.example.listener.JavaSimpleDistributeListener)1 JavaSimpleListener (com.dangdang.ddframe.job.example.listener.JavaSimpleListener)1 JobProperties (com.dangdang.ddframe.job.executor.handler.JobProperties)1 HashMap (java.util.HashMap)1