From c38c4bda17e3774ec0fd58f90ba5e59e1f0639a2 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期三, 30 十月 2019 16:39:29 +0800
Subject: [PATCH] swagger add ApiKeyAuth

---
 controllers/es.go |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 57 insertions(+), 1 deletions(-)

diff --git a/controllers/es.go b/controllers/es.go
index 93d686f..dd53714 100644
--- a/controllers/es.go
+++ b/controllers/es.go
@@ -21,6 +21,7 @@
 
 type EsController struct{}
 
+// @Security ApiKeyAuth
 // @Summary 姣斿鏁版嵁鏌ヨ
 // @Description  姣斿鏁版嵁鏌ヨ
 // @Accept  json
@@ -195,7 +196,7 @@
 		nodeInfo["ip"] = nodeIp
 		nodeInfo["nodeType"] = nodeType
 		url := "http://"+nodeIp+":9200"
-		buf := esutil.httpGet(url)
+		buf := esutil.HttpGet(url)
 		var info interface{}
 		json.Unmarshal(buf,&info)
 		tmpInfo := info.(map[string]interface{})
@@ -209,3 +210,58 @@
 
 	return nodeInfos,nil
 }
+
+func AddEsCluster(hosts []string) (string){
+	msg := "鍔犲叆澶辫触"
+	for i,val := range hosts{
+		val =val+":9300"
+		hosts[i] = val
+	}
+	verificationHosts := "[\""+strings.Replace(strings.Trim(fmt.Sprint(hosts), "[]"), " ", "\",\"", -1)+"\"]"
+	for i,val := range hosts{
+		val ="\\\""+val+"\\\""
+		hosts[i] = val
+	}
+	oldUnicastHost := "\\[\\\"0.0.0.0:9300\\\"\\]"
+	newUnicastHost := strings.Replace(strings.Trim(fmt.Sprint(hosts), ""), " ", ",", -1)
+	str := "sed -ie 's/discovery.zen.ping.unicast.hosts: "+oldUnicastHost+"/discovery.zen.ping.unicast.hosts: "+newUnicastHost+"/g' /opt/elasticsearch/config/elasticsearch.yml"
+	fmt.Println(str)
+	cmd := exec.Command("sh","-c",str)
+	var out bytes.Buffer
+	cmd.Stdout = &out
+	err := cmd.Run()
+	if err != nil {
+
+	}
+	res := getUnicastHosts()
+	fmt.Println("res:          ",res)
+	res1 := "discovery.zen.ping.unicast.hosts: "+verificationHosts+""
+	fmt.Println("res1:         ",res1)
+	if res == res1{
+		msg = "鍔犲叆鎴愬姛"
+	}
+	str2 := "echo \"node.master: true\" >> /opt/elasticsearch/config/elasticsearch.yml"
+	cmd2 := exec.Command("sh","-c",str2)
+	var out2 bytes.Buffer
+	cmd2.Stdout = &out2
+	err2 := cmd2.Run()
+	if err2 != nil {
+		msg = "鍔犲叆澶辫触"
+	}
+	return msg
+
+}
+
+func getUnicastHosts() (string){
+	str := "cat /opt/elasticsearch/config/elasticsearch.yml | grep discovery.zen.ping.unicast.hosts:"
+	cmd := exec.Command("sh","-c",str)
+	var out bytes.Buffer
+	cmd.Stdout = &out
+	err := cmd.Run()
+	if err != nil {
+
+	}
+	infos := strings.Split(string(out.String()),"\n")[0]
+	return infos
+
+}

--
Gitblit v1.8.0