summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-22 18:19:21 -0500
committerJeff Carr <[email protected]>2024-10-22 18:19:21 -0500
commitb1a943fa3dff6a9a0d7f802111334be7d1175492 (patch)
tree9bfc53db8a75466c51b0543a23f81285e3ab72eb
parent3ba9a5da209bf070a268b20df48a5a41f7b31109 (diff)
compiles and runs
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--configfiles.go4
-rw-r--r--event.go2
-rw-r--r--http.go10
-rw-r--r--poll.go20
-rw-r--r--structs.go3
5 files changed, 23 insertions, 16 deletions
diff --git a/configfiles.go b/configfiles.go
index dad2421..fbaee5a 100644
--- a/configfiles.go
+++ b/configfiles.go
@@ -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")
}
diff --git a/event.go b/event.go
index 0150994..a030736 100644
--- a/event.go
+++ b/event.go
@@ -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
diff --git a/http.go b/http.go
index be4a8c0..b8f8758 100644
--- a/http.go
+++ b/http.go
@@ -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
diff --git a/poll.go b/poll.go
index 41f0349..12c07af 100644
--- a/poll.go
+++ b/poll.go
@@ -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
diff --git a/structs.go b/structs.go
index 25a6169..b8584e4 100644
--- a/structs.go
+++ b/structs.go
@@ -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