use of com.dangdang.ddframe.job.config.JobTypeConfiguration 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();
}
use of com.dangdang.ddframe.job.config.JobTypeConfiguration in project elastic-job by dangdangdotcom.
the class JobScheduler method init.
/**
* 初始化作业.
*/
public void init() {
jobExecutor.init();
JobTypeConfiguration jobTypeConfig = jobExecutor.getSchedulerFacade().loadJobConfiguration().getTypeConfig();
JobScheduleController jobScheduleController = new JobScheduleController(createScheduler(jobTypeConfig.getCoreConfig().isMisfire()), createJobDetail(jobTypeConfig.getJobClass()), jobExecutor.getSchedulerFacade(), jobName);
jobScheduleController.scheduleJob(jobTypeConfig.getCoreConfig().getCron());
jobRegistry.addJobScheduleController(jobName, jobScheduleController);
}
use of com.dangdang.ddframe.job.config.JobTypeConfiguration 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);
}
use of com.dangdang.ddframe.job.config.JobTypeConfiguration in project elastic-job by dangdangdotcom.
the class AbstractJobConfigurationGsonTypeAdapter method getJobTypeConfiguration.
private JobTypeConfiguration getJobTypeConfiguration(final JobCoreConfiguration coreConfig, final JobType jobType, final String jobClass, final boolean streamingProcess, final String scriptCommandLine) {
JobTypeConfiguration result;
Preconditions.checkNotNull(jobType, "jobType cannot be null.");
switch(jobType) {
case SIMPLE:
Preconditions.checkArgument(!Strings.isNullOrEmpty(jobClass), "jobClass cannot be empty.");
result = new SimpleJobConfiguration(coreConfig, jobClass);
break;
case DATAFLOW:
Preconditions.checkArgument(!Strings.isNullOrEmpty(jobClass), "jobClass cannot be empty.");
result = new DataflowJobConfiguration(coreConfig, jobClass, streamingProcess);
break;
case SCRIPT:
result = new ScriptJobConfiguration(coreConfig, scriptCommandLine);
break;
default:
throw new UnsupportedOperationException(jobType.name());
}
return result;
}
Aggregations