예제 #1
0
  private Pair<Boolean, String> graphProductLineConfigAddOrUpdateSubmit(
      Payload payload, Model model) {
    ProductLine line = payload.getProductLine();
    String[] domains = payload.getDomains();
    String type = payload.getType();

    return m_productLineConfigManger.insertProductLine(line, domains, type);
  }
예제 #2
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));
    }
  }
예제 #3
0
  private void graphEdgeConfigAdd(Payload payload, Model model) {
    String type = payload.getType();
    String from = payload.getFrom();
    String to = payload.getTo();
    EdgeConfig config = m_topologyConfigManager.queryEdgeConfig(type, from, to);

    model.setEdgeConfig(config);
  }
예제 #4
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));
    }
  }
예제 #5
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;
    }
  }
예제 #6
0
  private boolean graphNodeConfigAddOrUpdateSubmit(Payload payload, Model model) {
    String type = payload.getType();
    DomainConfig config = payload.getDomainConfig();
    String domain = config.getId();
    model.setDomainConfig(config);

    if (Constants.ALL.equalsIgnoreCase(domain)) {
      return m_topologyConfigManager.insertDomainDefaultConfig(type, config);
    } else {
      return m_topologyConfigManager.insertDomainConfig(type, config);
    }
  }
예제 #7
0
  private void buildListInfo(Model model, Payload payload) {
    int id = 0;
    List<Command> commands = m_appConfigManager.queryCommands();

    if ("code".equals(payload.getType()) && payload.getId() > 0) {
      id = payload.getId();
    } else {
      if (!commands.isEmpty()) {
        id = commands.iterator().next().getId();
      }
    }
    Command cmd = m_appConfigManager.getRawCommands().get(id);

    if (cmd != null) {
      model.setUpdateCommand(cmd);
      model.setId(String.valueOf(id));
    }

    buildBatchApiConfig(payload, model);
    model.setSpeeds(m_appSpeedConfigManager.getConfig().getSpeeds());
    model.setCodes(m_appConfigManager.getCodes());
  }
예제 #8
0
  public void appRuleBatchUpdate(Payload payload, Model model) {
    String content = payload.getContent();
    String[] paths = content.split(",");

    for (String path : paths) {
      try {
        if (StringUtils.isNotEmpty(path) && !m_appConfigManager.getCommands().containsKey(path)) {
          Command command = new Command();

          command.setDomain("").setTitle(path).setName(path);
          m_appConfigManager.addCommand(command);
        }
      } catch (Exception e) {
        Cat.logError(e);
      }
    }
  }
예제 #9
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());
    }
  }
예제 #10
0
 private boolean graphNodeConfigDelete(Payload payload) {
   return m_topologyConfigManager.deleteDomainConfig(payload.getType(), payload.getDomain());
 }
예제 #11
0
 private boolean graphEdgeConfigDelete(Payload payload) {
   return m_topologyConfigManager.deleteEdgeConfig(
       payload.getType(), payload.getFrom(), payload.getTo());
 }
