Esempio n. 1
0
  @Override
  @OutboundActionMeta(name = "t")
  public void handleOutbound(Context ctx) throws ServletException, IOException {
    Model model = new Model(ctx);
    Payload payload = ctx.getPayload();

    normalize(model, payload);
    String type = payload.getType();

    switch (payload.getAction()) {
      case HOURLY_REPORT:
        showHourlyReport(model, payload);
        DisplayNames displayNameReport = model.getDisplayNameReport();
        if ((!StringUtils.isEmpty(type)) && displayNameReport != null) {
          buildTransactionNameGraph(displayNameReport.getResults(), model);
        }
        break;
      case HISTORY_REPORT:
        showSummarizeReport(model, payload);
        displayNameReport = model.getDisplayNameReport();
        if ((!StringUtils.isEmpty(type)) && displayNameReport != null) {
          buildTransactionNameGraph(displayNameReport.getResults(), model);
        }
        break;
      case HISTORY_GRAPH:
        m_historyGraph.buildTrendGraph(model, payload);
        break;
      case GRAPHS:
        showHourlyGraphs(model, payload);
        break;
      case MOBILE:
        showHourlyReport(model, payload);
        if (!StringUtils.isEmpty(payload.getType())) {
          DisplayNames report = model.getDisplayNameReport();
          String json = m_gson.toJson(report);
          model.setMobileResponse(json);
        } else {
          DisplayTypes report = model.getDisplayTypeReport();
          String json = m_gson.toJson(report);
          model.setMobileResponse(json);
        }
        break;
      case MOBILE_GRAPHS:
        MobileGraphs graphs = showMobileGraphs(model, payload);
        if (graphs != null) {
          model.setMobileResponse(m_gson.toJson(graphs));
        }
        break;
    }

    if (payload.isXml()) {
      m_xmlViewer.view(ctx, model);
    } else {
      m_jspViewer.view(ctx, model);
    }
  }
Esempio n. 2
0
  private void normalize(Model model, Payload payload) {
    model.setPage(ReportPage.TRANSACTION);
    m_normalizePayload.normalize(model, payload);

    if (StringUtils.isEmpty(payload.getQueryName())) {
      payload.setQueryName(null);
    }
    if (StringUtils.isEmpty(payload.getType())) {
      payload.setType(null);
    }

    String queryName = payload.getQueryName();
    if (queryName != null) {
      model.setQueryName(queryName);
    }
  }
Esempio n. 3
0
  private void processVersion2(Payload payload, HttpServletRequest request, String userIp) {
    String content = payload.getContent();
    String records[] = content.split("\n");
    IpInfo ipInfo = m_ipService.findIpInfoByString(userIp);

    if (ipInfo != null) {
      String province = ipInfo.getProvince();
      String operatorStr = ipInfo.getChannel();
      Integer cityId = m_appConfigManager.getCities().get(province);
      Integer operatorId = m_appConfigManager.getOperators().get(operatorStr);

      if (cityId != null && operatorId != null) {
        for (String record : records) {
          try {
            if (!StringUtils.isEmpty(record)) {
              processOneRecord(cityId, operatorId, record);
            }
          } catch (Exception e) {
            Cat.logError(e);
          }
        }
      } else {
        Cat.logEvent("Unknown", province + ":" + operatorStr, Event.SUCCESS, null);
      }
    }
  }
  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;
  }
Esempio n. 5
0
  private void graphNodeConfigAddOrUpdate(Payload payload, Model model) {
    String domain = payload.getDomain();
    String type = payload.getType();

    if (!StringUtils.isEmpty(domain)) {
      model.setDomainConfig(m_topologyConfigManager.queryNodeConfig(type, domain));
    }
  }
Esempio n. 6
0
  private void graphPruductLineAddOrUpdate(Payload payload, Model model) {
    String name = payload.getProductLineName();
    String type = payload.getType();

    if (!StringUtils.isEmpty(name)) {
      model.setProductLine(m_productLineConfigManger.findProductLine(name, type));
    }
  }
