forked from docker-archive/classicswarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrategy.go
38 lines (31 loc) · 932 Bytes
/
strategy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package strategy
import (
"errors"
log "github.com/Sirupsen/logrus"
"github.com/docker/swarm/cluster"
"github.com/samalba/dockerclient"
)
type PlacementStrategy interface {
Initialize() error
// Given a container configuration and a set of nodes, select the target
// node where the container should be scheduled.
PlaceContainer(config *dockerclient.ContainerConfig, nodes []*cluster.Node) (*cluster.Node, error)
}
var (
strategies map[string]PlacementStrategy
ErrNotSupported = errors.New("strategy not supported")
)
func init() {
strategies = map[string]PlacementStrategy{
"binpacking": &BinPackingPlacementStrategy{},
"random": &RandomPlacementStrategy{},
}
}
func New(name string) (PlacementStrategy, error) {
if strategy, exists := strategies[name]; exists {
log.Debugf("Initializing %q strategy", name)
err := strategy.Initialize()
return strategy, err
}
return nil, ErrNotSupported
}