| 90 | } |
| 91 | |
| 92 | func (handler *ShardHandler) Remove(c *gin.Context) { |
| 93 | ns := c.Param("namespace") |
| 94 | shardIdx, err := strconv.Atoi(c.Param("shard")) |
| 95 | if err != nil { |
| 96 | helper.ResponseBadRequest(c, err) |
| 97 | return |
| 98 | } |
| 99 | cluster, _ := c.MustGet(consts.ContextKeyCluster).(*store.Cluster) |
| 100 | |
| 101 | if shardIdx < 0 || shardIdx >= len(cluster.Shards) { |
| 102 | helper.ResponseBadRequest(c, consts.ErrIndexOutOfRange) |
| 103 | return |
| 104 | } |
| 105 | if cluster.Shards[shardIdx].IsServicing() { |
| 106 | helper.ResponseBadRequest(c, consts.ErrShardIsServicing) |
| 107 | return |
| 108 | } |
| 109 | cluster.Shards = append(cluster.Shards[:shardIdx], cluster.Shards[shardIdx+1:]...) |
| 110 | if err := handler.s.UpdateCluster(c, ns, cluster); err != nil { |
| 111 | helper.ResponseError(c, err) |
| 112 | return |
| 113 | } |
| 114 | helper.ResponseNoContent(c) |
| 115 | } |
| 116 | |
| 117 | func (handler *ShardHandler) Failover(c *gin.Context) { |
| 118 | ns := c.Param("namespace") |