diff options
| author | Jeff Carr <[email protected]> | 2025-02-15 11:39:25 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-02-15 12:21:32 -0600 |
| commit | 97f29457dbee65a4404570fd17fd5d0f08e21502 (patch) | |
| tree | a088ec6ecfc9d5720ff541df05ba6f15189175ec | |
| parent | 8eed7faa7c123ab64b013f3362be35248a389d03 (diff) | |
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | machine.go | 31 |
2 files changed, 24 insertions, 11 deletions
@@ -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 @@ -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) |