Esempio n. 7
0
  public Map<String, double[]> buildGraphDatasForHour(
      Date start, Date end, String type, String name, List<Graph> graphs) {
    Map<String, double[]> result = new HashMap<String, double[]>();
    int size = (int) ((end.getTime() - start.getTime()) / TimeUtil.ONE_HOUR * 12);
    double[] total_count = new double[size];
    double[] failure_count = new double[size];

    if (!StringUtils.isEmpty(type) && StringUtils.isEmpty(name)) {
      for (Graph graph : graphs) {
        int indexOfperiod =
            (int) ((graph.getPeriod().getTime() - start.getTime()) / TimeUtil.ONE_HOUR * 12);
        String summaryContent = graph.getSummaryContent();
        String[] allLines = summaryContent.split("\n");
        for (int j = 0; j < allLines.length; j++) {
          String[] records = allLines[j].split("\t");
          if (records[SummaryOrder.TYPE.ordinal()].equals(type)) {
            appendArray(
                total_count, indexOfperiod, records[SummaryOrder.TOTAL_COUNT.ordinal()], 12);
            appendArray(
                failure_count, indexOfperiod, records[SummaryOrder.FAILURE_COUNT.ordinal()], 12);
          }
        }
      }
    } else if (!StringUtils.isEmpty(type) && !StringUtils.isEmpty(name)) {
      for (Graph graph : graphs) {
        int indexOfperiod =
            (int) ((graph.getPeriod().getTime() - start.getTime()) / TimeUtil.ONE_HOUR * 12);
        String detailContent = graph.getDetailContent();
        String[] allLines = detailContent.split("\n");
        for (int j = 0; j < allLines.length; j++) {
          String[] records = allLines[j].split("\t");
          if (records[DetailOrder.TYPE.ordinal()].equals(type)
              && records[DetailOrder.NAME.ordinal()].equals(name)) {

            appendArray(total_count, indexOfperiod, records[DetailOrder.TOTAL_COUNT.ordinal()], 12);
            appendArray(
                failure_count, indexOfperiod, records[DetailOrder.FAILURE_COUNT.ordinal()], 12);
          }
        }
      }
    }

    result.put("total_count", total_count);
    result.put("failure_count", failure_count);
    return result;
  }
Esempio n. 8
0
  @Override
  public void visitMachine(Machine machine) {
    m_currentIp = machine.getIp();

    if (StringUtils.isEmpty(m_domain)) {
      incDistribute(m_currentIp, queryValue(m_attribute, machine));
    } else {
      super.visitMachine(machine);
    }
  }
Esempio n. 9
0
  private boolean graphEdgeConfigAddOrUpdateSubmit(Payload payload, Model model) {
    EdgeConfig config = payload.getEdgeConfig();

    if (!StringUtils.isEmpty(config.getType())) {
      model.setEdgeConfig(config);
      payload.setType(config.getType());
      return m_topologyConfigManager.insertEdgeConfig(config);
    } else {
      return false;
    }
  }
Esempio n. 10
0
  private void processVersion1(Payload payload, HttpServletRequest request, String userIp) {
    try {
      String content = payload.getContent();
      String[] lines = content.split("\n");
      long time = System.currentTimeMillis();

      for (String line : lines) {
        String[] tabs = line.split("\t");
        // timstampTABtargetUrlTABdurationTABhttpCodeTABerrorCodeENTER
        if (tabs.length == 5 && validate(tabs[3], tabs[4])) {
          MonitorEntity entity = new MonitorEntity();
          String httpStatus = tabs[3];
          String errorCode = tabs[4];

          if (StringUtils.isEmpty(errorCode)) {
            errorCode = Constrants.NOT_SET;
          }
          if (StringUtils.isEmpty(httpStatus)) {
            httpStatus = Constrants.NOT_SET;
          }
          // entity.setTimestamp(Long.parseLong(tabs[0]));
          entity.setTimestamp(time);
          entity.setTargetUrl(tabs[1]);
          entity.setDuration(Double.parseDouble(tabs[2]));
          entity.setHttpStatus(httpStatus);
          entity.setErrorCode(errorCode);
          entity.setIp(userIp);

          if ("200".equals(httpStatus)) {
            entity.setCount(10);
          } else {
            entity.setCount(1);
          }
          m_manager.offer(entity);
        }
      }
    } catch (Exception e) {
      m_logger.error(e.getMessage(), e);
    }
  }
