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

Method handleConfigConvert

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

Source from the content-addressed store, hash-verified

251}
252
253func (t *cmdAdmin) handleConfigConvert(d map[string]interface{}) {
254 defer func() {
255 if x := recover(); x != nil {
256 log.Panicf("convert config failed: %+v", x)
257 }
258 }()
259
260 cfg1 := t.loadJsonConfigV1(utils.ArgumentMust(d, "--config-convert"))
261 cfg2 := &ConfigV3{}
262
263 if slots := cfg1["slots"]; slots != nil {
264 temp := make(map[int]*models.SlotMapping)
265 for _, v := range slots.(map[string]interface{}) {
266 t.convertSlotsV1(temp, v)
267 }
268 for i := 0; i < models.MaxSlotNum; i++ {
269 if temp[i] == nil {
270 continue
271 }
272 cfg2.Slots = append(cfg2.Slots, temp[i])
273 }
274 }
275
276 if servers := cfg1["servers"]; servers != nil {
277 group := make(map[int]*models.Group)
278 for _, g := range servers.(map[string]interface{}) {
279 for _, v := range g.(map[string]interface{}) {
280 t.convertGroupV1(group, v)
281 }
282 }
283 cfg2.Group = models.SortGroup(group)
284 }
285
286 b, err := json.MarshalIndent(cfg2, "", " ")
287 if err != nil {
288 log.PanicErrorf(err, "json marshal failed")
289 }
290 fmt.Println(string(b))
291}
292
293func (t *cmdAdmin) loadJsonConfigV3(file string) *ConfigV3 {
294 b, err := ioutil.ReadFile(file)

Callers 1

MainMethod · 0.95

Calls 6

loadJsonConfigV1Method · 0.95
convertSlotsV1Method · 0.95
convertGroupV1Method · 0.95
PanicfMethod · 0.80
PanicErrorfMethod · 0.80
PrintlnMethod · 0.80

Tested by

no test coverage detected