mirror of https://github.com/docker/docs.git
move discovery out of the cluster interface
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
ce98e66c63
commit
6348fdd849
|
|
@ -1,9 +1,6 @@
|
|||
package cluster
|
||||
|
||||
import (
|
||||
"github.com/docker/swarm/discovery"
|
||||
"github.com/samalba/dockerclient"
|
||||
)
|
||||
import "github.com/samalba/dockerclient"
|
||||
|
||||
type Cluster interface {
|
||||
CreateContainer(config *dockerclient.ContainerConfig, name string) (*Container, error)
|
||||
|
|
@ -13,5 +10,4 @@ type Cluster interface {
|
|||
Nodes() []*Node
|
||||
Containers() []*Container
|
||||
Container(IdOrName string) *Container
|
||||
NewEntries(entries []*discovery.Entry)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/docker/swarm/cluster"
|
||||
"github.com/docker/swarm/discovery"
|
||||
"github.com/samalba/dockerclient"
|
||||
)
|
||||
|
||||
|
|
@ -23,6 +22,9 @@ type MesosCluster struct {
|
|||
|
||||
func NewCluster(options *cluster.Options) cluster.Cluster {
|
||||
log.WithFields(log.Fields{"name": "mesos"}).Debug("Initializing cluster")
|
||||
|
||||
//TODO: get the list of mesos masters using options.Discovery (zk://<ip1>,<ip2>,<ip3>/mesos)
|
||||
|
||||
return &MesosCluster{
|
||||
nodes: cluster.NewNodes(),
|
||||
options: options,
|
||||
|
|
@ -57,19 +59,6 @@ func (s *MesosCluster) RemoveContainer(container *cluster.Container, force bool)
|
|||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
// Entries are Mesos masters
|
||||
func (s *MesosCluster) NewEntries(entries []*discovery.Entry) {
|
||||
|
||||
//TODO: get list of actual docker nodes from mesos masters
|
||||
// - cluster.NewNode(m.String(), s.options.OvercommitRatio)
|
||||
|
||||
//TODO: create direct connection to those nodes
|
||||
// - n.Connect(s.options.TLSConfig)
|
||||
|
||||
//TODO: add them to the cluster
|
||||
// - s.nodes.Add(n)
|
||||
}
|
||||
|
||||
func (s *MesosCluster) Events(eventsHandler cluster.EventHandler) {
|
||||
s.nodes.Events(eventsHandler)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,4 +5,6 @@ import "crypto/tls"
|
|||
type Options struct {
|
||||
TLSConfig *tls.Config
|
||||
OvercommitRatio float64
|
||||
Discovery string
|
||||
Heartbeat int
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,12 +22,32 @@ type SwarmCluster struct {
|
|||
|
||||
func NewCluster(scheduler *scheduler.Scheduler, store *state.Store, options *cluster.Options) cluster.Cluster {
|
||||
log.WithFields(log.Fields{"name": "swarm"}).Debug("Initializing cluster")
|
||||
return &SwarmCluster{
|
||||
|
||||
cluster := &SwarmCluster{
|
||||
nodes: cluster.NewNodes(),
|
||||
scheduler: scheduler,
|
||||
options: options,
|
||||
store: store,
|
||||
}
|
||||
|
||||
// get the list of entries from the discovery service
|
||||
go func() {
|
||||
d, err := discovery.New(options.Discovery, options.Heartbeat)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
entries, err := d.Fetch()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
}
|
||||
cluster.newEntries(entries)
|
||||
|
||||
go d.Watch(cluster.newEntries)
|
||||
}()
|
||||
|
||||
return cluster
|
||||
}
|
||||
|
||||
// Schedule a brand new container into the cluster.
|
||||
|
|
@ -75,7 +95,7 @@ func (s *SwarmCluster) RemoveContainer(container *cluster.Container, force bool)
|
|||
}
|
||||
|
||||
// Entries are Docker Nodes
|
||||
func (s *SwarmCluster) NewEntries(entries []*discovery.Entry) {
|
||||
func (s *SwarmCluster) newEntries(entries []*discovery.Entry) {
|
||||
for _, entry := range entries {
|
||||
go func(m *discovery.Entry) {
|
||||
if s.nodes.Get(m.String()) == nil {
|
||||
|
|
|
|||
20
manage.go
20
manage.go
|
|
@ -13,7 +13,6 @@ import (
|
|||
"github.com/docker/swarm/cluster"
|
||||
"github.com/docker/swarm/cluster/mesos"
|
||||
"github.com/docker/swarm/cluster/swarm"
|
||||
"github.com/docker/swarm/discovery"
|
||||
"github.com/docker/swarm/scheduler"
|
||||
"github.com/docker/swarm/scheduler/filter"
|
||||
"github.com/docker/swarm/scheduler/strategy"
|
||||
|
|
@ -124,6 +123,8 @@ func manage(c *cli.Context) {
|
|||
options := &cluster.Options{
|
||||
TLSConfig: tlsConfig,
|
||||
OvercommitRatio: c.Float64("overcommit"),
|
||||
Discovery: dflag,
|
||||
Heartbeat: c.Int("heartbeat"),
|
||||
}
|
||||
|
||||
var cluster cluster.Cluster
|
||||
|
|
@ -137,23 +138,6 @@ func manage(c *cli.Context) {
|
|||
log.Fatalf("cluster %q not supported", c.String("cluster"))
|
||||
}
|
||||
|
||||
// get the list of entries from the discovery service
|
||||
go func() {
|
||||
d, err := discovery.New(dflag, c.Int("heartbeat"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
entries, err := d.Fetch()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
}
|
||||
cluster.NewEntries(entries)
|
||||
|
||||
go d.Watch(cluster.NewEntries)
|
||||
}()
|
||||
|
||||
// see https://github.com/codegangsta/cli/issues/160
|
||||
hosts := c.StringSlice("host")
|
||||
if c.IsSet("host") || c.IsSet("H") {
|
||||
|
|
|
|||
Loading…
Reference in New Issue