Esempio n. 11
0
  @Override
  public void visitName(Name name) {
    String role = m_currentRole;

    if (StringUtils.isEmpty(m_query) || isFit(m_query, name.getId())) {
      if (role != null && role.endsWith("Client")) {
        addServiceProject(m_currentType, name);
      } else if (role != null && role.endsWith("Server")) {
        addCallProject(m_currentType, name);
      } else if (role != null && role.endsWith("Caller")) {
        addCallerProject(m_currentType, name);
      }
    }
  }
Esempio n. 12
0
  private void buildTransactionMetaInfo(Model model, Payload payload, TransactionReport report) {
    String type = payload.getType();
    String sorted = payload.getSortBy();
    String queryName = payload.getQueryName();
    String ip = payload.getIpAddress();

    if (!StringUtils.isEmpty(type)) {
      DisplayNames displayNames = new DisplayNames();

      model.setDisplayNameReport(displayNames.display(sorted, type, ip, report, queryName));
      buildTransactionNamePieChart(displayNames.getResults(), model);
    } else {
      model.setDisplayTypeReport(new DisplayTypes().display(sorted, ip, report));
    }
  }
Esempio n. 13
0
  @Override
  public void visitType(EventType type) {
    if (m_type != null && m_type.equals(type.getId())) {
      if (StringUtils.isEmpty(m_name)) {
        DistributionDetail detail = new DistributionDetail();

        detail
            .setTotalCount(type.getTotalCount())
            .setFailCount(type.getFailCount())
            .setFailPercent(type.getFailPercent())
            .setIp(m_ip);
        m_details.add(detail);
      } else {
        super.visitType(type);
      }
    }
  }
Esempio n. 14
0
  public void generateRuleConfigContent(String key, BaseRuleConfigManager manager, Model model) {
    String configsStr = "";
    String ruleId = "";

    if (!StringUtils.isEmpty(key)) {
      Rule rule = manager.queryRule(key);

      if (rule != null) {
        ruleId = rule.getId();
        configsStr = new DefaultJsonBuilder(true).buildArray(rule.getConfigs());
        String configHeader = new DefaultJsonBuilder(true).buildArray(rule.getMetricItems());

        model.setConfigHeader(configHeader);
      }
    }
    String content = m_ruleDecorator.generateConfigsHtml(configsStr);

    model.setContent(content);
    model.setId(ruleId);
  }
Esempio n. 15
0
  private void showSummarizeReport(Model model, Payload payload) {
    String type = payload.getType();
    String sorted = payload.getSortBy();
    String ip = payload.getIpAddress();
    String domain = model.getDomain();

    Date start = payload.getHistoryStartDate();
    Date end = payload.getHistoryEndDate();
    TransactionReport transactionReport =
        m_reportService.queryTransactionReport(domain, start, end);
    calculateTps(payload, transactionReport);
    model.setReport(transactionReport);
    if (transactionReport != null) {
      if (!StringUtils.isEmpty(type)) {
        model.setDisplayNameReport(
            new DisplayNames()
                .display(sorted, type, ip, transactionReport, payload.getQueryName()));
      } else {
        model.setDisplayTypeReport(new DisplayTypes().display(sorted, ip, transactionReport));
      }
    }
  }
