compiles and runs

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-22 18:19:21 -05:00
parent 3ba9a5da20
commit b1a943fa3d
5 changed files with 23 additions and 16 deletions

View File

@ -68,10 +68,10 @@ func readDropletFile(filename string) {
d.pb.StartState = "ON"
}
if len(fields) >= 3 {
d.hyperPreferred = fields[2]
d.pb.PreferredHypervisor = fields[2]
}
me.droplets = append(me.droplets, d)
log.Log(EVENT, "config new droplet", d.pb.Hostname, d.pb.StartState, d.hyperPreferred)
log.Log(EVENT, "config new droplet", d.pb.Hostname, d.pb.StartState, d.pb.PreferredHypervisor)
} else {
log.Info("not sure what to do here. duplicate droplet", name, "in config file")
}

View File

@ -101,7 +101,7 @@ func Start(name string) (bool, string) {
var pool []*HyperT
for _, h := range me.hypers {
result += fmt.Sprintln("could start droplet on", name, "on", h.pb.Hostname, h.pb.Active)
if d.hyperPreferred == h.pb.Hostname {
if d.pb.PreferredHypervisor == h.pb.Hostname {
// the config file says this droplet should run on this hypervisor
a, b := h.Start(d)
return a, result + b

10
http.go
View File

@ -27,11 +27,17 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
continue
}
dur := time.Since(d.lastpoll) // Calculate the elapsed time
var hname string
if d.h == nil {
hname = ""
} else {
hname = d.h.pb.Hostname
}
if d.CurrentState != "ON" {
fmt.Fprintln(w, "BAD STATE ", d.pb.Hostname, d.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 {
dur := time.Since(d.lastpoll) // Calculate the elapsed time
fmt.Fprintln(w, "GOOD STATE ON", d.pb.Hostname, d.hname, shell.FormatDuration(dur))
fmt.Fprintln(w, "GOOD STATE ON", d.pb.Hostname, hname, shell.FormatDuration(dur))
}
}
return

20
poll.go
View File

@ -36,7 +36,7 @@ func (h *HyperT) pollHypervisor() {
// this is a new unknown droplet (not in the config file)
d = new(DropletT)
d.pb.Hostname = name
d.hname = h.pb.Hostname
d.h = h
d.lastpoll = time.Now()
d.CurrentState = "ON"
me.droplets = append(me.droplets, d)
@ -49,24 +49,24 @@ func (h *HyperT) pollHypervisor() {
d.lastpoll = time.Now()
// this means the droplet is still where it was before
if d.hname == h.pb.Hostname {
if d.h.pb.Hostname == h.pb.Hostname {
continue
}
if d.hname == "" {
if d.h == nil {
// this means the droplet was in the config file
// but this is the first time it's shown up as running
// this should mean a droplet is running where the config file says it probably should be running
if d.hyperPreferred == h.pb.Hostname {
if d.pb.PreferredHypervisor == h.pb.Hostname {
log.Log(EVENT, "new droplet", d.pb.Hostname, "(matches config hypervisor", h.pb.Hostname+")")
d.hname = h.pb.Hostname
d.h = h
continue
}
log.Log(EVENT, "new droplet", d.pb.Hostname, "on", h.pb.Hostname, "(in config file without preferred hypervisor)")
}
d.hname = h.pb.Hostname
d.h = h
}
continue
}
@ -115,14 +115,18 @@ func clusterHealthy() (bool, string) {
unknownList = append(unknownList, d.pb.Hostname)
continue
}
var hname string
if d.h != nil {
hname = d.h.pb.Hostname
}
if d.CurrentState != "ON" {
log.Info("BAD STATE", d.pb.StartState, d.pb.Hostname, d.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
failed += 1
} else {
dur := time.Since(d.lastpoll) // Calculate the elapsed time
if dur > time.Minute {
log.Info("GOOD STATE MISSING", d.pb.Hostname, d.hname, shell.FormatDuration(dur))
log.Info("GOOD STATE MISSING", d.pb.Hostname, hname, shell.FormatDuration(dur))
good = false
d.CurrentState = "MISSING"
failed += 1

View File

@ -41,10 +41,7 @@ type HyperT struct {
// the stuff that is needed for a hypervisor
type DropletT struct {
pb *pb.Droplet // the Droplet protobuf
// ConfigState string // what the state of the droplet is SUPPOSED TO BE
CurrentState string // what the state of the droplet is ACTUALLY IS
hyperPreferred string // the hypervisor to prefer to run the droplet on
hname string // the hypervisor it's currently running on
h *HyperT // the hypervisor it's currently running on
lastpoll time.Time // the last time the droplet was seen running
starts int // how many times a start event has been attempted