sunty
2020-04-17 f4c1ad199cdd31a454a60e50661db0de1747977a
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package controllers
 
import (
    "fmt"
    "github.com/gin-gonic/gin"
    "strings"
    "swfs/code"
    "swfs/config"
    "swfs/tools/es"
    "swfs/tools/middleware"
    "swfs/tools/script"
    "swfs/util"
    "time"
)
 
type SeaweedfsController struct{}
 
type SWFSInfo struct {
    Role string `json:"role"`
}
 
func (sc *SeaweedfsController) UpdateSWFSServiceController(c *gin.Context) {
    script.ReplaceLineContentBySearch(es.GetNewPeers(), config.Peer, config.Server.ScriptPath, config.StartServerScript)
    util.ResponseFormat(c, code.Success, config.Server.EsServerIp+"更新成功")
}
 
// @Security ApiKeyAuth
// @Summary 新节点加入
// @Description  新节点加入
// @Accept  json
// @Produce json
// @Tags swfs
// @Param obj body SWFSInfo true "加入角色参数"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /node/api-v/swfs/addSWFSNode [POST]
func (sc *SeaweedfsController) AddSWFSNodeController(c *gin.Context) {
    var body SWFSInfo
    c.BindJSON(&body)
    role := body.Role
    if role == "master" {
        middleware.AsMaster(role)
        util.ResponseFormat(c, code.AddSuccess, "加入节点成功")
        return
    } else if role == "volume" {
        status := middleware.AsVolume()
        if status == true {
            util.ResponseFormat(c, code.AddSuccess, "加入节点成功")
            return
        } else {
            util.ResponseFormat(c, code.AddClusterInfoErr, "当前还没有主节点")
            return
        }
    } else if role == "master+volume" {
        middleware.AsMaVo(role)
        util.ResponseFormat(c, code.AddSuccess, "加入节点成功")
    } else {
        util.ResponseFormat(c, code.RequestParamError, "选择节点类型错误")
        return
    }
 
}
 
func (sc *SeaweedfsController) RoleOfVolumeToMasterController(c *gin.Context) {
    middleware.AsMaster("master+volume")
    util.ResponseFormat(c, code.Success, "角色添加成功")
}
 
func (sc *SeaweedfsController) RestartServerController(c *gin.Context) {
    script.StopServer(config.Server.ScriptPath)
    script.StartServer(config.Server.ScriptPath)
    time.Sleep(time.Second * 1)
    //fmt.Println("GetLocalStartupItem: ", GetLocalStartupItem(config.Server.ScriptPath, StartServerScript))
    result := strings.Split(middleware.GetLocalStartupItem(config.Server.ScriptPath, config.StartServerScript), "=")[1]
    fmt.Println("result: ", result)
    util.ResponseFormat(c, code.Success, result)
}