(w fmt.State, _ rune)
| 39 | } |
| 40 | |
| 41 | func (c Cluster) Format(w fmt.State, _ rune) { |
| 42 | tw := new(tabwriter.Writer) |
| 43 | fmt.Fprintf(w, "CLUSTER: %q\n\n", c.ClusterID) |
| 44 | |
| 45 | tw.Init(w, 0, 8, 2, ' ', 0) |
| 46 | fmt.Fprint(tw, " BROKER\tHOST\tPORT\tRACK\tCONTROLLER\n") |
| 47 | |
| 48 | for _, id := range c.BrokerIDs() { |
| 49 | broker := c.Brokers[id] |
| 50 | fmt.Fprintf(tw, " %d\t%s\t%d\t%s\t%t\n", broker.ID, broker.Host, broker.Port, broker.Rack, broker.ID == c.Controller) |
| 51 | } |
| 52 | |
| 53 | tw.Flush() |
| 54 | fmt.Fprintln(w) |
| 55 | |
| 56 | tw.Init(w, 0, 8, 2, ' ', 0) |
| 57 | fmt.Fprint(tw, " TOPIC\tPARTITIONS\tBROKERS\n") |
| 58 | topicNames := c.TopicNames() |
| 59 | brokers := make(map[int32]struct{}, len(c.Brokers)) |
| 60 | brokerIDs := make([]int32, 0, len(c.Brokers)) |
| 61 | |
| 62 | for _, name := range topicNames { |
| 63 | topic := c.Topics[name] |
| 64 | |
| 65 | for _, p := range topic.Partitions { |
| 66 | for _, id := range p.Replicas { |
| 67 | brokers[id] = struct{}{} |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | for id := range brokers { |
| 72 | brokerIDs = append(brokerIDs, id) |
| 73 | } |
| 74 | |
| 75 | fmt.Fprintf(tw, " %s\t%d\t%s\n", topic.Name, len(topic.Partitions), formatBrokerIDs(brokerIDs, -1)) |
| 76 | |
| 77 | for id := range brokers { |
| 78 | delete(brokers, id) |
| 79 | } |
| 80 | |
| 81 | brokerIDs = brokerIDs[:0] |
| 82 | } |
| 83 | |
| 84 | tw.Flush() |
| 85 | fmt.Fprintln(w) |
| 86 | |
| 87 | if w.Flag('+') { |
| 88 | for _, name := range topicNames { |
| 89 | fmt.Fprintf(w, " TOPIC: %q\n\n", name) |
| 90 | |
| 91 | tw.Init(w, 0, 8, 2, ' ', 0) |
| 92 | fmt.Fprint(tw, " PARTITION\tREPLICAS\tISR\tOFFLINE\n") |
| 93 | |
| 94 | for _, p := range c.Topics[name].Partitions { |
| 95 | fmt.Fprintf(tw, " %d\t%s\t%s\t%s\n", p.ID, |
| 96 | formatBrokerIDs(p.Replicas, -1), |
| 97 | formatBrokerIDs(p.ISR, p.Leader), |
| 98 | formatBrokerIDs(p.Offline, -1), |
nothing calls this directly
no test coverage detected