Compare commits

...

2 Commits

Author SHA1 Message Date
Jeff Carr 687e97ab09 zood upgrade worked for the first time. added Kuma check 2025-03-12 15:34:07 -05:00
Jeff Carr 767380abd0 the forgotten patch 2025-03-12 13:17:19 -05:00
8 changed files with 190 additions and 163 deletions

View File

@ -7,7 +7,7 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
# REDOMOD = $(shell if [ -e go.mod ]; then echo go.mod; else echo no go mod; fi) # REDOMOD = $(shell if [ -e go.mod ]; then echo go.mod; else echo no go mod; fi)
REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE= go mod init; GO111MODULE= go mod tidy; fi) REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE= go mod init; GO111MODULE= go mod tidy; fi)
all: goimports gocui all: goimports gocui-debugging
# ./zookeeper # ./zookeeper
vet: vet:
@ -18,7 +18,10 @@ nogui:
./zookeeper --gui nocui ./zookeeper --gui nocui
gocui: build gocui: build
./zookeeper --gui gocui >/tmp/forge.log 2>&1 ./zookeeper --gui gocui
gocui-debugging: build
./zookeeper --gui gocui --gui-file ~/go/src/go.wit.com/toolkits/gocui/gocui.so >/tmp/forge.log 2>&1
build: goimports vet build: goimports vet
GO111MODULE=off go build -v -x \ GO111MODULE=off go build -v -x \
@ -61,14 +64,5 @@ http-toogle-ZOOD:
http-list-machines: http-list-machines:
curl --silent http://localhost:8080/list curl --silent http://localhost:8080/list
http-ConfigSave: http-uptime:
curl --silent http://localhost:8080/save curl --silent http://localhost:8080/uptime
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,17 +11,27 @@ 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"
) )
// refresh the windows & tables the user has open // refresh the windows & tables the user has open
func refresh() { func refresh() {
time.Sleep(90 * time.Second)
if argv.Verbose { if argv.Verbose {
log.Info("zookeeper scan here") log.Info("zookeeper scan here")
} }
if me.zood != nil { if me.zood != nil {
doMachinesUpgradeTable() me.zood.doMachinesUpgradeTable(me.machines)
all := me.machines.All()
for all.Scan() {
m := all.Next()
if me.hostname == m.Hostname {
// this is me! This is the version of zood that should be installed everywhere
v := findVersion(m, "zood")
me.zood.version = v
me.zood.versionL.SetText(v)
}
}
} }
} }
@ -51,7 +61,7 @@ func doGui() {
me.zood.Toggle() me.zood.Toggle()
return return
} }
makeZoodWin() me.zood = makeZoodWin()
}) })
grid.NewButton("Cluster Events", func() { grid.NewButton("Cluster Events", func() {
@ -61,5 +71,18 @@ func doGui() {
// sit here forever refreshing the GUI // sit here forever refreshing the GUI
for { for {
refresh() refresh()
time.Sleep(90 * time.Second)
} }
} }
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()
}

124
http.go
View File

@ -9,7 +9,6 @@ import (
"net/http" "net/http"
"strings" "strings"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log" "go.wit.com/log"
) )
@ -24,9 +23,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
route := cleanURL(r.URL.Path) route := cleanURL(r.URL.Path)
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")
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 {
@ -43,84 +40,61 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
if route == "/status" { /*
var packs *zoopb.Packages if route == "/status" {
packs = new(zoopb.Packages) var packs *zoopb.Packages
if err := packs.Unmarshal(msg); err != nil { packs = new(zoopb.Packages)
log.Info("/status proto.Unmarshal() failed on wire message len", len(msg), "from", hostname) if err := packs.Unmarshal(msg); err != nil {
log.Info("/status proto.Unmarshal() failed on wire message len", len(msg), "from", hostname)
return
}
log.Info("/status Unmarshal worked with msg len", len(msg), "from", hostname)
log.Info("/status hostname", hostname, "has", packs.Len(), "packages installed")
fmt.Fprintln(w, "upgrade")
return return
} }
*/
log.Info("/status Unmarshal worked with msg len", len(msg), "from", hostname)
log.Info("/status hostname", hostname, "has", packs.Len(), "packages installed")
fmt.Fprintln(w, "upgrade")
return
}
// list out the machines and thier version of zood // list out the machines and thier version of zood
if route == "/list" { /*
log.HttpMode(w) if route == "/list" {
defer log.HttpMode(nil) log.HttpMode(w)
loop := me.machines.SortByHostname() defer log.HttpMode(nil)
for loop.Scan() { loop := me.machines.SortByHostname()
m := loop.Next() for loop.Scan() {
zood := m.Packages.FindByName("zood") m := loop.Next()
v := me.targets["zood"] // this is the target version zood := m.Packages.FindByName("zood")
if zood == nil { v := me.targets["zood"] // this is the target version
log.Info("machine", m.Hostname, "does not have zood installed") if zood == nil {
} else { log.Info("machine", m.Hostname, "does not have zood installed")
log.Info(fmt.Sprintf("zood version %s vs target version %s on machine %s", zood.Version, v, m.Hostname)) } else {
log.Info(fmt.Sprintf("zood version %s vs target version %s on machine %s", zood.Version, v, m.Hostname))
}
}
return
}
*/
if route == "/uptime" {
if me.zood == nil {
fmt.Fprintf(w, "BAD zood == nil\n")
return
}
var count int
var bad int
all := me.machines.All()
for all.Scan() {
m := all.Next()
count += 1
if findVersion(m, "zood") != me.zood.version {
bad += 1
} }
} }
return if bad == 0 {
} fmt.Fprintf(w, "GOOD machine count=(%d) all machines are version %s\n", count, me.zood.version)
// 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 { } else {
log.Log(NOW, "ConfigSave() failed", err) fmt.Fprintf(w, "BAD machine count=(%d) upgrade=(%d) to %s\n", count, bad, me.zood.version)
}
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)
defer log.HttpMode(nil)
log.Info("going to toggle flag:", flag)
switch flag {
case "ZOOD":
if ZOOD.Enabled() {
log.Log(NOW, "toogle ZOOD false")
ZOOD.SetBool(false)
} else {
log.Log(NOW, "toogle ZOOD true")
ZOOD.SetBool(true)
}
default:
log.Info("unknown looging flag:", flag)
} }
return return
} }

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)

