mirror of https://github.com/docker/docs.git
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package scheduler
|
|
|
|
import (
|
|
"strings"
|
|
"sync"
|
|
|
|
"github.com/docker/swarm/cluster"
|
|
"github.com/docker/swarm/scheduler/filter"
|
|
"github.com/docker/swarm/scheduler/node"
|
|
"github.com/docker/swarm/scheduler/strategy"
|
|
)
|
|
|
|
// Scheduler is exported
|
|
type Scheduler struct {
|
|
sync.Mutex
|
|
|
|
strategy strategy.PlacementStrategy
|
|
filters []filter.Filter
|
|
}
|
|
|
|
// New is exported
|
|
func New(strategy strategy.PlacementStrategy, filters []filter.Filter) *Scheduler {
|
|
return &Scheduler{
|
|
strategy: strategy,
|
|
filters: filters,
|
|
}
|
|
}
|
|
|
|
// SelectNodeForContainer will find a nice home for our container.
|
|
func (s *Scheduler) SelectNodeForContainer(nodes []*node.Node, config *cluster.ContainerConfig) (*node.Node, error) {
|
|
accepted, err := filter.ApplyFilters(s.filters, config, nodes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
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, ", ")
|
|
}
|