Skip to content

Commit 1d8432f

Browse files
author
Tim Middleton
authored
Add report ownership (#228)
* Add report ownership * Fix sonarcloud * Minor formatting
1 parent cdee274 commit 1d8432f

File tree

12 files changed

+623
-9
lines changed

12 files changed

+623
-9
lines changed

pkg/cmd/cluster.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,9 @@ var (
732732
extendClientParam bool
733733
grpcClientParam bool
734734
profileFirstParam bool
735+
machineParam string
736+
rackParam string
737+
siteParam string
735738
skipMavenDepsParam bool
736739
backupLogFilesParam bool
737740
validPersistenceModes = []string{"on-demand", "active", "active-backup", "active-async"}
@@ -1450,6 +1453,9 @@ func init() {
14501453
createClusterCmd.Flags().Int32VarP(&jmxRemotePortParam, jmxPortArg, "J", 0, jmxPortMessage)
14511454
createClusterCmd.Flags().StringVarP(&jmxRemoteHostParam, jmxHostArg, "j", "", jmxHostMessage)
14521455
createClusterCmd.Flags().BoolVarP(&profileFirstParam, profileFirstArg, "F", false, profileFirstMessage)
1456+
createClusterCmd.Flags().StringVarP(&machineParam, machineArg, "", "", machineMessage)
1457+
createClusterCmd.Flags().StringVarP(&rackParam, rackArg, "", "", rackMessage)
1458+
createClusterCmd.Flags().StringVarP(&siteParam, siteArg, "", "", siteMessage)
14531459

14541460
stopClusterCmd.Flags().BoolVarP(&automaticallyConfirm, "yes", "y", false, confirmOptionMessage)
14551461

@@ -1465,6 +1471,9 @@ func init() {
14651471
startClusterCmd.Flags().StringVarP(&jmxRemoteHostParam, jmxHostArg, "j", "", jmxHostMessage)
14661472
startClusterCmd.Flags().BoolVarP(&profileFirstParam, profileFirstArg, "F", false, profileFirstMessage)
14671473
startClusterCmd.Flags().BoolVarP(&backupLogFilesParam, backupLogFilesArg, "B", false, backupLogFilesMessage)
1474+
startClusterCmd.Flags().StringVarP(&machineParam, machineArg, "", "", machineMessage)
1475+
startClusterCmd.Flags().StringVarP(&rackParam, rackArg, "", "", rackMessage)
1476+
startClusterCmd.Flags().StringVarP(&siteParam, siteArg, "", "", siteMessage)
14681477

14691478
startConsoleCmd.Flags().StringVarP(&heapMemoryParam, heapMemoryArg, "M", defaultHeap, heapMemoryMessage)
14701479
startConsoleCmd.Flags().Int32VarP(&logLevelParam, logLevelArg, "l", 5, logLevelMessage)
@@ -1493,6 +1502,9 @@ func init() {
14931502
scaleClusterCmd.Flags().StringVarP(&profileValueParam, profileArg, "P", "", profileMessage)
14941503
scaleClusterCmd.Flags().StringVarP(&serverStartClassParam, startClassArg, "S", "", startClassMessage)
14951504
scaleClusterCmd.Flags().BoolVarP(&backupLogFilesParam, backupLogFilesArg, "B", false, backupLogFilesMessage)
1505+
scaleClusterCmd.Flags().StringVarP(&machineParam, machineArg, "", "", machineMessage)
1506+
scaleClusterCmd.Flags().StringVarP(&rackParam, rackArg, "", "", rackMessage)
1507+
scaleClusterCmd.Flags().StringVarP(&siteParam, siteArg, "", "", siteMessage)
14961508
}
14971509

14981510
// sanitizeConnectionName sanitizes a cluster connection

pkg/cmd/cluster_utils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,18 @@ func getCacheServerArgs(connection ClusterConnection, member string, httpPort in
412412
}
413413
}
414414

415+
if machineParam != "" {
416+
baseArgs = append(baseArgs, fmt.Sprintf("-Dcoherence.machine=%s", machineParam))
417+
}
418+
419+
if rackParam != "" {
420+
baseArgs = append(baseArgs, fmt.Sprintf("-Dcoherence.rack=%s", rackParam))
421+
}
422+
423+
if siteParam != "" {
424+
baseArgs = append(baseArgs, fmt.Sprintf("-Dcoherence.site=%s", siteParam))
425+
}
426+
415427
// if default heap is overridden, then use this
416428
if heapMemoryParam != defaultHeap {
417429
heap = heapMemoryParam

pkg/cmd/formatting.go

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
583656
func 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

pkg/cmd/monitor_cluster.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ var validPanels = []panelImpl{
102102
createContentPanel(8, "services", "Services", "show services", servicesContent, servicesPanelData),
103103
createContentPanel(8, "service-members", "Service Members (%SERVICE)", "show service members", serviceMembersContent, servicesPanelData),
104104
createContentPanel(8, "service-distributions", "Service Distributions (%SERVICE)", "show service distributions", serviceDistributionsContent, servicesPanelData),
105+
createContentPanel(8, "service-ownership", "Service Ownership (%SERVICE)", "show service ownership", serviceOwnershipContent, servicesPanelData),
105106
createContentPanel(8, "service-storage", "Service Storage", "show service storage", serviceStorageContent, servicesPanelData),
106107
createContentPanel(8, "topic-members", "Topic Members (%SERVICE/%TOPIC)", "show topic members", topicMembersContent, topicsPanelData),
107108
createContentPanel(8, "subscribers", "Topic Subscribers (%SERVICE/%TOPIC)", "show topic subscribers", topicSubscribersContent, topicsPanelData),
@@ -639,6 +640,61 @@ var serviceDistributionsContent = func(dataFetcher fetcher.Fetcher, _ clusterSum
639640
return strings.Split(distributions.ScheduledDistributions, "\n"), nil
640641
}
641642

643+
var serviceOwnershipContent = func(dataFetcher fetcher.Fetcher, _ clusterSummaryInfo) ([]string, error) {
644+
var (
645+
membersResult []byte
646+
memberNodeID string
647+
membersDetails = config.ServiceMemberDetails{}
648+
)
649+
650+
if serviceName == "" {
651+
return emptyStringArray, errSelectService
652+
}
653+
654+
servicesResult, err := GetDistributedServices(dataFetcher)
655+
if err != nil {
656+
return emptyStringArray, err
657+
}
658+
659+
if !utils.SliceContains(servicesResult, serviceName) {
660+
return emptyStringArray, fmt.Errorf(unableToFindService, serviceName)
661+
}
662+
663+
// find storage member node
664+
membersResult, err = dataFetcher.GetServiceMembersDetailsJSON(serviceName)
665+
if err != nil {
666+
return emptyStringArray, err
667+
}
668+
669+
if len(membersResult) != 0 {
670+
err = json.Unmarshal(membersResult, &membersDetails)
671+
if err != nil {
672+
return emptyStringArray, utils.GetError("unable to unmarshall members ownership", err)
673+
}
674+
675+
for _, v := range membersDetails.Services {
676+
memberNodeID = v.NodeID
677+
break
678+
}
679+
680+
var ownershipData []byte
681+
682+
ownershipData, err = dataFetcher.GetServiceOwnershipJSON(serviceName, memberNodeID)
683+
if err != nil {
684+
return emptyStringArray, err
685+
}
686+
687+
result, err := getOwnershipData(dataFetcher, ownershipData)
688+
if err != nil {
689+
return emptyStringArray, err
690+
}
691+
692+
return strings.Split(FormatPartitionOwnership(result), "\n"), nil
693+
}
694+
695+
return noContentArray, nil
696+
}
697+
642698
var serviceStorageContent = func(dataFetcher fetcher.Fetcher, _ clusterSummaryInfo) ([]string, error) {
643699
storageSummary, err := getServiceStorageDetails(dataFetcher)
644700

pkg/cmd/root.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ const (
8585
healthPortMessage = "starting port for health"
8686
jmxPortMessage = "remote JMX port for management member"
8787
jmxHostMessage = "remote JMX RMI host for management member"
88+
machineMessage = "the machine name to use"
89+
rackMessage = "the rack name to use"
90+
siteMessage = "the site name to use"
8891
cacheConfigMessage = "cache configuration file"
8992
operationalConfigMessage = "override override file"
9093
cacheConfigArg = "cache-config"
@@ -94,6 +97,9 @@ const (
9497
healthPortArg = "health-port"
9598
jmxPortArg = "jmx-port"
9699
jmxHostArg = "jmx-host"
100+
machineArg = "machine"
101+
rackArg = "rack"
102+
siteArg = "site"
97103
logLevelMessage = "coherence log level"
98104
profileMessage = "profile to add to cluster startup command line"
99105
backupLogFilesMessage = "backup old cache server log files"
@@ -507,6 +513,7 @@ func Initialize(command *cobra.Command) *cobra.Command {
507513
getCmd.AddCommand(getProxyConnectionsCmd)
508514
getCmd.AddCommand(getUseGradleCmd)
509515
getCmd.AddCommand(getServiceStorageCmd)
516+
getCmd.AddCommand(getServiceOwnershipCmd)
510517
getCmd.AddCommand(getCacheStoresCmd)
511518
getCmd.AddCommand(getColorCmd)
512519
getCmd.AddCommand(getNetworkStatsCmd)

0 commit comments

Comments
 (0)