MCPcopy Create free account
hub / github.com/apache/kvrocks-controller / Create

Method Create

server/api/node.go:42–68  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

40}
41
42func (handler *NodeHandler) Create(c *gin.Context) {
43 ns := c.Param("namespace")
44 cluster, _ := c.MustGet(consts.ContextKeyCluster).(*store.Cluster)
45 var req struct {
46 Addr string `json:"addr" binding:"required"`
47 Role string `json:"role"`
48 Password string `json:"password"`
49 }
50 if err := c.ShouldBindJSON(&req); err != nil {
51 helper.ResponseBadRequest(c, err)
52 return
53 }
54 if req.Role == "" {
55 req.Role = store.RoleSlave
56 }
57 shardIndex, _ := strconv.Atoi(c.Param("shard"))
58 newNode, err := cluster.AddNode(shardIndex, req.Addr, req.Role, req.Password)
59 if err != nil {
60 helper.ResponseError(c, err)
61 return
62 }
63 if err := handler.s.UpdateCluster(c, ns, cluster); err != nil {
64 helper.ResponseError(c, err)
65 return
66 }
67 helper.ResponseCreated(c, newNode.ID())
68}
69
70func (handler *NodeHandler) Remove(c *gin.Context) {
71 ns := c.Param("namespace")

Callers 1

TestNodeBasicsFunction · 0.95

Calls 6

ResponseBadRequestFunction · 0.92
ResponseErrorFunction · 0.92
ResponseCreatedFunction · 0.92
UpdateClusterMethod · 0.65
IDMethod · 0.65
AddNodeMethod · 0.45

Tested by 1

TestNodeBasicsFunction · 0.76