Ejemplo n.º 1
0
  private int callQaService() throws IOException {
    String localIp = NetworkInterfaceManager.INSTANCE.getLocalHostAddress();
    String qaServiceUrlPrefix = task.getQaServiceUrlPrefix();
    DomainHealthCheckInfo deployInfo =
        new DomainHealthCheckInfo(
            task.getDomain(),
            config.getEnv(),
            localIp,
            config.getContainerPort(),
            qaServiceUrlPrefix);

    int exitCode = DeployStep.CODE_OK;
    if (!StringUtils.isEmpty(StringUtils.trimAll(qaServiceUrlPrefix))) {
      logger.info(
          String.format(
              "qa service url is given, checking domain status via %s", qaServiceUrlPrefix));

      CheckResult checkResult = CheckResult.FAIL;
      try {
        checkResult =
            qaService.isDomainHealthy(
                deployInfo, config.getQaServiceTimeout(), config.getQaServiceQueryInterval());
      } catch (RuntimeException e) {
        checkResult = CheckResult.AGENT_LOCAL_EXCEPTION;
        logger.error("agent local exception when calling qa service", e);
      }

      exitCode = qaCheckResultToExitCode(checkResult);
    } else {
      logger.info("qa service url is not given, skip checking domain status");
    }
    return exitCode;
  }
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 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.º 4
0
  @Override
  public boolean buildMonthlyTask(String name, String domain, Date period) {
    ServiceReport serviceReport =
        queryDailyReportsByDuration(domain, period, TaskHelper.nextMonthStart(period));
    MonthlyReport report = new MonthlyReport();

    report.setCreationDate(new Date());
    report.setDomain(domain);
    report.setIp(NetworkInterfaceManager.INSTANCE.getLocalHostAddress());
    report.setName(name);
    report.setPeriod(period);
    report.setType(1);
    byte[] binaryContent = DefaultNativeBuilder.build(serviceReport);
    return m_reportService.insertMonthlyReport(report, binaryContent);
  }
Ejemplo n.º 5
0
  @Override
  protected void process(MessageTree tree) {
    StateReport report = m_reportManager.getHourlyReport(getStartTime(), Constants.CAT, true);
    String domain = tree.getDomain();
    String ip = tree.getIpAddress();
    Machine machine =
        report.findOrCreateMachine(NetworkInterfaceManager.INSTANCE.getLocalHostAddress());

    machine.findOrCreateProcessDomain(domain).addIp(ip);
    if (m_serverConfigManager.validateDomain(domain)) {
      if (!m_domainManager.containsDomainInCat(domain)) {
        boolean insert = m_domainManager.insertDomain(domain);

        if (!insert) {
          m_logger.warn(String.format("Error when insert domain %s info", domain));
        }
      }
      Hostinfo info = m_domainManager.queryHostInfoByIp(ip);

      if (info == null) {
        m_domainManager.insert(domain, ip);
      } else {
        String oldDomain = info.getDomain();

        if (!oldDomain.equals(domain) && !oldDomain.equals(Constants.CAT)) {
          // only work on online environment
          long current = System.currentTimeMillis();
          Date lastModifiedDate = info.getLastModifiedDate();

          if (lastModifiedDate != null && (current - lastModifiedDate.getTime()) > ONE_HOUR) {
            m_domainManager.update(info.getId(), domain, ip);
            m_logger.info(
                String.format("old domain is %s , change ip %s to %s", oldDomain, ip, domain));
          }
        }
      }
    }
  }
Ejemplo n.º 6
0
  @Override
  public boolean buildMonthlyTask(String name, String domain, Date period) {
    BugReport bugReport =
        queryDailyReportsByDuration(domain, period, TaskHelper.nextMonthStart(period));

    for (Domain d : bugReport.getDomains().values()) {
      d.setProblemUrl(
          String.format(
              "http://%s/cat/r/p?op=history&reportType=month&domain=%s&date=%s",
              getDomainName(), d.getId(), m_daily_formate.format(period)));
    }
    MonthlyReport report = new MonthlyReport();

    report.setContent("");
    report.setCreationDate(new Date());
    report.setDomain(domain);
    report.setIp(NetworkInterfaceManager.INSTANCE.getLocalHostAddress());
    report.setName(name);
    report.setPeriod(period);
    report.setType(1);
    byte[] binaryContent = DefaultNativeBuilder.build(bugReport);
    return m_reportService.insertMonthlyReport(report, binaryContent);
  }
