From 15574512dca10c90c9c872c8049d8f4cd4135998 Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期五, 01 十一月 2019 18:10:13 +0800 Subject: [PATCH] fix add cluster --- controllers/es.go | 64 ++++++++++++++++++++++---------- 1 files changed, 44 insertions(+), 20 deletions(-) diff --git a/controllers/es.go b/controllers/es.go index 412d64f..46cacf6 100644 --- a/controllers/es.go +++ b/controllers/es.go @@ -26,7 +26,7 @@ type EsClusterInfo struct { Ip string `json:"ip"` } - +// @Security ApiKeyAuth // @Summary 姣斿鏁版嵁鏌ヨ // @Description 姣斿鏁版嵁鏌ヨ // @Accept json @@ -43,28 +43,28 @@ 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{} { @@ -114,7 +114,7 @@ //浣跨敤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 } @@ -163,7 +163,16 @@ 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) @@ -185,7 +194,7 @@ util.ResponseFormat(c, code.QueryClusterInfoErr, err) return } - util.ResponseFormat(c, code.QueryClusterInfoErr, nodeInfos) + util.ResponseFormat(c, code.Success, nodeInfos) } //鏌ヨES闆嗙兢淇℃伅-涓氬姟閫昏緫 @@ -230,7 +239,15 @@ 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" @@ -241,10 +258,8 @@ 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 @@ -252,7 +267,16 @@ 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) @@ -260,7 +284,7 @@ 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 { @@ -301,8 +325,8 @@ 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() -- Gitblit v1.8.0