mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1428 from jonboulle/subpackages
pkg: move everything into subpackages
This commit is contained in:
commit
585881a870
@ -29,7 +29,7 @@ import (
|
||||
|
||||
"github.com/coreos/etcd/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
|
||||
"github.com/coreos/etcd/pkg"
|
||||
"github.com/coreos/etcd/pkg/testutil"
|
||||
"github.com/coreos/etcd/raft"
|
||||
"github.com/coreos/etcd/raft/raftpb"
|
||||
"github.com/coreos/etcd/store"
|
||||
@ -674,7 +674,7 @@ func TestSync(t *testing.T) {
|
||||
t.Errorf("CallSyncTime = %v, want < %v", d, time.Millisecond)
|
||||
}
|
||||
|
||||
pkg.ForceGosched()
|
||||
testutil.ForceGosched()
|
||||
data := n.data()
|
||||
if len(data) != 1 {
|
||||
t.Fatalf("len(proposeData) = %d, want 1", len(data))
|
||||
@ -705,7 +705,7 @@ func TestSyncTimeout(t *testing.T) {
|
||||
|
||||
// give time for goroutine in sync to cancel
|
||||
// TODO: use fake clock
|
||||
pkg.ForceGosched()
|
||||
testutil.ForceGosched()
|
||||
w := []action{action{name: "Propose blocked"}}
|
||||
if g := n.Action(); !reflect.DeepEqual(g, w) {
|
||||
t.Errorf("action = %v, want %v", g, w)
|
||||
@ -849,7 +849,7 @@ func TestRecvSnapshot(t *testing.T) {
|
||||
s.start()
|
||||
n.readyc <- raft.Ready{Snapshot: raftpb.Snapshot{Index: 1}}
|
||||
// make goroutines move forward to receive snapshot
|
||||
pkg.ForceGosched()
|
||||
testutil.ForceGosched()
|
||||
s.Stop()
|
||||
|
||||
wactions := []action{action{name: "Recovery"}}
|
||||
@ -877,12 +877,12 @@ func TestRecvSlowSnapshot(t *testing.T) {
|
||||
s.start()
|
||||
n.readyc <- raft.Ready{Snapshot: raftpb.Snapshot{Index: 1}}
|
||||
// make goroutines move forward to receive snapshot
|
||||
pkg.ForceGosched()
|
||||
testutil.ForceGosched()
|
||||
action := st.Action()
|
||||
|
||||
n.readyc <- raft.Ready{Snapshot: raftpb.Snapshot{Index: 1}}
|
||||
// make goroutines move forward to receive snapshot
|
||||
pkg.ForceGosched()
|
||||
testutil.ForceGosched()
|
||||
s.Stop()
|
||||
|
||||
if g := st.Action(); !reflect.DeepEqual(g, action) {
|
||||
|
62
main.go
62
main.go
@ -26,8 +26,8 @@ import (
|
||||
|
||||
"github.com/coreos/etcd/etcdserver"
|
||||
"github.com/coreos/etcd/etcdserver/etcdhttp"
|
||||
"github.com/coreos/etcd/pkg"
|
||||
flagtypes "github.com/coreos/etcd/pkg/flags"
|
||||
"github.com/coreos/etcd/pkg/cors"
|
||||
"github.com/coreos/etcd/pkg/flags"
|
||||
"github.com/coreos/etcd/pkg/transport"
|
||||
"github.com/coreos/etcd/pkg/types"
|
||||
"github.com/coreos/etcd/proxy"
|
||||
@ -51,8 +51,8 @@ var (
|
||||
initialClusterName = fs.String("initial-cluster-name", "etcd", "Initial name for the etcd cluster during bootstrap")
|
||||
clusterState = new(etcdserver.ClusterState)
|
||||
|
||||
cors = &pkg.CORSInfo{}
|
||||
proxyFlag = new(flagtypes.Proxy)
|
||||
corsInfo = &cors.CORSInfo{}
|
||||
proxyFlag = new(flags.Proxy)
|
||||
|
||||
clientTLSInfo = transport.TLSInfo{}
|
||||
peerTLSInfo = transport.TLSInfo{}
|
||||
@ -78,15 +78,15 @@ func init() {
|
||||
fs.Var(clusterState, "initial-cluster-state", "Initial cluster configuration for bootstrapping")
|
||||
clusterState.Set(etcdserver.ClusterStateValueNew)
|
||||
|
||||
fs.Var(flagtypes.NewURLsValue("http://localhost:2380,http://localhost:7001"), "initial-advertise-peer-urls", "List of this member's peer URLs to advertise to the rest of the cluster")
|
||||
fs.Var(flagtypes.NewURLsValue("http://localhost:2379,http://localhost:4001"), "advertise-client-urls", "List of this member's client URLs to advertise to the rest of the cluster")
|
||||
fs.Var(flagtypes.NewURLsValue("http://localhost:2380,http://localhost:7001"), "listen-peer-urls", "List of URLs to listen on for peer traffic")
|
||||
fs.Var(flagtypes.NewURLsValue("http://localhost:2379,http://localhost:4001"), "listen-client-urls", "List of URLs to listen on for client traffic")
|
||||
fs.Var(flags.NewURLsValue("http://localhost:2380,http://localhost:7001"), "initial-advertise-peer-urls", "List of this member's peer URLs to advertise to the rest of the cluster")
|
||||
fs.Var(flags.NewURLsValue("http://localhost:2379,http://localhost:4001"), "advertise-client-urls", "List of this member's client URLs to advertise to the rest of the cluster")
|
||||
fs.Var(flags.NewURLsValue("http://localhost:2380,http://localhost:7001"), "listen-peer-urls", "List of URLs to listen on for peer traffic")
|
||||
fs.Var(flags.NewURLsValue("http://localhost:2379,http://localhost:4001"), "listen-client-urls", "List of URLs to listen on for client traffic")
|
||||
|
||||
fs.Var(cors, "cors", "Comma-separated white list of origins for CORS (cross-origin resource sharing).")
|
||||
fs.Var(corsInfo, "cors", "Comma-separated white list of origins for CORS (cross-origin resource sharing).")
|
||||
|
||||
fs.Var(proxyFlag, "proxy", fmt.Sprintf("Valid values include %s", strings.Join(flagtypes.ProxyValues, ", ")))
|
||||
proxyFlag.Set(flagtypes.ProxyValueOff)
|
||||
fs.Var(proxyFlag, "proxy", fmt.Sprintf("Valid values include %s", strings.Join(flags.ProxyValues, ", ")))
|
||||
proxyFlag.Set(flags.ProxyValueOff)
|
||||
|
||||
fs.StringVar(&clientTLSInfo.CAFile, "ca-file", "", "Path to the client server TLS CA file.")
|
||||
fs.StringVar(&clientTLSInfo.CertFile, "cert-file", "", "Path to the client server TLS cert file.")
|
||||
@ -97,21 +97,21 @@ func init() {
|
||||
fs.StringVar(&peerTLSInfo.KeyFile, "peer-key-file", "", "Path to the peer server TLS key file.")
|
||||
|
||||
// backwards-compatibility with v0.4.6
|
||||
fs.Var(&flagtypes.IPAddressPort{}, "addr", "DEPRECATED: Use -advertise-client-urls instead.")
|
||||
fs.Var(&flagtypes.IPAddressPort{}, "bind-addr", "DEPRECATED: Use -listen-client-urls instead.")
|
||||
fs.Var(&flagtypes.IPAddressPort{}, "peer-addr", "DEPRECATED: Use -initial-advertise-peer-urls instead.")
|
||||
fs.Var(&flagtypes.IPAddressPort{}, "peer-bind-addr", "DEPRECATED: Use -listen-peer-urls instead.")
|
||||
fs.Var(&flags.IPAddressPort{}, "addr", "DEPRECATED: Use -advertise-client-urls instead.")
|
||||
fs.Var(&flags.IPAddressPort{}, "bind-addr", "DEPRECATED: Use -listen-client-urls instead.")
|
||||
fs.Var(&flags.IPAddressPort{}, "peer-addr", "DEPRECATED: Use -initial-advertise-peer-urls instead.")
|
||||
fs.Var(&flags.IPAddressPort{}, "peer-bind-addr", "DEPRECATED: Use -listen-peer-urls instead.")
|
||||
|
||||
for _, f := range ignored {
|
||||
fs.Var(&pkg.IgnoredFlag{Name: f}, f, "")
|
||||
fs.Var(&flags.IgnoredFlag{Name: f}, f, "")
|
||||
}
|
||||
|
||||
fs.Var(&pkg.DeprecatedFlag{Name: "peers"}, "peers", "DEPRECATED: Use -initial-cluster instead")
|
||||
fs.Var(&pkg.DeprecatedFlag{Name: "peers-file"}, "peers-file", "DEPRECATED: Use -initial-cluster instead")
|
||||
fs.Var(&flags.DeprecatedFlag{Name: "peers"}, "peers", "DEPRECATED: Use -initial-cluster instead")
|
||||
fs.Var(&flags.DeprecatedFlag{Name: "peers-file"}, "peers-file", "DEPRECATED: Use -initial-cluster instead")
|
||||
}
|
||||
|
||||
func main() {
|
||||
fs.Usage = pkg.UsageWithIgnoredFlagsFunc(fs, ignored)
|
||||
fs.Usage = flags.UsageWithIgnoredFlagsFunc(fs, ignored)
|
||||
err := fs.Parse(os.Args[1:])
|
||||
switch err {
|
||||
case nil:
|
||||
@ -126,9 +126,9 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
pkg.SetFlagsFromEnv(fs)
|
||||
flags.SetFlagsFromEnv(fs)
|
||||
|
||||
if string(*proxyFlag) == flagtypes.ProxyValueOff {
|
||||
if string(*proxyFlag) == flags.ProxyValueOff {
|
||||
startEtcd()
|
||||
} else {
|
||||
startProxy()
|
||||
@ -158,7 +158,7 @@ func startEtcd() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
acurls, err := pkg.URLsFromFlags(fs, "advertise-client-urls", "addr", clientTLSInfo)
|
||||
acurls, err := flags.URLsFromFlags(fs, "advertise-client-urls", "addr", clientTLSInfo)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
@ -175,13 +175,13 @@ func startEtcd() {
|
||||
s := etcdserver.NewServer(cfg)
|
||||
s.Start()
|
||||
|
||||
ch := &pkg.CORSHandler{
|
||||
ch := &cors.CORSHandler{
|
||||
Handler: etcdhttp.NewClientHandler(s),
|
||||
Info: cors,
|
||||
Info: corsInfo,
|
||||
}
|
||||
ph := etcdhttp.NewPeerHandler(s)
|
||||
|
||||
lpurls, err := pkg.URLsFromFlags(fs, "listen-peer-urls", "peer-bind-addr", peerTLSInfo)
|
||||
lpurls, err := flags.URLsFromFlags(fs, "listen-peer-urls", "peer-bind-addr", peerTLSInfo)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
@ -200,7 +200,7 @@ func startEtcd() {
|
||||
}()
|
||||
}
|
||||
|
||||
lcurls, err := pkg.URLsFromFlags(fs, "listen-client-urls", "bind-addr", clientTLSInfo)
|
||||
lcurls, err := flags.URLsFromFlags(fs, "listen-client-urls", "bind-addr", clientTLSInfo)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
@ -244,16 +244,16 @@ func startProxy() {
|
||||
return cls.ClientURLs()
|
||||
}
|
||||
ph := proxy.NewHandler(pt, uf)
|
||||
ph = &pkg.CORSHandler{
|
||||
ph = &cors.CORSHandler{
|
||||
Handler: ph,
|
||||
Info: cors,
|
||||
Info: corsInfo,
|
||||
}
|
||||
|
||||
if string(*proxyFlag) == flagtypes.ProxyValueReadonly {
|
||||
if string(*proxyFlag) == flags.ProxyValueReadonly {
|
||||
ph = proxy.NewReadonlyHandler(ph)
|
||||
}
|
||||
|
||||
lcurls, err := pkg.URLsFromFlags(fs, "listen-client-urls", "bind-addr", clientTLSInfo)
|
||||
lcurls, err := flags.URLsFromFlags(fs, "listen-client-urls", "bind-addr", clientTLSInfo)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
@ -281,7 +281,7 @@ func setupCluster() (*etcdserver.Cluster, error) {
|
||||
if set["discovery"] && set["initial-cluster"] {
|
||||
return nil, fmt.Errorf("both discovery and bootstrap-config are set")
|
||||
}
|
||||
apurls, err := pkg.URLsFromFlags(fs, "initial-advertise-peer-urls", "addr", peerTLSInfo)
|
||||
apurls, err := flags.URLsFromFlags(fs, "initial-advertise-peer-urls", "addr", peerTLSInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package pkg
|
||||
package cors
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -14,7 +14,7 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package pkg
|
||||
package flags
|
||||
|
||||
import (
|
||||
"flag"
|
||||
@ -24,7 +24,6 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/etcd/pkg/flags"
|
||||
"github.com/coreos/etcd/pkg/transport"
|
||||
)
|
||||
|
||||
@ -126,7 +125,7 @@ func URLsFromFlags(fs *flag.FlagSet, urlsFlagName string, addrFlagName string, t
|
||||
return nil, fmt.Errorf("Set only one of flags -%s and -%s", urlsFlagName, addrFlagName)
|
||||
}
|
||||
|
||||
addr := *fs.Lookup(addrFlagName).Value.(*flags.IPAddressPort)
|
||||
addr := *fs.Lookup(addrFlagName).Value.(*IPAddressPort)
|
||||
addrURL := url.URL{Scheme: "http", Host: addr.String()}
|
||||
if !tlsInfo.Empty() {
|
||||
addrURL.Scheme = "https"
|
||||
@ -134,5 +133,5 @@ func URLsFromFlags(fs *flag.FlagSet, urlsFlagName string, addrFlagName string, t
|
||||
return []url.URL{addrURL}, nil
|
||||
}
|
||||
|
||||
return []url.URL(*fs.Lookup(urlsFlagName).Value.(*flags.URLsValue)), nil
|
||||
return []url.URL(*fs.Lookup(urlsFlagName).Value.(*URLsValue)), nil
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package pkg
|
||||
package flags
|
||||
|
||||
import (
|
||||
"flag"
|
||||
@ -23,7 +23,6 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/coreos/etcd/pkg/flags"
|
||||
"github.com/coreos/etcd/pkg/transport"
|
||||
)
|
||||
|
||||
@ -133,8 +132,8 @@ func TestURLsFromFlags(t *testing.T) {
|
||||
|
||||
for i, tt := range tests {
|
||||
fs := flag.NewFlagSet("test", flag.PanicOnError)
|
||||
fs.Var(flags.NewURLsValue("http://127.0.0.1:2379"), "urls", "")
|
||||
fs.Var(&flags.IPAddressPort{}, "addr", "")
|
||||
fs.Var(NewURLsValue("http://127.0.0.1:2379"), "urls", "")
|
||||
fs.Var(&IPAddressPort{}, "addr", "")
|
||||
|
||||
if err := fs.Parse(tt.args); err != nil {
|
||||
t.Errorf("#%d: failed to parse flags: %v", i, err)
|
@ -14,7 +14,7 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package pkg
|
||||
package testutil
|
||||
|
||||
import (
|
||||
"runtime"
|
@ -22,7 +22,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/coreos/etcd/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||
"github.com/coreos/etcd/pkg"
|
||||
"github.com/coreos/etcd/pkg/testutil"
|
||||
"github.com/coreos/etcd/raft/raftpb"
|
||||
)
|
||||
|
||||
@ -121,7 +121,7 @@ func TestBlockProposal(t *testing.T) {
|
||||
errc <- n.Propose(context.TODO(), []byte("somedata"))
|
||||
}()
|
||||
|
||||
pkg.ForceGosched()
|
||||
testutil.ForceGosched()
|
||||
select {
|
||||
case err := <-errc:
|
||||
t.Errorf("err = %v, want blocking", err)
|
||||
@ -129,7 +129,7 @@ func TestBlockProposal(t *testing.T) {
|
||||
}
|
||||
|
||||
n.Campaign(context.TODO())
|
||||
pkg.ForceGosched()
|
||||
testutil.ForceGosched()
|
||||
select {
|
||||
case err := <-errc:
|
||||
if err != nil {
|
||||
@ -253,7 +253,7 @@ func TestNodeCompact(t *testing.T) {
|
||||
Nodes: []uint64{1},
|
||||
}
|
||||
|
||||
pkg.ForceGosched()
|
||||
testutil.ForceGosched()
|
||||
select {
|
||||
case <-n.Ready():
|
||||
default:
|
||||
@ -261,7 +261,7 @@ func TestNodeCompact(t *testing.T) {
|
||||
}
|
||||
|
||||
n.Compact(w.Index, w.Nodes, w.Data)
|
||||
pkg.ForceGosched()
|
||||
testutil.ForceGosched()
|
||||
select {
|
||||
case rd := <-n.Ready():
|
||||
if !reflect.DeepEqual(rd.Snapshot, w) {
|
||||
@ -270,7 +270,7 @@ func TestNodeCompact(t *testing.T) {
|
||||
default:
|
||||
t.Fatalf("unexpected compact failure: unable to create a snapshot")
|
||||
}
|
||||
pkg.ForceGosched()
|
||||
testutil.ForceGosched()
|
||||
// TODO: this test the run updates the snapi correctly... should be tested
|
||||
// separately with other kinds of updates
|
||||
select {
|
||||
|
2
test
2
test
@ -15,7 +15,7 @@ COVER=${COVER:-"-cover"}
|
||||
source ./build
|
||||
|
||||
# Hack: gofmt ./ will recursively check the .git directory. So use *.go for gofmt.
|
||||
TESTABLE_AND_FORMATTABLE="client discovery etcdctl/command etcdserver etcdserver/etcdhttp etcdserver/etcdserverpb integration pkg pkg/flags pkg/transport proxy raft snap store wait wal"
|
||||
TESTABLE_AND_FORMATTABLE="client discovery etcdctl/command etcdserver etcdserver/etcdhttp etcdserver/etcdserverpb integration pkg/flags pkg/transport proxy raft snap store wait wal"
|
||||
TESTABLE="$TESTABLE_AND_FORMATTABLE ./"
|
||||
FORMATTABLE="$TESTABLE_AND_FORMATTABLE *.go etcdctl/"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user