diff options
Diffstat (limited to 'poll.go')
| -rw-r--r-- | poll.go | 50 |
1 files changed, 26 insertions, 24 deletions
@@ -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 |