14
main.go
View File

@ -37,17 +37,19 @@ func main() {
me = new(zookeep) me = new(zookeep)
me.hostname, _ = os.Hostname() me.hostname, _ = os.Hostname()
me.pollDelay = 10 * time.Second me.pollDelay = time.Hour
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 { /*
log.Warn("load config failed", err) if err := me.machines2.ConfigLoad(); err != nil {
os.Exit(-1) 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.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"
@ -16,14 +15,14 @@ var me *zookeep
// this app's variables // this app's variables
type zookeep struct { type zookeep struct {
hostname string // my fqdn dns zookeeper hostname hostname string // my fqdn dns zookeeper hostname
pollDelay time.Duration // how often to report our status pollDelay time.Duration // how often to report our status
dog *time.Ticker // the watchdog timer dog *time.Ticker // the watchdog timer
dogchan chan bool // can kill the watchdog dogchan chan bool // can kill the watchdog
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

@ -55,7 +55,7 @@ func NewWatchdog() {
// log.Info("know about machine", m.Hostname, "zood version", zood.Version) // log.Info("know about machine", m.Hostname, "zood version", zood.Version)
} }
} }
log.Info("zookeeper has", counter, "machines. Current time:", t) log.Info("hour watchdog:", counter, "machines. Current time:", t)
// h.pollHypervisor() // h.pollHypervisor()
// h.Scan() // h.Scan()

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,87 @@ 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
version string // the current zood version
versionL *gui.Node // label widget to display the current zood version
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.NewButton("show active", func() {
grid.NewButton("update", func() { zood.doMachinesUpgradeTable(me.machines)
doMachinesUpgradeTable() })
grid.NewButton("refresh", func() {
refresh()
})
zood.versionL = grid.NewLabel("scan")
grid.NewButton("show out of date", func() {
found := zoopb.NewMachines()
all := me.machines.All()
for all.Scan() {
m := all.Next()
if findVersion(m, "zood") != me.zood.version {
found.Append(m)
}
}
zood.doMachinesUpgradeTable(found)
}) })
// 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 {
@ -56,11 +102,22 @@ func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable {
t.NewUuid() t.NewUuid()
t.SetParent(tbox) t.SetParent(tbox)
f := func(m *zoopb.Machine) string { upbut := t.AddButtonFunc("upgrade", func(m *zoopb.Machine) string {
log.Info("machine =", m.Hostname) if me.zood != nil {
mver := findVersion(m, "zood")
if mver == me.zood.version {
return ""
} else {
// log.Info("machine mismatch", m.Hostname, mver, me.zood.version)
}
}
// log.Info("machine =", m.Hostname)
return "now" return "now"
})
upbut.Custom = func(m *zoopb.Machine) {
log.Info("Triggering machine", m.Hostname, "to upgrade zood")
m.Upgrade = true
} }
t.AddButtonFunc("upgrade", f)
t.AddHostname() t.AddHostname()
t.AddMemory() t.AddMemory()
@ -72,6 +129,10 @@ 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 {
return "delete"
}
t.AddButtonFunc("delete", delf)
/* /*
// show if the machine needs to be upgraded // show if the machine needs to be upgraded
@ -98,15 +159,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()
}