Esempio n. 16
0
  private void showHourlyReport(Model model, Payload payload) {
    try {
      TransactionReport report = getHourlyReport(payload);

      if (report != null) {
        report.accept(m_computer);
        model.setReport(report);

        String type = payload.getType();
        String sorted = payload.getSortBy();
        String queryName = payload.getQueryName();
        String ip = payload.getIpAddress();
        if (!StringUtils.isEmpty(type)) {
          model.setDisplayNameReport(
              new DisplayNames().display(sorted, type, ip, report, queryName));
        } else {
          model.setDisplayTypeReport(new DisplayTypes().display(sorted, ip, report));
        }
      }
    } catch (Throwable e) {
      Cat.logError(e);
      model.setException(e);
    }
  }
Esempio n. 17
0
  public void process(Action action, Payload payload, Model model) {
    switch (action) {
      case TOPOLOGY_GRAPH_NODE_CONFIG_LIST:
        model.setGraphConfig(m_topologyConfigManager.getConfig());
        break;
      case TOPOLOGY_GRAPH_NODE_CONFIG_ADD_OR_UPDATE:
        graphNodeConfigAddOrUpdate(payload, model);
        model.setProjects(m_globalConfigManager.queryAllProjects());
        break;
      case TOPOLOGY_GRAPH_NODE_CONFIG_ADD_OR_UPDATE_SUBMIT:
        model.setOpState(graphNodeConfigAddOrUpdateSubmit(payload, model));
        model.setGraphConfig(m_topologyConfigManager.getConfig());
        break;
      case TOPOLOGY_GRAPH_NODE_CONFIG_DELETE:
        model.setOpState(graphNodeConfigDelete(payload));
        model.setConfig(m_topologyConfigManager.getConfig());
        break;
      case TOPOLOGY_GRAPH_EDGE_CONFIG_LIST:
        model.setGraphConfig(m_topologyConfigManager.getConfig());
        model.buildEdgeInfo();
        break;
      case TOPOLOGY_GRAPH_EDGE_CONFIG_ADD_OR_UPDATE:
        graphEdgeConfigAdd(payload, model);
        model.setProjects(m_globalConfigManager.queryAllProjects());
        break;
      case TOPOLOGY_GRAPH_EDGE_CONFIG_ADD_OR_UPDATE_SUBMIT:
        model.setOpState(graphEdgeConfigAddOrUpdateSubmit(payload, model));
        model.setGraphConfig(m_topologyConfigManager.getConfig());
        model.buildEdgeInfo();
        break;
      case TOPOLOGY_GRAPH_EDGE_CONFIG_DELETE:
        model.setGraphConfig(m_topologyConfigManager.getConfig());
        model.setOpState(graphEdgeConfigDelete(payload));
        model.buildEdgeInfo();
        break;
      case TOPOLOGY_GRAPH_PRODUCT_LINE:
        model.setProductLines(m_productLineConfigManger.queryAllProductLines());
        model.setTypeToProductLines(m_productLineConfigManger.queryTypeProductLines());
        break;
      case TOPOLOGY_GRAPH_PRODUCT_LINE_ADD_OR_UPDATE:
        graphPruductLineAddOrUpdate(payload, model);
        model.setProjects(m_globalConfigManager.queryAllProjects());
        break;
      case TOPOLOGY_GRAPH_PRODUCT_LINE_DELETE:
        model.setOpState(
            m_productLineConfigManger.deleteProductLine(
                payload.getProductLineName(), payload.getType()));
        model.setProductLines(m_productLineConfigManger.queryAllProductLines());
        model.setTypeToProductLines(m_productLineConfigManger.queryTypeProductLines());
        break;
      case TOPOLOGY_GRAPH_PRODUCT_LINE_ADD_OR_UPDATE_SUBMIT:
        Pair<Boolean, String> addProductlineResult =
            graphProductLineConfigAddOrUpdateSubmit(payload, model);
        String duplicateDomains = addProductlineResult.getValue();

        model.setOpState(addProductlineResult.getKey());
        if (!StringUtils.isEmpty(duplicateDomains)) {
          model.setDuplicateDomains(addProductlineResult.getValue());
        }
        model.setProductLines(m_productLineConfigManger.queryAllProductLines());
        model.setTypeToProductLines(m_productLineConfigManger.queryTypeProductLines());
        break;
      case TOPO_GRAPH_FORMAT_CONFIG_UPDATE:
        String topoGraphFormat = payload.getContent();
        if (!StringUtils.isEmpty(topoGraphFormat)) {
          model.setOpState(m_formatConfigManager.insert(topoGraphFormat));
        }
        model.setContent(m_formatConfigManager.getConfig().toString());
        break;
      default:
        throw new RuntimeException("Error action name " + action.getName());
    }
  }