예제 #12
0
  public void process(Action action, Payload payload, Model model) {
    int id;

    switch (action) {
      case APP_NAME_CHECK:
        if (m_appConfigManager.isNameDuplicate(payload.getName())) {
          model.setNameUniqueResult("{\"isNameUnique\" : false}");
        } else {
          model.setNameUniqueResult("{\"isNameUnique\" : true}");
        }
        break;
      case APP_LIST:
        buildListInfo(model, payload);
        break;
      case APP_COMMMAND_UPDATE:
        id = payload.getId();

        if (m_appConfigManager.containCommand(id)) {
          Command command = m_appConfigManager.getConfig().findCommand(id);

          if (command == null) {
            command = new Command();
          }
          model.setUpdateCommand(command);
        }
        break;
      case APP_COMMAND_SUBMIT:
        id = payload.getId();
        String domain = payload.getDomain();
        String name = payload.getName();
        String title = payload.getTitle();
        boolean all = payload.isAll();
        int timeThreshold = payload.getThreshold();

        if (m_appConfigManager.containCommand(id)) {
          Command command = new Command();

          command
              .setDomain(domain)
              .setName(name)
              .setTitle(title)
              .setAll(all)
              .setThreshold(timeThreshold);

          if (m_appConfigManager.updateCommand(id, command)) {
            model.setOpState(true);
          } else {
            model.setOpState(false);
          }
        } else {
          try {
            Command command =
                new Command()
                    .setDomain(domain)
                    .setTitle(title)
                    .setName(name)
                    .setAll(all)
                    .setThreshold(timeThreshold);

            if (m_appConfigManager.addCommand(command).getKey()) {
              model.setOpState(true);
            } else {
              model.setOpState(false);
            }
          } catch (Exception e) {
            model.setOpState(false);
          }
        }
        buildListInfo(model, payload);
        break;
      case APP_COMMAND_DELETE:
        id = payload.getId();

        if (m_appConfigManager.deleteCommand(id)) {
          model.setOpState(true);
        } else {
          model.setOpState(false);
        }
        buildListInfo(model, payload);
        break;
      case APP_CODE_UPDATE:
        id = payload.getId();
        int codeId = payload.getCode();

        if (payload.isConstant()) {
          Code code = m_appConfigManager.getConfig().getCodes().get(codeId);

          model.setCode(code);
        } else {
          Command cmd = m_appConfigManager.getRawCommands().get(id);

          if (cmd != null) {
            Code code = cmd.getCodes().get(codeId);

            model.setCode(code);
            model.setUpdateCommand(cmd);
          }
        }
        break;
      case APP_CODE_SUBMIT:
        try {
          id = payload.getId();
          String codeStr = payload.getContent();
          List<String> strs = Splitters.by(":").split(codeStr);
          codeId = Integer.parseInt(strs.get(0));
          name = strs.get(1);
          int status = Integer.parseInt(strs.get(2));

          Code code = new Code(codeId);
          code.setName(name).setStatus(status);

          if (payload.isConstant()) {
            m_appConfigManager.updateCode(code);
          } else {
            m_appConfigManager.updateCode(id, code);
          }
          buildListInfo(model, payload);
        } catch (Exception e) {
          Cat.logError(e);
        }
        break;
      case APP_CODE_ADD:
        id = payload.getId();

        model.setId(String.valueOf(id));
        break;
      case APP_CODE_DELETE:
        try {
          id = payload.getId();
          codeId = payload.getCode();

          if (payload.isConstant()) {
            m_appConfigManager.getCodes().remove(codeId);
          } else {
            m_appConfigManager.deleteCode(id, codeId);
          }
          buildListInfo(model, payload);
        } catch (Exception e) {
          Cat.logError(e);
        }
        break;
      case APP_SPEED_UPDATE:
      case APP_SPEED_ADD:
        id = payload.getId();
        Speed speed = m_appSpeedConfigManager.getConfig().getSpeeds().get(id);

        if (speed != null) {
          model.setSpeed(speed);
        }
        break;
      case APP_SPEED_DELETE:
        try {
          id = payload.getId();

          m_appSpeedConfigManager.deleteSpeed(id);
          buildListInfo(model, payload);
        } catch (Exception e) {
          Cat.logError(e);
        }
        break;
      case APP_SPEED_SUBMIT:
        try {
          id = payload.getId();
          String speedStr = payload.getContent();
          List<String> strs = Splitters.by(":").split(speedStr);
          String page = strs.get(0).trim();
          int step = Integer.parseInt(strs.get(1).trim());
          title = strs.get(2).trim();
          int threshold = Integer.parseInt(strs.get(3).trim());
          int speedId = id > 0 ? id : m_appSpeedConfigManager.generateId();
          speed = new Speed(speedId);

          speed.setPage(page).setStep(step).setTitle(title).setThreshold(threshold);
          m_appSpeedConfigManager.updateConfig(speed);
          buildListInfo(model, payload);
        } catch (Exception e) {
          Cat.logError(e);
        }
        break;
      case APP_CONFIG_UPDATE:
        String appConfig = payload.getContent();
        if (!StringUtils.isEmpty(appConfig)) {
          model.setOpState(m_appConfigManager.insert(appConfig));
        }
        model.setContent(m_appConfigManager.getConfig().toString());
        break;
      case APP_RULE:
        buildAppConfigInfo(m_appConfigManager, model);
        model.setRules(m_appRuleConfigManager.getMonitorRules().getRules().values());
        break;
      case APP_RULE_ADD_OR_UPDATE:
        buildAppConfigInfo(m_appConfigManager, model);
        generateRuleConfigContent(payload.getRuleId(), m_appRuleConfigManager, model);
        break;
      case APP_RULE_ADD_OR_UPDATE_SUBMIT:
        buildAppConfigInfo(m_appConfigManager, model);
        model.setOpState(
            addSubmitRule(m_appRuleConfigManager, payload.getRuleId(), "", payload.getConfigs()));
        model.setRules(m_appRuleConfigManager.getMonitorRules().getRules().values());
        break;
      case APP_RULE_DELETE:
        buildAppConfigInfo(m_appConfigManager, model);
        model.setOpState(deleteRule(m_appRuleConfigManager, payload.getRuleId()));
        model.setRules(m_appRuleConfigManager.getMonitorRules().getRules().values());
        break;
      case APP_COMPARISON_CONFIG_UPDATE:
        String appComparisonConfig = payload.getContent();
        if (!StringUtils.isEmpty(appComparisonConfig)) {
          model.setOpState(m_appComparisonConfigManager.insert(appComparisonConfig));
        }
        model.setContent(m_appComparisonConfigManager.getConfig().toString());
        break;
      case APP_RULE_BATCH_UPDATE:
        appRuleBatchUpdate(payload, model);
        buildListInfo(model, payload);
        break;
      case APP_CONSTANT_ADD:
        break;
      case APP_CONSTANT_UPDATE:
        Item item = m_appConfigManager.queryItem(payload.getType(), payload.getId());

        model.setAppItem(item);
        break;
      case APP_CONSTATN_SUBMIT:
        try {
          id = payload.getId();
          String content = payload.getContent();
          String[] strs = content.split(":");
          String type = strs[0];
          int constantId = Integer.valueOf(strs[1]);
          String value = strs[2];

          model.setOpState(m_appConfigManager.addConstant(type, constantId, value));
          buildListInfo(model, payload);
        } catch (Exception e) {
          Cat.logError(e);
        }
        break;
      case APP_COMMAND_FORMAT_CONFIG:
        String content = payload.getContent();

        if (StringUtils.isNotEmpty(content)) {
          m_urlConfigManager.insert(content);
        }
        model.setContent(m_urlConfigManager.getUrlFormat().toString());
        break;
      default:
        throw new RuntimeException("Error action name " + action.getName());
    }
  }