Package com.dianping.cat.home.rule.entity

Examples of com.dianping.cat.home.rule.entity.Rule


  private void metricRuleAdd(Payload payload, Model model) {
    String ruleId = "";
    String configHeader = "";
    String configsStr = "";
    String key = m_metricConfigManager.buildMetricKey(payload.getDomain(), payload.getType(), payload.getMetricKey());
    Rule rule = m_businessRuleConfigManager.queryRule(payload.getProductLineName(), key);

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

    model.setId(ruleId);
    model.setConfigHeader(configHeader);
View Full Code Here


  public void generateRuleConfigContent(String key, BaseRuleConfigManager manager, Model model) {
    String configsStr = "";
    String ruleId = "";

    if (!StringUtil.isEmpty(key)) {
      Rule rule = manager.queryRule(key);
      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);
View Full Code Here

  protected int m_configId;

  protected MonitorRules m_config;

  protected Rule copyRuleWithDeepCopyConditions(Rule rule) {
    Rule result = new Rule(rule.getId());

    for (MetricItem item : rule.getMetricItems()) {
      result.addMetricItem(item);
    }
    for (Config config : decorateConfigOnRead(rule.getConfigs())) {
      transformConfig(config);
      result.addConfig(config);
    }
    return result;
  }
View Full Code Here

    return result;
  }

  public String deleteRule(String key) {
    Rule rule = m_config.getRules().get(key);

    if (rule != null) {
      decorateConfigOnDelete(rule.getConfigs());
      m_config.getRules().remove(key);
    }
    return m_config.toString();
  }
View Full Code Here

    }
    return decorateConfigOnRead(configs);
  }

  public Rule queryRule(String key) {
    Rule rule = m_config.getRules().get(key);

    if (rule != null) {
      return copyRuleWithDeepCopyConditions(rule);
    } else {
      return null;
View Full Code Here

      }
    }
  }

  public String updateRule(String id, String metricsStr, String configsStr) throws Exception {
    Rule rule = new Rule(id);
    List<MetricItem> metricItems = DefaultJsonParser.parseArray(MetricItem.class, metricsStr);
    List<Config> configs = DefaultJsonParser.parseArray(Config.class, configsStr);
    for (MetricItem metricItem : metricItems) {
      rule.addMetricItem(metricItem);
    }
    for (Config config : configs) {
      rule.addConfig(config);
    }
    decorateConfigOnStore(rule.getConfigs());
    m_config.getRules().put(id, rule);
    return m_config.toString();
  }
View Full Code Here

  @Test
  public void testJson() {
    try {
      InputStream is = this.getClass().getResourceAsStream(jsonPath);
      Rule rule = DefaultJsonParser.parse(Rule.class, is);

      Assert.assertNotNull(rule);
    } catch (Exception e) {
      Assert.assertNotNull(null);
    }
View Full Code Here

  private static final String CONFIG_NAME = "appRule";

  public void addDefultRule(String name, Integer commandId) {
    String ruleId = buildRuleId(name, commandId);
    Rule rule = new Rule(ruleId);

    rule.addConfig(buildDefaultConfig());
    m_config.addRule(rule);
    if (!storeConfig()) {
      Cat.logError("store app command rule error: " + name + " " + " " + commandId, new RuntimeException());
    }
  }
View Full Code Here

    return config;
  }

  private Rule buildDefaultRule(String product, String metricKey) {
    Rule rule = new Rule(metricKey);
    MetricItem item = new MetricItem();

    item.setProductText(product);
    item.setMetricItemText(metricKey);

    MetricItemConfig metricItem = m_metricConfigManager.queryMetricItemConfig(metricKey);
    if (metricItem != null) {
      if (metricItem.isShowAvg()) {
        item.setMonitorAvg(true);
      }
      if (metricItem.isShowCount()) {
        item.setMonitorCount(true);
      }
      if (metricItem.isShowSum()) {
        item.setMonitorSum(true);
      }
    }

    rule.addMetricItem(item);
    rule.addConfig(buildDefaultConfig());
    return rule;
  }
View Full Code Here

    }
  }

  @Override
  public List<com.dianping.cat.home.rule.entity.Config> queryConfigs(String product, String metricKey, MetricType type) {
    Rule rule = m_config.getRules().get(metricKey);
    List<com.dianping.cat.home.rule.entity.Config> configs = new ArrayList<com.dianping.cat.home.rule.entity.Config>();

    if (rule == null) {
      configs.add(buildDefaultConfig());
      return configs;
    } else {
      for (MetricItem item : rule.getMetricItems()) {
        if (type == MetricType.COUNT && item.isMonitorCount()) {
          configs.addAll(rule.getConfigs());
          break;
        } else if (type == MetricType.AVG && item.isMonitorAvg()) {
          configs.addAll(rule.getConfigs());
          break;
        } else if (type == MetricType.SUM && item.isMonitorSum()) {
          configs.addAll(rule.getConfigs());
          break;
        } else {
          Cat.logError("No Metric Type find. product:" + product + " metric key:" + metricKey,
                new RuntimeException());
        }
      }
      if (configs.size() == 0) {
        configs.add(buildDefaultConfig());
      } else {
        Cat.logEvent("FindRule:" + getConfigName(), rule.getId(), Event.SUCCESS, product + "," + metricKey);
      }
      return decorateConfigOnRead(configs);
    }
  }
View Full Code Here

TOP

Related Classes of com.dianping.cat.home.rule.entity.Rule

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.