From 748f9b4608ccc03f71f40bf961948816a662b1ba Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 31 Oct 2024 05:02:20 -0500 Subject: [PATCH] compiles. maybe works on some stuff still Signed-off-by: Jeff Carr --- create.go | 10 +++++----- event.go | 27 +++++++++------------------ structs.go | 18 +++++++++--------- watchdog.go | 25 ------------------------- 4 files changed, 23 insertions(+), 57 deletions(-) diff --git a/create.go b/create.go index ff8c89b..0846b1d 100644 --- a/create.go +++ b/create.go @@ -35,11 +35,11 @@ func createFilename(dir string, filename string) error { url := urlbase + "/create" -// body, err := postDropletJSON(url, newDroplet) -// if err != nil { -// log.Info("postDropletJSON() failed:", err) -// return err -// } + // body, err := postDropletJSON(url, newDroplet) + // if err != nil { + // log.Info("postDropletJSON() failed:", err) + // return err + // } body, err := postDropletWIRE(url, newDroplet) if err != nil { diff --git a/event.go b/event.go index a2406b9..f8569f1 100644 --- a/event.go +++ b/event.go @@ -26,6 +26,9 @@ func (h *HyperT) RestartVirtigod() { } // checks if the cluster is ready and stable +// func (c *Cluster) DropletReady(d *Droplet) (bool, string) { + +/* func clusterReady() (bool, string) { last := time.Since(me.unstable) if last > me.unstableTimeout { @@ -36,30 +39,24 @@ func clusterReady() (bool, string) { log.Warn("clusterReady() is unstable for", shell.FormatDuration(last)) return false, "clusterReady() is unstable for " + shell.FormatDuration(last) } +*/ +/* 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 true, "" } +*/ // this must be bool in string because accumulated output is sometimes // written to STDOUT, sometimes to http func (h *HyperT) start(d *pb.Droplet) (bool, string) { - ready, result := clusterReady() - if !ready { - return false, result - } - ready, result = dropletReady(d) - if !ready { - return false, result - } - url := "http://" + h.pb.Hostname + ":2520/start?start=" + d.Hostname var msg string var data []byte @@ -72,15 +69,9 @@ func (h *HyperT) start(d *pb.Droplet) (bool, string) { log.Info("http post url:", url) log.Info("http post data:", msg) - result = "EVENT start droplet url: " + url + "\n" + result := "EVENT start droplet url: " + url + "\n" result += "EVENT start droplet response: " + string(req) - // increment the counter for a start attempt working - d.Starts += 1 - - // mark the cluster as unstable so droplet starts can be throttled - me.unstable = time.Now() - return true, result } diff --git a/structs.go b/structs.go index 715231a..edd304b 100644 --- a/structs.go +++ b/structs.go @@ -20,15 +20,15 @@ func (b *virtigoT) Enable() { // this app's variables type virtigoT struct { - cluster *pb.Cluster // basic cluster settings - hmap map[*pb.Hypervisor]*HyperT // map to the local struct - names []string - hypers []*HyperT - killcount int - unstable time.Time // the last time the cluster was incorrect - changed bool - hyperPollDelay time.Duration // how often to poll the hypervisors - unstableTimeout time.Duration // how long a droplet can be unstable until it's declared dead + cluster *pb.Cluster // basic cluster settings + hmap map[*pb.Hypervisor]*HyperT // map to the local struct + names []string + hypers []*HyperT + killcount int + unstable time.Time // the last time the cluster was incorrect + changed bool + // hyperPollDelay time.Duration // how often to poll the hypervisors + // unstableTimeout time.Duration // how long a droplet can be unstable until it's declared dead clusterStableDuration time.Duration // how long the cluster must be stable before new droplets can be started missingDropletTimeout time.Duration // how long a droplet can be missing for } diff --git a/watchdog.go b/watchdog.go index 7a72a54..0849f65 100644 --- a/watchdog.go +++ b/watchdog.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "time" pb "go.wit.com/lib/protobuf/virtbuf" @@ -37,27 +36,3 @@ func (h *HyperT) sendDirs() { log.Info("EVENT start droplet response: " + string(req)) } - -func (h *HyperT) NewWatchdog() { - h.dog = time.NewTicker(me.hyperPollDelay) - defer h.dog.Stop() - done := make(chan bool) - /* - // this example would exit/destroy the ticker in 10 seconds - go func() { - time.Sleep(10 * time.Second) - done <- true - }() - */ - for { - select { - case <-done: - fmt.Println("Done!") - return - case t := <-h.dog.C: - log.Log(POLL, "Watchdog() ticked", h.pb.Hostname, "Current time: ", t) - // h.pollHypervisor() - // h.Scan() - } - } -}