Package com.dianping.cat.home.utilization.entity

Examples of com.dianping.cat.home.utilization.entity.UtilizationReport


    return report;
  }

  @Override
  public UtilizationReport queryDailyReport(String domain, Date start, Date end) {
    UtilizationReportMerger merger = new UtilizationReportMerger(new UtilizationReport(domain));
    long startTime = start.getTime();
    long endTime = end.getTime();
    String name = Constants.REPORT_UTILIZATION;

    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) {
          UtilizationReport reportModel = com.dianping.cat.home.utilization.transform.DefaultSaxParser.parse(xml);
          reportModel.accept(merger);
        } else {
          UtilizationReport reportModel = queryFromDailyBinary(report.getId(), domain);
          reportModel.accept(merger);
        }
      } catch (DalNotFoundException e) {
        //ignore
      } catch (Exception e) {
        Cat.logError(e);
      }
    }
    UtilizationReport utilizationReport = merger.getUtilizationReport();

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


    DailyReportContent content = m_dailyReportContentDao.findByPK(id, DailyReportContentEntity.READSET_FULL);

    if (content != null) {
      return DefaultNativeParser.parse(content.getContent());
    } else {
      return new UtilizationReport(domain);
    }
  }
View Full Code Here

    HourlyReportContent content = m_hourlyReportContentDao.findByPK(id, HourlyReportContentEntity.READSET_FULL);

    if (content != null) {
      return DefaultNativeParser.parse(content.getContent());
    } else {
      return new UtilizationReport(domain);
    }
  }
View Full Code Here

    MonthlyReportContent content = m_monthlyReportContentDao.findByPK(id, MonthlyReportContentEntity.READSET_FULL);

    if (content != null) {
      return DefaultNativeParser.parse(content.getContent());
    } else {
      return new UtilizationReport(domain);
    }
  }
View Full Code Here

    WeeklyReportContent content = m_weeklyReportContentDao.findByPK(id, WeeklyReportContentEntity.READSET_FULL);

    if (content != null) {
      return DefaultNativeParser.parse(content.getContent());
    } else {
      return new UtilizationReport(domain);
    }
  }
View Full Code Here

    }
  }

  @Override
  public UtilizationReport queryHourlyReport(String domain, Date start, Date end) {
    UtilizationReportMerger merger = new UtilizationReportMerger(new UtilizationReport(domain));
    long startTime = start.getTime();
    long endTime = end.getTime();
    String name = Constants.REPORT_UTILIZATION;

    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) {
              UtilizationReport reportModel = com.dianping.cat.home.utilization.transform.DefaultSaxParser
                    .parse(xml);
              reportModel.accept(merger);
            } else {
              UtilizationReport reportModel = queryFromHourlyBinary(report.getId(), domain);
              reportModel.accept(merger);
            }
          } catch (DalNotFoundException e) {
            //ignore
          } catch (Exception e) {
            Cat.logError(e);
          }
        }
      }
    }
    UtilizationReport utilizationReport = merger.getUtilizationReport();

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

    return utilizationReport;
  }
View Full Code Here

    } catch (DalNotFoundException e) {
      //ignore
    } catch (Exception e) {
      Cat.logError(e);
    }
    return new UtilizationReport(domain);
  }
View Full Code Here

    } catch (DalNotFoundException e) {
      //ignore
    } catch (Exception e) {
      Cat.logError(e);
    }
    return new UtilizationReport(domain);
  }
View Full Code Here

public class UtilizationReportMergerTest {
  @Test
  public void testUtilizationReportMerge() throws Exception {
    String oldXml = Files.forIO().readFrom(getClass().getResourceAsStream("UtilizationReportOld.xml"), "utf-8");
    String newXml = Files.forIO().readFrom(getClass().getResourceAsStream("UtilizationReportNew.xml"), "utf-8");
    UtilizationReport reportOld = DefaultSaxParser.parse(oldXml);
    UtilizationReport reportNew = DefaultSaxParser.parse(newXml);
    String expected = Files.forIO().readFrom(getClass().getResourceAsStream("UtilizationReportResult.xml"),
          "utf-8");
    UtilizationReportMerger merger = new UtilizationReportMerger(new UtilizationReport(reportOld.getDomain()));

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

    Assert.assertEquals("Check the merge result!", expected.replace("\r", ""), merger.getUtilizationReport()
          .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.home.utilization.entity.UtilizationReport

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.