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

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


      if(logger.isInfoEnabled()) {
          logger.info("start build rule in " + configFile);
      }
    InputStream in = null;
    XMLEventReader r = null;
    Report report = null;
    StringBuilder globalConditions = new StringBuilder();
    StringBuilder globalValuefilter = new StringBuilder();
    List<String> globalMapClass = new ArrayList<String>();

    String domain = null;

    String localdir = new StringBuilder()
        .append(System.getProperty("user.dir"))
        .append(File.separatorChar).toString();

    if (configFile == null || "".equals(configFile)) {
      String error = "configFile can not be null !";
      logger.error(error);
      throw new AnalysisException(error);
    }

    try {
      XMLInputFactory factory = XMLInputFactory.newInstance();
      ClassLoader loader = Thread.currentThread().getContextClassLoader();

      if (configFile.startsWith("file:")) {
        try {
          in = new java.io.FileInputStream(new File(
              configFile.substring(configFile.indexOf("file:")
                  + "file:".length())));
        } catch (Exception e) {
          logger.error(e,e);
        }

        if (in == null)
          in = new java.io.FileInputStream(new File(localdir
              + configFile.substring(configFile.indexOf("file:")
                  + "file:".length())));
      } else {
        URL url = loader.getResource(configFile);

        if (url == null) {
          String error = "configFile: " + configFile + " not exist !";
          logger.error(error);
          throw new java.lang.RuntimeException(error);
        }

        in = url.openStream();
      }

      r = factory.createXMLEventReader(in);
      List<String> parents = new ArrayList<String>();

      while (r.hasNext()) {
        XMLEvent event = r.nextEvent();

        if (event.isStartElement()) {
          StartElement start = event.asStartElement();

          String tag = start.getName().getLocalPart();

          if (tag.equalsIgnoreCase("domain")) {
            if (start.getAttributeByName(new QName("", "value")) != null) {
              domain = start.getAttributeByName(
                  new QName("", "value")).getValue();
              rule.setDomain(domain);
            }

            continue;
          }

          if (tag.equalsIgnoreCase("alias")) {
            Alias alias = new Alias();
            alias.setName(start.getAttributeByName(
                new QName("", "name")).getValue());
            alias.setKey(Integer.valueOf(start.getAttributeByName(
                new QName("", "key")).getValue()));

            rule.getAliasPool().put(alias.getName(), alias);

            continue;
          }
         
          if (tag.equalsIgnoreCase("inner-key")){
            InnerKey innerKey = new InnerKey();
           
            innerKey.setKey(Integer.parseInt(start.getAttributeByName(
                new QName("", "key")).getValue()));
           
            boolean isExist = false;
           
            for(InnerKey ik : rule.getInnerKeyPool())
            {
              if (ik.getKey() == innerKey.getKey())
              {
                logger.error("duplicate innerkey define, key :" + innerKey.getKey());
               
                isExist = true;
                break;
              }
            }
           
            if (!isExist)
            {
              if (innerKey.setFile(start.getAttributeByName(
                  new QName("", "file")).getValue()))
                rule.getInnerKeyPool().add(innerKey);
              else
                logger.error("inner-key set error, file : " + innerKey.getFile());
             
            }
           
            continue;
           
          }

          if (tag.equalsIgnoreCase("global-condition")) {
            if (start.getAttributeByName(new QName("", "value")) != null) {
              if (globalConditions.length() > 0) {
                globalConditions.append("&"
                    + start.getAttributeByName(
                        new QName("", "value"))
                        .getValue());
              } else {
                globalConditions.append(start
                    .getAttributeByName(
                        new QName("", "value"))
                    .getValue());
              }

            }

            continue;
          }

          if (tag.equalsIgnoreCase("global-mapClass")) {
            if (start.getAttributeByName(new QName("", "value")) != null) {
              globalMapClass.add(start.getAttributeByName(
                  new QName("", "value")).getValue());
            }

            continue;
          }

          if (tag.equalsIgnoreCase("global-valuefilter")) {
            if (start.getAttributeByName(new QName("", "value")) != null) {
              globalValuefilter.append(
                  start.getAttributeByName(
                      new QName("", "value")).getValue())
                  .append("&");
            }

            continue;
          }

          if (tag.equalsIgnoreCase("ReportEntry")
              || tag.equalsIgnoreCase("entry")) {
            ReportEntry entry = new ReportEntry();
            if (tag.equalsIgnoreCase("ReportEntry"))
              setReportEntry(true, start, entry, report,
                  rule.getEntryPool(), rule.getAliasPool(),
                  globalConditions, globalValuefilter,
                  globalMapClass, parents);
            else {
              setReportEntry(false, start, entry, report,
                  rule.getEntryPool(), rule.getAliasPool(),
                  globalConditions, globalValuefilter,
                  globalMapClass, parents);
            }

            if (entry.getId() != null) {
              if (rule.getEntryPool().get(entry.getId()) != null)
                throw new java.lang.RuntimeException(
                    "ID confict:" + entry.getId());
              rule.getEntryPool().put(entry.getId(), entry);
            }

            // 增加引用标识
            if (tag.equalsIgnoreCase("entry")) {
              if (entry.getId() != null)
                rule.getReferEntrys().put(entry.getId(), entry);
              else if (report.getReportEntrys() != null
                  && report.getReportEntrys().size() > 0)
                rule.getReferEntrys().put(
                    report.getReportEntrys()
                        .get(report.getReportEntrys()
                            .size() - 1).getId(),
                    report.getReportEntrys()
                        .get(report.getReportEntrys()
                            .size() - 1));
            }

            ReportEntry _tmpEntry = entry;

            if (_tmpEntry.getId() == null
                && report.getReportEntrys() != null
                && report.getReportEntrys().size() > 0)
              _tmpEntry = report.getReportEntrys().get(
                  report.getReportEntrys().size() - 1);
           
            List<Object> bindingStack = ((SimpleCalculator)_tmpEntry.getCalculator()).getBindingStack();
            String valueExpression = ((SimpleCalculator)_tmpEntry.getCalculator()).getValue();
            if (bindingStack != null) {
              if (valueExpression != null
                  && valueExpression.indexOf(
                      "entry(") >= 0)
                for (Object k : bindingStack) {
                  rule.getReferEntrys().put((String)k, null);
                }
            }

            continue;
          }

          if (tag.equalsIgnoreCase("report")) {
            if (report != null) {
                if(report.getId() != null) {
                    if(rule.getReportPool().get(report.getId()) != null)
                        throw new java.lang.RuntimeException(
                                        "ID confict:" + report.getId());
                }
              rule.getReportPool().put(report.getId(), report);
            }

            report = new Report();
            setReport(start, report, rule.getReportPool());
            continue;
          }

          if (tag.equalsIgnoreCase("entryList")) {
            report.setReportEntrys(new ArrayList<ReportEntry>());
            continue;
          }

        }

        if (event.isEndElement()) {
          EndElement end = event.asEndElement();

          String tag = end.getName().getLocalPart();

          if (tag.equalsIgnoreCase("reports") && report != null) {
            rule.getReportPool().put(report.getId(), report);
            continue;
          }

        }
View Full Code Here


   
    CountDownLatch countDownLatch = new CountDownLatch(statisticsRule.getReportPool().size());
    List<String> reportFiles = new ArrayList<String>();
   
    while (iter.hasNext()) {
      Report report = iter.next();
     
      if(logger.isInfoEnabled()) {
              logger.info("check report need to generated by this master " + report.getId() );
          }
      //判断是否是自己要输出的报表,在多个master情况下
      if (statisticsRule.getReport2Master() != null
          && statisticsRule.getReport2Master().size() > 0 && config != null)
      {
        String r = statisticsRule.getReport2Master().get(report.getId());
        if (r == null || !r.startsWith(ReportUtil.getIp()) || !r.endsWith(String.valueOf(config.getMasterPort())))
        {
          countDownLatch.countDown();
          continue;
        }
      }
      if(logger.isInfoEnabled()) {
                logger.info("report need to generated by this master " + report.getId() );
            }
     
      String reportFile;
      String reportDir = normalDir.toString();
      if(rootDir==null) reportDir = new StringBuilder(report.getFile()).append(File.separator).toString();

      // 增加对于周期性输出的报表处理,就是根据FileName创建目录,目录中文件是FileName+时间戳.
      if (report.isPeriod()) {
        if(start-report.getLastExportTime()>report.getExportInterval()){
          report.setLastExportTime(start);
        }else{
          countDownLatch.countDown();
          continue;
        }
       
        if(report.isAppend()){
          reportDir = new StringBuilder().append(periodRootDir)
          .append(report.getFile()).append(File.separator)
          .toString();
         
        }else{
          reportDir = new StringBuilder().append(periodDir)
          .append(report.getFile()).append(File.separator)
          .toString();
   
        }
       
        File tmpDir = new java.io.File(reportDir);

        if (!tmpDir.exists()
            || (tmpDir.exists() && !tmpDir.isDirectory())) {
          tmpDir.mkdirs();
        }

      }
     
      if (needTimeSuffix)
        reportFile = new StringBuilder().append(reportDir)
            .append(report.getFile()).append("_")
            .append(statTime).append(".csv").toString();
      else
        reportFile = new StringBuilder().append(reportDir)
            .append(report.getFile()).append(".csv").toString();

     
      // 对周期性输出增加时间戳到文件结尾
      if (report.isPeriod()) {
        if(report.isAppend()){
          long beg=System.currentTimeMillis();
          long currentRuntime = (beg + 8 * 60 * 60 * 1000) / 86400000;
          if(currentRuntime!=lastRuntime){
            lastRuntime=currentRuntime;
            String bakFile=new StringBuilder().append(reportDir)
            .append(report.getFile()).append("_").append(statTime).append(".csv").toString();
            new File(reportFile).renameTo(new File(bakFile));
           
          }
        }else{
          reportFile = new StringBuilder()
View Full Code Here

TOP

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

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.