mirror of https://github.com/docker/docs.git
add strategy and filters to docker info
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
parent
64d691a448
commit
20ec7a889e
|
@ -268,7 +268,11 @@ func (c *Cluster) listNodes() []cluster.Node {
|
|||
|
||||
// Info is exported
|
||||
func (c *Cluster) Info() [][2]string {
|
||||
info := [][2]string{{"\bNodes", fmt.Sprintf("%d", len(c.nodes))}}
|
||||
info := [][2]string{
|
||||
{"\bStrategy", c.scheduler.Strategy()},
|
||||
{"\bFilters", c.scheduler.Filters()},
|
||||
{"\bNodes", fmt.Sprintf("%d", len(c.nodes))},
|
||||
}
|
||||
|
||||
for _, node := range c.nodes {
|
||||
info = append(info, [2]string{node.Name(), node.Addr()})
|
||||
|
|
|
@ -13,6 +13,11 @@ import (
|
|||
type AffinityFilter struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the filter
|
||||
func (f *AffinityFilter) Name() string {
|
||||
return "affinity"
|
||||
}
|
||||
|
||||
// Filter is exported
|
||||
func (f *AffinityFilter) Filter(config *dockerclient.ContainerConfig, nodes []cluster.Node) ([]cluster.Node, error) {
|
||||
affinities, err := parseExprs("affinity", config.Env)
|
||||
|
|
|
@ -12,6 +12,11 @@ import (
|
|||
type ConstraintFilter struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the filter
|
||||
func (f *ConstraintFilter) Name() string {
|
||||
return "constraint"
|
||||
}
|
||||
|
||||
// Filter is exported
|
||||
func (f *ConstraintFilter) Filter(config *dockerclient.ContainerConfig, nodes []cluster.Node) ([]cluster.Node, error) {
|
||||
constraints, err := parseExprs("constraint", config.Env)
|
||||
|
|
|
@ -12,6 +12,11 @@ import (
|
|||
type DependencyFilter struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the filter
|
||||
func (f *DependencyFilter) Name() string {
|
||||
return "dependency"
|
||||
}
|
||||
|
||||
// Filter is exported
|
||||
func (f *DependencyFilter) Filter(config *dockerclient.ContainerConfig, nodes []cluster.Node) ([]cluster.Node, error) {
|
||||
if len(nodes) == 0 {
|
||||
|
|
|
@ -10,6 +10,8 @@ import (
|
|||
|
||||
// Filter is exported
|
||||
type Filter interface {
|
||||
Name() string
|
||||
|
||||
// Return a subset of nodes that were accepted by the filtering policy.
|
||||
Filter(*dockerclient.ContainerConfig, []cluster.Node) ([]cluster.Node, error)
|
||||
}
|
||||
|
|
|
@ -16,6 +16,11 @@ var (
|
|||
type HealthFilter struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the filter
|
||||
func (f *HealthFilter) Name() string {
|
||||
return "health"
|
||||
}
|
||||
|
||||
// Filter is exported
|
||||
func (f *HealthFilter) Filter(_ *dockerclient.ContainerConfig, nodes []cluster.Node) ([]cluster.Node, error) {
|
||||
result := []cluster.Node{}
|
||||
|
|
|
@ -13,6 +13,11 @@ import (
|
|||
type PortFilter struct {
|
||||
}
|
||||
|
||||
// Name returns the name of the filter
|
||||
func (p *PortFilter) Name() string {
|
||||
return "port"
|
||||
}
|
||||
|
||||
// Filter is exported
|
||||
func (p *PortFilter) Filter(config *dockerclient.ContainerConfig, nodes []cluster.Node) ([]cluster.Node, error) {
|
||||
for _, port := range config.HostConfig.PortBindings {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package scheduler
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/docker/swarm/cluster"
|
||||
|
@ -34,3 +35,18 @@ func (s *Scheduler) SelectNodeForContainer(nodes []cluster.Node, config *dockerc
|
|||
|
||||
return s.strategy.PlaceContainer(config, accepted)
|
||||
}
|
||||
|
||||
// Strategy returns the strategy name
|
||||
func (s *Scheduler) Strategy() string {
|
||||
return s.strategy.Name()
|
||||
}
|
||||
|
||||
// Filters returns the list of filter's name
|
||||
func (s *Scheduler) Filters() string {
|
||||
filters := []string{}
|
||||
for _, f := range s.filters {
|
||||
filters = append(filters, f.Name())
|
||||
}
|
||||
|
||||
return strings.Join(filters, ", ")
|
||||
}
|
||||
|
|
|
@ -16,6 +16,11 @@ func (p *BinpackPlacementStrategy) Initialize() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Name returns the name of the strategy
|
||||
func (p *BinpackPlacementStrategy) Name() string {
|
||||
return "binpack"
|
||||
}
|
||||
|
||||
// PlaceContainer is exported
|
||||
func (p *BinpackPlacementStrategy) PlaceContainer(config *dockerclient.ContainerConfig, nodes []cluster.Node) (cluster.Node, error) {
|
||||
weightedNodes, err := weighNodes(config, nodes)
|
||||
|
|
|
@ -18,6 +18,11 @@ func (p *RandomPlacementStrategy) Initialize() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Name returns the name of the strategy
|
||||
func (p *RandomPlacementStrategy) Name() string {
|
||||
return "random"
|
||||
}
|
||||
|
||||
// PlaceContainer is exported
|
||||
func (p *RandomPlacementStrategy) PlaceContainer(config *dockerclient.ContainerConfig, nodes []cluster.Node) (cluster.Node, error) {
|
||||
if size := len(nodes); size > 0 {
|
||||
|
|
|
@ -16,6 +16,11 @@ func (p *SpreadPlacementStrategy) Initialize() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Name returns the name of the strategy
|
||||
func (p *SpreadPlacementStrategy) Name() string {
|
||||
return "spread"
|
||||
}
|
||||
|
||||
// PlaceContainer is exported
|
||||
func (p *SpreadPlacementStrategy) PlaceContainer(config *dockerclient.ContainerConfig, nodes []cluster.Node) (cluster.Node, error) {
|
||||
weightedNodes, err := weighNodes(config, nodes)
|
||||
|
|
|
@ -10,6 +10,8 @@ import (
|
|||
|
||||
// PlacementStrategy is exported
|
||||
type PlacementStrategy interface {
|
||||
Name() string
|
||||
|
||||
Initialize() error
|
||||
// Given a container configuration and a set of nodes, select the target
|
||||
// node where the container should be scheduled.
|
||||
|
|
Loading…
Reference in New Issue