Package com.dianping.cat.consumer.transaction

Examples of com.dianping.cat.consumer.transaction.TransactionReportMerger


import com.dianping.cat.report.task.TaskHelper;

public class TransactionMerger {

  private TransactionReport merge(String reportDomain, List<TransactionReport> reports, boolean isDaily) {
    TransactionReportMerger merger = null;
    if (isDaily) {
      merger = new HistoryTransactionReportMerger(new TransactionReport(reportDomain));
    } else {
      merger = new TransactionReportMerger(new TransactionReport(reportDomain));
    }
    for (TransactionReport report : reports) {
      report.accept(merger);
    }

    return merger.getTransactionReport();
  }
View Full Code Here


  }

  private TransactionReport queryDailyReportsByDuration(String domain, Date start, Date end) {
    long startTime = start.getTime();
    long endTime = end.getTime();
    TransactionReportMerger merger = new TransactionReportMerger(new TransactionReport(domain));

    for (; startTime < endTime; startTime += TimeHelper.ONE_DAY) {
      try {
        TransactionReport reportModel = m_reportService.queryTransactionReport(domain, new Date(startTime),
              new Date(startTime + TimeHelper.ONE_DAY));

        reportModel.accept(merger);
      } catch (Exception e) {
        Cat.logError(e);
      }
    }
    TransactionReport transactionReport = merger.getTransactionReport();

    transactionReport.setStartTime(start);
    transactionReport.setEndTime(end);
    new TransactionReportCountFilter().visitTransactionReport(transactionReport);
    return transactionReport;
View Full Code Here

  @Override
  protected TransactionReport merge(ModelRequest request, List<ModelResponse<TransactionReport>> responses) {
    if (responses.size() == 0) {
      return null;
    }
    TransactionReportMerger merger = new TransactionReportMerger(new TransactionReport(request.getDomain()));

    for (ModelResponse<TransactionReport> response : responses) {
      if (response != null) {
        TransactionReport model = response.getModel();
        if (model != null) {
          model.accept(merger);
        }
      }
    }
    return merger.getTransactionReport();
  }
View Full Code Here

    String oldXml = Files.forIO().readFrom(getClass().getResourceAsStream("HistoryTransaction.xml"), "utf-8");
    TransactionReport report1 = DefaultSaxParser.parse(oldXml);
    TransactionReport report2 = DefaultSaxParser.parse(oldXml);
    String expected = Files.forIO().readFrom(getClass().getResourceAsStream("HistoryTransactionMergeResult.xml"),
          "utf-8");
    TransactionReportMerger merger = new HistoryTransactionReportMerger(new TransactionReport(report1.getDomain()));

    report1.accept(merger);
    report2.accept(merger);

    String actual = new DefaultXmlBuilder().buildXml(merger.getTransactionReport());

    Assert.assertEquals("Check the merge result!", expected.replace("\r", ""), actual.replace("\r", ""));

  }
View Full Code Here

    return report;
  }

  @Override
  public TransactionReport queryDailyReport(String domain, Date start, Date end) {
    TransactionReportMerger merger = new TransactionReportMerger(new TransactionReport(domain));
    long startTime = start.getTime();
    long endTime = end.getTime();
    String name = TransactionAnalyzer.ID;

    for (; startTime < endTime; startTime = startTime + TimeHelper.ONE_DAY) {
      try {
        DailyReport report = m_dailyReportDao.findByDomainNamePeriod(domain, name, new Date(startTime),
              DailyReportEntity.READSET_FULL);
        String xml = report.getContent();

        if (xml != null && xml.length() > 0) {
          TransactionReport reportModel = com.dianping.cat.consumer.transaction.model.transform.DefaultSaxParser
                .parse(xml);
          reportModel.accept(merger);
        } else {
          TransactionReport reportModel = queryFromDailyBinary(report.getId(), domain);

          reportModel.accept(merger);
        }
      } catch (DalNotFoundException e) {
        // ignore
      } catch (Exception e) {
        Cat.logError(e);
      }
    }
    TransactionReport transactionReport = merger.getTransactionReport();

    transactionReport.setStartTime(start);
    transactionReport.setEndTime(end);
    return transactionReport;
  }
View Full Code Here

    }
  }

  @Override
  public TransactionReport queryHourlyReport(String domain, Date start, Date end) {
    TransactionReportMerger merger = new TransactionReportMerger(new TransactionReport(domain));
    long startTime = start.getTime();
    long endTime = end.getTime();
    String name = TransactionAnalyzer.ID;

    for (; startTime < endTime; startTime = startTime + TimeHelper.ONE_HOUR) {
      List<HourlyReport> reports = null;
      try {
        reports = m_hourlyReportDao.findAllByDomainNamePeriod(new Date(startTime), domain, name,
              HourlyReportEntity.READSET_FULL);
      } catch (DalException e) {
        Cat.logError(e);
      }
      if (reports != null) {
        for (HourlyReport report : reports) {
          String xml = report.getContent();

          try {
            if (xml != null && xml.length() > 0) {// for old xml storage
              TransactionReport reportModel = com.dianping.cat.consumer.transaction.model.transform.DefaultSaxParser
                    .parse(xml);
              reportModel.accept(merger);
            } else {// for new binary storage, binary is same to report id
              TransactionReport reportModel = queryFromHourlyBinary(report.getId(), domain);

              reportModel.accept(merger);
            }
          } catch (DalNotFoundException e) {
            // ignore
          } catch (Exception e) {
            Cat.logError(e);
          }
        }
      }
    }
    TransactionReport transactionReport = merger.getTransactionReport();

    transactionReport.setStartTime(start);
    transactionReport.setEndTime(new Date(end.getTime() - 1));

    Set<String> domains = queryAllDomainNames(start, end, TransactionAnalyzer.ID);
View Full Code Here

    String newXml = Files.forIO().readFrom(getClass().getResourceAsStream("transaction_report_new.xml"), "utf-8");
    TransactionReport reportOld = DefaultSaxParser.parse(oldXml);
    TransactionReport reportNew = DefaultSaxParser.parse(newXml);
    String expected = Files.forIO().readFrom(getClass().getResourceAsStream("transaction_report_mergeResult.xml"),
          "utf-8");
    TransactionReportMerger merger = new TransactionReportMerger(new TransactionReport(reportOld.getDomain()));

    reportOld.accept(merger);
    reportNew.accept(merger);

    Assert.assertEquals("Check the merge result!", expected.replace("\r", ""), merger.getTransactionReport()
          .toString().replace("\r", ""));
    Assert.assertEquals("Source report is changed!", newXml.replace("\r", ""), reportNew.toString().replace("\r", ""));
  }
View Full Code Here

TOP

Related Classes of com.dianping.cat.consumer.transaction.TransactionReportMerger

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.