zhangzengfei
2023-09-04 e8e536d1cb52d2126c8c7ce2ba1c7a76f7208678
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package controllers
 
import (
    "basic.com/pubsub/esutil.git"
    "basic.com/valib/bhomeclient.git"
    "vamicro/config"
    "vamicro/system-service/sys"
)
 
type SyncEsNodeController struct {
}
 
type HostInfo struct {
    BinPath    string   `json:"binPath"`
    ConfigPath string   `json:"configPath"`
    Hosts      []string `json:"hosts"`
}
 
//同步Hosts
func (sen *SyncEsNodeController) SynchronizeHosts(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var hi HostInfo
    c.BindJSON(&hi)
    localIp, _, _ := sys.GetLocalIP(config.Server.NetworkAdapter)
    localPort := "9200"
    sp := esutil.StopServer(hi.BinPath, localIp, localPort)
    if sp == false {
        return &bhomeclient.Reply{Msg: "配置文件错误,本机ip获取失败"}
    }
    _, errS := esutil.SetDiscoveryZenPingUnicastHosts(hi.ConfigPath, hi.Hosts)
    if errS != nil {
        return &bhomeclient.Reply{Msg: errS.Error()}
    }
    st := esutil.StartServer(hi.BinPath, localIp, localPort)
    if st == false {
        return &bhomeclient.Reply{Msg: "服务启动超时"}
    }
    return &bhomeclient.Reply{Success: true, Msg: "修改成功"}
}