From 8eed7faa7c123ab64b013f3362be35248a389d03 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 15 Feb 2025 09:11:45 -0600 Subject: try to debug Unmarshal() panic --- Makefile | 6 ++++-- apt.go | 3 +++ apt_linux.go | 3 +++ argv.go | 3 +++ distro.go | 3 +++ doGui.go | 7 ++++++- http.go | 7 ++++++- machine.go | 27 +++++++++++++++++++++++++++ main.go | 18 ++++-------------- structs.go | 4 ++++ tableWindow.go | 1 + watchdog.go | 3 +++ 12 files changed, 67 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index 785389c..498b014 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,11 @@ 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.sum ]; then echo go.sum exists; else GO111MODULE= go mod init; GO111MODULE= go mod tidy; fi) -all: goimports build +all: goimports build nogui ./zookeeper --version - ./zookeeper + +nogui: + ./zookeeper --gui nocui build: GO111MODULE=off go build -v -x \ diff --git a/apt.go b/apt.go index df37dcd..89406f2 100644 --- a/apt.go +++ b/apt.go @@ -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 import ( diff --git a/apt_linux.go b/apt_linux.go index 7e534f0..1abb583 100644 --- a/apt_linux.go +++ b/apt_linux.go @@ -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 import ( diff --git a/argv.go b/argv.go index 80635c5..ae1ffde 100644 --- a/argv.go +++ b/argv.go @@ -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 /* diff --git a/distro.go b/distro.go index e6852b9..dcb759e 100644 --- a/distro.go +++ b/distro.go @@ -1,4 +1,7 @@ // 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. diff --git a/doGui.go b/doGui.go index d8a1f92..5f0be92 100644 --- a/doGui.go +++ b/doGui.go @@ -84,12 +84,17 @@ func (tw *tableWindow) showTable(allm *zoopb.Machines) { m := all.Next() tw.grid.NewLabel(m.Hostname) tw.grid.NewLabel(fmt.Sprintf("%d", m.Cpus)) - tw.grid.NewLabel(fmt.Sprintf("%d", m.Memory)) + gb := m.Memory / (1024 * 1024) + ms := fmt.Sprintf("%d MB", gb) + tw.grid.NewLabel(ms) tw.grid.NewLabel(m.Distro) tw.grid.NewLabel(findVersion(m, "zood")) tw.grid.NewLabel(findVersion(m, "bash")) dur := m.Laststamp.AsTime() tw.grid.NewLabel(fmt.Sprintf("%v", time.Since(dur))) + tw.grid.NewButton("upgrade", func() { + log.Info("figure out upgrade", m.Hostname) + }) tw.grid.NextRow() } } diff --git a/http.go b/http.go index 827f5e1..3f559ca 100644 --- a/http.go +++ b/http.go @@ -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 import ( @@ -37,6 +40,8 @@ func okHandler(w http.ResponseWriter, r *http.Request) { } if route == "/machine" { + handleMachine(w, hostname, msg) + var m *zoopb.Machine m = new(zoopb.Machine) if err := m.Unmarshal(msg); err != nil { @@ -97,7 +102,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { if route == "/save" { log.HttpMode(w) defer log.HttpMode(nil) - if err := me.machines.ConfigSave(); err == nil { + if err := me.machines2.ConfigSave(); err == nil { log.Log(NOW, "ConfigSave() ok") } else { log.Log(NOW, "ConfigSave() failed", err) diff --git a/machine.go b/machine.go index ea8f424..999e31b 100644 --- a/machine.go +++ b/machine.go @@ -1,6 +1,11 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + package main import ( + "net/http" + "strings" "time" "go.wit.com/lib/protobuf/zoopb" @@ -8,6 +13,26 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" ) +func handleMachine(w http.ResponseWriter, hostname string, data []byte) { + hostname = strings.TrimSpace(hostname) + if hostname == "" { + log.Info("something went wrong. hostname is blank") + } + log.Info("lookoing for", hostname) + m := me.machines.FindByHostname(hostname) + if m == nil { + newm := new(zoopb.Machine) + err := newm.Unmarshal(data) + if err != nil { + log.Info("machine Unmarshal() failed", hostname) + return + } + me.machines.Append(newm) + return + } + log.Info("not new machine", hostname) +} + // someone sent machine 'u' is it new? // if not, update the record of it func updateMachine(u *zoopb.Machine) string { @@ -18,6 +43,8 @@ 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.machines.ConfigSave() return "new" } // log.Info("updating machine", m.Hostname) diff --git a/main.go b/main.go index 01edde3..88115d1 100644 --- a/main.go +++ b/main.go @@ -1,16 +1,5 @@ -// Copyright 2016 The go-qemu Authors. -// -// 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. +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 package main @@ -47,7 +36,8 @@ func main() { me = new(stuff) me.hostname, _ = os.Hostname() me.pollDelay = 10 * time.Second - me.machines = new(zoopb.Machines) + me.machines = zoopb.NewMachines() + me.machines2 = zoopb.NewMachines() if err := me.machines.ConfigLoad(); err != nil { log.Warn("load config failed", err) os.Exit(-1) diff --git a/structs.go b/structs.go index 42846ee..f3978c3 100644 --- a/structs.go +++ b/structs.go @@ -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 import ( @@ -18,6 +21,7 @@ type stuff struct { 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 diff --git a/tableWindow.go b/tableWindow.go index 39e21b9..f4db2b9 100644 --- a/tableWindow.go +++ b/tableWindow.go @@ -89,6 +89,7 @@ func makeTableWindow() *tableWindow { pw.grid.NewLabel("zood") pw.grid.NewLabel("bash") pw.grid.NewLabel("age") + pw.grid.NewLabel("upgrade") pw.grid.NextRow() // add the patches to the grid diff --git a/watchdog.go b/watchdog.go index 9cce396..6cea461 100644 --- a/watchdog.go +++ b/watchdog.go @@ -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 import ( -- cgit v1.2.3