| | |
| | | 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) |
| | |
| | | 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() |