Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
|
687e97ab09 | |
|
767380abd0 | |
|
bb4a6a01df | |
|
76c5626d0a | |
|
e85a8ae69f | |
|
8c7f6c3c1b | |
|
8edebe18e1 | |
|
f97e2a48c6 | |
|
40fedc09b4 | |
|
53dbe44d38 | |
|
d214d670ac | |
|
b621bba629 | |
|
a57b2875af |
29
Makefile
29
Makefile
|
@ -7,13 +7,23 @@ 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 build
|
all: goimports gocui-debugging
|
||||||
./zookeeper
|
# ./zookeeper
|
||||||
|
|
||||||
|
vet:
|
||||||
|
@GO111MODULE=off go vet
|
||||||
|
@echo this go binary package builds okay
|
||||||
|
|
||||||
nogui:
|
nogui:
|
||||||
./zookeeper --gui nocui
|
./zookeeper --gui nocui
|
||||||
|
|
||||||
build:
|
gocui: build
|
||||||
|
./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
|
||||||
GO111MODULE=off go build -v -x \
|
GO111MODULE=off go build -v -x \
|
||||||
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
||||||
|
|
||||||
|
@ -54,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"
|
|
||||||
|
|
1
argv.go
1
argv.go
|
@ -15,6 +15,7 @@ import (
|
||||||
var argv args
|
var argv args
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
|
Verbose bool `arg:"--verbose" default:"false" help:"talk more"`
|
||||||
Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"`
|
Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"`
|
||||||
Port int `arg:"--port" default:"8080" help:"port to run on"`
|
Port int `arg:"--port" default:"8080" help:"port to run on"`
|
||||||
}
|
}
|
||||||
|
|
114
doGui.go
114
doGui.go
|
@ -6,7 +6,6 @@ package main
|
||||||
// An app to submit patches for the 30 GO GUI repos
|
// An app to submit patches for the 30 GO GUI repos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -16,10 +15,23 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func debug() {
|
// refresh the windows & tables the user has open
|
||||||
for {
|
func refresh() {
|
||||||
time.Sleep(90 * time.Second)
|
if argv.Verbose {
|
||||||
log.Info("TODO: zookeeper scan here. repo count =")
|
log.Info("zookeeper scan here")
|
||||||
|
}
|
||||||
|
if me.zood != nil {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,22 +40,14 @@ func doGui() {
|
||||||
me.myGui.InitEmbed(resources)
|
me.myGui.InitEmbed(resources)
|
||||||
me.myGui.Default()
|
me.myGui.Default()
|
||||||
|
|
||||||
mainWindow := gadgets.RawBasicWindow("Zookeeper: (inventory your cluster)")
|
win := gadgets.RawBasicWindow("Zookeeper: (inventory your cluster)")
|
||||||
mainWindow.Make()
|
win.Make()
|
||||||
mainWindow.Show()
|
win.Show()
|
||||||
mainWindow.Custom = func() {
|
win.Custom = func() {
|
||||||
log.Warn("Main window close")
|
log.Warn("Main window close")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
drawWindow(mainWindow)
|
|
||||||
|
|
||||||
// sits here forever
|
|
||||||
debug()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func drawWindow(win *gadgets.BasicWindow) {
|
|
||||||
box := win.Box()
|
box := win.Box()
|
||||||
|
|
||||||
vbox := box.NewVerticalBox("BOX2")
|
vbox := box.NewVerticalBox("BOX2")
|
||||||
|
@ -51,62 +55,34 @@ func drawWindow(win *gadgets.BasicWindow) {
|
||||||
group1 := vbox.NewGroup("Zookeeper Settings")
|
group1 := vbox.NewGroup("Zookeeper Settings")
|
||||||
grid := group1.NewGrid("buildOptions", 0, 0)
|
grid := group1.NewGrid("buildOptions", 0, 0)
|
||||||
|
|
||||||
var testWin *genericWindow
|
grid.NewButton("zood versions", func() {
|
||||||
grid.NewButton("machine list", func() {
|
// if the window exists, just toggle it open or closed
|
||||||
if testWin != nil {
|
if me.zood != nil {
|
||||||
testWin.Toggle()
|
me.zood.Toggle()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
testWin = makeMachineWindow(me.machines)
|
me.zood = makeZoodWin()
|
||||||
})
|
})
|
||||||
|
|
||||||
var test2 *genericWindow
|
grid.NewButton("Cluster Events", func() {
|
||||||
grid.NewButton("test2", func() {
|
log.Info("todo: start a list here!")
|
||||||
if test2 != nil {
|
|
||||||
test2.Toggle()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
test2 = makeMachineWindow(me.machines)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func findVersion(m *zoopb.Machine, pkgname string) string {
|
|
||||||
zood := m.Packages.FindByName(pkgname)
|
|
||||||
if zood == nil {
|
|
||||||
return "n/a"
|
|
||||||
}
|
|
||||||
return zood.Version
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeMachineWindow(pb *zoopb.Machines) *genericWindow {
|
|
||||||
win := initGenericWindow("Machines registered with Zookeeper", "Buttons of things")
|
|
||||||
grid := win.group.RawGrid()
|
|
||||||
grid.NewButton("List", func() {
|
|
||||||
log.Info("list...")
|
|
||||||
})
|
|
||||||
grid.NewButton("more", func() {
|
|
||||||
log.Info("?")
|
|
||||||
})
|
|
||||||
grid.NextRow()
|
|
||||||
grid.NewButton("smore", func() {
|
|
||||||
log.Info("smore")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
tbox := win.win.Box().Vertical() // a vertical box (like a stack of books)
|
// sit here forever refreshing the GUI
|
||||||
t := pb.NewTable("test 2")
|
for {
|
||||||
t.SetParent(tbox)
|
refresh()
|
||||||
t.AddHostname()
|
time.Sleep(90 * time.Second)
|
||||||
t.AddMemory()
|
}
|
||||||
t.AddCpus()
|
}
|
||||||
t.AddStringFunc("sMB", func(m *zoopb.Machine) string {
|
|
||||||
return fmt.Sprintf("%d mb", m.Memory/(1024*1024))
|
func saveMachineState() {
|
||||||
})
|
cur := zoopb.NewMachines()
|
||||||
t.AddStringFunc("zood", func(m *zoopb.Machine) string {
|
|
||||||
return findVersion(m, "zood")
|
all := me.machines.SortByHostname()
|
||||||
})
|
for all.Scan() {
|
||||||
t.AddTimeFunc("age", func(m *zoopb.Machine) time.Time {
|
m := all.Next()
|
||||||
return m.Laststamp.AsTime()
|
log.Info("have machine:", m.Hostname)
|
||||||
})
|
cur.Append(m)
|
||||||
t.ShowTable()
|
}
|
||||||
return win
|
cur.ConfigSave()
|
||||||
}
|
}
|
||||||
|
|
96
http.go
96
http.go
|
@ -9,8 +9,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
|
||||||
"go.wit.com/lib/protobuf/zoopb"
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,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 {
|
||||||
|
@ -42,31 +38,9 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if route == "/machine" {
|
if route == "/machine" {
|
||||||
handleMachine(r, w, hostname, msg)
|
handleMachine(r, w, hostname, msg)
|
||||||
return
|
return
|
||||||
|
|
||||||
var m *zoopb.Machine
|
|
||||||
m = new(zoopb.Machine)
|
|
||||||
if err := m.Unmarshal(msg); err != nil {
|
|
||||||
log.Info("zoo host sent unknown machine protobuf len", len(msg))
|
|
||||||
forgepb.IdentifyProtobuf(msg)
|
|
||||||
log.Info("error =", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
log.Log(INFO, "proto.Unmarshal() worked on wire message len", len(msg), "from", m.Hostname)
|
|
||||||
b := me.upgrade[m.Hostname]
|
|
||||||
switch updateMachine(m) {
|
|
||||||
case "upgrade":
|
|
||||||
if b {
|
|
||||||
fmt.Fprintln(w, "apt update")
|
|
||||||
me.upgrade[m.Hostname] = false
|
|
||||||
} else {
|
|
||||||
fmt.Fprintln(w, "upgrade")
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
fmt.Fprintln(w, "notsure")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if route == "/status" {
|
if route == "/status" {
|
||||||
var packs *zoopb.Packages
|
var packs *zoopb.Packages
|
||||||
packs = new(zoopb.Packages)
|
packs = new(zoopb.Packages)
|
||||||
|
@ -80,8 +54,10 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintln(w, "upgrade")
|
fmt.Fprintln(w, "upgrade")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// list out the machines and thier version of zood
|
// list out the machines and thier version of zood
|
||||||
|
/*
|
||||||
if route == "/list" {
|
if route == "/list" {
|
||||||
log.HttpMode(w)
|
log.HttpMode(w)
|
||||||
defer log.HttpMode(nil)
|
defer log.HttpMode(nil)
|
||||||
|
@ -98,53 +74,27 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// save the config file
|
if route == "/uptime" {
|
||||||
if route == "/save" {
|
if me.zood == nil {
|
||||||
log.HttpMode(w)
|
fmt.Fprintf(w, "BAD zood == nil\n")
|
||||||
defer log.HttpMode(nil)
|
return
|
||||||
if err := me.machines2.ConfigSave(); err == nil {
|
}
|
||||||
log.Log(NOW, "ConfigSave() ok")
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if bad == 0 {
|
||||||
|
fmt.Fprintf(w, "GOOD machine count=(%d) all machines are version %s\n", count, me.zood.version)
|
||||||
} 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
|
||||||
}
|
}
|
||||||
|
|
18
machine.go
18
machine.go
|
@ -4,6 +4,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -42,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
|
||||||
|
@ -53,6 +54,13 @@ func handleMachine(r *http.Request, w http.ResponseWriter, hostname string, data
|
||||||
log.Info("hostname ua changed len =", len(data), ra, hostname, ua)
|
log.Info("hostname ua changed len =", len(data), ra, hostname, ua)
|
||||||
m.UserAgent = ua
|
m.UserAgent = ua
|
||||||
}
|
}
|
||||||
|
if m.Upgrade {
|
||||||
|
log.Info(m.Hostname, "was told to upgrade zood")
|
||||||
|
fmt.Fprintln(w, "apt update")
|
||||||
|
m.Upgrade = false
|
||||||
|
} else {
|
||||||
|
fmt.Fprintln(w, "good")
|
||||||
|
}
|
||||||
// log.Info("update machine protobuf", hostname)
|
// log.Info("update machine protobuf", hostname)
|
||||||
updateMachine(newm)
|
updateMachine(newm)
|
||||||
}
|
}
|
||||||
|
@ -67,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)
|
||||||
|
|
8
main.go
8
main.go
|
@ -35,19 +35,21 @@ func main() {
|
||||||
log.DaemonMode(true)
|
log.DaemonMode(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
me = new(stuff)
|
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 {
|
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
|
||||||
|
|
||||||
|
|
11
structs.go
11
structs.go
|
@ -7,13 +7,14 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.wit.com/gui"
|
"go.wit.com/gui"
|
||||||
|
"go.wit.com/lib/gadgets"
|
||||||
"go.wit.com/lib/protobuf/zoopb"
|
"go.wit.com/lib/protobuf/zoopb"
|
||||||
)
|
)
|
||||||
|
|
||||||
var me *stuff
|
var me *zookeep
|
||||||
|
|
||||||
// this app's variables
|
// this app's variables
|
||||||
type stuff 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
|
||||||
|
@ -21,8 +22,12 @@ type stuff 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
|
||||||
|
machinesWin *gadgets.GenericWindow // the machines gui window
|
||||||
|
machinesBox *gui.Node // the machines gui parent box widget
|
||||||
|
machinesTB *zoopb.MachinesTable // the machines gui table buffer
|
||||||
|
zood *stdTableWin // the zood version window
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -1,92 +0,0 @@
|
||||||
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
|
||||||
// Use of this source code is governed by the GPL 3.0
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go.wit.com/lib/gadgets"
|
|
||||||
"go.wit.com/log"
|
|
||||||
|
|
||||||
"go.wit.com/gui"
|
|
||||||
)
|
|
||||||
|
|
||||||
type genericWindow struct {
|
|
||||||
win *gadgets.BasicWindow // the window widget itself
|
|
||||||
box *gui.Node // the top box of the repolist window
|
|
||||||
group *gui.Node // the default group
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *genericWindow) Hidden() bool {
|
|
||||||
if r == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if r.win == nil {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return r.win.Hidden()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *genericWindow) Toggle() {
|
|
||||||
if r.Hidden() {
|
|
||||||
r.Show()
|
|
||||||
} else {
|
|
||||||
r.Hide()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *genericWindow) Show() {
|
|
||||||
if r == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if r.win == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r.win.Show()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *genericWindow) Hide() {
|
|
||||||
if r == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if r.win == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r.win.Hide()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *genericWindow) Disable() {
|
|
||||||
if r == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if r.box == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r.box.Disable()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *genericWindow) Enable() {
|
|
||||||
if r == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if r.box == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
r.box.Enable()
|
|
||||||
}
|
|
||||||
|
|
||||||
func initGenericWindow(title string, grouptxt string) *genericWindow {
|
|
||||||
gw := new(genericWindow)
|
|
||||||
gw.win = gadgets.RawBasicWindow(title)
|
|
||||||
gw.win.Make()
|
|
||||||
|
|
||||||
gw.box = gw.win.Box().Vertical() // a vertical box (like a stack of books)
|
|
||||||
gw.win.Custom = func() {
|
|
||||||
log.Warn("Found Window close. setting hidden=true")
|
|
||||||
// sets the hidden flag to false so Toggle() works
|
|
||||||
gw.win.Hide()
|
|
||||||
}
|
|
||||||
gw.group = gw.box.NewGroup(grouptxt)
|
|
||||||
gw.Show()
|
|
||||||
|
|
||||||
return gw
|
|
||||||
}
|
|
|
@ -0,0 +1,161 @@
|
||||||
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by the GPL 3.0
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/gui"
|
||||||
|
"go.wit.com/lib/gadgets"
|
||||||
|
"go.wit.com/lib/protobuf/zoopb"
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
grid := zood.win.Group.RawGrid()
|
||||||
|
grid.NewButton("save machines.pb", func() {
|
||||||
|
saveMachineState()
|
||||||
|
})
|
||||||
|
grid.NewButton("show active", func() {
|
||||||
|
zood.doMachinesUpgradeTable(me.machines)
|
||||||
|
})
|
||||||
|
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
|
||||||
|
zood.box = zood.win.Bottom.Box().SetProgName("TBOX")
|
||||||
|
zood.doMachinesUpgradeTable(me.machines)
|
||||||
|
|
||||||
|
return zood
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
zood.TB = AddMachinesPB(zood.box, pb)
|
||||||
|
f := func(m *zoopb.Machine) {
|
||||||
|
log.Info("Triggering machine", m.Hostname, "to upgrade zood")
|
||||||
|
m.Upgrade = true
|
||||||
|
}
|
||||||
|
zood.TB.Custom(f)
|
||||||
|
log.Info("table has uuid", zood.TB.GetUuid())
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddMachinesPB(tbox *gui.Node, pb *zoopb.Machines) *zoopb.MachinesTable {
|
||||||
|
t := pb.NewTable("MachinesPB")
|
||||||
|
t.NewUuid()
|
||||||
|
t.SetParent(tbox)
|
||||||
|
|
||||||
|
upbut := t.AddButtonFunc("upgrade", func(m *zoopb.Machine) string {
|
||||||
|
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"
|
||||||
|
})
|
||||||
|
upbut.Custom = func(m *zoopb.Machine) {
|
||||||
|
log.Info("Triggering machine", m.Hostname, "to upgrade zood")
|
||||||
|
m.Upgrade = true
|
||||||
|
}
|
||||||
|
|
||||||
|
t.AddHostname()
|
||||||
|
t.AddMemory()
|
||||||
|
t.AddCpus()
|
||||||
|
t.AddStringFunc("sMB", func(m *zoopb.Machine) string {
|
||||||
|
return fmt.Sprintf("%d mb", m.Memory/(1024*1024))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.AddStringFunc("zood", func(m *zoopb.Machine) string {
|
||||||
|
return findVersion(m, "zood")
|
||||||
|
})
|
||||||
|
delf := func(m *zoopb.Machine) string {
|
||||||
|
return "delete"
|
||||||
|
}
|
||||||
|
t.AddButtonFunc("delete", delf)
|
||||||
|
|
||||||
|
/*
|
||||||
|
// show if the machine needs to be upgraded
|
||||||
|
t.AddStringFunc("triggered?", func(m *zoopb.Machine) string {
|
||||||
|
if m.Upgrade {
|
||||||
|
return "yes"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
})
|
||||||
|
*/
|
||||||
|
|
||||||
|
t.AddTimeFunc("age", func(m *zoopb.Machine) time.Time {
|
||||||
|
return m.Laststamp.AsTime()
|
||||||
|
})
|
||||||
|
|
||||||
|
t.ShowTable()
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
func findVersion(m *zoopb.Machine, pkgname string) string {
|
||||||
|
zood := m.Packages.FindByName(pkgname)
|
||||||
|
if zood == nil {
|
||||||
|
return "n/a"
|
||||||
|
}
|
||||||
|
return zood.Version
|
||||||
|
}
|
Loading…
Reference in New Issue