compiles after lots of protobuf changes

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-31 06:41:30 -05:00
parent 22111183a5
commit e6ea90f8de
8 changed files with 50 additions and 46 deletions

View File

@ -1,3 +1,5 @@
.PHONY: build
VERSION = $(shell git describe --tags)
# create the go.mod and go.sum if this is a brand new repo

View File

@ -35,7 +35,7 @@ func create(w http.ResponseWriter, r *http.Request) (string, error) {
}
}
d.StartState = pb.DropletState_OFF
d.CurrentState = pb.DropletState_OFF
d.Current.State = pb.DropletState_OFF
d.Memory = 2048 * 1024 * 1024
d.Cpus = 2
@ -51,7 +51,7 @@ func create(w http.ResponseWriter, r *http.Request) (string, error) {
return s, err
}
tmpd := findDroplet(name)
tmpd := me.cluster.FindDropletByName(name)
if tmpd != nil {
result := "create error: Droplet " + name + " is already defined"
log.Info(result)
@ -98,7 +98,7 @@ func startDroplet(d *pb.Droplet) (string, error) {
}
// is the droplet already on?
if d.CurrentState == pb.DropletState_ON {
if d.Current.State == pb.DropletState_ON {
result = "EVENT start droplet " + d.Hostname + " is already ON"
return result, errors.New(result)
}

View File

@ -38,14 +38,14 @@ func dumpDroplets(w http.ResponseWriter, full bool) {
}
// this line in golang could replace 80 lines of COBOL
header := fmt.Sprintf("%-3s %20s %-8s", d.CurrentState, strings.Join(macs, " "), d.CurrentHypervisor)
header := fmt.Sprintf("%-3s %20s %-8s", d.Current.State, strings.Join(macs, " "), d.Current.Hypervisor)
var filenames string
for _, disk := range d.Disks {
filenames += disk.Filename
}
if d.CurrentState == pb.DropletState_ON {
if d.Current.State == pb.DropletState_ON {
fmt.Fprintln(w, header, d.Hostname)
continue
}
@ -72,12 +72,12 @@ func dumpHypervisors(w http.ResponseWriter) {
dur := time.Since(t)
tmp := shell.FormatDuration(dur)
totalDroplets += 1
d := findDroplet(name)
d := me.cluster.FindDropletByName(name)
if d == nil {
totalUnknownDroplets += 1
fmt.Fprintln(w, "\t", h.pb.Hostname, "name =", name, "lastpoll:", tmp)
} else {
fmt.Fprintln(w, "\t", h.pb.Hostname, "name =", name, "lastpoll:", tmp, d.CurrentState)
fmt.Fprintln(w, "\t", h.pb.Hostname, "name =", name, "lastpoll:", tmp, d.Current.State)
}
}
}

View File

@ -38,12 +38,12 @@ func clusterReady() (bool, string) {
}
func dropletReady(d *pb.Droplet) (bool, string) {
if d.CurrentState == pb.DropletState_ON {
if d.Current.State == pb.DropletState_ON {
return false, "EVENT start droplet is already ON"
}
if d.Starts > 2 {
if d.Current.StartAttempts > 2 {
// reason := "EVENT start droplet has already been started " + d.starts + " times"
return false, fmt.Sprintln("EVENT start droplet has already been started ", d.Starts, " times")
return false, fmt.Sprintln("EVENT start droplet has already been started ", d.Current.StartAttempts, " times")
}
return true, ""
}
@ -76,7 +76,7 @@ func (h *HyperT) start(d *pb.Droplet) (bool, string) {
result += "EVENT start droplet response: " + string(req)
// increment the counter for a start attempt working
d.Starts += 1
d.Current.StartAttempts += 1
// mark the cluster as unstable so droplet starts can be throttled
me.unstable = time.Now()
@ -84,7 +84,7 @@ func (h *HyperT) start(d *pb.Droplet) (bool, string) {
return true, result
}
func findDroplet(name string) *pb.Droplet {
func findDropletByName(name string) *pb.Droplet {
for _, d := range me.cluster.Droplets {
if d.Hostname == name {
return d

View File

@ -60,11 +60,11 @@ func main() {
}
for i, d := range me.cluster.Droplets {
d.CurrentState = pb.DropletState_OFF
d.Current.State = pb.DropletState_OFF
log.Info(i, "droplet", d.Hostname)
}
hmm := "pihole.wit.com"
d := findDroplet(hmm)
d := me.cluster.FindDropletByName(hmm)
if d == nil {
log.Info("did not find found droplet", hmm)
} else {

50
poll.go
View File

@ -28,11 +28,13 @@ func (h *HyperT) pollHypervisor() {
}
fields := strings.Fields(line)
if len(fields) < 2 {
log.Log(WARN, "locally defined:", h.pb.Hostname, fields)
continue
}
state := fields[0]
name := fields[1]
if state == "OFF" {
log.Log(WARN, "locally defined:", h.pb.Hostname, fields)
// skip locally defined libvirt vms
continue
}
@ -42,7 +44,7 @@ func (h *HyperT) pollHypervisor() {
// }
// try the protobuf
d := findDroplet(name)
d := me.cluster.FindDropletByName(name)
if d == nil {
// not sure whawt now?
log.Log(WARN, name, "is unknown on", h.pb.Hostname, "state =", state)
@ -55,59 +57,59 @@ func (h *HyperT) pollHypervisor() {
log.Log(INFO, "ALREADY RECORDED", d.Hostname)
// update the status to ON
d.CurrentState = pb.DropletState_ON
d.Current.State = pb.DropletState_ON
// set the LastPoll time to now
now := time.Now()
d.LastPoll = timestamppb.New(now)
d.Current.LastPoll = timestamppb.New(now)
if d.CurrentHypervisor == "" {
if d.Current.Hypervisor == "" {
// 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.PreferredHypervisor == h.pb.Hostname {
log.Log(EVENT, "poll shows new droplet", d.Hostname, "(matches config hypervisor", h.pb.Hostname+")")
d.CurrentHypervisor = h.pb.Hostname
d.Current.Hypervisor = h.pb.Hostname
continue
}
log.Log(EVENT, "poll shows new droplet", d.Hostname, "on", h.pb.Hostname, "(in config file without preferred hypervisor)")
d.CurrentHypervisor = h.pb.Hostname
d.Current.Hypervisor = h.pb.Hostname
continue
}
// if this is blank, the droplet has probably never booted yet
if d.CurrentHypervisor == "" {
d.CurrentHypervisor = h.pb.Hostname
if d.Current.Hypervisor == "" {
d.Current.Hypervisor = h.pb.Hostname
continue
}
// this means the droplet has moved
if d.CurrentHypervisor != h.pb.Hostname {
if d.Current.Hypervisor != h.pb.Hostname {
log.Log(EVENT, "droplet", d.Hostname, "moved to", h.pb.Hostname)
// record the droplet migrated (or booted somewhere else? recording this is a work in progress)
me.cluster.DropletMoved(d, h.pb)
continue
}
d.CurrentHypervisor = h.pb.Hostname
d.Current.Hypervisor = h.pb.Hostname
}
}
for name, t := range h.lastDroplets {
dur := time.Since(t)
if dur > me.hyperPollDelay {
d := findDroplet(name)
d := me.cluster.FindDropletByName(name)
if d == nil {
log.Info("droplet has probably powered down", name, "but findDroplet returned nil")
// should delete this from h.lastDroplets
continue
}
// everthing below here is dumb and needs to be rethought
if d.CurrentState != pb.DropletState_UNKNOWN {
d.CurrentState = pb.DropletState_UNKNOWN
if d.Current.State != pb.DropletState_UNKNOWN {
d.Current.State = pb.DropletState_UNKNOWN
log.Info("set state UNKNOWN here", name)
}
if d.CurrentState == pb.DropletState_UNKNOWN {
if d.Current.State == pb.DropletState_UNKNOWN {
if dur > time.Minute*2 {
// what this means is the droplet probably wasn't migrated or the migrate failed
// where should this be checked? the status needs to be changed to OFF
@ -117,7 +119,7 @@ func (h *HyperT) pollHypervisor() {
// it might be safe to set the status to OFF here. not really. this poll needs
// to be moved somewhere else. there needs to be a new goroutine not tied to the
// hypervisor
d.CurrentState = pb.DropletState_OFF
d.Current.State = pb.DropletState_OFF
}
}
}
@ -142,28 +144,28 @@ func uptimeCheck() (bool, string) {
if d.StartState != pb.DropletState_ON {
continue
}
dur := time.Since(d.LastPoll.AsTime()) // Calculate the elapsed time
if d.CurrentState == pb.DropletState_UNKNOWN {
dur := time.Since(d.Current.LastPoll.AsTime()) // Calculate the elapsed time
if d.Current.State == pb.DropletState_UNKNOWN {
// log.Info("SKIP. hostname has not been polled yet", d.Hostname, d.hname)
unknown += 1
unknownList = append(unknownList, d.Hostname)
continue
}
var hname string
if d.CurrentHypervisor != "" {
hname = d.CurrentHypervisor
if d.Current.Hypervisor != "" {
hname = d.Current.Hypervisor
}
if d.CurrentState != pb.DropletState_ON {
log.Info("BAD STATE", d.StartState, d.Hostname, hname, "CurrentState =", d.CurrentState, shell.FormatDuration(dur))
if d.Current.State != pb.DropletState_ON {
log.Info("BAD STATE", d.StartState, d.Hostname, hname, "Current.State =", d.Current.State, shell.FormatDuration(dur))
good = false
failed += 1
missing = append(missing, d)
} else {
dur := time.Since(d.LastPoll.AsTime()) // Calculate the elapsed time
dur := time.Since(d.Current.LastPoll.AsTime()) // Calculate the elapsed time
if dur > me.missingDropletTimeout {
log.Info("GOOD STATE MISSING", d.Hostname, hname, shell.FormatDuration(dur))
good = false
d.CurrentState = pb.DropletState_UNKNOWN
d.Current.State = pb.DropletState_UNKNOWN
failed += 1
continue
}
@ -203,7 +205,7 @@ func uptimeCheck() (bool, string) {
summary += "(unstable=" + s + ")"
}
for _, d := range missing {
summary += fmt.Sprint("\nmissing droplet: ", d.Hostname, " current state ", d.CurrentState)
summary += fmt.Sprint("\nmissing droplet: ", d.Hostname, " current state ", d.Current.State)
}
if good {
return good, "GOOD=true " + summary

View File

@ -38,7 +38,7 @@ func Start(name string) (string, error) {
}
// lookup the droplet by name
d := findDroplet(name)
d := me.cluster.FindDropletByName(name)
if d == nil {
result = "can't start unknown droplet: " + name
return result, errors.New(result)
@ -51,7 +51,7 @@ func Start(name string) (string, error) {
}
// is the droplet already on?
if d.CurrentState == pb.DropletState_ON {
if d.Current.State == pb.DropletState_ON {
result = "EVENT start droplet " + d.Hostname + " is already ON"
return result, errors.New(result)
}

View File

@ -286,17 +286,17 @@ func setUniqueSpicePort(check *pb.Droplet) error {
}
if dup, ok := ports[d.SpicePort]; ok {
// dup := ports[d.SpicePort]
log.Warn("duplicate ports", d.SpicePort, d.Hostname, d.CurrentState)
if d.CurrentState != pb.DropletState_ON {
log.Warn("duplicate ports", d.SpicePort, d.Hostname, d.Current.State)
if d.Current.State != pb.DropletState_ON {
// hack for now. should be safe to erase this
d.SpicePort = 0
log.Warn("erasing port for non-ON droplet", d.SpicePort, d.Hostname, d.CurrentState)
log.Warn("erasing port for non-ON droplet", d.SpicePort, d.Hostname, d.Current.State)
}
log.Warn("duplicate ports", dup.SpicePort, dup.Hostname, dup.CurrentState)
if dup.CurrentState != pb.DropletState_ON {
log.Warn("duplicate ports", dup.SpicePort, dup.Hostname, dup.Current.State)
if dup.Current.State != pb.DropletState_ON {
// hack for now. should be safe to erase this
dup.SpicePort = 0
log.Warn("erasing port for non-ON droplet", dup.SpicePort, dup.Hostname, dup.CurrentState)
log.Warn("erasing port for non-ON droplet", dup.SpicePort, dup.Hostname, dup.Current.State)
}
// todo: fix this somewhow
return errors.New("duplicate ports")