try to debug Unmarshal() panic
This commit is contained in:
parent
8ad5e77931
commit
8eed7faa7c
6
Makefile
6
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 \
|
||||
|
|
3
apt.go
3
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 (
|
||||
|
|
|
@ -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 (
|
||||
|
|
3
argv.go
3
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
|
||||
|
||||
/*
|
||||
|
|
|
@ -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.
|
||||
|
|
7
doGui.go
7
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()
|
||||
}
|
||||
}
|
||||
|
|
7
http.go
7
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)
|
||||
|
|
27
machine.go
27
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)
|
||||
|
|
18
main.go
18
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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 (
|
||||
|
|
Loading…
Reference in New Issue