Package com.dianping.cat.consumer.problem

Examples of com.dianping.cat.consumer.problem.ProblemReportMerger


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

public class ProblemMerger {

  private ProblemReport merge(String reportDomain, List<ProblemReport> reports, boolean isDaily) {
    ProblemReportMerger merger = null;

    if (isDaily) {
      merger = new HistoryProblemReportMerger(new ProblemReport(reportDomain));
    } else {
      merger = new ProblemReportMerger(new ProblemReport(reportDomain));
    }
    for (ProblemReport report : reports) {
      report.accept(merger);
    }

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


  }

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

    for (; startTime < endTime; startTime += TimeHelper.ONE_DAY) {
      try {
        ProblemReport reportModel = m_reportService.queryProblemReport(domain, new Date(startTime), new Date(
              startTime + TimeHelper.ONE_DAY));
        reportModel.accept(merger);
      } catch (Exception e) {
        Cat.logError(e);
      }
    }
    ProblemReport problemReport = merger.getProblemReport();

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

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

    for (ModelResponse<ProblemReport> response : responses) {
      if (response != null) {
        ProblemReport model = response.getModel();

        if (model != null) {
          model.accept(merger);
        }
      }
    }

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

    String newXml = Files.forIO().readFrom(getClass().getResourceAsStream("ProblemReportNew.xml"), "utf-8");
    ProblemReport reportOld = DefaultSaxParser.parse(oldXml);
    ProblemReport reportNew = DefaultSaxParser.parse(newXml);
    String expected = Files.forIO().readFrom(getClass().getResourceAsStream("ProblemReportMergeAllResult.xml"),
          "utf-8");
    ProblemReportMerger merger = new HistoryProblemReportMerger(new ProblemReport(reportOld.getDomain()));

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

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

  @Test
  public void testProblemReportMergerSize() throws Exception {
    String oldXml = Files.forIO().readFrom(getClass().getResourceAsStream("ProblemMobile.xml"), "utf-8");
    ProblemReport reportOld = DefaultSaxParser.parse(oldXml);
    ProblemReportMerger merger = new HistoryProblemReportMerger(new ProblemReport(reportOld.getDomain()));

    for (int i = 0; i < 24; i++) {
      reportOld.accept(merger);
    }
    ProblemReport problemReport = merger.getProblemReport();
    for (Machine machine : problemReport.getMachines().values()) {
      List<Entry> entries = machine.getEntries();
      for (Entry entry : entries) {
        int size = entry.getThreads().size();
        Assert.assertEquals(0, size);
View Full Code Here

    return report;
  }

  @Override
  public ProblemReport queryDailyReport(String domain, Date start, Date end) {
    ProblemReportMerger merger = new ProblemReportMerger(new ProblemReport(domain));
    long startTime = start.getTime();
    long endTime = end.getTime();
    String name = ProblemAnalyzer.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) {
          ProblemReport reportModel = com.dianping.cat.consumer.problem.model.transform.DefaultSaxParser
                .parse(xml);
          reportModel.accept(merger);
        } else {
          ProblemReport reportModel = queryFromDailyBinary(report.getId(), domain);

          reportModel.accept(merger);
        }
      } catch (DalNotFoundException e) {
        //ignore
      } catch (Exception e) {
        Cat.logError(e);
      }
    }
    ProblemReport problemReport = merger.getProblemReport();

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

    }
  }

  @Override
  public ProblemReport queryHourlyReport(String domain, Date start, Date end) {
    ProblemReportMerger merger = new ProblemReportMerger(new ProblemReport(domain));
    long startTime = start.getTime();
    long endTime = end.getTime();
    String name = ProblemAnalyzer.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
              ProblemReport reportModel = com.dianping.cat.consumer.problem.model.transform.DefaultSaxParser
                    .parse(xml);
              reportModel.accept(merger);
            } else {// for new binary storage, binary is same to report id
              ProblemReport reportModel = queryFromHourlyBinary(report.getId(), domain);

              reportModel.accept(merger);
            }
          } catch (DalNotFoundException e) {
            //ignore
          } catch (Exception e) {
            Cat.logError(e);
          }
        }
      }
    }
    ProblemReport problemReport = merger.getProblemReport();

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

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

TOP

Related Classes of com.dianping.cat.consumer.problem.ProblemReportMerger

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.