Package com.taobao.top.analysis.statistics.data

Examples of com.taobao.top.analysis.statistics.data.Rule


       
        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(" , ");
              }
             
View Full Code Here


      if(logger.isInfoEnabled()) {
          logger.info("start to handle task result");
      }
    statisticsEngine.doExport(jobTask,jobTaskResult);
   
    final Rule rule = jobTask.getStatisticsRule();
    Map<String, String> report2Master = rule.getReport2Master();
    if(logger.isInfoEnabled()) {
        for(String key : report2Master.keySet()) {
            logger.info("report to master : " + report2Master.get(key));
        }
    }
   
    //判断是否需要分开多个master投递结果
    if (report2Master!= null
        && report2Master.size() > 0)
    {
        if(logger.isInfoEnabled()) {
              logger.info("start to send result to multi master");
          }
      Map<String, Map<String, Object>> _entryResults = jobTaskResult.getResults();
     
      //第一级String为masteraddress
      Map<String,Map<String, Map<String, Object>>> _masterEntryResults = new HashMap<String,Map<String, Map<String, Object>>>();
     
      Set<String> masters = jobTask.getStatisticsRule().getMasters();
     
      for(String entryId : _entryResults.keySet())
      {
        ReportEntry reportEntry = rule.getEntryPool().get(entryId);
        Set<String> reports = reportEntry.getReports();
        if(reports == null || reports.size() == 0) {
            String master = config.getMasterAddress()+":"+config.getMasterPort();
            logger.error("reportEntry has no report " + reportEntry.getId());
            if (_masterEntryResults.get(master) == null)
View Full Code Here

TOP

Related Classes of com.taobao.top.analysis.statistics.data.Rule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.