MCPcopy
hub / github.com/eolinker/goku_lite / AddNode

Function AddNode

console/controller/node/node.go:47–122  ·  view source on GitHub ↗

AddNode 新增节点信息

(httpResponse http.ResponseWriter, httpRequest *http.Request)

Source from the content-addressed store, hash-verified

45
46//AddNode 新增节点信息
47func AddNode(httpResponse http.ResponseWriter, httpRequest *http.Request) {
48
49 cluserName := httpRequest.PostFormValue("cluster")
50
51 clusterID := cluster.GetClusterIDByName(cluserName)
52 if clusterID == 0 {
53 controller.WriteError(httpResponse, "340003", "", "[ERROR]Illegal cluster!", nil)
54 return
55 }
56
57 //nodeNumber := rsa.CertConf["nodeNumber"].(int)
58 type NodeParam struct {
59 NodeName string `opt:"nodeName,require"`
60 ListenAddress string `opt:"listenAddress,require"`
61 AdminAddress string `opt:"adminAddress,require"`
62 GroupID int `opt:"groupID,require"`
63 Path string `opt:"gatewayPath"`
64 }
65
66 param := new(NodeParam)
67 err := auto.SetValues(httpRequest.Form, param)
68 if err != nil {
69 controller.WriteError(httpResponse, "230015", "", "[ERROR]", err)
70 return
71 }
72 if !utils.ValidateRemoteAddr(param.ListenAddress) {
73 controller.WriteError(httpResponse,
74 "230006",
75 "node", "[ERROR]Illegal listenAddress!",
76 errors.New("illegal listenAddress"))
77 return
78 }
79 if !utils.ValidateRemoteAddr(param.AdminAddress) {
80 controller.WriteError(httpResponse,
81 "230007",
82 "node", "[ERROR]Illegal listenAddress!",
83 errors.New("illegal listenAddress"))
84 return
85 }
86 if param.GroupID != 0 {
87 // 检查分组是否存在
88 flag, err := node.CheckNodeGroupIsExist(param.GroupID)
89
90 if !flag {
91 controller.WriteError(
92 httpResponse,
93 "230014",
94 "node",
95 "[ERROR]The node group does not exist!",
96 err)
97 return
98 }
99 }
100
101 id, v, result, err := node.AddNode(clusterID, param.NodeName, param.ListenAddress, param.AdminAddress, param.Path, param.GroupID)
102
103 if err != nil {
104 controller.WriteError(httpResponse,

Callers

nothing calls this directly

Calls 7

GetClusterIDByNameFunction · 0.92
WriteErrorFunction · 0.92
ValidateRemoteAddrFunction · 0.92
CheckNodeGroupIsExistFunction · 0.92
AddNodeFunction · 0.92
NewMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected