Ejemplo n.º 1
0
  @Override
  public boolean buildHourlyTask(String name, String domain, Date start) {
    BugReport bugReport = new BugReport(Constants.CAT);
    ProblemReportVisitor visitor = new ProblemReportVisitor().setReport(bugReport);
    Date end = new Date(start.getTime() + TimeUtil.ONE_HOUR);
    Set<String> domains = m_reportService.queryAllDomainNames(start, end, ProblemAnalyzer.ID);

    for (String domainName : domains) {
      if (validateDomain(domainName)) {
        ProblemReport problemReport = m_reportService.queryProblemReport(domainName, start, end);
        visitor.visitProblemReport(problemReport);
      }
    }

    for (Domain d : bugReport.getDomains().values()) {
      d.setProblemUrl(
          String.format(
              "http://%s/cat/r/p?domain=%s&date=%s",
              getDomainName(), d.getId(), m_hourly_formate.format(start)));
    }
    HourlyReport report = new HourlyReport();

    report.setContent("");
    report.setCreationDate(new Date());
    report.setDomain(domain);
    report.setIp(NetworkInterfaceManager.INSTANCE.getLocalHostAddress());
    report.setName(name);
    report.setPeriod(start);
    report.setType(1);
    byte[] binaryContent = DefaultNativeBuilder.build(bugReport);
    return m_reportService.insertHourlyReport(report, binaryContent);
  }
Ejemplo n.º 2
0
  @Override
  public boolean buildHourlyTask(String name, String domain, Date start) {
    ServiceReport serviceReport = new ServiceReport(Constants.CAT);
    Date end = new Date(start.getTime() + TimeHelper.ONE_HOUR);
    Set<String> domains = m_reportService.queryAllDomainNames(start, end, CrossAnalyzer.ID);

    for (String domainName : domains) {
      if (m_configManger.validateDomain(domainName)) {
        CrossReport crossReport = m_crossReportService.queryReport(domainName, start, end);
        ProjectInfo projectInfo = new ProjectInfo(TimeHelper.ONE_HOUR);

        projectInfo.setClientIp(Constants.ALL);
        projectInfo.visitCrossReport(crossReport);
        Collection<TypeDetailInfo> callInfos = projectInfo.getCallProjectsInfo();

        for (TypeDetailInfo typeInfo : callInfos) {
          if (!validataService(typeInfo)) {
            merge(serviceReport.findOrCreateDomain(typeInfo.getProjectName()), typeInfo);
          }
        }
      }
    }
    HourlyReport report = new HourlyReport();

    report.setCreationDate(new Date());
    report.setDomain(domain);
    report.setIp(NetworkInterfaceManager.INSTANCE.getLocalHostAddress());
    report.setName(name);
    report.setPeriod(start);
    report.setType(1);
    byte[] binaryContent = DefaultNativeBuilder.build(serviceReport);
    return m_reportService.insertHourlyReport(report, binaryContent);
  }
Ejemplo n.º 3
0
  @Override
  public StateReport queryHourlyReport(String domain, Date start, Date end) {
    StateReportMerger merger = new StateReportMerger(new StateReport(domain));
    long startTime = start.getTime();
    long endTime = end.getTime();
    String name = StateAnalyzer.ID;

    for (; startTime < endTime; startTime = startTime + TimeUtil.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
              StateReport reportModel =
                  com.dianping.cat.consumer.state.model.transform.DefaultSaxParser.parse(xml);
              reportModel.accept(merger);
            } else { // for new binary storage, binary is same to report id
              StateReport reportModel = queryFromHourlyBinary(report.getId(), domain);

              reportModel.accept(merger);
            }
          } catch (DalNotFoundException e) {
            // ignore
          } catch (Exception e) {
            Cat.logError(e);
          }
        }
      }
    }
    StateReport stateReport = merger.getStateReport();

    stateReport.setStartTime(start);
    stateReport.setEndTime(new Date(end.getTime() - 1));
    return stateReport;
  }
Ejemplo n.º 4
0
  @Override
  public HeavyReport queryHourlyReport(String domain, Date start, Date end) {
    HeavyReportMerger merger = new HeavyReportMerger(new HeavyReport(domain));
    long startTime = start.getTime();
    long endTime = end.getTime();
    String name = Constants.REPORT_HEAVY;

    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) {
          try {
            HeavyReport reportModel = queryFromHourlyBinary(report.getId(), domain);
            reportModel.accept(merger);
          } catch (DalNotFoundException e) {
            // ignore
          } catch (Exception e) {
            Cat.logError(e);
          }
        }
      }
    }
    HeavyReport heavyReport = merger.getHeavyReport();

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

    return heavyReport;
  }