use HealthFilter

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2015-01-15 19:32:48 +00:00
parent 93d63a3fea
commit 7260a66886
2 changed files with 12 additions and 3 deletions

View File

@ -15,6 +15,7 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/docker/swarm/cluster"
"github.com/docker/swarm/scheduler"
"github.com/docker/swarm/scheduler/filter"
"github.com/gorilla/mux"
"github.com/samalba/dockerclient"
)
@ -253,9 +254,17 @@ func proxyContainer(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) {
nodes := c.cluster.Nodes()
candidates := c.cluster.Nodes()
if err := proxy(c.tlsConfig, nodes[rand.Intn(len(nodes))].Addr, w, r); err != nil {
healthFilter := &filter.HealthFilter{}
accepted, err := healthFilter.Filter(nil, candidates)
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
if err := proxy(c.tlsConfig, accepted[rand.Intn(len(accepted))].Addr, w, r); err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
}
}

View File

@ -15,7 +15,7 @@ var (
type HealthFilter struct {
}
func (f *HealthFilter) Filter(config *dockerclient.ContainerConfig, nodes []*cluster.Node) ([]*cluster.Node, error) {
func (f *HealthFilter) Filter(_ *dockerclient.ContainerConfig, nodes []*cluster.Node) ([]*cluster.Node, error) {
result := []*cluster.Node{}
for _, node := range nodes {
if node.IsHealthy() {