Ejemplo n.º 7
0
  private String getDomainName() {
    String ip = NetworkInterfaceManager.INSTANCE.getLocalHostAddress();

    return ip + ":8080";
  }
Ejemplo n.º 8
0
public class StateAnalyzer extends AbstractMessageAnalyzer<StateReport> implements LogEnabled {
  public static final String ID = "state";

  @Inject(ID)
  private ReportManager<StateReport> m_reportManager;

  @Inject private ServerStatisticManager m_serverStateManager;

  @Inject private DomainManager m_domainManager;

  @Inject private ServerConfigManager m_serverConfigManager;

  @Inject private String m_ip = NetworkInterfaceManager.INSTANCE.getLocalHostAddress();

  private Machine buildStateInfo(Machine machine) {
    long minute = 1000 * 60;
    long start = m_startTime;
    long end = m_startTime + minute * 60;
    double maxTps = 0;
    long current = System.currentTimeMillis();
    int size = 0;

    if (end > current) {
      end = current;
    }
    for (; start < end; start += minute) {
      Statistic state = m_serverStateManager.findOrCreateState(start);
      Message temp = machine.findOrCreateMessage(start);
      Map<String, AtomicLong> totals = state.getMessageTotals();
      Map<String, AtomicLong> totalLosses = state.getMessageTotalLosses();
      Map<String, AtomicLong> sizes = state.getMessageSizes();

      for (Entry<String, AtomicLong> entry : totals.entrySet()) {
        String domain = entry.getKey();
        long value = entry.getValue().get();
        ProcessDomain processDomain = machine.findOrCreateProcessDomain(domain);
        Detail detail = processDomain.findOrCreateDetail(start);

        processDomain.setTotal(value + processDomain.getTotal());
        detail.setTotal(value + detail.getTotal());
      }
      for (Entry<String, AtomicLong> entry : totalLosses.entrySet()) {
        String domain = entry.getKey();
        long value = entry.getValue().get();
        ProcessDomain processDomain = machine.findOrCreateProcessDomain(domain);
        Detail detail = processDomain.findOrCreateDetail(start);

        processDomain.setTotalLoss(value + processDomain.getTotalLoss());
        detail.setTotalLoss(value + detail.getTotalLoss());
      }
      for (Entry<String, AtomicLong> entry : sizes.entrySet()) {
        String domain = entry.getKey();
        long value = entry.getValue().get();
        ProcessDomain processDomain = machine.findOrCreateProcessDomain(domain);
        Detail detail = processDomain.findOrCreateDetail(start);

        processDomain.setSize(value + processDomain.getSize());
        detail.setSize(value + detail.getSize());
      }

      long messageTotal = state.getMessageTotal();
      long messageTotalLoss = state.getMessageTotalLoss();
      long messageSize = state.getMessageSize();
      long blockTotal = state.getBlockTotal();
      long blockLoss = state.getBlockLoss();
      long blockTime = state.getBlockTime();
      long pigeonTimeError = state.getPigeonTimeError();
      long networkTimeError = state.getNetworkTimeError();
      long messageDump = state.getMessageDump();
      long messageDumpLoss = state.getMessageDumpLoss();
      int processDelayCount = state.getProcessDelayCount();
      double processDelaySum = state.getProcessDelaySum();

      temp.setTotal(messageTotal).setTotalLoss(messageTotalLoss).setSize(messageSize);
      temp.setBlockTotal(blockTotal).setBlockLoss(blockLoss).setBlockTime(blockTime);
      temp.setPigeonTimeError(pigeonTimeError)
          .setNetworkTimeError(networkTimeError)
          .setDump(messageDump);
      temp.setDumpLoss(messageDumpLoss)
          .setDelayCount(processDelayCount)
          .setDelaySum(processDelaySum);

      machine
          .setTotal(messageTotal + machine.getTotal())
          .setTotalLoss(messageTotalLoss + machine.getTotalLoss())
          .setSize(messageSize + machine.getSize());
      machine
          .setBlockTotal(machine.getBlockTotal() + blockTotal)
          .setBlockLoss(machine.getBlockLoss() + blockLoss)
          .setBlockTime(machine.getBlockTime() + blockTime);
      machine
          .setPigeonTimeError(machine.getPigeonTimeError() + pigeonTimeError)
          .setNetworkTimeError(machine.getNetworkTimeError() + networkTimeError)
          .setDump(machine.getDump() + messageDump);
      machine
          .setDumpLoss(machine.getDumpLoss() + messageDumpLoss)
          .setDelayCount(machine.getDelayCount() + processDelayCount)
          .setDelaySum(machine.getDelaySum() + processDelaySum);

      double avg = 0;
      long count = machine.getDelayCount();

      if (count > 0) {
        avg = machine.getDelaySum() / count;
        machine.setDelayAvg(avg);
      }
      if (messageTotal > maxTps) {
        maxTps = messageTotal;
      }
      temp.setTime(new Date(start));
      size++;
    }

    double avgTps = 0;
    if (size > 0) {
      avgTps = machine.getTotal() / (double) size;
    }
    machine.setAvgTps(avgTps);
    machine.setMaxTps(maxTps);
    return machine;
  }

