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

Function printCluster

cmd/client/command/helper.go:40–62  ·  view source on GitHub ↗
(cluster *store.Cluster)

Source from the content-addressed store, hash-verified

38}
39
40func printCluster(cluster *store.Cluster) {
41 writer := tablewriter.NewWriter(os.Stdout)
42 printLine("")
43 printLine("cluster: %s", cluster.Name)
44 printLine("version: %d\n", cluster.Version.Load())
45 writer.SetHeader([]string{"SHARD", "NODE_ID", "ADDRESS", "ROLE", "MIGRATING"})
46 writer.SetCenterSeparator("|")
47 for i, shard := range cluster.Shards {
48 for _, node := range shard.Nodes {
49 role := strings.ToUpper(store.RoleSlave)
50 if node.IsMaster() {
51 role = strings.ToUpper(store.RoleMaster)
52 }
53 migratingStatus := "NO"
54 if shard.IsMigrating() {
55 migratingStatus = fmt.Sprintf("%s --> %d", shard.MigratingSlot, shard.TargetShardIndex)
56 }
57 columns := []string{fmt.Sprintf("%d", i), node.ID(), node.Addr(), role, migratingStatus}
58 writer.Append(columns)
59 }
60 }
61 writer.Render()
62}

Callers 1

getClusterFunction · 0.85

Calls 5

printLineFunction · 0.85
IsMigratingMethod · 0.80
IsMasterMethod · 0.65
IDMethod · 0.65
AddrMethod · 0.65

Tested by

no test coverage detected