mirror of https://github.com/docker/docs.git
add build
improve random selection Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
parent
8506acbed2
commit
d74e872952
|
@ -15,7 +15,6 @@ Some endpoints have not yet been implemented and will return a 404 error.
|
||||||
```
|
```
|
||||||
GET "/images/get"
|
GET "/images/get"
|
||||||
|
|
||||||
POST "/build"
|
|
||||||
POST "/images/load"
|
POST "/images/load"
|
||||||
POST "/images/create" : "docker import" flow not implement
|
POST "/images/create" : "docker import" flow not implement
|
||||||
```
|
```
|
||||||
|
|
|
@ -395,7 +395,7 @@ func proxyImage(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Proxy a request to a random node
|
// Proxy a request to a random node
|
||||||
func proxyRandom(c *context, w http.ResponseWriter, r *http.Request) {
|
func proxyRandom(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
engine, err := c.cluster.RandomEngine_()
|
engine, err := c.cluster.RANDOMENGINE()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, err.Error(), http.StatusInternalServerError)
|
httpError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
|
@ -46,7 +46,7 @@ var routes = map[string]map[string]handler{
|
||||||
"POST": {
|
"POST": {
|
||||||
"/auth": proxyRandom,
|
"/auth": proxyRandom,
|
||||||
"/commit": postCommit,
|
"/commit": postCommit,
|
||||||
"/build": notImplementedHandler,
|
"/build": proxyRandom,
|
||||||
"/images/create": postImagesCreate,
|
"/images/create": postImagesCreate,
|
||||||
"/images/load": notImplementedHandler,
|
"/images/load": notImplementedHandler,
|
||||||
"/images/{name:.*}/push": proxyImage,
|
"/images/{name:.*}/push": proxyImage,
|
||||||
|
|
|
@ -42,5 +42,5 @@ type Cluster interface {
|
||||||
|
|
||||||
// FIXME: remove this method
|
// FIXME: remove this method
|
||||||
// Return a random engine
|
// Return a random engine
|
||||||
RandomEngine_() (*Engine, error)
|
RANDOMENGINE() (*Engine, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package swarm
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
@ -12,7 +11,6 @@ import (
|
||||||
"github.com/docker/swarm/cluster"
|
"github.com/docker/swarm/cluster"
|
||||||
"github.com/docker/swarm/discovery"
|
"github.com/docker/swarm/discovery"
|
||||||
"github.com/docker/swarm/scheduler"
|
"github.com/docker/swarm/scheduler"
|
||||||
"github.com/docker/swarm/scheduler/filter"
|
|
||||||
"github.com/docker/swarm/scheduler/node"
|
"github.com/docker/swarm/scheduler/node"
|
||||||
"github.com/docker/swarm/state"
|
"github.com/docker/swarm/state"
|
||||||
"github.com/samalba/dockerclient"
|
"github.com/samalba/dockerclient"
|
||||||
|
@ -310,17 +308,14 @@ func (c *Cluster) Info() [][2]string {
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
// RandomEngine_ returns a random engine.
|
// RANDOMENGINE returns a random engine.
|
||||||
func (c *Cluster) RandomEngine_() (*cluster.Engine, error) {
|
func (c *Cluster) RANDOMENGINE() (*cluster.Engine, error) {
|
||||||
healthFilter := &filter.HealthFilter{}
|
n, err := c.scheduler.SelectNodeForContainer(c.listNodes(), &dockerclient.ContainerConfig{})
|
||||||
accepted, err := healthFilter.Filter(nil, c.listNodes())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if size := len(accepted); size > 0 {
|
if n != nil {
|
||||||
if n, ok := c.engines[accepted[rand.Intn(size)].ID]; ok {
|
return c.engines[n.ID], nil
|
||||||
return n, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue