for(String j : instances)
{
try {
Job job = new Job();
Rule rule = new Rule();
JobConfig jobconfig = new JobConfig();
job.setStatisticsRule(rule);
job.setJobConfig(jobconfig);
job.setJobName(j);
getConfigFromProps(j, jobconfig, prop);
if (jobconfig.getReportConfigs() == null
|| (jobconfig.getReportConfigs() != null && jobconfig.getReportConfigs().length == 0)) {
throw new AnalysisException("job Config files should not be null!");
}
buildRule(jobconfig.getReportConfigs(), rule);
//增加一个获得当前临时文件数据源游标的操作
// JobDataOperation jobDataOperation = new JobDataOperation(job,
// AnalysisConstants.JOBMANAGER_EVENT_LOADDATA,this.config);
// jobDataOperation.run();
JobDataOperation.getSourceTimeStamp(job, this.config);
// JobDataOperation.loadDataToTmp(job, this.config);
// JobDataOperation.loadData(job, this.config);
buildTasks(job);
jobs.put(job.getJobName(), job);
this.jobConfigs.put(job.getJobName(),
new JobResource(job.getJobName(), jobconfig.getReportConfigs()));
if (job.getJobConfig().getSaveTmpResultToFile() == null && this.config != null)
job.getJobConfig().setSaveTmpResultToFile(
String.valueOf(this.config.getSaveTmpResultToFile()));
if (job.getJobConfig().getAsynLoadDiskFilePrecent() < 0 && this.config != null)
job.getJobConfig().setAsynLoadDiskFilePrecent(
String.valueOf(this.config.getAsynLoadDiskFilePrecent()));
}
catch (Throwable e) {
logger.error("build job error : " + j, e);
}
}
//编译好rule后针对当前是否有mastergroup来做多master的report分配
if (this.config != null && StringUtils.isNotEmpty(this.config.getMasterGroup()))
{
String[] ms = StringUtils.split(this.config.getMasterGroup(),",");
List<String> masters = new ArrayList<String>();
List<String> reports = new ArrayList<String>();
for(String m : ms)
masters.add(m);
for(Job j : jobs.values())
{
Rule rule = j.getStatisticsRule();
reports.clear();
for(Report r : rule.getReportPool().values())
{
reports.add(new StringBuilder().append(r.getId())
.append("|").append(r.getWeight()).toString());
}
//做一下改进,如果原来已经有分配的,为了保证数据一致性,则不再分配(保证中间结果的连贯性)
//考虑原来就是比较平均分配的,然后将新来业务平均分配也是一样的
// Map<String, String> report2Master = ReportUtil.SimpleAllocationAlgorithm(masters, reports, "|");
Map<String, String> report2Master = new HashMap<String, String>();
//此处将report2Master传入方法中进行修改,并非好的代码处理方式
// AnalyzerUtil.loadReportToMaster(masters, reports, report2Master, j);
if(this.config.getReportToMaster() != null && this.config.getReportToMaster().size() > 0) {
report2Master.putAll(this.config.getReportToMaster());
}
for(Report r : rule.getReportPool().values()) {
if(!report2Master.containsKey(r.getId()) && this.config.getDispatchMaster()) {
report2Master.put(r.getId(), ReportUtil.getIp() + ":" + this.config.getMasterPort());
}
}
for(Entry<String,String> rm : report2Master.entrySet())
// if (rule.getReport2Master().get(rm.getKey()) == null)
rule.getReport2Master().put(rm.getKey(), rm.getValue());
if (logger.isWarnEnabled() && rule.getReport2Master() != null)
{
StringBuilder report2MasterStr = new StringBuilder("report2Master Info : ");
for(Entry<String,String> r : rule.getReport2Master().entrySet())
{
report2MasterStr.append("report: ")
.append(r.getKey()).append(" -> master: ").append(r.getValue()).append(" , ");
}