the forgotten patch

This commit is contained in:
Jeff Carr 2025-03-12 13:16:05 -05:00
parent bb4a6a01df
commit 767380abd0
7 changed files with 95 additions and 111 deletions

View File

@ -18,6 +18,9 @@ nogui:
./zookeeper --gui nocui
gocui: build
./zookeeper --gui gocui
gocui-debugging: build
./zookeeper --gui gocui >/tmp/forge.log 2>&1
build: goimports vet
@ -60,15 +63,3 @@ http-toogle-ZOOD:
http-list-machines:
curl --silent http://localhost:8080/list
http-ConfigSave:
curl --silent http://localhost:8080/save
http-set-zood-target:
curl --silent "http://localhost:8080/target?package=zood&version=v0.0.8"
http-upgrade-hpdev2.grid.wit.com:
curl --silent "http://localhost:8080/upgrade?hostname=hpdev2.grid.wit.com"
http-upgrade-mirrors.wit.com:
curl --silent "http://localhost:8080/upgrade?hostname=mirrors.wit.com"

View File

@ -11,6 +11,7 @@ import (
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log"
)
@ -21,7 +22,7 @@ func refresh() {
log.Info("zookeeper scan here")
}
if me.zood != nil {
doMachinesUpgradeTable()
me.zood.doMachinesUpgradeTable(me.machines)
}
}
@ -63,3 +64,15 @@ func doGui() {
refresh()
}
}
func saveMachineState() {
cur := zoopb.NewMachines()
all := me.machines.SortByHostname()
for all.Scan() {
m := all.Next()
log.Info("have machine:", m.Hostname)
cur.Append(m)
}
cur.ConfigSave()
}

34
http.go
View File

