From d09f4e25c25dced54d688597b5e9a903c456573d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 23 Oct 2024 19:15:51 -0500 Subject: [PATCH] switched to pb.DropletState enum Signed-off-by: Jeff Carr --- addDroplet.go | 3 ++- event.go | 5 +++-- http.go | 5 +++-- poll.go | 13 +++++++------ structs.go | 2 +- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/addDroplet.go b/addDroplet.go index 0484758..8c805cb 100644 --- a/addDroplet.go +++ b/addDroplet.go @@ -25,7 +25,8 @@ func addDomainDroplet(domcfg *libvirtxml.Domain) (*DropletT, error) { d = new(DropletT) d.pb = me.cluster.AddDroplet(domcfg.UUID, domcfg.Name, 2, 2*1024*1024) - d.pb.StartState = "off" + d.pb.StartState = pb.DropletState_OFF + d.CurrentState = pb.DropletState_UNKNOWN me.droplets = append(me.droplets, d) me.changed = true diff --git a/event.go b/event.go index a030736..4358ab6 100644 --- a/event.go +++ b/event.go @@ -6,6 +6,7 @@ import ( "time" "go.wit.com/lib/gui/shell" + pb "go.wit.com/lib/protobuf/virtbuf" "go.wit.com/log" ) @@ -43,7 +44,7 @@ func clusterReady() (bool, string) { } func (d *DropletT) dropletReady() (bool, string) { - if d.CurrentState == "ON" { + if d.CurrentState == pb.DropletState_ON { return false, "EVENT start droplet is already ON" } if d.starts > 2 { @@ -86,7 +87,7 @@ func Start(name string) (bool, string) { return false, result } - if d.CurrentState == "ON" { + if d.CurrentState == pb.DropletState_ON { return false, "EVENT start droplet is already ON" } diff --git a/http.go b/http.go index ba1559a..fd1ff1d 100644 --- a/http.go +++ b/http.go @@ -7,6 +7,7 @@ import ( "time" "go.wit.com/lib/gui/shell" + pb "go.wit.com/lib/protobuf/virtbuf" "go.wit.com/log" ) @@ -23,7 +24,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { // is the cluster running what it should? if tmp == "/droplets" { for _, d := range me.droplets { - if d.pb.StartState != "ON" { + if d.pb.StartState != pb.DropletState_ON { continue } dur := time.Since(d.lastpoll) // Calculate the elapsed time @@ -33,7 +34,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) { } else { hname = d.h.pb.Hostname } - if d.CurrentState != "ON" { + if d.CurrentState != pb.DropletState_ON { fmt.Fprintln(w, "BAD STATE ", d.pb.Hostname, hname, "(", d.pb.StartState, "vs", d.CurrentState, ")", shell.FormatDuration(dur)) } else { dur := time.Since(d.lastpoll) // Calculate the elapsed time diff --git a/poll.go b/poll.go index 7cd7ba6..b8134f5 100644 --- a/poll.go +++ b/poll.go @@ -6,6 +6,7 @@ import ( "time" "go.wit.com/lib/gui/shell" + pb "go.wit.com/lib/protobuf/virtbuf" "go.wit.com/log" ) @@ -38,14 +39,14 @@ func (h *HyperT) pollHypervisor() { d.pb.Hostname = name d.h = h d.lastpoll = time.Now() - d.CurrentState = "ON" + d.CurrentState = pb.DropletState_ON me.droplets = append(me.droplets, d) log.Log(EVENT, name, "IS NEW. ADDED ON", h.pb.Hostname) } log.Log(INFO, "ALREADY RECORDED", d.pb.Hostname) // update the status to ON and the last polled value - d.CurrentState = "ON" + d.CurrentState = pb.DropletState_ON d.lastpoll = time.Now() if d.h == nil { @@ -108,11 +109,11 @@ func clusterHealthy() (bool, string) { for _, d := range me.droplets { total += 1 - if d.pb.StartState != "ON" { + if d.pb.StartState != pb.DropletState_ON { continue } dur := time.Since(d.lastpoll) // Calculate the elapsed time - if d.CurrentState == "" { + if d.CurrentState == pb.DropletState_UNKNOWN { // log.Info("SKIP. hostname has not been polled yet", d.pb.Hostname, d.hname) unknown += 1 unknownList = append(unknownList, d.pb.Hostname) @@ -122,7 +123,7 @@ func clusterHealthy() (bool, string) { if d.h != nil { hname = d.h.pb.Hostname } - if d.CurrentState != "ON" { + if d.CurrentState != pb.DropletState_ON { log.Info("BAD STATE", d.pb.StartState, d.pb.Hostname, hname, "CurrentState =", d.CurrentState, shell.FormatDuration(dur)) good = false failed += 1 @@ -131,7 +132,7 @@ func clusterHealthy() (bool, string) { if dur > time.Minute { log.Info("GOOD STATE MISSING", d.pb.Hostname, hname, shell.FormatDuration(dur)) good = false - d.CurrentState = "MISSING" + d.CurrentState = pb.DropletState_UNKNOWN failed += 1 continue } diff --git a/structs.go b/structs.go index 50f2af1..190cd67 100644 --- a/structs.go +++ b/structs.go @@ -44,7 +44,7 @@ type DropletT struct { pb *pb.Droplet // the Droplet protobuf xml *libvirtxml.Domain // a xml representation from libvirt h *HyperT // the hypervisor it's currently running on - CurrentState string // what the state of the droplet is ACTUALLY IS + CurrentState pb.DropletState // what the state of the droplet is ACTUALLY IS lastpoll time.Time // the last time the droplet was seen running starts int // how many times a start event has been attempted }