Esempio n. 18
0
  @Override
  @OutboundActionMeta(name = "t")
  public void handleOutbound(Context ctx) throws ServletException, IOException {
    Model model = new Model(ctx);
    Payload payload = ctx.getPayload();

    normalize(model, payload);
    String domain = payload.getDomain();
    Action action = payload.getAction();
    String ipAddress = payload.getIpAddress();
    String group = payload.getGroup();
    String type = payload.getType();
    String name = payload.getName();
    String ip = payload.getIpAddress();

    if (StringUtils.isEmpty(group)) {
      group = m_configManager.queryDefaultGroup(domain);
      payload.setGroup(group);
    }
    model.setGroupIps(m_configManager.queryIpByDomainAndGroup(domain, group));
    model.setGroups(m_configManager.queryDomainGroup(payload.getDomain()));
    switch (action) {
      case HOURLY_REPORT:
        TransactionReport report = getHourlyReport(payload);

        report = m_mergeManager.mergerAllIp(report, ipAddress);
        calculateTps(payload, report);
        if (report != null) {
          model.setReport(report);
          buildTransactionMetaInfo(model, payload, report);
        }
        break;
      case HISTORY_REPORT:
        report =
            m_reportService.queryTransactionReport(
                domain, payload.getHistoryStartDate(), payload.getHistoryEndDate());
        calculateTps(payload, report);

        if (report != null) {
          model.setReport(report);
          buildTransactionMetaInfo(model, payload, report);
        }
        break;
      case HISTORY_GRAPH:
        m_historyGraph.buildTrendGraph(model, payload);
        break;
      case GRAPHS:
        report = getTransactionGraphReport(model, payload);

        if (name == null || name.length() == 0) {
          name = Constants.ALL;
        }
        report = m_mergeManager.mergerAllName(report, ip, name);
        model.setReport(report);
        buildTransactionNameGraph(model, report, type, name, ip);
        break;
      case HOURLY_GROUP_REPORT:
        report = getHourlyReport(payload);
        report = filterReportByGroup(report, domain, group);
        report = m_mergeManager.mergerAllIp(report, ipAddress);
        calculateTps(payload, report);
        if (report != null) {
          model.setReport(report);

          buildTransactionMetaInfo(model, payload, report);
        }
        break;
      case HISTORY_GROUP_REPORT:
        report =
            m_reportService.queryTransactionReport(
                domain, payload.getHistoryStartDate(), payload.getHistoryEndDate());

        calculateTps(payload, report);
        report = filterReportByGroup(report, domain, group);
        report = m_mergeManager.mergerAllIp(report, ipAddress);
        if (report != null) {
          model.setReport(report);
          buildTransactionMetaInfo(model, payload, report);
        }
        break;
      case GROUP_GRAPHS:
        report = getTransactionGraphReport(model, payload);
        report = filterReportByGroup(report, domain, group);

        if (name == null || name.length() == 0) {
          name = Constants.ALL;
        }
        report = m_mergeManager.mergerAllName(report, ip, name);
        model.setReport(report);
        buildTransactionNameGraph(model, report, type, name, ip);
        break;
      case HISTORY_GROUP_GRAPH:
        List<String> ips = m_configManager.queryIpByDomainAndGroup(domain, group);

        m_historyGraph.buildGroupTrendGraph(model, payload, ips);
        break;
    }

    if (payload.isXml()) {
      m_xmlViewer.view(ctx, model);
    } else {
      m_jspViewer.view(ctx, model);
    }
  }