public void buildTasks(Job job) throws AnalysisException {
if (job.getJobTasks() != null)
job.getJobTasks().clear();
JobConfig jobConfig = job.getJobConfig();
if (jobConfig == null)
throw new AnalysisException("generateJobTasks error, jobConfig is null.");
//允许定义多个job通过逗号分割
if (jobConfig.getInputParams() == null && jobConfig.getInput().indexOf(",") <= 0)
{
JobTask jobTask = new JobTask(jobConfig);
jobTask.setStatisticsRule(job.getStatisticsRule());
jobTask.setJobName(job.getJobName());
jobTask.setUrl(jobTask.getInput());
jobTask.setJobSourceTimeStamp(job.getJobSourceTimeStamp());
jobTask.setInput(generateJobInputAddition(jobTask.getInput(),job));
jobTask.setTaskId(getTaskIdFromUrl(job.getJobName(), jobTask.getUrl(), job.getTaskCount()));
/**
* 目前使用master游标管理方式的只有hub
*/
Long begin = jobConfig.getBegin();
if(begin == null)
begin = 0L;
if(jobTask.getUrl().startsWith("hub://")) {
String key = jobTask.getUrl().substring(0, jobTask.getUrl().indexOf('?'));
job.getCursorMap().putIfAbsent(key, begin);
job.getTimestampMap().putIfAbsent(key, -1L);
jobTask.setJobSourceTimeStamp(job.getTimestampMap().get(key));
}
job.addTaskCount();
jobTask.getTailCursor().set(jobConfig.getInit());
job.getJobTasks().add(jobTask);
}
else
{
if (jobConfig.getInputParams() != null)
{
String[] p = StringUtils.split(jobConfig.getInputParams(),":");
String key = new StringBuilder("$").append(p[0]).append("$").toString();
if (p.length != 2 || jobConfig.getInput().indexOf(key) < 0)
throw new AnalysisException("inputParams invalidate : " + jobConfig.getInputParams());
String[] params = StringUtils.split(p[1],",");
for(String ps : params)
{
JobTask jobTask = new JobTask(jobConfig);
jobTask.setStatisticsRule(job.getStatisticsRule());
jobTask.setJobName(job.getJobName());
jobTask.setUrl(jobConfig.getInput().replace(key, ps));
jobTask.setJobSourceTimeStamp(job.getJobSourceTimeStamp());
jobTask.setInput(generateJobInputAddition(jobConfig.getInput().replace(key, ps),job));
jobTask.setTaskId(getTaskIdFromUrl(job.getJobName(), jobTask.getUrl(), job.getTaskCount()));
/**
* 目前使用master游标管理方式的只有hub
*/
Long begin = jobConfig.getBegin();
if(begin == null)
begin = 0L;
if(jobTask.getUrl().startsWith("hub://")) {
String keyU = jobTask.getUrl().substring(0, jobTask.getUrl().indexOf('?'));
job.getCursorMap().putIfAbsent(keyU, begin);
job.getTimestampMap().putIfAbsent(keyU, -1L);
jobTask.setJobSourceTimeStamp(job.getTimestampMap().get(keyU));
}
jobTask.getTailCursor().set(jobConfig.getInit());
job.addTaskCount();
job.getJobTasks().add(jobTask);
}
}
else
{
String[] inputs = StringUtils.split(jobConfig.getInput(),",");
for(String input : inputs)
{
JobTask jobTask = new JobTask(jobConfig);
jobTask.setStatisticsRule(job.getStatisticsRule());
jobTask.setJobName(job.getJobName());
jobTask.setInput(generateJobInputAddition(input,job));
jobTask.setUrl(input);
jobTask.setTaskId(getTaskIdFromUrl(job.getJobName(), jobTask.getUrl(), job.getTaskCount()));
/**
* 目前使用master游标管理方式的只有hub
*/
Long begin = jobConfig.getBegin();
if(begin == null)
begin = 0L;
if(jobTask.getUrl().startsWith("hub://")) {
String key = jobTask.getUrl().substring(0, jobTask.getUrl().indexOf('?'));
job.getCursorMap().putIfAbsent(key, begin);
job.getTimestampMap().putIfAbsent(key, -1L);
jobTask.setJobSourceTimeStamp(job.getTimestampMap().get(key));
}
jobTask.getTailCursor().set(jobConfig.getInit());
job.addTaskCount();
job.getJobTasks().add(jobTask);
}
}