runs and saves config
This commit is contained in:
parent
8eed7faa7c
commit
2a47b8d48a
4
Makefile
4
Makefile
|
@ -7,8 +7,8 @@ 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 nogui
|
||||
./zookeeper --version
|
||||
all: goimports build
|
||||
./zookeeper
|
||||
|
||||
nogui:
|
||||
./zookeeper --gui nocui
|
||||
|
|
31
machine.go
31
machine.go
|
@ -13,21 +13,34 @@ import (
|
|||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
func rawGetHostname(data []byte) *zoopb.Machine {
|
||||
newm := new(zoopb.Machine)
|
||||
newm.Unmarshal(data)
|
||||
return newm
|
||||
}
|
||||
|
||||
func handleMachine(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 == "" {
|
||||
log.Info("something went wrong. hostname is blank")
|
||||
log.Info("hostname is blank even after unmarshal. data len =", len(data))
|
||||
return
|
||||
}
|
||||
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)
|
||||
am := new(zoopb.Machine)
|
||||
am.Hostname = newm.Hostname
|
||||
am.Memory = newm.Memory
|
||||
me.machines2.Append(am)
|
||||
return
|
||||
}
|
||||
log.Info("not new machine", hostname)
|
||||
|
@ -44,7 +57,7 @@ func updateMachine(u *zoopb.Machine) string {
|
|||
log.Info("adding new machine", u.Hostname)
|
||||
me.machines.Append(u)
|
||||
log.Info("save machines pb file here...")
|
||||
// me.machines.ConfigSave()
|
||||
me.machines2.ConfigSave()
|
||||
return "new"
|
||||
}
|
||||
// log.Info("updating machine", m.Hostname)
|
||||
|
|
Loading…
Reference in New Issue