Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-22 17:59:27 -05:00
parent 673bcc6cc9
commit 3ba9a5da20
6 changed files with 17 additions and 19 deletions

View File

@ -61,17 +61,17 @@ func readDropletFile(filename string) {
if d == nil {
// this is a new unknown droplet (not in the config file)
d = new(DropletT)
d.pb = me.cluster.AddDroplet(name, 16, 256)
if len(fields) > 1 && fields[1] != "ON" {
d.ConfigState = "OFF"
d.pb.StartState = "OFF"
} else {
d.ConfigState = "ON"
d.pb.StartState = "ON"
}
if len(fields) >= 3 {
d.hyperPreferred = fields[2]
}
d.pb = me.cluster.AddDroplet(name, 16, 256)
me.droplets = append(me.droplets, d)
log.Log(EVENT, "config new droplet", d.pb.Hostname, d.ConfigState, d.hyperPreferred)
log.Log(EVENT, "config new droplet", d.pb.Hostname, d.pb.StartState, d.hyperPreferred)
} else {
log.Info("not sure what to do here. duplicate droplet", name, "in config file")
}
@ -99,9 +99,9 @@ func readHypervisorFile(filename string) {
name := fields[0]
h := addHypervisor(name)
if len(fields) < 2 || fields[1] != "active" {
h.Active = false
h.pb.Active = false
} else {
h.Active = true
h.pb.Active = true
}
}
}
@ -115,13 +115,13 @@ func addHypervisor(name string) *HyperT {
}
log.Log(EVENT, "config new hypervisor", name)
h = new(HyperT)
h.Autoscan = true
h.Delay = 5 * time.Second
h.lastpoll = time.Now()
h.Scan = func() {
h.pollHypervisor()
}
h.pb = me.cluster.AddHypervisor(name, 16, 256)
h.pb.Autoscan = true
me.hypers = append(me.hypers, h)
return h
}

View File

@ -100,14 +100,14 @@ func Start(name string) (bool, string) {
// make the list of hypervisors that are active and can start new droplets
var pool []*HyperT
for _, h := range me.hypers {
result += fmt.Sprintln("could start droplet on", name, "on", h.pb.Hostname, h.Active)
result += fmt.Sprintln("could start droplet on", name, "on", h.pb.Hostname, h.pb.Active)
if d.hyperPreferred == h.pb.Hostname {
// the config file says this droplet should run on this hypervisor
a, b := h.Start(d)
return a, result + b
}
if h.Active != true {
if h.pb.Active != true {
continue
}
pool = append(pool, h)

View File

@ -23,12 +23,12 @@ 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.ConfigState != "ON" {
if d.pb.StartState != "ON" {
continue
}
dur := time.Since(d.lastpoll) // Calculate the elapsed time
if d.CurrentState != "ON" {
fmt.Fprintln(w, "BAD STATE ", d.pb.Hostname, d.hname, "(", d.ConfigState, "vs", d.CurrentState, ")", shell.FormatDuration(dur))
fmt.Fprintln(w, "BAD STATE ", d.pb.Hostname, d.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))
@ -65,7 +65,7 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
// l := shell.FormatDuration(dur)
// log.Warn("HOST =", h.pb.Hostname, "Last poll =", l)
//if d.ConfigState != "ON" {
//if d.pb.StartState != "ON" {
// continue
//}
// dur := time.Since(d.lastpoll) // Calculate the elapsed time

View File

@ -45,7 +45,7 @@ func main() {
continue
}
h = addHypervisor(name)
h.Active = true
h.pb.Active = true
}
if argv.Start != "" {

View File

@ -105,7 +105,7 @@ func clusterHealthy() (bool, string) {
for _, d := range me.droplets {
total += 1
if d.ConfigState != "ON" {
if d.pb.StartState != "ON" {
continue
}
dur := time.Since(d.lastpoll) // Calculate the elapsed time
@ -116,7 +116,7 @@ func clusterHealthy() (bool, string) {
continue
}
if d.CurrentState != "ON" {
log.Info("BAD STATE", d.ConfigState, d.pb.Hostname, d.hname, "CurrentState =", d.CurrentState, shell.FormatDuration(dur))
log.Info("BAD STATE", d.pb.StartState, d.pb.Hostname, d.hname, "CurrentState =", d.CurrentState, shell.FormatDuration(dur))
good = false
failed += 1
} else {

View File

@ -31,19 +31,17 @@ type virtigoT struct {
// the stuff that is needed for a hypervisor
type HyperT struct {
pb *pb.Hypervisor // the Hypervisor protobuf
Active bool // is allowed to start new droplets
Scan func() // the function to run to scan the hypervisor
Autoscan bool // to scan or not to scan
Delay time.Duration // how often to poll the hypervisor
Dog *time.Ticker // the watchdog timer itself
lastpoll time.Time // the last time the hypervisor polled
killcount int
Scan func() // the function to run to scan the hypervisor
}
// 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
// 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