reject start and create early if grid unstable
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
eacf3b8bef
commit
41673f3170
|
@ -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"
|
||||
|
|
28
start.go
28
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 {
|
||||
|
|
Loading…
Reference in New Issue