compiles after lots of protobuf changes
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
22111183a5
commit
e6ea90f8de
2
Makefile
2
Makefile
|
@ -1,3 +1,5 @@
|
||||||
|
.PHONY: build
|
||||||
|
|
||||||
VERSION = $(shell git describe --tags)
|
VERSION = $(shell git describe --tags)
|
||||||
|
|
||||||
# create the go.mod and go.sum if this is a brand new repo
|
# create the go.mod and go.sum if this is a brand new repo
|
||||||
|
|
|
@ -35,7 +35,7 @@ func create(w http.ResponseWriter, r *http.Request) (string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d.StartState = pb.DropletState_OFF
|
d.StartState = pb.DropletState_OFF
|
||||||
d.CurrentState = pb.DropletState_OFF
|
d.Current.State = pb.DropletState_OFF
|
||||||
d.Memory = 2048 * 1024 * 1024
|
d.Memory = 2048 * 1024 * 1024
|
||||||
d.Cpus = 2
|
d.Cpus = 2
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ func create(w http.ResponseWriter, r *http.Request) (string, error) {
|
||||||
return s, err
|
return s, err
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpd := findDroplet(name)
|
tmpd := me.cluster.FindDropletByName(name)
|
||||||
if tmpd != nil {
|
if tmpd != nil {
|
||||||
result := "create error: Droplet " + name + " is already defined"
|
result := "create error: Droplet " + name + " is already defined"
|
||||||
log.Info(result)
|
log.Info(result)
|
||||||
|
@ -98,7 +98,7 @@ func startDroplet(d *pb.Droplet) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// is the droplet already on?
|
// 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"
|
result = "EVENT start droplet " + d.Hostname + " is already ON"
|
||||||
return result, errors.New(result)
|
return result, errors.New(result)
|
||||||
}
|
}
|
||||||
|
|
8
dump.go
8
dump.go
|
@ -38,14 +38,14 @@ func dumpDroplets(w http.ResponseWriter, full bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// this line in golang could replace 80 lines of COBOL
|
// 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
|
var filenames string
|
||||||
for _, disk := range d.Disks {
|
for _, disk := range d.Disks {
|
||||||
filenames += disk.Filename
|
filenames += disk.Filename
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.CurrentState == pb.DropletState_ON {
|
if d.Current.State == pb.DropletState_ON {
|
||||||
fmt.Fprintln(w, header, d.Hostname)
|
fmt.Fprintln(w, header, d.Hostname)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ func dumpHypervisors(w http.ResponseWriter) {
|
||||||
dur := time.Since(t)
|
dur := time.Since(t)
|
||||||
tmp := shell.FormatDuration(dur)
|
tmp := shell.FormatDuration(dur)
|
||||||
totalDroplets += 1
|
totalDroplets += 1
|
||||||
d := findDroplet(name)
|
d := me.cluster.FindDropletByName(name)
|
||||||
if d == nil {
|
if d == nil {
|
||||||
totalUnknownDroplets += 1
|
totalUnknownDroplets += 1
|
||||||
fmt.Fprintln(w, "\t", h.pb.Hostname, "name =", name, "lastpoll:", tmp)
|
fmt.Fprintln(w, "\t", h.pb.Hostname, "name =", name, "lastpoll:", tmp)
|
||||||
} else {
|
} 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
event.go
10
event.go
|
@ -38,12 +38,12 @@ func clusterReady() (bool, string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func dropletReady(d *pb.Droplet) (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"
|
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"
|
// 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, ""
|
return true, ""
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ func (h *HyperT) start(d *pb.Droplet) (bool, string) {
|
||||||
result += "EVENT start droplet response: " + string(req)
|
result += "EVENT start droplet response: " + string(req)
|
||||||
|
|
||||||
// increment the counter for a start attempt working
|
// 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
|
// mark the cluster as unstable so droplet starts can be throttled
|
||||||
me.unstable = time.Now()
|
me.unstable = time.Now()
|
||||||
|
@ -84,7 +84,7 @@ func (h *HyperT) start(d *pb.Droplet) (bool, string) {
|
||||||
return true, result
|
return true, result
|
||||||
}
|
}
|
||||||
|
|
||||||
func findDroplet(name string) *pb.Droplet {
|
func findDropletByName(name string) *pb.Droplet {
|
||||||
for _, d := range me.cluster.Droplets {
|
for _, d := range me.cluster.Droplets {
|
||||||
if d.Hostname == name {
|
if d.Hostname == name {
|
||||||
return d
|
return d
|
||||||
|
|
4
main.go
4
main.go
|
@ -60,11 +60,11 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, d := range me.cluster.Droplets {
|
for i, d := range me.cluster.Droplets {
|
||||||
d.CurrentState = pb.DropletState_OFF
|
d.Current.State = pb.DropletState_OFF
|
||||||
log.Info(i, "droplet", d.Hostname)
|
log.Info(i, "droplet", d.Hostname)
|
||||||
}
|
}
|
||||||
hmm := "pihole.wit.com"
|
hmm := "pihole.wit.com"
|
||||||
d := findDroplet(hmm)
|
d := me.cluster.FindDropletByName(hmm)
|
||||||
if d == nil {
|
if d == nil {
|
||||||
log.Info("did not find found droplet", hmm)
|
log.Info("did not find found droplet", hmm)
|
||||||
} else {
|
} else {
|
||||||
|
|
50
poll.go
50
poll.go
|
@ -28,11 +28,13 @@ func (h *HyperT) pollHypervisor() {
|
||||||
}
|
}
|
||||||
fields := strings.Fields(line)
|
fields := strings.Fields(line)
|
||||||
if len(fields) < 2 {
|
if len(fields) < 2 {
|
||||||
|
log.Log(WARN, "locally defined:", h.pb.Hostname, fields)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
state := fields[0]
|
state := fields[0]
|
||||||
name := fields[1]
|
name := fields[1]
|
||||||
if state == "OFF" {
|
if state == "OFF" {
|
||||||
|
log.Log(WARN, "locally defined:", h.pb.Hostname, fields)
|
||||||
// skip locally defined libvirt vms
|
// skip locally defined libvirt vms
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -42,7 +44,7 @@ func (h *HyperT) pollHypervisor() {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// try the protobuf
|
// try the protobuf
|
||||||
d := findDroplet(name)
|
d := me.cluster.FindDropletByName(name)
|
||||||
if d == nil {
|
if d == nil {
|
||||||
// not sure whawt now?
|
// not sure whawt now?
|
||||||
log.Log(WARN, name, "is unknown on", h.pb.Hostname, "state =", state)
|
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)
|
log.Log(INFO, "ALREADY RECORDED", d.Hostname)
|
||||||
|
|
||||||
// update the status to ON
|
// update the status to ON
|
||||||
d.CurrentState = pb.DropletState_ON
|
d.Current.State = pb.DropletState_ON
|
||||||
|
|
||||||
// set the LastPoll time to now
|
// set the LastPoll time to now
|
||||||
now := time.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
|
// this means the droplet was in the config file
|
||||||
// but this is the first time it's shown up as running
|
// 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
|
// this should mean a droplet is running where the config file says it probably should be running
|
||||||
if d.PreferredHypervisor == h.pb.Hostname {
|
if d.PreferredHypervisor == h.pb.Hostname {
|
||||||
log.Log(EVENT, "poll shows new droplet", d.Hostname, "(matches config hypervisor", 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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Log(EVENT, "poll shows new droplet", d.Hostname, "on", h.pb.Hostname, "(in config file without preferred hypervisor)")
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// if this is blank, the droplet has probably never booted yet
|
// if this is blank, the droplet has probably never booted yet
|
||||||
if d.CurrentHypervisor == "" {
|
if d.Current.Hypervisor == "" {
|
||||||
d.CurrentHypervisor = h.pb.Hostname
|
d.Current.Hypervisor = h.pb.Hostname
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// this means the droplet has moved
|
// 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)
|
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)
|
// record the droplet migrated (or booted somewhere else? recording this is a work in progress)
|
||||||
me.cluster.DropletMoved(d, h.pb)
|
me.cluster.DropletMoved(d, h.pb)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
d.CurrentHypervisor = h.pb.Hostname
|
d.Current.Hypervisor = h.pb.Hostname
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for name, t := range h.lastDroplets {
|
for name, t := range h.lastDroplets {
|
||||||
dur := time.Since(t)
|
dur := time.Since(t)
|
||||||
if dur > me.hyperPollDelay {
|
if dur > me.hyperPollDelay {
|
||||||
d := findDroplet(name)
|
d := me.cluster.FindDropletByName(name)
|
||||||
if d == nil {
|
if d == nil {
|
||||||
log.Info("droplet has probably powered down", name, "but findDroplet returned nil")
|
log.Info("droplet has probably powered down", name, "but findDroplet returned nil")
|
||||||
// should delete this from h.lastDroplets
|
// should delete this from h.lastDroplets
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// everthing below here is dumb and needs to be rethought
|
// everthing below here is dumb and needs to be rethought
|
||||||
if d.CurrentState != pb.DropletState_UNKNOWN {
|
if d.Current.State != pb.DropletState_UNKNOWN {
|
||||||
d.CurrentState = pb.DropletState_UNKNOWN
|
d.Current.State = pb.DropletState_UNKNOWN
|
||||||
log.Info("set state UNKNOWN here", name)
|
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 {
|
if dur > time.Minute*2 {
|
||||||
// what this means is the droplet probably wasn't migrated or the migrate failed
|
// 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
|
// 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
|
// 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
|
// to be moved somewhere else. there needs to be a new goroutine not tied to the
|
||||||
// hypervisor
|
// 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 {
|
if d.StartState != pb.DropletState_ON {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
dur := time.Since(d.LastPoll.AsTime()) // Calculate the elapsed time
|
dur := time.Since(d.Current.LastPoll.AsTime()) // Calculate the elapsed time
|
||||||
if d.CurrentState == pb.DropletState_UNKNOWN {
|
if d.Current.State == pb.DropletState_UNKNOWN {
|
||||||
// log.Info("SKIP. hostname has not been polled yet", d.Hostname, d.hname)
|
// log.Info("SKIP. hostname has not been polled yet", d.Hostname, d.hname)
|
||||||
unknown += 1
|
unknown += 1
|
||||||
unknownList = append(unknownList, d.Hostname)
|
unknownList = append(unknownList, d.Hostname)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var hname string
|
var hname string
|
||||||
if d.CurrentHypervisor != "" {
|
if d.Current.Hypervisor != "" {
|
||||||
hname = d.CurrentHypervisor
|
hname = d.Current.Hypervisor
|
||||||
}
|
}
|
||||||
if d.CurrentState != pb.DropletState_ON {
|
if d.Current.State != pb.DropletState_ON {
|
||||||
log.Info("BAD STATE", d.StartState, d.Hostname, hname, "CurrentState =", d.CurrentState, shell.FormatDuration(dur))
|
log.Info("BAD STATE", d.StartState, d.Hostname, hname, "Current.State =", d.Current.State, shell.FormatDuration(dur))
|
||||||
good = false
|
good = false
|
||||||
failed += 1
|
failed += 1
|
||||||
missing = append(missing, d)
|
missing = append(missing, d)
|
||||||
} else {
|
} 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 {
|
if dur > me.missingDropletTimeout {
|
||||||
log.Info("GOOD STATE MISSING", d.Hostname, hname, shell.FormatDuration(dur))
|
log.Info("GOOD STATE MISSING", d.Hostname, hname, shell.FormatDuration(dur))
|
||||||
good = false
|
good = false
|
||||||
d.CurrentState = pb.DropletState_UNKNOWN
|
d.Current.State = pb.DropletState_UNKNOWN
|
||||||
failed += 1
|
failed += 1
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -203,7 +205,7 @@ func uptimeCheck() (bool, string) {
|
||||||
summary += "(unstable=" + s + ")"
|
summary += "(unstable=" + s + ")"
|
||||||
}
|
}
|
||||||
for _, d := range missing {
|
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 {
|
if good {
|
||||||
return good, "GOOD=true " + summary
|
return good, "GOOD=true " + summary
|
||||||
|
|
4
start.go
4
start.go
|
@ -38,7 +38,7 @@ func Start(name string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// lookup the droplet by name
|
// lookup the droplet by name
|
||||||
d := findDroplet(name)
|
d := me.cluster.FindDropletByName(name)
|
||||||
if d == nil {
|
if d == nil {
|
||||||
result = "can't start unknown droplet: " + name
|
result = "can't start unknown droplet: " + name
|
||||||
return result, errors.New(result)
|
return result, errors.New(result)
|
||||||
|
@ -51,7 +51,7 @@ func Start(name string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// is the droplet already on?
|
// 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"
|
result = "EVENT start droplet " + d.Hostname + " is already ON"
|
||||||
return result, errors.New(result)
|
return result, errors.New(result)
|
||||||
}
|
}
|
||||||
|
|
12
validate.go
12
validate.go
|
@ -286,17 +286,17 @@ func setUniqueSpicePort(check *pb.Droplet) error {
|
||||||
}
|
}
|
||||||
if dup, ok := ports[d.SpicePort]; ok {
|
if dup, ok := ports[d.SpicePort]; ok {
|
||||||
// dup := ports[d.SpicePort]
|
// dup := ports[d.SpicePort]
|
||||||
log.Warn("duplicate ports", d.SpicePort, d.Hostname, d.CurrentState)
|
log.Warn("duplicate ports", d.SpicePort, d.Hostname, d.Current.State)
|
||||||
if d.CurrentState != pb.DropletState_ON {
|
if d.Current.State != pb.DropletState_ON {
|
||||||
// hack for now. should be safe to erase this
|
// hack for now. should be safe to erase this
|
||||||
d.SpicePort = 0
|
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)
|
log.Warn("duplicate ports", dup.SpicePort, dup.Hostname, dup.Current.State)
|
||||||
if dup.CurrentState != pb.DropletState_ON {
|
if dup.Current.State != pb.DropletState_ON {
|
||||||
// hack for now. should be safe to erase this
|
// hack for now. should be safe to erase this
|
||||||
dup.SpicePort = 0
|
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
|
// todo: fix this somewhow
|
||||||
return errors.New("duplicate ports")
|
return errors.New("duplicate ports")
|
||||||
|
|
Loading…
Reference in New Issue