Skip to content

Commit

Permalink
Add the arbitrator status to the tui
Browse files Browse the repository at this point in the history
  • Loading branch information
cvaroqui committed Oct 29, 2024
1 parent 37ef35e commit 1d9cab4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 10 deletions.
19 changes: 19 additions & 0 deletions core/clusterdump/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package clusterdump

import (
"encoding/json"
"sort"

"github.com/opensvc/om3/core/cluster"
"github.com/opensvc/om3/core/instance"
"github.com/opensvc/om3/core/naming"
Expand Down Expand Up @@ -45,6 +47,23 @@ func (s *Data) DeepCopy() *Data {
return &newStatus
}

func (s *Data) ArbitratorNames() []string {
m := make(map[string]any)
for _, nodeData := range s.Cluster.Node {
for name, _ := range nodeData.Status.Arbitrators {
m[name] = nil
}
}
l := make([]string, len(m))
i := 0
for name := range m {
l[i] = name
i++
}
sort.Strings(l)
return l
}

func (s *Data) ObjectPaths() naming.Paths {
allPaths := make(naming.Paths, len(s.Cluster.Object))
i := 0
Expand Down
20 changes: 13 additions & 7 deletions core/monitor/frame_arbitrators.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@ func (f Frame) wArbitrators() {
if i == 0 {
s += bold(" "+name) + "\t\t\t" + f.info.separator + "\t"
}
aStatus := f.Current.Cluster.Node[node].Status.Arbitrators[name].Status
switch aStatus {
case status.Up:
s += iconUp + "\t"
default:
s += iconDown + "\t"
}
s += f.StrNodeArbitratorStatus(name, node) + "\t"
}
s += "\n"
}
fmt.Fprintf(f.w, s)
fmt.Fprintln(f.w, f.info.empty)
}

func (f Frame) StrNodeArbitratorStatus(name, node string) string {
s := ""
aStatus := f.Current.Cluster.Node[node].Status.Arbitrators[name].Status
switch aStatus {
case status.Up:
s += iconUp
default:
s += iconDown
}
return s
}
34 changes: 31 additions & 3 deletions core/tui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,14 +775,21 @@ func (t *App) updateObjects() {
}
}

nodesArbitratorCells := func(row int, arbitratorName string) {
for i, nodename := range t.Current.Cluster.Config.Nodes {
s := tview.TranslateANSI(t.StrNodeArbitratorStatus(arbitratorName, nodename))
t.objects.SetCell(row, t.firstInstanceCol+i, tview.NewTableCell(s).SetSelectable(false))
}
}

t.lastDraw = time.Now()

t.objects.Clear()
t.objects.SetTitle(fmt.Sprintf("%s objects", t.Frame.Selector))

row := 0
t.objects.SetCell(row, 0, tview.NewTableCell("").SetTextColor(colorTitle).SetSelectable(false))
t.objects.SetCell(row, 1, tview.NewTableCell("").SetSelectable(true))
t.objects.SetCell(row, 0, tview.NewTableCell("CLUSTER").SetTextColor(colorTitle).SetSelectable(false))
t.objects.SetCell(row, 1, tview.NewTableCell(t.Current.Cluster.Config.Name).SetSelectable(true))
t.objects.SetCell(row, 2, tview.NewTableCell("").SetSelectable(false))
t.objects.SetCell(row, 3, tview.NewTableCell("NODE").SetTextColor(colorTitle).SetSelectable(false))
t.objects.SetCell(row, 4, tview.NewTableCell("│").SetTextColor(colorTitle).SetSelectable(false))
Expand Down Expand Up @@ -830,7 +837,7 @@ func (t *App) updateObjects() {
nodesHbCells(row)

for _, hbStatus := range t.Current.Cluster.Node[t.Frame.Nodename].Daemon.Heartbeat.Streams {
name := "│" + hbStatus.ID + monitor.StrThreadAlerts(hbStatus.Alerts)
name := "│" + strings.TrimPrefix(hbStatus.ID, "hb#") + monitor.StrThreadAlerts(hbStatus.Alerts)
row++
t.objects.SetCell(row, 0, tview.NewTableCell("").SetSelectable(false))
t.objects.SetCell(row, 1, tview.NewTableCell("").SetSelectable(false))
Expand All @@ -841,6 +848,27 @@ func (t *App) updateObjects() {
}
}

arbitratorNames := t.Current.ArbitratorNames()
if len(arbitratorNames) > 0 {
row++
t.objects.SetCell(row, 0, tview.NewTableCell("").SetSelectable(false))
t.objects.SetCell(row, 1, tview.NewTableCell("").SetSelectable(false))
t.objects.SetCell(row, 2, tview.NewTableCell("").SetSelectable(false))
t.objects.SetCell(row, 3, tview.NewTableCell("ARBITRATORS").SetTextColor(colorTitle).SetSelectable(false))
t.objects.SetCell(row, 4, tview.NewTableCell("│").SetTextColor(colorTitle).SetSelectable(false))

for _, arbitratorName := range arbitratorNames {
name := "│" + arbitratorName
row++
t.objects.SetCell(row, 0, tview.NewTableCell("").SetSelectable(false))
t.objects.SetCell(row, 1, tview.NewTableCell("").SetSelectable(false))
t.objects.SetCell(row, 2, tview.NewTableCell("").SetSelectable(false))
t.objects.SetCell(row, 3, tview.NewTableCell(name).SetTextColor(colorTitle).SetSelectable(false))
t.objects.SetCell(row, 4, tview.NewTableCell("│").SetTextColor(colorTitle).SetSelectable(false))
nodesArbitratorCells(row, arbitratorName)
}
}

row++
t.objects.SetCell(row, 0, tview.NewTableCell("").SetSelectable(false))
t.objects.SetCell(row, 1, tview.NewTableCell("").SetSelectable(false))
Expand Down

0 comments on commit 1d9cab4

Please sign in to comment.