switched to pb.DropletState enum

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-23 19:15:51 -05:00
parent 3ce3a0d7f6
commit d09f4e25c2
5 changed files with 16 additions and 12 deletions

View File

@ -25,7 +25,8 @@ func addDomainDroplet(domcfg *libvirtxml.Domain) (*DropletT, error) {
d = new(DropletT) d = new(DropletT)
d.pb = me.cluster.AddDroplet(domcfg.UUID, domcfg.Name, 2, 2*1024*1024) 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.droplets = append(me.droplets, d)
me.changed = true me.changed = true

View File

@ -6,6 +6,7 @@ import (
"time" "time"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/log" "go.wit.com/log"
) )
@ -43,7 +44,7 @@ func clusterReady() (bool, string) {
} }
func (d *DropletT) dropletReady() (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" return false, "EVENT start droplet is already ON"
} }
if d.starts > 2 { if d.starts > 2 {
@ -86,7 +87,7 @@ func Start(name string) (bool, string) {
return false, result return false, result
} }
if d.CurrentState == "ON" { if d.CurrentState == pb.DropletState_ON {
return false, "EVENT start droplet is already ON" return false, "EVENT start droplet is already ON"
} }

View File

@ -7,6 +7,7 @@ import (
"time" "time"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/log" "go.wit.com/log"
) )
@ -23,7 +24,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
// is the cluster running what it should? // is the cluster running what it should?
if tmp == "/droplets" { if tmp == "/droplets" {
for _, d := range me.droplets { for _, d := range me.droplets {
if d.pb.StartState != "ON" { if d.pb.StartState != pb.DropletState_ON {
continue continue
} }
dur := time.Since(d.lastpoll) // Calculate the elapsed time dur := time.Since(d.lastpoll) // Calculate the elapsed time
@ -33,7 +34,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
} else { } else {
hname = d.h.pb.Hostname 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)) fmt.Fprintln(w, "BAD STATE ", d.pb.Hostname, hname, "(", d.pb.StartState, "vs", d.CurrentState, ")", shell.FormatDuration(dur))
} else { } else {
dur := time.Since(d.lastpoll) // Calculate the elapsed time dur := time.Since(d.lastpoll) // Calculate the elapsed time

13
poll.go
View File

@ -6,6 +6,7 @@ import (
"time" "time"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
pb "go.wit.com/lib/protobuf/virtbuf"
"go.wit.com/log" "go.wit.com/log"
) )
@ -38,14 +39,14 @@ func (h *HyperT) pollHypervisor() {
d.pb.Hostname = name d.pb.Hostname = name
d.h = h d.h = h
d.lastpoll = time.Now() d.lastpoll = time.Now()
d.CurrentState = "ON" d.CurrentState = pb.DropletState_ON
me.droplets = append(me.droplets, d) me.droplets = append(me.droplets, d)
log.Log(EVENT, name, "IS NEW. ADDED ON", h.pb.Hostname) log.Log(EVENT, name, "IS NEW. ADDED ON", h.pb.Hostname)
} }
log.Log(INFO, "ALREADY RECORDED", d.pb.Hostname) log.Log(INFO, "ALREADY RECORDED", d.pb.Hostname)
// update the status to ON and the last polled value // update the status to ON and the last polled value
d.CurrentState = "ON" d.CurrentState = pb.DropletState_ON
d.lastpoll = time.Now() d.lastpoll = time.Now()
if d.h == nil { if d.h == nil {
@ -108,11 +109,11 @@ func clusterHealthy() (bool, string) {
for _, d := range me.droplets { for _, d := range me.droplets {
total += 1 total += 1
if d.pb.StartState != "ON" { if d.pb.StartState != pb.DropletState_ON {
continue continue
} }
dur := time.Since(d.lastpoll) // Calculate the elapsed time 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) // log.Info("SKIP. hostname has not been polled yet", d.pb.Hostname, d.hname)
unknown += 1 unknown += 1
unknownList = append(unknownList, d.pb.Hostname) unknownList = append(unknownList, d.pb.Hostname)
@ -122,7 +123,7 @@ func clusterHealthy() (bool, string) {
if d.h != nil { if d.h != nil {
hname = d.h.pb.Hostname 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)) log.Info("BAD STATE", d.pb.StartState, d.pb.Hostname, hname, "CurrentState =", d.CurrentState, shell.FormatDuration(dur))
good = false good = false
failed += 1 failed += 1
@ -131,7 +132,7 @@ func clusterHealthy() (bool, string) {
if dur > time.Minute { if dur > time.Minute {
log.Info("GOOD STATE MISSING", d.pb.Hostname, hname, shell.FormatDuration(dur)) log.Info("GOOD STATE MISSING", d.pb.Hostname, hname, shell.FormatDuration(dur))
good = false good = false
d.CurrentState = "MISSING" d.CurrentState = pb.DropletState_UNKNOWN
failed += 1 failed += 1
continue continue
} }

View File

@ -44,7 +44,7 @@ type DropletT struct {
pb *pb.Droplet // the Droplet protobuf pb *pb.Droplet // the Droplet protobuf
xml *libvirtxml.Domain // a xml representation from libvirt xml *libvirtxml.Domain // a xml representation from libvirt
h *HyperT // the hypervisor it's currently running on 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 lastpoll time.Time // the last time the droplet was seen running
starts int // how many times a start event has been attempted starts int // how many times a start event has been attempted
} }