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 ./zookeeper --gui nocui
gocui: build gocui: build
./zookeeper --gui gocui
gocui-debugging: build
./zookeeper --gui gocui >/tmp/forge.log 2>&1 ./zookeeper --gui gocui >/tmp/forge.log 2>&1
build: goimports vet build: goimports vet
@ -60,15 +63,3 @@ http-toogle-ZOOD:
http-list-machines: http-list-machines:
curl --silent http://localhost:8080/list 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/gui"
"go.wit.com/lib/gadgets" "go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log" "go.wit.com/log"
) )
@ -21,7 +22,7 @@ func refresh() {
log.Info("zookeeper scan here") log.Info("zookeeper scan here")
} }
if me.zood != nil { if me.zood != nil {
doMachinesUpgradeTable() me.zood.doMachinesUpgradeTable(me.machines)
} }
} }
@ -63,3 +64,15 @@ func doGui() {
refresh() 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") hostname := r.URL.Query().Get("hostname")
flag := r.URL.Query().Get("flag") flag := r.URL.Query().Get("flag")
packname := r.URL.Query().Get("package") // packname := r.URL.Query().Get("package")
version := r.URL.Query().Get("version") // version := r.URL.Query().Get("version")
msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte
if err != nil { if err != nil {
@ -75,36 +75,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return 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 // toggle logging flags
if route == "/flag" { if route == "/flag" {
log.HttpMode(w) 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 := new(zoopb.Machine)
am.Hostname = newm.Hostname am.Hostname = newm.Hostname
am.Memory = newm.Memory am.Memory = newm.Memory
me.machines2.Append(am) // me.machines2.Append(am)
me.machines.Append(newm) me.machines.Append(newm)
log.Info("new machine", am.Hostname, am.Memory) log.Info("new machine", am.Hostname, am.Memory)
return return
@ -59,7 +59,7 @@ func handleMachine(r *http.Request, w http.ResponseWriter, hostname string, data
fmt.Fprintln(w, "apt update") fmt.Fprintln(w, "apt update")
m.Upgrade = false m.Upgrade = false
} else { } else {
fmt.Fprintln(w, "upgrade") fmt.Fprintln(w, "good")
} }
// log.Info("update machine protobuf", hostname) // log.Info("update machine protobuf", hostname)
updateMachine(newm) updateMachine(newm)
@ -75,8 +75,12 @@ func updateMachine(u *zoopb.Machine) string {
if m == nil { if m == nil {
log.Info("adding new machine", u.Hostname) log.Info("adding new machine", u.Hostname)
me.machines.Append(u) me.machines.Append(u)
log.Info("save machines pb file here...") if me.zood == nil {
me.machines2.ConfigSave() // do nothing. window has not been opened
} else {
me.zood.doMachinesUpgradeTable(me.machines)
}
saveMachineState()
return "new" return "new"
} }
// log.Info("updating machine", m.Hostname) // log.Info("updating machine", m.Hostname)

View File

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

View File

@ -4,7 +4,6 @@
package main package main
import ( import (
"sync"
"time" "time"
"go.wit.com/gui" "go.wit.com/gui"
@ -23,7 +22,7 @@ type zookeep struct {
distro string // debian,redhat,gentoo,macos,wincrap distro string // debian,redhat,gentoo,macos,wincrap
packages *zoopb.Packages // installed packages and versions packages *zoopb.Packages // installed packages and versions
machines *zoopb.Machines // every machine that has reported itself to the zookeeper machines *zoopb.Machines // every machine that has reported itself to the zookeeper
machines2 *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 targets map[string]string // what versions the machines should be running
upgrade map[string]bool // use this to trigger builds upgrade map[string]bool // use this to trigger builds
myGui *gui.Node // the gui toolkit handle myGui *gui.Node // the gui toolkit handle
@ -32,21 +31,3 @@ type zookeep struct {
machinesTB *zoopb.MachinesTable // the machines gui table buffer machinesTB *zoopb.MachinesTable // the machines gui table buffer
zood *stdTableWin // the zood version window 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 ( import (
"fmt" "fmt"
"sync"
"time" "time"
"go.wit.com/gui" "go.wit.com/gui"
@ -13,42 +14,71 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
func makeZoodWin() { type stdTableWin struct {
me.zood = new(stdTableWin) sync.Mutex
me.zood.win = gadgets.NewGenericWindow("zood daemon versions", "todo: add global controls here") win *gadgets.GenericWindow // the machines gui window
me.zood.win.Custom = func() { 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") log.Info("test delete window here")
} }
grid := me.zood.win.Group.RawGrid() grid := zood.win.Group.RawGrid()
grid.NewButton("save machines.pb", func() { grid.NewButton("save machines.pb", func() {
saveMachineState() saveMachineState()
}) })
grid.NewCheckbox("hide active") grid.NewCheckbox("hide active")
grid.NewButton("update", func() { grid.NewButton("update", func() {
doMachinesUpgradeTable() zood.doMachinesUpgradeTable(me.machines)
}) })
// make a box at the bottom of the window for the protobuf table // make a box at the bottom of the window for the protobuf table
me.zood.box = me.zood.win.Bottom.Box().SetProgName("TBOX") zood.box = zood.win.Bottom.Box().SetProgName("TBOX")
doMachinesUpgradeTable() zood.doMachinesUpgradeTable(me.machines)
return zood
} }
func doMachinesUpgradeTable() { func (zood *stdTableWin) doMachinesUpgradeTable(pb *zoopb.Machines) {
me.zood.Lock() zood.Lock()
defer me.zood.Unlock() defer zood.Unlock()
if me.zood.TB != nil { if zood.TB != nil {
me.zood.TB.Delete() zood.TB.Delete()
me.zood.TB = nil zood.TB = nil
} }
/*
found := zoopb.NewMachines()
all := pb.SortByHostname()
for all.Scan() {
m := all.Next()
found.Append(m)
}
*/
// display the protobuf // display the protobuf
me.zood.TB = AddMachinesPB(me.zood.box, me.machines) zood.TB = AddMachinesPB(zood.box, pb)
f := func(m *zoopb.Machine) { f := func(m *zoopb.Machine) {
log.Info("Triggering machine", m.Hostname, "to upgrade zood") log.Info("Triggering machine", m.Hostname, "to upgrade zood")
m.Upgrade = true m.Upgrade = true
} }
me.zood.TB.Custom(f) zood.TB.Custom(f)
log.Info("table has uuid", me.zood.TB.GetUuid()) log.Info("table has uuid", zood.TB.GetUuid())
} }
func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable { 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) t.SetParent(tbox)
f := func(m *zoopb.Machine) string { f := func(m *zoopb.Machine) string {
log.Info("machine =", m.Hostname) // log.Info("machine =", m.Hostname)
return "now" return "now"
} }
t.AddButtonFunc("upgrade", f) 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 { t.AddStringFunc("zood", func(m *zoopb.Machine) string {
return findVersion(m, "zood") 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 // show if the machine needs to be upgraded
@ -98,15 +133,3 @@ func findVersion(m *zoopb.Machine, pkgname string) string {
} }
return zood.Version 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()
}