  @Override
  public void doCheckpoint(boolean atEnd) {
    long startTime = getStartTime();
    StateReport stateReport = getReport(Constants.CAT);
    Map<String, StateReport> reports = m_reportManager.getHourlyReports(startTime);

    reports.put(Constants.CAT, stateReport);
    if (atEnd && !isLocalMode()) {
      m_reportManager.storeHourlyReports(startTime, StoragePolicy.FILE_AND_DB);
    } else {
      m_reportManager.storeHourlyReports(startTime, StoragePolicy.FILE);
    }
    if (atEnd) {
      long minute = 1000 * 60;
      long start = m_startTime - minute * 60 * 2;
      long end = m_startTime - minute * 60;

      for (; start < end; start += minute) {
        m_serverStateManager.removeState(start);
      }
    }
  }

  @Override
  public void enableLogging(Logger logger) {
    m_logger = logger;
  }

  @Override
  public StateReport getReport(String domain) {
    StateReport report = new StateReport(Constants.CAT);

    report.setStartTime(new Date(m_startTime));
    report.setEndTime(new Date(m_startTime + MINUTE * 60 - 1));

    Machine machine = buildStateInfo(report.findOrCreateMachine(m_ip));
    StateReport stateReport = m_reportManager.getHourlyReport(getStartTime(), Constants.CAT, true);
    Map<String, ProcessDomain> processDomains =
        stateReport.findOrCreateMachine(m_ip).getProcessDomains();

    for (Map.Entry<String, ProcessDomain> entry : machine.getProcessDomains().entrySet()) {
      ProcessDomain processDomain = processDomains.get(entry.getKey());

      if (processDomain != null) {
        entry.getValue().getIps().addAll(processDomain.getIps());
      }
    }
    return report;
  }

  @Override
  protected void process(MessageTree tree) {
    StateReport report = m_reportManager.getHourlyReport(getStartTime(), Constants.CAT, true);
    String domain = tree.getDomain();
    String ip = tree.getIpAddress();
    Machine machine =
        report.findOrCreateMachine(NetworkInterfaceManager.INSTANCE.getLocalHostAddress());

    machine.findOrCreateProcessDomain(domain).addIp(ip);
    if (m_serverConfigManager.validateDomain(domain)) {
      if (!m_domainManager.containsDomainInCat(domain)) {
        boolean insert = m_domainManager.insertDomain(domain);

        if (!insert) {
          m_logger.warn(String.format("Error when insert domain %s info", domain));
        }
      }
      Hostinfo info = m_domainManager.queryHostInfoByIp(ip);

      if (info == null) {
        m_domainManager.insert(domain, ip);
      } else {
        String oldDomain = info.getDomain();

        if (!oldDomain.equals(domain) && !oldDomain.equals(Constants.CAT)) {
          // only work on online environment
          long current = System.currentTimeMillis();
          Date lastModifiedDate = info.getLastModifiedDate();

          if (lastModifiedDate != null && (current - lastModifiedDate.getTime()) > ONE_HOUR) {
            m_domainManager.update(info.getId(), domain, ip);
            m_logger.info(
                String.format("old domain is %s , change ip %s to %s", oldDomain, ip, domain));
          }
        }
      }
    }
  }
}