2014-10-18 02:41:22 +04:00
|
|
|
/*
|
|
|
|
Copyright 2014 CoreOS, Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-10-07 03:42:13 +04:00
|
|
|
package etcdserver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2014-10-11 17:03:03 +04:00
|
|
|
"path"
|
2014-10-07 03:42:13 +04:00
|
|
|
|
|
|
|
"github.com/coreos/etcd/pkg/types"
|
2014-10-18 02:37:30 +04:00
|
|
|
"github.com/coreos/etcd/raft"
|
2014-10-07 03:42:13 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
// ServerConfig holds the configuration of etcd as taken from the command line or discovery.
|
|
|
|
type ServerConfig struct {
|
2014-10-14 02:40:25 +04:00
|
|
|
Name string
|
2014-10-07 03:42:13 +04:00
|
|
|
DiscoveryURL string
|
|
|
|
ClientURLs types.URLs
|
|
|
|
DataDir string
|
2014-10-08 15:58:53 +04:00
|
|
|
SnapCount uint64
|
2014-10-07 03:42:13 +04:00
|
|
|
Cluster *Cluster
|
|
|
|
ClusterState ClusterState
|
|
|
|
Transport *http.Transport
|
|
|
|
}
|
|
|
|
|
2014-10-18 02:43:56 +04:00
|
|
|
// VerifyBootstrapConfig sanity-checks the initial config and returns an error
|
|
|
|
// for things that should never happen.
|
|
|
|
func (c *ServerConfig) VerifyBootstrapConfig() error {
|
2014-10-23 22:08:42 +04:00
|
|
|
m := c.Cluster.MemberByName(c.Name)
|
2014-10-23 01:31:27 +04:00
|
|
|
// Make sure the cluster at least contains the local server.
|
|
|
|
if m == nil {
|
|
|
|
return fmt.Errorf("couldn't find local name %s in the initial cluster configuration", c.Name)
|
|
|
|
}
|
2014-10-31 03:31:14 +03:00
|
|
|
if uint64(m.ID) == raft.None {
|
2014-10-24 09:39:53 +04:00
|
|
|
return fmt.Errorf("cannot use %x as member id", raft.None)
|
2014-10-22 21:49:24 +04:00
|
|
|
}
|
|
|
|
|
2014-10-18 02:43:56 +04:00
|
|
|
if c.DiscoveryURL == "" && c.ClusterState != ClusterStateValueNew {
|
|
|
|
return fmt.Errorf("initial cluster state unset and no wal or discovery URL found")
|
|
|
|
}
|
|
|
|
|
2014-10-07 04:07:51 +04:00
|
|
|
// No identical IPs in the cluster peer list
|
|
|
|
urlMap := make(map[string]bool)
|
2014-10-11 15:20:14 +04:00
|
|
|
for _, m := range c.Cluster.Members() {
|
2014-10-07 04:07:51 +04:00
|
|
|
for _, url := range m.PeerURLs {
|
|
|
|
if urlMap[url] {
|
2014-10-21 21:25:34 +04:00
|
|
|
return fmt.Errorf("duplicate url %v in cluster config", url)
|
2014-10-07 03:42:13 +04:00
|
|
|
}
|
2014-10-07 04:07:51 +04:00
|
|
|
urlMap[url] = true
|
2014-10-07 03:42:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2014-10-11 17:03:03 +04:00
|
|
|
|
|
|
|
func (c *ServerConfig) WALDir() string { return path.Join(c.DataDir, "wal") }
|
|
|
|
|
|
|
|
func (c *ServerConfig) SnapDir() string { return path.Join(c.DataDir, "snap") }
|
|
|
|
|
2014-10-11 17:47:44 +04:00
|
|
|
func (c *ServerConfig) ShouldDiscover() bool {
|
|
|
|
return c.DiscoveryURL != ""
|
|
|
|
}
|