zookeeper/doGui.go

125 lines
2.4 KiB
Go
Raw Normal View History

2025-02-15 03:45:32 -06:00
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
// An app to submit patches for the 30 GO GUI repos
import (
2025-02-15 06:44:25 -06:00
"fmt"
2025-02-15 03:45:32 -06:00
"os"
"time"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
2025-02-15 04:12:27 -06:00
"go.wit.com/lib/protobuf/zoopb"
2025-02-15 03:45:32 -06:00
"go.wit.com/log"
)
func debug() {
for {
time.Sleep(90 * time.Second)
log.Info("TODO: zookeeper scan here. repo count =")
}
}
func doGui() {
me.myGui = gui.New()
me.myGui.InitEmbed(resources)
me.myGui.Default()
mainWindow := gadgets.RawBasicWindow("Zookeeper: (inventory your cluster)")
mainWindow.Make()
mainWindow.Show()
mainWindow.Custom = func() {
log.Warn("Main window close")
os.Exit(0)
}
drawWindow(mainWindow)
// sits here forever
debug()
}
func drawWindow(win *gadgets.BasicWindow) {
box := win.Box()
vbox := box.NewVerticalBox("BOX2")
group1 := vbox.NewGroup("Zookeeper Settings")
grid := group1.NewGrid("buildOptions", 0, 0)
2025-02-15 03:59:08 -06:00
var tbwin *tableWindow
2025-02-15 03:45:32 -06:00
grid.NewButton("show zoo", func() {
win.Disable()
defer win.Enable()
2025-02-15 04:12:27 -06:00
if tbwin == nil {
log.Info("show zoo here")
tbwin = makeTableWindow()
2025-02-15 06:44:25 -06:00
tbwin.showTable(me.machines)
2025-02-15 04:12:27 -06:00
}
if tbwin.Hidden() {
tbwin.Show()
} else {
tbwin.Hide()
2025-02-15 03:59:08 -06:00
}
2025-02-15 04:12:27 -06:00
return
2025-02-15 03:59:08 -06:00
2025-02-15 03:45:32 -06:00
})
2025-02-15 04:12:27 -06:00
2025-02-15 07:17:35 -06:00
grid.NewButton("update table", func() {
newwin := makeTableWindow()
newwin.showTable(me.machines)
newwin.Show()
2025-02-15 04:12:27 -06:00
})
2025-02-18 14:58:16 -06:00
2025-02-18 20:09:12 -06:00
grid.NewButton("me.machines.ShowTable()", func() {
t := me.machines.NewTable("test 2")
2025-02-19 02:49:44 -06:00
t.AddHostname()
2025-02-18 20:09:12 -06:00
t.ShowTable()
})
2025-02-18 14:58:16 -06:00
grid.NewButton("ConfigSave(me.machines)", func() {
log.Info("saving config...")
me.machines.ConfigSave()
})
2025-02-18 20:09:12 -06:00
2025-02-18 14:58:16 -06:00
grid.NewButton("ConfigSave(me.machines2)", func() {
log.Info("saving config...")
me.machines2.ConfigSave()
})
2025-02-15 04:12:27 -06:00
}
func (tw *tableWindow) showTable(allm *zoopb.Machines) {
all := allm.All()
for all.Scan() {
m := all.Next()
tw.grid.NewLabel(m.Hostname)
2025-02-15 06:44:25 -06:00
tw.grid.NewLabel(fmt.Sprintf("%d", m.Cpus))
2025-02-15 09:11:45 -06:00
gb := m.Memory / (1024 * 1024)
ms := fmt.Sprintf("%d MB", gb)
tw.grid.NewLabel(ms)
2025-02-15 06:44:25 -06:00
tw.grid.NewLabel(m.Distro)
tw.grid.NewLabel(findVersion(m, "zood"))
tw.grid.NewLabel(findVersion(m, "bash"))
2025-02-15 07:17:35 -06:00
dur := m.Laststamp.AsTime()
tw.grid.NewLabel(fmt.Sprintf("%v", time.Since(dur)))
2025-02-15 09:11:45 -06:00
tw.grid.NewButton("upgrade", func() {
log.Info("figure out upgrade", m.Hostname)
})
2025-02-15 04:12:27 -06:00
tw.grid.NextRow()
}
2025-02-15 03:45:32 -06:00
}
2025-02-15 06:44:25 -06:00
func findVersion(m *zoopb.Machine, pkgname string) string {
zood := m.Packages.FindByName(pkgname)
if zood == nil {
return "n/a"
}
return zood.Version
}