| | |
| | | type EsClusterInfo struct { |
| | | Ip string `json:"ip"` |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 比对数据查询 |
| | | // @Description 比对数据查询 |
| | | // @Accept json |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | if searchBody.CompareNum != "" { |
| | | if searchBody.CompareNum !="" { |
| | | //二次搜索,不需要再比对了 |
| | | co := service.GetCompResultByNum(searchBody.CompareNum) |
| | | if co != nil { |
| | | //二次搜索和排序 |
| | | twiceM := GetCompareDataTwice(co, searchBody) |
| | | util.ResponseFormat(c, code.Success, twiceM) |
| | | twiceM := GetCompareDataTwice(co,searchBody) |
| | | util.ResponseFormat(c,code.Success,twiceM) |
| | | return |
| | | } else { |
| | | m := make(map[string]interface{}, 0) |
| | | m :=make(map[string]interface{},0) |
| | | m["compareNum"] = searchBody.CompareNum |
| | | m["total"] = 0 |
| | | m["totalList"] = []CompareResult{} |
| | | util.ResponseFormat(c, code.CompareResultGone, m) |
| | | util.ResponseFormat(c,code.CompareResultGone,m) |
| | | return |
| | | } |
| | | } |
| | | m := make(map[string]interface{}, 0) |
| | | m :=make(map[string]interface{},0) |
| | | m["compareNum"] = searchBody.CompareNum |
| | | m["total"] = 0 |
| | | m["totalList"] = []CompareResult{} |
| | | util.ResponseFormat(c, code.CompareResultGone, m) |
| | | util.ResponseFormat(c,code.CompareResultGone,m) |
| | | } |
| | | |
| | | func searchEsData(searchBody models.EsSearch) map[string]interface{} { |
| | |
| | | //使用es底层机制处理分页 |
| | | //请求头 |
| | | localConf, err2 := cache.GetServerInfo() |
| | | if err2 != nil || localConf.AlarmIp == "" || localConf.ServerId == "" { |
| | | if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" { |
| | | logger.Debug("localConfig is wrong!!!") |
| | | return nil |
| | | } |
| | |
| | | return dataSource |
| | | } |
| | | |
| | | //查询ES集群信息-入口 |
| | | // @Security ApiKeyAuth |
| | | // @Summary 查询ES集群信息-入口 |
| | | // @Description 查询ES集群信息-入口 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags es |
| | | // @Param obj body controllers.EsClusterInfo true "查询集群参数" |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/es/getEsClusterInfo [POST] |
| | | func (em *EsManagementController) GetEsClusterInfo(c *gin.Context) { |
| | | var body EsClusterInfo |
| | | c.BindJSON(&body) |
| | |
| | | util.ResponseFormat(c, code.QueryClusterInfoErr, err) |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.QueryClusterInfoErr, nodeInfos) |
| | | util.ResponseFormat(c, code.Success, nodeInfos) |
| | | } |
| | | |
| | | //查询ES集群信息-业务逻辑 |
| | |
| | | return nodeInfos, err |
| | | } |
| | | |
| | | //创建节点 |
| | | // @Security ApiKeyAuth |
| | | // @Summary 创建节点 |
| | | // @Description 创建节点 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags es |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/es/createNode [POST] |
| | | func (em *EsManagementController) CreateNode(c *gin.Context) { |
| | | msg := "创建节点失败,请联系管理员" |
| | | str := "sh /opt/script/create_first_node.sh" |
| | |
| | | if err != nil { |
| | | |
| | | } |
| | | infos := strings.Split(string(out.String()), "\n") |
| | | len := len(infos) |
| | | res := infos[len-1] |
| | | if res == "服务启动成功" { |
| | | infos := strings.Split(string(out.String()), "\n")[0] |
| | | if infos == "服务启动成功" { |
| | | msg = "创建节点成功" |
| | | util.ResponseFormat(c, code.Success, msg) |
| | | return |
| | |
| | | util.ResponseFormat(c, code.CreateFirstNodeErr, msg) |
| | | } |
| | | |
| | | //加入集群 |
| | | // @Security ApiKeyAuth |
| | | // @Summary 加入集群 |
| | | // @Description 加入集群 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags es |
| | | // @Param obj body controllers.AddCluster true "加入集群参数" |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/es/addCluster [POST] |
| | | func (em *EsManagementController) AddCluster(c *gin.Context) { |
| | | var ac AddCluster |
| | | err := c.BindJSON(&ac) |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | str := "sh /opt/script/create_node.sh " + ac.Option + "" |
| | | str := "sh /opt/script/add_cluster.sh " + ac.Option + "" |
| | | if ac.Option == "1" { |
| | | info, err := updateUnicastHosts(ac.Ip) |
| | | if err != nil || info == false { |
| | |
| | | cmd := exec.Command("sh", "-c", str) |
| | | var out bytes.Buffer |
| | | cmd.Stdout = &out |
| | | err1 := cmd.Run() |
| | | if err1 != nil { |
| | | err := cmd.Run() |
| | | if err != nil { |
| | | return "运行失败" |
| | | } |
| | | return out.String() |