@@ -55,6 +55,9 @@ const (
5555 NameColumn = "NAME"
5656 publisherColumn = "PUBLISHER"
5757 receiverColumn = "RECEIVER"
58+ machineColumn = "MACHINE"
59+ rackColumn = "RACK"
60+ siteColumn = "SITE"
5861 avgSize = "AVG SIZE"
5962 avgApply = "AVG APPLY"
6063 avgBacklogDelay = "AVG BACKLOG DELAY"
@@ -579,6 +582,76 @@ func FormatTopicsSummary(topicDetails []config.TopicDetail) string {
579582 return table .String ()
580583}
581584
585+ // FormatPartitionOwnership returns the partition ownership in column formatted output.
586+ func FormatPartitionOwnership (partitionDetails map [int ]* config.PartitionOwnership ) string {
587+ var (
588+ ownershipCount = len (partitionDetails )
589+ keys = make ([]int , 0 )
590+ header = []string {MemberColumn , "PRIMARIES" , "BACKUPS" , "PRIMARY PARTITIONS" }
591+ )
592+ if ownershipCount == 0 {
593+ return ""
594+ }
595+
596+ // get and sort the keys
597+ for k := range partitionDetails {
598+ keys = append (keys , k )
599+ }
600+ sort .Ints (keys )
601+
602+ // get the backup-count
603+ backupCount := utils .GetBackupCount (partitionDetails )
604+
605+ if OutputFormat == constants .WIDE {
606+ header = []string {MemberColumn , machineColumn , rackColumn , siteColumn , "PRIMARIES" , "BACKUPS" , "PRIMARY" }
607+ }
608+
609+ // build the header for the backups
610+ for i := 0 ; i < backupCount ; i ++ {
611+ header = append (header , fmt .Sprintf ("BACKUP %d" , i + 1 ))
612+ }
613+
614+ table := newFormattedTable ().WithAlignment (generateColumnFormats (backupCount )... ).WithHeader (header ... )
615+
616+ for j := 0 ; j < len (keys ); j ++ {
617+ key := keys [j ]
618+ value := partitionDetails [key ]
619+
620+ memberID := "Orphaned"
621+ if value .MemberID != - 1 {
622+ memberID = fmt .Sprintf ("%v" , value .MemberID )
623+ }
624+
625+ table .AddRow (memberID )
626+
627+ if OutputFormat == constants .WIDE {
628+ table .AddColumnsToRow (value .Machine , value .Rack , value .Site )
629+ }
630+
631+ table .AddColumnsToRow (formatSmallInteger (int32 (value .PrimaryPartitions )),
632+ formatSmallInteger (int32 (value .BackupPartitions )))
633+
634+ // add primaries and backups
635+ for i := 0 ; i <= backupCount ; i ++ {
636+ table .AddColumnsToRow (utils .FormatPartitions (value .PartitionMap [i ]))
637+ }
638+ }
639+
640+ return table .String ()
641+ }
642+
643+ func generateColumnFormats (count int ) []string {
644+ result := []string {R , R , R , L }
645+ if OutputFormat == constants .WIDE {
646+ result = []string {R , L , L , L , R , R , L }
647+ }
648+
649+ for i := 0 ; i < count ; i ++ {
650+ result = append (result , L )
651+ }
652+ return result
653+ }
654+
582655// FormatTopicsSubscribers returns the topics subscriber details in column formatted output
583656func FormatTopicsSubscribers (topicsSubscribers []config.TopicsSubscriberDetail ) string {
584657 var (
@@ -1388,7 +1461,7 @@ func FormatMembers(members []config.Member, verbose bool, storageMap map[int]boo
13881461 WithAlignment (finalAlignment ... )
13891462
13901463 if OutputFormat == constants .WIDE {
1391- table .AddHeaderColumns ("MACHINE" , "RACK" , "SITE" , publisherColumn , receiverColumn )
1464+ table .AddHeaderColumns (machineColumn , rackColumn , siteColumn , publisherColumn , receiverColumn )
13921465 table .AddFormattingFunction (9 , networkStatsFormatter )
13931466 table .AddFormattingFunction (10 , networkStatsFormatter )
13941467 }
@@ -1813,7 +1886,7 @@ func FormatMachines(machines []config.Machine) string {
18131886 return strings .Compare (machines [p ].MachineName , machines [q ].MachineName ) < 0
18141887 })
18151888
1816- table := newFormattedTable ().WithHeader ("MACHINE" , "PROCESSORS" , "LOAD" , "TOTAL MEMORY" , "FREE MEMORY" ,
1889+ table := newFormattedTable ().WithHeader (machineColumn , "PROCESSORS" , "LOAD" , "TOTAL MEMORY" , "FREE MEMORY" ,
18171890 "% FREE" , "OS" , "ARCH" , "VERSION" ).WithAlignment (L , R , R , R , R , R , L , L , L )
18181891 table .AddFormattingFunction (5 , machineMemoryFormatting )
18191892
0 commit comments