From 41673f31706a4c68a26d580e42983380a0f15934 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 30 Oct 2024 19:38:12 -0500 Subject: [PATCH] reject start and create early if grid unstable Signed-off-by: Jeff Carr --- create.go | 9 +++++++++ start.go | 28 ++++++++++++++++++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/create.go b/create.go index ab36093..60bf128 100644 --- a/create.go +++ b/create.go @@ -42,6 +42,15 @@ func create(w http.ResponseWriter, r *http.Request) (string, error) { log.Info("Got msg:", string(msg)) log.Info("hostname =", d.Hostname) name := d.Hostname + + // don't continue past here if the grid is unstable anyway + // because this will add the droplet to cluster.Droplets + if s, err := isClusterStable(); err != nil { + log.Info(s) + fmt.Fprintln(w, s) + return s, err + } + tmpd := findDroplet(name) if tmpd != nil { result := "create error: Droplet " + name + " is already defined" diff --git a/start.go b/start.go index 556c2d0..ae1be08 100644 --- a/start.go +++ b/start.go @@ -14,11 +14,29 @@ import ( pb "go.wit.com/lib/protobuf/virtbuf" ) +func isClusterStable() (string, error) { + // how long has the cluster been stable? + // wait until it is stable. use this to throttle droplet starts + dur := time.Since(me.unstable) + good := fmt.Sprintln("trying to start droplet here. grid stable for: ", shell.FormatDuration(dur)) + if dur < me.unstableTimeout { + tmp := shell.FormatDuration(me.unstableTimeout) + err := "grid is still too unstable (unstable timeout = " + tmp + ")\n" + return good + err, errors.New(err) + } + return good, nil +} + // for now, because sometimes this should write to stdout and // sometimes to http socket, it returns a string func Start(name string) (string, error) { var result string + if s, err := isClusterStable(); err != nil { + result += s + return result, err + } + // lookup the droplet by name d := findDroplet(name) if d == nil { @@ -38,16 +56,6 @@ func Start(name string) (string, error) { return result, errors.New(result) } - // how long has the cluster been stable? - // wait until it is stable. use this to throttle droplet starts - dur := time.Since(me.unstable) - result = fmt.Sprintln("should start droplet", name, "here. grid stable for:", shell.FormatDuration(dur)) - if dur < me.unstableTimeout { - tmp := shell.FormatDuration(me.unstableTimeout) - result += "grid is still too unstable (unstable timeout = " + tmp + ")" - return result, errors.New("grid is still unstable") - } - // make the list of hypervisors that are active and can start new droplets var pool []*HyperT for _, h := range me.hypers {