diff --git a/cluster/options.go b/cluster/options.go index 9855fc69ff..5c3b37ffee 100644 --- a/cluster/options.go +++ b/cluster/options.go @@ -7,5 +7,5 @@ type Options struct { TLSConfig *tls.Config OvercommitRatio float64 Discovery string - Heartbeat int + Heartbeat uint64 } diff --git a/discovery/consul/consul.go b/discovery/consul/consul.go index 86cb18158d..d93f0ce4b5 100644 --- a/discovery/consul/consul.go +++ b/discovery/consul/consul.go @@ -24,7 +24,7 @@ func init() { } // Initialize is exported -func (s *ConsulDiscoveryService) Initialize(uris string, heartbeat int) error { +func (s *ConsulDiscoveryService) Initialize(uris string, heartbeat uint64) error { parts := strings.SplitN(uris, "/", 2) if len(parts) < 2 { return fmt.Errorf("invalid format %q, missing ", uris) diff --git a/discovery/discovery.go b/discovery/discovery.go index e837d30ea9..8135b3e174 100644 --- a/discovery/discovery.go +++ b/discovery/discovery.go @@ -33,7 +33,7 @@ type WatchCallback func(entries []*Entry) // DiscoveryService is exported type DiscoveryService interface { - Initialize(string, int) error + Initialize(string, uint64) error Fetch() ([]*Entry, error) Watch(WatchCallback) Register(string) error @@ -73,7 +73,7 @@ func parse(rawurl string) (string, string) { } // New is exported -func New(rawurl string, heartbeat int) (DiscoveryService, error) { +func New(rawurl string, heartbeat uint64) (DiscoveryService, error) { scheme, uri := parse(rawurl) if discovery, exists := discoveries[scheme]; exists { diff --git a/discovery/etcd/etcd.go b/discovery/etcd/etcd.go index e634b34b89..202b041886 100644 --- a/discovery/etcd/etcd.go +++ b/discovery/etcd/etcd.go @@ -22,7 +22,7 @@ func init() { } // Initialize is exported -func (s *EtcdDiscoveryService) Initialize(uris string, heartbeat int) error { +func (s *EtcdDiscoveryService) Initialize(uris string, heartbeat uint64) error { var ( // split here because uris can contain multiples ips // like `etcd://192.168.0.1,192.168.0.2,192.168.0.3/path` diff --git a/discovery/file/file.go b/discovery/file/file.go index bda7465ed0..a262baeb74 100644 --- a/discovery/file/file.go +++ b/discovery/file/file.go @@ -10,7 +10,7 @@ import ( // FileDiscoveryService is exported type FileDiscoveryService struct { - heartbeat int + heartbeat uint64 path string } @@ -19,7 +19,7 @@ func init() { } // Initialize is exported -func (s *FileDiscoveryService) Initialize(path string, heartbeat int) error { +func (s *FileDiscoveryService) Initialize(path string, heartbeat uint64) error { s.path = path s.heartbeat = heartbeat return nil diff --git a/discovery/nodes/nodes.go b/discovery/nodes/nodes.go index d40ec61747..2851394ec0 100644 --- a/discovery/nodes/nodes.go +++ b/discovery/nodes/nodes.go @@ -16,7 +16,7 @@ func init() { } // Initialize is exported -func (s *NodesDiscoveryService) Initialize(uris string, _ int) error { +func (s *NodesDiscoveryService) Initialize(uris string, _ uint64) error { for _, input := range strings.Split(uris, ",") { for _, ip := range discovery.Generate(input) { entry, err := discovery.NewEntry(ip) diff --git a/discovery/token/token.go b/discovery/token/token.go index ce09789f27..e9f4197e31 100644 --- a/discovery/token/token.go +++ b/discovery/token/token.go @@ -17,7 +17,7 @@ const DiscoveryURL = "https://discovery-stage.hub.docker.com/v1" // TokenDiscoveryService is exported type TokenDiscoveryService struct { - heartbeat int + heartbeat uint64 url string token string } @@ -27,7 +27,7 @@ func init() { } // Initialize is exported -func (s *TokenDiscoveryService) Initialize(urltoken string, heartbeat int) error { +func (s *TokenDiscoveryService) Initialize(urltoken string, heartbeat uint64) error { if i := strings.LastIndex(urltoken, "/"); i != -1 { s.url = "https://" + urltoken[:i] s.token = urltoken[i+1:] diff --git a/discovery/zookeeper/zookeeper.go b/discovery/zookeeper/zookeeper.go index 2e3786e7c9..8a0f813409 100644 --- a/discovery/zookeeper/zookeeper.go +++ b/discovery/zookeeper/zookeeper.go @@ -15,7 +15,7 @@ import ( type ZkDiscoveryService struct { conn *zk.Conn path []string - heartbeat int + heartbeat uint64 } func init() { @@ -41,7 +41,7 @@ func (s *ZkDiscoveryService) createFullpath() error { } // Initialize is exported -func (s *ZkDiscoveryService) Initialize(uris string, heartbeat int) error { +func (s *ZkDiscoveryService) Initialize(uris string, heartbeat uint64) error { var ( // split here because uris can contain multiples ips // like `zk://192.168.0.1,192.168.0.2,192.168.0.3/path` diff --git a/join.go b/join.go index 7440ef4abe..aa17d62758 100644 --- a/join.go +++ b/join.go @@ -2,6 +2,7 @@ package main import ( "regexp" + "strconv" "time" log "github.com/Sirupsen/logrus" @@ -20,7 +21,12 @@ func join(c *cli.Context) { log.Fatalf("discovery required to join a cluster. See '%s join --help'.", c.App.Name) } - d, err := discovery.New(dflag, c.Int("heartbeat")) + hb, err := strconv.ParseUint(c.String("heartbeat"), 0, 32) + if hb < 1 || err != nil { + log.Fatal("--heartbeat should be an unsigned integer and greater than 0") + } + + d, err := discovery.New(dflag, hb) if err != nil { log.Fatal(err) } @@ -35,10 +41,10 @@ func join(c *cli.Context) { log.Fatal(err) } - hb := time.Duration(c.Int("heartbeat")) + hbval := time.Duration(hb) for { - log.WithFields(log.Fields{"addr": addr, "discovery": dflag}).Infof("Registering on the discovery service every %d seconds...", hb) - time.Sleep(hb * time.Second) + log.WithFields(log.Fields{"addr": addr, "discovery": dflag}).Infof("Registering on the discovery service every %d seconds...", hbval) + time.Sleep(hbval * time.Second) if err := d.Register(addr); err != nil { log.Error(err) } diff --git a/manage.go b/manage.go index 932a30f116..d37ac94666 100644 --- a/manage.go +++ b/manage.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "path" + "strconv" log "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" @@ -120,11 +121,15 @@ func manage(c *cli.Context) { sched := scheduler.New(s, fs) eventsHandler := api.NewEventsHandler() + hb, err := strconv.ParseUint(c.String("heartbeat"), 0, 32) + if hb < 1 || err != nil { + log.Fatal("--heartbeat should be an unsigned integer and greater than 0") + } options := &cluster.Options{ TLSConfig: tlsConfig, OvercommitRatio: c.Float64("overcommit"), Discovery: dflag, - Heartbeat: c.Int("heartbeat"), + Heartbeat: hb, } cluster := swarm.NewCluster(sched, store, eventsHandler, options)