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.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 nogui
|
all: goimports build
|
||||||
./zookeeper --version
|
./zookeeper
|
||||||
|
|
||||||
nogui:
|
nogui:
|
||||||
./zookeeper --gui nocui
|
./zookeeper --gui nocui
|
||||||
|
|
31
machine.go
31
machine.go
|
@ -13,21 +13,34 @@ import (
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"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) {
|
func handleMachine(w http.ResponseWriter, hostname string, data []byte) {
|
||||||
hostname = strings.TrimSpace(hostname)
|
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 == "" {
|
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)
|
log.Info("lookoing for", hostname)
|
||||||
m := me.machines.FindByHostname(hostname)
|
m := me.machines.FindByHostname(hostname)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
newm := new(zoopb.Machine)
|
am := new(zoopb.Machine)
|
||||||
err := newm.Unmarshal(data)
|
am.Hostname = newm.Hostname
|
||||||
if err != nil {
|
am.Memory = newm.Memory
|
||||||
log.Info("machine Unmarshal() failed", hostname)
|
me.machines2.Append(am)
|
||||||
return
|
|
||||||
}
|
|
||||||
me.machines.Append(newm)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("not new machine", hostname)
|
log.Info("not new machine", hostname)
|
||||||
|
@ -44,7 +57,7 @@ func updateMachine(u *zoopb.Machine) string {
|
||||||
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...")
|
log.Info("save machines pb file here...")
|
||||||
// me.machines.ConfigSave()
|
me.machines2.ConfigSave()
|
||||||
return "new"
|
return "new"
|
||||||
}
|
}
|
||||||
// log.Info("updating machine", m.Hostname)
|
// log.Info("updating machine", m.Hostname)
|
||||||
|
|
Loading…
Reference in New Issue