MCPcopy
hub / github.com/CodisLabs/codis / handleSlotsCommand

Method handleSlotsCommand

cmd/admin/dashboard.go:204–280  ·  view source on GitHub ↗
(d map[string]interface{})

Source from the content-addressed store, hash-verified

202}
203
204func (t *cmdDashboard) handleSlotsCommand(d map[string]interface{}) {
205 c := t.newTopomClient()
206
207 switch {
208
209 case d["--slots-status"].(bool):
210
211 log.Debugf("call rpc slots to dashboard %s", t.addr)
212 o, err := c.Slots()
213 if err != nil {
214 log.PanicErrorf(err, "call rpc slots to dashboard %s failed", t.addr)
215 }
216 log.Debugf("call rpc slots OK")
217
218 b, err := json.MarshalIndent(o, "", " ")
219 if err != nil {
220 log.PanicErrorf(err, "json marshal failed")
221 }
222 fmt.Println(string(b))
223
224 case d["--slots-assign"].(bool) && d["--offline"].(bool):
225
226 beg := utils.ArgumentIntegerMust(d, "--beg")
227 end := utils.ArgumentIntegerMust(d, "--end")
228
229 slots := []*models.SlotMapping{}
230 for i := beg; i <= end; i++ {
231 slots = append(slots, &models.SlotMapping{
232 Id: i,
233 })
234 }
235
236 if !d["--confirm"].(bool) {
237 b, err := json.MarshalIndent(slots, "", " ")
238 if err != nil {
239 log.PanicErrorf(err, "json marshal failed")
240 }
241 fmt.Println(string(b))
242 return
243 }
244
245 log.Debugf("call rpc slots-assign to dashboard %s", t.addr)
246 if err := c.SlotsAssignOffline(slots); err != nil {
247 log.PanicErrorf(err, "call rpc slots-assign to dashboard %s failed", t.addr)
248 }
249 log.Debugf("call rpc slots-assign OK")
250
251 case d["--slots-assign"].(bool) && !d["--offline"].(bool):
252
253 beg := utils.ArgumentIntegerMust(d, "--beg")
254 end := utils.ArgumentIntegerMust(d, "--end")
255 gid := utils.ArgumentIntegerMust(d, "--gid")
256
257 slots := []*models.SlotMapping{}
258 for i := beg; i <= end; i++ {
259 slots = append(slots, &models.SlotMapping{
260 Id: i, GroupId: gid,
261 })

Callers 1

MainMethod · 0.95

Calls 7

newTopomClientMethod · 0.95
DebugfMethod · 0.80
PanicErrorfMethod · 0.80
PrintlnMethod · 0.80
SlotsMethod · 0.45
SlotsAssignOfflineMethod · 0.45
SlotsAssignGroupMethod · 0.45

Tested by

no test coverage detected