Compare commits

...

41 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
Jeff Carr bb4a6a01df try to fix zood update 2025-03-06 07:54:56 -06:00
Jeff Carr 76c5626d0a trigger apt upgrade 2025-03-06 05:34:25 -06:00
Jeff Carr e85a8ae69f talking with zood again 2025-03-06 05:34:25 -06:00
Jeff Carr 8c7f6c3c1b more gui buttons 2025-03-06 05:34:25 -06:00
Jeff Carr 8edebe18e1 cleaner window code 2025-03-06 05:34:25 -06:00
Jeff Carr f97e2a48c6 1st really awesome table with auto updates 2025-03-06 05:34:25 -06:00
Jeff Carr 40fedc09b4 autogenpb changes 2025-03-05 22:14:21 -06:00
Jeff Carr 53dbe44d38 fixes for 'go vet' 2025-03-05 13:33:04 -06:00
Jeff Carr d214d670ac continue locally now 2025-03-05 12:42:50 -06:00
Jeff Carr b621bba629 testing code 2025-03-05 12:42:50 -06:00
Jeff Carr a57b2875af protobuf update works 2025-03-05 12:42:50 -06:00
Jeff Carr 46f69bee21 rm old code 2025-02-22 14:46:17 -06:00
Jeff Carr c5f840ec2f fixes for go-args 2025-02-22 14:31:08 -06:00
Jeff Carr 7e19f3b9ae rm old code. long live generic protobuf tables 2025-02-22 13:50:27 -06:00
Jeff Carr 49d2653fd4 convert to pb grid 2025-02-22 13:50:27 -06:00
Jeff Carr e9f7b99846 time in a table works 2025-02-20 03:23:14 -06:00
Jeff Carr d667d8c26a attempt a table string func 2025-02-19 17:39:45 -06:00
Jeff Carr 3a42f0f9a5 string rows 2025-02-19 17:39:45 -06:00
Jeff Carr 58ff04ba4d more table tests 2025-02-19 17:39:45 -06:00
Jeff Carr 656f706aa1 testing close window 2025-02-19 17:39:44 -06:00
Jeff Carr b53e71ed9e app works again 2025-02-16 12:05:28 -06:00
Jeff Carr 97f29457db runs and saves config 2025-02-15 12:21:32 -06:00
Jeff Carr 8eed7faa7c try to debug Unmarshal() panic 2025-02-15 12:21:28 -06:00
Jeff Carr 8ad5e77931 show some more details in the table 2025-02-15 07:28:42 -06:00
Jeff Carr d3b6c1725d preliminary table 2025-02-15 07:28:39 -06:00
Jeff Carr 875da60adb adds machines to table 2025-02-15 07:28:36 -06:00
Jeff Carr 25bc18c55f start a table window 2025-02-15 07:28:34 -06:00
Jeff Carr 940d259bbf start a gui 2025-02-15 07:28:30 -06:00
Jeff Carr 6b3651edb7 minor autogenpb api change 2025-02-08 19:01:02 -06:00
Jeff Carr b7368c92fd func name change 2025-02-07 04:41:04 -06:00
Jeff Carr 08bf0f5703 fix build 2025-01-18 15:48:34 -06:00
Jeff Carr d9fa76289d trash git notes 2025-01-18 03:59:25 -06:00
Jeff Carr 53b9ce8a11 Merge branch 'jcarr' of gitea.wit.com:jcarr/zookeeper into jcarr 2025-01-18 03:56:22 -06:00
Jeff Carr 128591a3b9 notsure on this thing. still probably do something else 2024-12-30 04:40:00 -06:00
Jeff Carr cea50e3541 do targets some other way
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-12-30 01:35:32 -06:00
Jeff Carr 95fe5a4eab Merge branch 'jcarr' of gitea.wit.com:jcarr/zookeeper into jcarr 2024-12-29 23:21:46 -06:00
Jeff Carr d62931e46a do targets some other way
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-12-29 23:21:21 -06:00
Jeff Carr 1abcc862fe code is better because of autogenpb 2024-12-04 02:25:46 -06:00
Jeff Carr 5d9eb5add6 runs and reports versions
Signed-off-by: Jeff Carr <jcarr@wit.com>
2024-11-24 23:22:52 -06:00
13 changed files with 550 additions and 169 deletions