@ -25,8 +25,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
hostname := r.URL.Query().Get("hostname")
flag := r.URL.Query().Get("flag")
packname := r.URL.Query().Get("package")
version := r.URL.Query().Get("version")
// packname := r.URL.Query().Get("package")
// version := r.URL.Query().Get("version")
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
if err != nil {
@ -75,36 +75,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
// save the config file
if route == "/save" {
log.HttpMode(w)
defer log.HttpMode(nil)
if err := me.machines2.ConfigSave(); err == nil {
log.Log(NOW, "ConfigSave() ok")
} else {
log.Log(NOW, "ConfigSave() failed", err)
}
return
}
// flag a package to attempt to upgrade
if route == "/upgrade" {
log.HttpMode(w)
defer log.HttpMode(nil)
me.upgrade[hostname] = true
log.Log(NOW, "setting package ", packname, " to upgrade")
return
}
// set the target version for a package
if route == "/target" {
log.HttpMode(w)
defer log.HttpMode(nil)
// me.targets[packname] = version
log.Log(NOW, "setting package/version to ", packname, " ", version)
return
}
// toggle logging flags
if route == "/flag" {
log.HttpMode(w)

View File

@ -43,7 +43,7 @@ func handleMachine(r *http.Request, w http.ResponseWriter, hostname string, data
am := new(zoopb.Machine)
am.Hostname = newm.Hostname
am.Memory = newm.Memory
me.machines2.Append(am)
// me.machines2.Append(am)
me.machines.Append(newm)
log.Info("new machine", am.Hostname, am.Memory)
return
@ -59,7 +59,7 @@ func handleMachine(r *http.Request, w http.ResponseWriter, hostname string, data
fmt.Fprintln(w, "apt update")
m.Upgrade = false
} else {
fmt.Fprintln(w, "upgrade")
fmt.Fprintln(w, "good")
}
// log.Info("update machine protobuf", hostname)
updateMachine(newm)
@ -75,8 +75,12 @@ func updateMachine(u *zoopb.Machine) string {
if m == nil {
log.Info("adding new machine", u.Hostname)
me.machines.Append(u)
log.Info("save machines pb file here...")
me.machines2.ConfigSave()
if me.zood == nil {
// do nothing. window has not been opened
} else {
me.zood.doMachinesUpgradeTable(me.machines)
}
saveMachineState()
return "new"
}
// log.Info("updating machine", m.Hostname)

12
main.go
View File

@ -39,15 +39,17 @@ func main() {
me.hostname, _ = os.Hostname()
me.pollDelay = 10 * time.Second
me.machines = zoopb.NewMachines()
me.machines2 = zoopb.NewMachines()
// me.machines2 = zoopb.NewMachines()
if err := me.machines.ConfigLoad(); err != nil {
log.Warn("load config failed", err)
os.Exit(-1)
}
if err := me.machines2.ConfigLoad(); err != nil {
log.Warn("load config failed", err)
os.Exit(-1)
}
/*
if err := me.machines2.ConfigLoad(); err != nil {
log.Warn("load config failed", err)
os.Exit(-1)
}
*/
// me.targets = make(map[string]string) // keep track of what versions the machines should be running
me.upgrade = make(map[string]bool) // used to trigger upgrade attempts

View File

@ -4,7 +4,6 @@
package main
import (
"sync"
"time"
"go.wit.com/gui"
@ -16,14 +15,14 @@ var me *zookeep
// this app's variables
type zookeep struct {
hostname string // my fqdn dns zookeeper hostname
pollDelay time.Duration // how often to report our status
dog *time.Ticker // the watchdog timer
dogchan chan bool // can kill the watchdog
distro string // debian,redhat,gentoo,macos,wincrap
packages *zoopb.Packages // installed packages and versions
machines *zoopb.Machines // every machine that has reported itself to the zookeeper
machines2 *zoopb.Machines // every machine that has reported itself to the zookeeper
hostname string // my fqdn dns zookeeper hostname
pollDelay time.Duration // how often to report our status
dog *time.Ticker // the watchdog timer
dogchan chan bool // can kill the watchdog
distro string // debian,redhat,gentoo,macos,wincrap
packages *zoopb.Packages // installed packages and versions
machines *zoopb.Machines // every machine that has reported itself to the zookeeper
// machines2 *zoopb.Machines // every machine that has reported itself to the zookeeper
targets map[string]string // what versions the machines should be running
upgrade map[string]bool // use this to trigger builds
myGui *gui.Node // the gui toolkit handle
@ -32,21 +31,3 @@ type zookeep struct {
machinesTB *zoopb.MachinesTable // the machines gui table buffer
zood *stdTableWin // the zood version window
}
type stdTableWin struct {
sync.Mutex
win *gadgets.GenericWindow // the machines gui window
box *gui.Node // the machines gui parent box widget
TB *zoopb.MachinesTable // the machines gui table buffer
update bool // if the window should be updated
}
func (w *stdTableWin) Toggle() {
if w == nil {
return
}
if w.win == nil {
return
}
w.win.Toggle()
}

View File

@ -5,6 +5,7 @@ package main
import (
"fmt"
"sync"
"time"
"go.wit.com/gui"
@ -13,42 +14,71 @@ import (
"go.wit.com/log"
)
func makeZoodWin() {
me.zood = new(stdTableWin)
me.zood.win = gadgets.NewGenericWindow("zood daemon versions", "todo: add global controls here")
me.zood.win.Custom = func() {
type stdTableWin struct {
sync.Mutex
win *gadgets.GenericWindow // the machines gui window
box *gui.Node // the machines gui parent box widget
TB *zoopb.MachinesTable // the machines gui table buffer
update bool // if the window should be updated
}
func (w *stdTableWin) Toggle() {
if w == nil {
return
}
if w.win == nil {
return
}
w.win.Toggle()
}
func makeZoodWin() *stdTableWin {
zood := new(stdTableWin)
zood.win = gadgets.NewGenericWindow("zood daemon versions", "todo: add global controls here")
zood.win.Custom = func() {
log.Info("test delete window here")
}
grid := me.zood.win.Group.RawGrid()
grid := zood.win.Group.RawGrid()
grid.NewButton("save machines.pb", func() {
saveMachineState()
})
grid.NewCheckbox("hide active")
grid.NewButton("update", func() {
doMachinesUpgradeTable()
zood.doMachinesUpgradeTable(me.machines)
})
// make a box at the bottom of the window for the protobuf table
me.zood.box = me.zood.win.Bottom.Box().SetProgName("TBOX")
doMachinesUpgradeTable()
zood.box = zood.win.Bottom.Box().SetProgName("TBOX")
zood.doMachinesUpgradeTable(me.machines)
return zood
}
func doMachinesUpgradeTable() {
me.zood.Lock()
defer me.zood.Unlock()
if me.zood.TB != nil {
me.zood.TB.Delete()
me.zood.TB = nil
func (zood *stdTableWin) doMachinesUpgradeTable(pb *zoopb.Machines) {
zood.Lock()
defer zood.Unlock()
if zood.TB != nil {
zood.TB.Delete()
zood.TB = nil
}
/*
found := zoopb.NewMachines()
all := pb.SortByHostname()
for all.Scan() {
m := all.Next()
found.Append(m)
}
*/
// display the protobuf
me.zood.TB = AddMachinesPB(me.zood.box, me.machines)
zood.TB = AddMachinesPB(zood.box, pb)
f := func(m *zoopb.Machine) {
log.Info("Triggering machine", m.Hostname, "to upgrade zood")
m.Upgrade = true
}
me.zood.TB.Custom(f)
log.Info("table has uuid", me.zood.TB.GetUuid())
zood.TB.Custom(f)
log.Info("table has uuid", zood.TB.GetUuid())
}
func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable {
@ -57,7 +87,7 @@ func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable {
t.SetParent(tbox)
f := func(m *zoopb.Machine) string {
log.Info("machine =", m.Hostname)
// log.Info("machine =", m.Hostname)
return "now"
}
t.AddButtonFunc("upgrade", f)
@ -72,6 +102,11 @@ func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable {
t.AddStringFunc("zood", func(m *zoopb.Machine) string {
return findVersion(m, "zood")
})
delf := func(m *zoopb.Machine) string {
pb.DeleteByHostname(m.Hostname)
return "delete"
}
t.AddButtonFunc("delete", delf)
/*
// show if the machine needs to be upgraded
@ -98,15 +133,3 @@ func findVersion(m *zoopb.Machine, pkgname string) string {
}
return zood.Version
}
func saveMachineState() {
cur := zoopb.NewMachines()
all := me.machines.SortByHostname()
for all.Scan() {
m := all.Next()
log.Info("have machine:", m.Hostname)
cur.Append(m)
}
cur.ConfigSave()
}