From 96241c6b794ec0200cc78ee50bbf1c2a7fe2fece Mon Sep 17 00:00:00 2001 From: Alexandre Beslic Date: Tue, 26 May 2015 11:01:17 -0700 Subject: [PATCH] pull out the log.Fatal from pkg/store to the discovery level Signed-off-by: Alexandre Beslic --- discovery/kv/kv.go | 10 +++++++++- pkg/store/consul.go | 10 +++++++--- pkg/store/store.go | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/discovery/kv/kv.go b/discovery/kv/kv.go index 64850bfeda..0627788833 100644 --- a/discovery/kv/kv.go +++ b/discovery/kv/kv.go @@ -61,7 +61,15 @@ func (s *Discovery) Initialize(uris string, heartbeat time.Duration, ttl time.Du EphemeralTTL: s.ttl, }, ) - return err + + if err != nil { + if err == store.ErrInvalidTTL { + log.Fatal(err) + } + return err + } + + return nil } // Watch the store until either there's a store error or we receive a stop request. diff --git a/pkg/store/consul.go b/pkg/store/consul.go index beb3ec74a3..3335bdff2a 100644 --- a/pkg/store/consul.go +++ b/pkg/store/consul.go @@ -56,7 +56,10 @@ func InitializeConsul(endpoints []string, options *Config) (Store, error) { s.setTimeout(options.ConnectionTimeout) } if options.EphemeralTTL != 0 { - s.setEphemeralTTL(options.EphemeralTTL) + err := s.setEphemeralTTL(options.EphemeralTTL) + if err != nil { + return nil, err + } } } @@ -85,11 +88,12 @@ func (s *Consul) setTimeout(time time.Duration) { } // SetEphemeralTTL sets the ttl for ephemeral nodes -func (s *Consul) setEphemeralTTL(ttl time.Duration) { +func (s *Consul) setEphemeralTTL(ttl time.Duration) error { if ttl < MinimumTimeToLive { - log.Fatal("Consul does not allow a ttl < 10s, please specify a ttl >= 10s") + return ErrInvalidTTL } s.ephemeralTTL = ttl + return nil } // CreateEphemeralSession creates the a global session diff --git a/pkg/store/store.go b/pkg/store/store.go index 0fc390a232..a372a3dc95 100644 --- a/pkg/store/store.go +++ b/pkg/store/store.go @@ -23,6 +23,8 @@ const ( ) var ( + // ErrInvalidTTL is a specific error to consul + ErrInvalidTTL = errors.New("Invalid TTL, please change the value to the miminum allowed ttl for the chosen store") // ErrNotSupported is exported ErrNotSupported = errors.New("Backend storage not supported yet, please choose another one") // ErrNotImplemented is exported