View File

@ -7,12 +7,24 @@ 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: build all: goimports gocui-debugging
./zookeeper --version # ./zookeeper
./zookeeper
build: vet:
GO111MODULE=off go build \ @GO111MODULE=off go vet
@echo this go binary package builds okay
nogui:
./zookeeper --gui nocui
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 \
-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}"
install: install:
@ -39,6 +51,7 @@ redomod:
clean: clean:
rm -f go.* rm -f go.*
rm -f zookeeper rm -f zookeeper
go-mod-clean --purge
# git clone the sources and all the golang dependancies into ~/go/src # git clone the sources and all the golang dependancies into ~/go/src
# if you don't have go-clone, you can get it from http://go.wit.com/ # if you don't have go-clone, you can get it from http://go.wit.com/
@ -51,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"

13
apt.go
View File

@ -1,3 +1,6 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main package main
import ( import (
@ -21,19 +24,15 @@ func initPackages() {
new1 := new(zoopb.Package) new1 := new(zoopb.Package)
new1.Name = pkg new1.Name = pkg
new1.Version = version new1.Version = version
if me.packages.Append(new1) { me.packages.Append(new1)
// log.Info("added", new1.Name, "ok")
} else {
log.Info("added", new1.Name, "failed")
}
} }
log.Info(me.hostname, "has distro", me.distro, "with", me.packages.Len(), "packages installed") log.Info(me.hostname, "has distro", me.distro, "with", me.packages.Len(), "packages installed")
} }
func addNew(name string, version string) bool { func addNew(name string, version string) {
new1 := new(zoopb.Package) new1 := new(zoopb.Package)
new1.Name = name new1.Name = name
new1.Version = version new1.Version = version
return me.packages.Append(new1) me.packages.Append(new1)
} }

View File

