From d74e87295262131663355f39ba87d154185977bb Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 8 Apr 2015 17:14:52 -0700 Subject: [PATCH] add build improve random selection Signed-off-by: Victor Vieux --- api/README.md | 1 - api/handlers.go | 2 +- api/router.go | 2 +- cluster/cluster.go | 2 +- cluster/swarm/cluster.go | 15 +++++---------- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/api/README.md b/api/README.md index 014538cecb..6c83bb242d 100644 --- a/api/README.md +++ b/api/README.md @@ -15,7 +15,6 @@ Some endpoints have not yet been implemented and will return a 404 error. ``` GET "/images/get" -POST "/build" POST "/images/load" POST "/images/create" : "docker import" flow not implement ``` diff --git a/api/handlers.go b/api/handlers.go index 65c82a0652..ff64d13bdc 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -395,7 +395,7 @@ func proxyImage(c *context, w http.ResponseWriter, r *http.Request) { // Proxy a request to a random node func proxyRandom(c *context, w http.ResponseWriter, r *http.Request) { - engine, err := c.cluster.RandomEngine_() + engine, err := c.cluster.RANDOMENGINE() if err != nil { httpError(w, err.Error(), http.StatusInternalServerError) return diff --git a/api/router.go b/api/router.go index 6fc7955530..1e192788b3 100644 --- a/api/router.go +++ b/api/router.go @@ -46,7 +46,7 @@ var routes = map[string]map[string]handler{ "POST": { "/auth": proxyRandom, "/commit": postCommit, - "/build": notImplementedHandler, + "/build": proxyRandom, "/images/create": postImagesCreate, "/images/load": notImplementedHandler, "/images/{name:.*}/push": proxyImage, diff --git a/cluster/cluster.go b/cluster/cluster.go index 5723aa9334..3b0beaab7d 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -42,5 +42,5 @@ type Cluster interface { // FIXME: remove this method // Return a random engine - RandomEngine_() (*Engine, error) + RANDOMENGINE() (*Engine, error) } diff --git a/cluster/swarm/cluster.go b/cluster/swarm/cluster.go index 12d833ed06..483f6092c2 100644 --- a/cluster/swarm/cluster.go +++ b/cluster/swarm/cluster.go @@ -3,7 +3,6 @@ package swarm import ( "errors" "fmt" - "math/rand" "sort" "sync" @@ -12,7 +11,6 @@ import ( "github.com/docker/swarm/cluster" "github.com/docker/swarm/discovery" "github.com/docker/swarm/scheduler" - "github.com/docker/swarm/scheduler/filter" "github.com/docker/swarm/scheduler/node" "github.com/docker/swarm/state" "github.com/samalba/dockerclient" @@ -310,17 +308,14 @@ func (c *Cluster) Info() [][2]string { return info } -// RandomEngine_ returns a random engine. -func (c *Cluster) RandomEngine_() (*cluster.Engine, error) { - healthFilter := &filter.HealthFilter{} - accepted, err := healthFilter.Filter(nil, c.listNodes()) +// RANDOMENGINE returns a random engine. +func (c *Cluster) RANDOMENGINE() (*cluster.Engine, error) { + n, err := c.scheduler.SelectNodeForContainer(c.listNodes(), &dockerclient.ContainerConfig{}) if err != nil { return nil, err } - if size := len(accepted); size > 0 { - if n, ok := c.engines[accepted[rand.Intn(size)].ID]; ok { - return n, nil - } + if n != nil { + return c.engines[n.ID], nil } return nil, nil }