pull out the log.Fatal from pkg/store to the discovery level

Signed-off-by: Alexandre Beslic <abronan@docker.com>
This commit is contained in:
Alexandre Beslic 2015-05-26 11:01:17 -07:00
parent bf6427ad23
commit 96241c6b79
3 changed files with 18 additions and 4 deletions

View File

@ -61,7 +61,15 @@ func (s *Discovery) Initialize(uris string, heartbeat time.Duration, ttl time.Du
EphemeralTTL: s.ttl, 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. // Watch the store until either there's a store error or we receive a stop request.

View File

@ -56,7 +56,10 @@ func InitializeConsul(endpoints []string, options *Config) (Store, error) {
s.setTimeout(options.ConnectionTimeout) s.setTimeout(options.ConnectionTimeout)
} }
if options.EphemeralTTL != 0 { 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 // 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 { if ttl < MinimumTimeToLive {
log.Fatal("Consul does not allow a ttl < 10s, please specify a ttl >= 10s") return ErrInvalidTTL
} }
s.ephemeralTTL = ttl s.ephemeralTTL = ttl
return nil
} }
// CreateEphemeralSession creates the a global session // CreateEphemeralSession creates the a global session

View File

@ -23,6 +23,8 @@ const (
) )
var ( 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 is exported
ErrNotSupported = errors.New("Backend storage not supported yet, please choose another one") ErrNotSupported = errors.New("Backend storage not supported yet, please choose another one")
// ErrNotImplemented is exported // ErrNotImplemented is exported