@ -1,3 +1,6 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main package main
import ( import (

13
argv.go
View File

@ -1,3 +1,6 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main package main
/* /*
@ -6,24 +9,26 @@ package main
*/ */
import ( import (
"go.wit.com/dev/alexflint/arg"
"go.wit.com/log" "go.wit.com/log"
) )
var argv args var argv args
type args struct { type args struct {
Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"` Verbose bool `arg:"--verbose" default:"false" help:"talk more"`
Port int `arg:"--port" default:"8080" help:"port to run on"` Daemon bool `arg:"--daemon" default:"false" help:"run in daemon mode"`
Port int `arg:"--port" default:"8080" help:"port to run on"`
} }
func (args) Version() string { func (args) Version() string {
return "zood " + VERSION + " Built on: " + BUILDTIME return "zookeeper " + VERSION + " Built on: " + BUILDTIME
} }
/*
func init() { func init() {
arg.MustParse(&argv) arg.MustParse(&argv)
} }
*/
func (a args) Description() string { func (a args) Description() string {
return ` return `

View File

@ -1,4 +1,7 @@
// Copyright 2016 The go-qemu Authors. // Copyright 2016 The go-qemu Authors.
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.

88
doGui.go Normal file
View File

@ -0,0 +1,88 @@
// 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 (
"os"
"time"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log"
)
// refresh the windows & tables the user has open
func refresh() {
if argv.Verbose {
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)
}
}
}
}
func doGui() {
me.myGui = gui.New()
me.myGui.InitEmbed(resources)
me.myGui.Default()
win := gadgets.RawBasicWindow("Zookeeper: (inventory your cluster)")
win.Make()
win.Show()
win.Custom = func() {
log.Warn("Main window close")
os.Exit(0)
}
box := win.Box()
vbox := box.NewVerticalBox("BOX2")
group1 := vbox.NewGroup("Zookeeper Settings")
grid := group1.NewGrid("buildOptions", 0, 0)
grid.NewButton("zood versions", func() {
// if the window exists, just toggle it open or closed
if me.zood != nil {
me.zood.Toggle()
return
}
me.zood = makeZoodWin()
})
grid.NewButton("Cluster Events", func() {
log.Info("todo: start a list here!")
})
// sit here forever refreshing the GUI
for {
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()
}

154
http.go
View File

@ -1,3 +1,6 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main package main
import ( import (
@ -6,7 +9,6 @@ import (
"net/http" "net/http"
"strings" "strings"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log" "go.wit.com/log"
) )
@ -21,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 {
@ -36,115 +36,65 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
} }
if route == "/machine" { if route == "/machine" {
var m *zoopb.Machine handleMachine(r, w, hostname, msg)
m = new(zoopb.Machine) return
if err := m.Unmarshal(msg); err != nil { }
log.Info("proto.Unmarshal() failed on wire message len", len(msg))
log.Info("error =", err) /*
return if route == "/status" {
} var packs *zoopb.Packages
log.Log(INFO, "proto.Unmarshal() worked on wire message len", len(msg), "from", m.Hostname) packs = new(zoopb.Packages)
b := me.upgrade[m.Hostname] if err := packs.Unmarshal(msg); err != nil {
switch updateMachine(m) { log.Info("/status proto.Unmarshal() failed on wire message len", len(msg), "from", hostname)
case "upgrade": return
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" { log.Info("/status Unmarshal worked with msg len", len(msg), "from", hostname)
if hostname == "" { log.Info("/status hostname", hostname, "has", packs.Len(), "packages installed")
// ignore junk fmt.Fprintln(w, "upgrade")
log.Info("hostname was blank")
return return
} }
var packs *zoopb.Packages */
packs = new(zoopb.Packages)
if err := packs.Unmarshal(msg); err != nil {
log.Info("proto.Unmarshal() failed on wire message len", len(msg), "from", hostname)
return
}
log.Info("Unmarshal worked with msg len", len(msg), "from", hostname)
log.Info(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.SortByName() defer log.HttpMode(nil)
for loop.Scan() { loop := me.machines.SortByHostname()
m := loop.Machine() for loop.Scan() {
zood := m.FindPackageByName("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("zood version", zood.Version, "vs target version", v, "on machine", m.Hostname) } else {
log.Info(fmt.Sprintf("zood version %s vs target version %s on machine %s", zood.Version, v, m.Hostname))
}
} }
}
return
}
// save the config file
if route == "/save" {
log.HttpMode(w)
defer log.HttpMode(nil)
data, err := me.machines.Marshal()
if err != nil {
log.Info("proto.Marshal() failed len", len(msg), err)
return return
} }
log.Info("proto.Marshal() worked len", len(msg)) */
// me.machines.ConfigSave()
zoopb.ConfigSaveRaw(data)
return
}
// flag a package to attempt to upgrade if route == "/uptime" {
if route == "/upgrade" { if me.zood == nil {
log.HttpMode(w) fmt.Fprintf(w, "BAD zood == nil\n")
defer log.HttpMode(nil) return
me.upgrade[hostname] = true }
log.Log(NOW, "setting package ", packname, " to upgrade") var count int
return var bad int
} all := me.machines.All()
for all.Scan() {
// set the target version for a package m := all.Next()
if route == "/target" { count += 1
log.HttpMode(w) if findVersion(m, "zood") != me.zood.version {
defer log.HttpMode(nil) bad += 1
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.Bool() {
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) if bad == 0 {
fmt.Fprintf(w, "GOOD machine count=(%d) all machines are version %s\n", count, me.zood.version)
} else {
fmt.Fprintf(w, "BAD machine count=(%d) upgrade=(%d) to %s\n", count, bad, me.zood.version)
} }
return return
} }

83
httpDump.go Normal file
View File

@ -0,0 +1,83 @@
package main
import (
"fmt"
"net/http"
)
func dumpRemoteAddr(r *http.Request) string {
return r.RemoteAddr
}
func dumpUserAgent(r *http.Request) string {
var all string
for param, values := range r.URL.Query() {
for _, value := range values {
all += fmt.Sprint(" Query:", param, value)
}
}
// hostname := r.URL.Query().Get("hostname")
return r.UserAgent() + all
}
func dumpClient(r *http.Request) {
/*
var host, url, proto, addr, agent string
host = r.Host
url = r.URL.String()
proto = r.Proto
addr = r.RemoteAddr
agent = r.UserAgent()
log.Warn(host, proto, addr, url, agent)
fmt.Fprintln(accessf, time.Now(), host, proto, addr, url, agent)
// return
fmt.Fprintln(clientf)
fmt.Fprintln(clientf, time.Now())
// Basic request information
fmt.Fprintln(clientf, "Method:", r.Method)
fmt.Fprintln(clientf, "URL:", r.URL)
fmt.Fprintln(clientf, "Protocol:", r.Proto)
fmt.Fprintln(clientf, "Host:", r.Host)
fmt.Fprintln(clientf, "Remote Address:", r.RemoteAddr)
// Headers
fmt.Fprintln(clientf, "Headers:")
for name, values := range r.Header {
for _, value := range values {
fmt.Fprintln(clientf, "Headers:", name, value)
}
}
// Query parameters
fmt.Fprintln(clientf, "Query Parameters:")
for param, values := range r.URL.Query() {
for _, value := range values {
fmt.Fprintln(clientf, "Query:", param, value)
}
}
// User-Agent
fmt.Fprintln(clientf, "User-Agent:", r.UserAgent())
// Content Length
fmt.Fprintln(clientf, "Content Length:", r.ContentLength)
// Cookies
fmt.Fprintln(clientf, "Cookies:")
for _, cookie := range r.Cookies() {
fmt.Fprintln(clientf, cookie.Name, cookie.Value)
}
// Request Body (if applicable)
if r.Body != nil {
body, err := ioutil.ReadAll(r.Body)
if err == nil {
fmt.Fprintln(clientf, "Body:", string(body))
}
}
*/
}

View File

@ -1,20 +1,86 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main package main
import ( import (
"fmt"
"net/http"
"strings"
"time"
"go.wit.com/lib/protobuf/zoopb" "go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log" "go.wit.com/log"
"google.golang.org/protobuf/types/known/timestamppb"
) )
func rawGetHostname(data []byte) *zoopb.Machine {
newm := new(zoopb.Machine)
newm.Unmarshal(data)
return newm
}
func handleMachine(r *http.Request, w http.ResponseWriter, hostname string, data []byte) {
hostname = strings.TrimSpace(hostname)
newm := rawGetHostname(data)
if newm == nil {
log.Info("unmarshal failed on data len =", len(data))
}
if hostname != newm.Hostname {
// log.Info("hostname mismatch", hostname, "vs", newm.Hostname)
hostname = newm.Hostname
}
if hostname == "" {
ua := dumpUserAgent(r)
ra := dumpRemoteAddr(r)
log.Info("hostname is blank even after unmarshal. data len =", len(data), ra, ua, newm.Cpus, newm.Hostname)
return
}
// log.Info("lookoing for", hostname)
m := me.machines.FindByHostname(hostname)
if m == nil {
am := new(zoopb.Machine)
am.Hostname = newm.Hostname
am.Memory = newm.Memory
// me.machines2.Append(am)
me.machines.Append(newm)
log.Info("new machine", am.Hostname, am.Memory)
return
}
ua := dumpUserAgent(r)
ra := dumpRemoteAddr(r)
if m.UserAgent != ua {
log.Info("hostname ua changed len =", len(data), ra, hostname, 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)
updateMachine(newm)
}
// someone sent machine 'u' is it new? // someone sent machine 'u' is it new?
// if not, update the record of it // if not, update the record of it
func updateMachine(u *zoopb.Machine) string { func updateMachine(u *zoopb.Machine) string {
if u == nil { if u == nil {
return "nil" return "nil"
} }
m := me.machines.FindByName(u.Hostname) m := me.machines.FindByHostname(u.Hostname)
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)
if me.zood == nil {
// 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)
@ -38,9 +104,10 @@ func updateMachine(u *zoopb.Machine) string {
if u.Packages == nil { if u.Packages == nil {
u.Packages = new(zoopb.Packages) u.Packages = new(zoopb.Packages)
} }
if zood := m.FindPackageByName("zood"); zood != nil { if zood := m.Packages.FindByName("zood"); zood != nil {
log.Log(INFO, m.Hostname, "has zood version", zood.Version) log.Log(INFO, m.Hostname, "has zood version", zood.Version)
} }
m.Laststamp = timestamppb.New(time.Now())
updatePackages(m, u.Packages) updatePackages(m, u.Packages)
return "upgrade" return "upgrade"
@ -55,18 +122,18 @@ func updatePackages(m *zoopb.Machine, newp *zoopb.Packages) bool {
loop := newp.SortByName() loop := newp.SortByName()
for loop.Scan() { for loop.Scan() {
p := loop.Package() p := loop.Next()
if p.Name == "zood" { if p.Name == "zood" {
if pold := m.FindPackageByName("zood"); pold == nil { if pold := m.Packages.FindByName("zood"); pold == nil {
changed = true changed = true
log.Log(ZOOD, "updatePackages() new package", p.Name , "version", p.Version, "machine", m.Hostname) log.Log(ZOOD, "updatePackages() new package", p.Name, "version", p.Version, "machine", m.Hostname)
m.Packages.Append(p) m.Packages.Append(p)
} else { } else {
if p.Version == pold.Version { if p.Version == pold.Version {
log.Log(ZOOD, "updatePackages() unchanged", p.Version, "machine", m.Hostname) log.Log(ZOOD, "updatePackages() unchanged", p.Version, "machine", m.Hostname)
} else { } else {
changed = true changed = true
log.Log(NOW, "updatePackages() package", p.Name , "version changed", pold.Version, "to", p.Version, "machine", m.Hostname) log.Log(NOW, "updatePackages() package", p.Name, "version changed", pold.Version, "to", p.Version, "machine", m.Hostname)
pold.Version = p.Version pold.Version = p.Version
} }
} }

42
main.go
View File

@ -1,16 +1,5 @@
// Copyright 2016 The go-qemu Authors. // Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// // Use of this source code is governed by the GPL 3.0
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main package main
@ -20,6 +9,7 @@ import (
"time" "time"
"go.wit.com/dev/alexflint/arg" "go.wit.com/dev/alexflint/arg"
"go.wit.com/gui"
"go.wit.com/lib/protobuf/zoopb" "go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log" "go.wit.com/log"
) )
@ -32,6 +22,7 @@ var resources embed.FS
func main() { func main() {
var pp *arg.Parser var pp *arg.Parser
gui.InitArg()
pp = arg.MustParse(&argv) pp = arg.MustParse(&argv)
if pp == nil { if pp == nil {
@ -44,14 +35,27 @@ 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 = new(zoopb.Machines) me.machines = zoopb.NewMachines()
me.targets = make(map[string]string) // keep track of what versions the machines should be running // me.machines2 = zoopb.NewMachines()
me.upgrade = make(map[string]bool) // used to trigger upgrade attempts 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)
}
*/
// 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
go NewWatchdog() go NewWatchdog()
startHTTP() go startHTTP()
doGui()
} }

View File

@ -1,22 +1,33 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main package main
import ( import (
"time" "time"
"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
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
targets map[string]string // what versions the machines should be running // machines2 *zoopb.Machines // every machine that has reported itself to the zookeeper
upgrade map[string]bool // use this to trigger builds 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
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
} }

View File

@ -1,3 +1,6 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main package main
import ( import (
@ -41,18 +44,18 @@ func NewWatchdog() {
case t := <-me.dog.C: case t := <-me.dog.C:
// log.Info("zookeeper Watchdog() ticked", me.hostname, "Current time: ", t) // log.Info("zookeeper Watchdog() ticked", me.hostname, "Current time: ", t)
var counter int var counter int
loop := me.machines.SortByName() loop := me.machines.SortByHostname()
for loop.Scan() { for loop.Scan() {
m := loop.Machine() m := loop.Next()
counter += 1 counter += 1
zood := m.FindPackageByName("zood") zood := m.Packages.FindByName("zood")
if zood == nil { if zood == nil {
log.Info("machine", m.Hostname, "does not have zood installed") log.Info("machine", m.Hostname, "does not have zood installed")
} else { } else {
// 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()

161
windowZood.go Normal file
View File

@ -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
}