Esempio n. 1
0
 public RainbowContext addMySQL(RainbowContext context) {
   Map<String, Object> attr = context.getAttr();
   MySqlServer m = JSONArray.parseObject(String.valueOf(attr.get("value")), MySqlServer.class);
   if (StringUtils.isEmpty(m.getName())) {
     context.setSuccess(false);
     context.setMsg("mysql名称为空");
     return context;
   }
   try {
     boolean existsNode = handler.existsNode(MyCAT_MYSQLS + "/" + m.getName());
     String guid_bak = null;
     if (existsNode
         && (StringUtils.isEmpty(attr.get("guid"))
             || !m.getName().equals(String.valueOf(attr.get("guid"))))) {
       context.setSuccess(false);
       context.setMsg("mysql实例已经存在");
       return context;
     }
     if ((!StringUtils.isEmpty(attr.get("guid")))) guid_bak = String.valueOf(attr.get("guid"));
     m.setGuid(m.getName());
     handler.updateNodeData(MyCAT_MYSQLS + "/" + m.getName(), JSONArray.toJSONString(m));
     if (!m.getName().equals(guid_bak) && (!StringUtils.isEmpty(guid_bak))) {
       handler.deleteNode(MyCAT_MYSQLS + "/" + guid_bak);
     }
     context.setSuccess(true);
     return context;
   } catch (Exception e) {
     // TODO Auto-generated catch block
     context.setSuccess(false);
     e.printStackTrace();
   }
   context.setSuccess(false);
   context.setMsg("违法操作");
   return context;
 }
Esempio n. 2
0
  public RainbowContext addMyRep(RainbowContext context) {
    Map<String, Object> attr = context.getAttr();
    String valueOf = String.valueOf(attr.get("value"));
    String ztree = String.valueOf(attr.get("ztree"));
    MySqlRep m = JSONArray.parseObject(String.valueOf(attr.get("value")), MySqlRep.class);
    if (StringUtils.isEmpty(m.getName())) {
      context.setSuccess(false);
      context.setMsg("mysql-rep名称为空");
      return context;
    }

    try {
      boolean existsNode = handler.existsNode(MyCAT_MYSQLGROUP + "/" + m.getName());
      String guid_bak = null;
      if (existsNode
          && (StringUtils.isEmpty(attr.get("guid"))
              || !m.getName().equals(String.valueOf(attr.get("guid"))))) {
        context.setSuccess(false);
        context.setMsg("mysql实例已经存在");
        return context;
      }

      List<ZtreeModel> list = JSONArray.parseArray(ztree, ZtreeModel.class);
      List<Map<String, String>> rep = new ArrayList<Map<String, String>>();
      for (ZtreeModel z : list) {
        Map<String, String> map = new HashMap<String, String>();
        String writeHost = z.getName();
        String readHosts = "";
        List<ZtreeModel> children = z.getChildren();
        if (children == null) continue;
        for (ZtreeModel ztreeModel : children) {
          readHosts = readHosts + "," + ztreeModel.getName();
        }
        map.put("writeHost", writeHost);
        if (!StringUtils.isEmpty(readHosts)) {
          map.put("readHosts", readHosts.substring(1));
        }
        rep.add(map);
      }
      if ((!StringUtils.isEmpty(attr.get("guid")))) guid_bak = String.valueOf(attr.get("guid"));
      m.setRep(rep);
      m.setGuid(m.getName());
      handler.updateNodeData(MyCAT_MYSQLGROUP + "/" + m.getName(), JSONArray.toJSONString(m));

      if (!m.getName().equals(guid_bak) && (!StringUtils.isEmpty(guid_bak))) {
        handler.deleteNode(MyCAT_MYSQLGROUP + "/" + guid_bak);
      }
      context.setSuccess(true);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      context.setSuccess(false);
      e.printStackTrace();
    }

    return context;
  }