mirror of https://github.com/status-im/consul.git
Rename server_details package to agent
This commit is contained in:
parent
80f9f54bb3
commit
7cdc056ca5
|
@ -1,4 +1,9 @@
|
||||||
package server_details
|
// Package agent provides a logical endpoint for Consul agents in the
|
||||||
|
// network. agent data originates from Serf gossip and is primarily used to
|
||||||
|
// communicate Consul server information. Gossiped information that ends up
|
||||||
|
// in Server contains the necessary metadata required for servers.Manager to
|
||||||
|
// select which server an RPC request should be routed to.
|
||||||
|
package agent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -18,8 +23,8 @@ func (k *Key) Equal(x *Key) bool {
|
||||||
return k.name == x.name
|
return k.name == x.name
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerDetails is used to return details of a consul server
|
// Server is used to return details of a consul server
|
||||||
type ServerDetails struct {
|
type Server struct {
|
||||||
Name string
|
Name string
|
||||||
Datacenter string
|
Datacenter string
|
||||||
Port int
|
Port int
|
||||||
|
@ -30,14 +35,14 @@ type ServerDetails struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key returns the corresponding Key
|
// Key returns the corresponding Key
|
||||||
func (s *ServerDetails) Key() *Key {
|
func (s *Server) Key() *Key {
|
||||||
return &Key{
|
return &Key{
|
||||||
name: s.Name,
|
name: s.Name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns a string representation of ServerDetails
|
// String returns a string representation of Server
|
||||||
func (s *ServerDetails) String() string {
|
func (s *Server) String() string {
|
||||||
var addrStr, networkStr string
|
var addrStr, networkStr string
|
||||||
if s.Addr != nil {
|
if s.Addr != nil {
|
||||||
addrStr = s.Addr.String()
|
addrStr = s.Addr.String()
|
||||||
|
@ -47,9 +52,9 @@ func (s *ServerDetails) String() string {
|
||||||
return fmt.Sprintf("%s (Addr: %s/%s) (DC: %s)", s.Name, networkStr, addrStr, s.Datacenter)
|
return fmt.Sprintf("%s (Addr: %s/%s) (DC: %s)", s.Name, networkStr, addrStr, s.Datacenter)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsConsulServer returns true if a serf member is a consul server. Returns a
|
// IsConsulServer returns true if a serf member is a consul server
|
||||||
// bool and a pointer to the ServerDetails.
|
// agent. Returns a bool and a pointer to the Server.
|
||||||
func IsConsulServer(m serf.Member) (bool, *ServerDetails) {
|
func IsConsulServer(m serf.Member) (bool, *Server) {
|
||||||
if m.Tags["role"] != "consul" {
|
if m.Tags["role"] != "consul" {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
@ -81,7 +86,7 @@ func IsConsulServer(m serf.Member) (bool, *ServerDetails) {
|
||||||
|
|
||||||
addr := &net.TCPAddr{IP: m.Addr, Port: port}
|
addr := &net.TCPAddr{IP: m.Addr, Port: port}
|
||||||
|
|
||||||
parts := &ServerDetails{
|
parts := &Server{
|
||||||
Name: m.Name,
|
Name: m.Name,
|
||||||
Datacenter: datacenter,
|
Datacenter: datacenter,
|
||||||
Port: port,
|
Port: port,
|
|
@ -1,10 +1,10 @@
|
||||||
package server_details
|
package agent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServerDetails_Key_Equal(t *testing.T) {
|
func TestServer_Key_Equal(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
k1 *Key
|
k1 *Key
|
||||||
|
@ -47,16 +47,16 @@ func TestServerDetails_Key_Equal(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServerDetails_Key(t *testing.T) {
|
func TestServer_Key(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
sd *ServerDetails
|
sd *Server
|
||||||
k *Key
|
k *Key
|
||||||
equal bool
|
equal bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Key equality",
|
name: "Key equality",
|
||||||
sd: &ServerDetails{
|
sd: &Server{
|
||||||
Name: "s1",
|
Name: "s1",
|
||||||
},
|
},
|
||||||
k: &Key{
|
k: &Key{
|
||||||
|
@ -66,7 +66,7 @@ func TestServerDetails_Key(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Key inequality",
|
name: "Key inequality",
|
||||||
sd: &ServerDetails{
|
sd: &Server{
|
||||||
Name: "s1",
|
Name: "s1",
|
||||||
},
|
},
|
||||||
k: &Key{
|
k: &Key{
|
|
@ -1,32 +1,32 @@
|
||||||
package server_details_test
|
package agent_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/consul/server_details"
|
"github.com/hashicorp/consul/consul/agent"
|
||||||
"github.com/hashicorp/serf/serf"
|
"github.com/hashicorp/serf/serf"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServerDetails_Key_params(t *testing.T) {
|
func TestServer_Key_params(t *testing.T) {
|
||||||
ipv4a := net.ParseIP("127.0.0.1")
|
ipv4a := net.ParseIP("127.0.0.1")
|
||||||
ipv4b := net.ParseIP("1.2.3.4")
|
ipv4b := net.ParseIP("1.2.3.4")
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
sd1 *server_details.ServerDetails
|
sd1 *agent.Server
|
||||||
sd2 *server_details.ServerDetails
|
sd2 *agent.Server
|
||||||
equal bool
|
equal bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Addr inequality",
|
name: "Addr inequality",
|
||||||
sd1: &server_details.ServerDetails{
|
sd1: &agent.Server{
|
||||||
Name: "s1",
|
Name: "s1",
|
||||||
Datacenter: "dc1",
|
Datacenter: "dc1",
|
||||||
Port: 8300,
|
Port: 8300,
|
||||||
Addr: &net.IPAddr{IP: ipv4a},
|
Addr: &net.IPAddr{IP: ipv4a},
|
||||||
},
|
},
|
||||||
sd2: &server_details.ServerDetails{
|
sd2: &agent.Server{
|
||||||
Name: "s1",
|
Name: "s1",
|
||||||
Datacenter: "dc1",
|
Datacenter: "dc1",
|
||||||
Port: 8300,
|
Port: 8300,
|
||||||
|
@ -42,7 +42,7 @@ func TestServerDetails_Key_params(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test Key to make sure it actually works as a key
|
// Test Key to make sure it actually works as a key
|
||||||
m := make(map[server_details.Key]bool)
|
m := make(map[agent.Key]bool)
|
||||||
m[*test.sd1.Key()] = true
|
m[*test.sd1.Key()] = true
|
||||||
if _, found := m[*test.sd2.Key()]; found != test.equal {
|
if _, found := m[*test.sd2.Key()]; found != test.equal {
|
||||||
t.Errorf("Expected a %v result from map test %s", test.equal, test.name)
|
t.Errorf("Expected a %v result from map test %s", test.equal, test.name)
|
||||||
|
@ -61,7 +61,7 @@ func TestIsConsulServer(t *testing.T) {
|
||||||
"vsn": "1",
|
"vsn": "1",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ok, parts := server_details.IsConsulServer(m)
|
ok, parts := agent.IsConsulServer(m)
|
||||||
if !ok || parts.Datacenter != "east-aws" || parts.Port != 10000 {
|
if !ok || parts.Datacenter != "east-aws" || parts.Port != 10000 {
|
||||||
t.Fatalf("bad: %v %v", ok, parts)
|
t.Fatalf("bad: %v %v", ok, parts)
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ func TestIsConsulServer(t *testing.T) {
|
||||||
}
|
}
|
||||||
m.Tags["bootstrap"] = "1"
|
m.Tags["bootstrap"] = "1"
|
||||||
m.Tags["disabled"] = "1"
|
m.Tags["disabled"] = "1"
|
||||||
ok, parts = server_details.IsConsulServer(m)
|
ok, parts = agent.IsConsulServer(m)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("expected a valid consul server")
|
t.Fatalf("expected a valid consul server")
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ func TestIsConsulServer(t *testing.T) {
|
||||||
m.Tags["expect"] = "3"
|
m.Tags["expect"] = "3"
|
||||||
delete(m.Tags, "bootstrap")
|
delete(m.Tags, "bootstrap")
|
||||||
delete(m.Tags, "disabled")
|
delete(m.Tags, "disabled")
|
||||||
ok, parts = server_details.IsConsulServer(m)
|
ok, parts = agent.IsConsulServer(m)
|
||||||
if !ok || parts.Expect != 3 {
|
if !ok || parts.Expect != 3 {
|
||||||
t.Fatalf("bad: %v", parts.Expect)
|
t.Fatalf("bad: %v", parts.Expect)
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ func TestIsConsulServer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(m.Tags, "role")
|
delete(m.Tags, "role")
|
||||||
ok, parts = server_details.IsConsulServer(m)
|
ok, parts = agent.IsConsulServer(m)
|
||||||
if ok {
|
if ok {
|
||||||
t.Fatalf("unexpected ok server")
|
t.Fatalf("unexpected ok server")
|
||||||
}
|
}
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/consul/server_details"
|
"github.com/hashicorp/consul/consul/agent"
|
||||||
"github.com/hashicorp/consul/consul/servers"
|
"github.com/hashicorp/consul/consul/servers"
|
||||||
"github.com/hashicorp/consul/consul/structs"
|
"github.com/hashicorp/consul/consul/structs"
|
||||||
"github.com/hashicorp/serf/coordinate"
|
"github.com/hashicorp/serf/coordinate"
|
||||||
|
@ -261,7 +261,7 @@ func (c *Client) lanEventHandler() {
|
||||||
// nodeJoin is used to handle join events on the serf cluster
|
// nodeJoin is used to handle join events on the serf cluster
|
||||||
func (c *Client) nodeJoin(me serf.MemberEvent) {
|
func (c *Client) nodeJoin(me serf.MemberEvent) {
|
||||||
for _, m := range me.Members {
|
for _, m := range me.Members {
|
||||||
ok, parts := server_details.IsConsulServer(m)
|
ok, parts := agent.IsConsulServer(m)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ func (c *Client) nodeJoin(me serf.MemberEvent) {
|
||||||
// nodeFail is used to handle fail events on the serf cluster
|
// nodeFail is used to handle fail events on the serf cluster
|
||||||
func (c *Client) nodeFail(me serf.MemberEvent) {
|
func (c *Client) nodeFail(me serf.MemberEvent) {
|
||||||
for _, m := range me.Members {
|
for _, m := range me.Members {
|
||||||
ok, parts := server_details.IsConsulServer(m)
|
ok, parts := agent.IsConsulServer(m)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/armon/go-metrics"
|
"github.com/armon/go-metrics"
|
||||||
"github.com/hashicorp/consul/consul/server_details"
|
"github.com/hashicorp/consul/consul/agent"
|
||||||
"github.com/hashicorp/consul/consul/structs"
|
"github.com/hashicorp/consul/consul/structs"
|
||||||
"github.com/hashicorp/raft"
|
"github.com/hashicorp/raft"
|
||||||
"github.com/hashicorp/serf/serf"
|
"github.com/hashicorp/serf/serf"
|
||||||
|
@ -350,7 +350,7 @@ func (s *Server) shouldHandleMember(member serf.Member) bool {
|
||||||
if valid, dc := isConsulNode(member); valid && dc == s.config.Datacenter {
|
if valid, dc := isConsulNode(member); valid && dc == s.config.Datacenter {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if valid, parts := server_details.IsConsulServer(member); valid && parts.Datacenter == s.config.Datacenter {
|
if valid, parts := agent.IsConsulServer(member); valid && parts.Datacenter == s.config.Datacenter {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -361,7 +361,7 @@ func (s *Server) shouldHandleMember(member serf.Member) bool {
|
||||||
func (s *Server) handleAliveMember(member serf.Member) error {
|
func (s *Server) handleAliveMember(member serf.Member) error {
|
||||||
// Register consul service if a server
|
// Register consul service if a server
|
||||||
var service *structs.NodeService
|
var service *structs.NodeService
|
||||||
if valid, parts := server_details.IsConsulServer(member); valid {
|
if valid, parts := agent.IsConsulServer(member); valid {
|
||||||
service = &structs.NodeService{
|
service = &structs.NodeService{
|
||||||
ID: ConsulServiceID,
|
ID: ConsulServiceID,
|
||||||
Service: ConsulServiceName,
|
Service: ConsulServiceName,
|
||||||
|
@ -497,7 +497,7 @@ func (s *Server) handleDeregisterMember(reason string, member serf.Member) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove from Raft peers if this was a server
|
// Remove from Raft peers if this was a server
|
||||||
if valid, parts := server_details.IsConsulServer(member); valid {
|
if valid, parts := agent.IsConsulServer(member); valid {
|
||||||
if err := s.removeConsulServer(member, parts.Port); err != nil {
|
if err := s.removeConsulServer(member, parts.Port); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -524,7 +524,7 @@ func (s *Server) handleDeregisterMember(reason string, member serf.Member) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// joinConsulServer is used to try to join another consul server
|
// joinConsulServer is used to try to join another consul server
|
||||||
func (s *Server) joinConsulServer(m serf.Member, parts *server_details.ServerDetails) error {
|
func (s *Server) joinConsulServer(m serf.Member, parts *agent.Server) error {
|
||||||
// Do not join ourself
|
// Do not join ourself
|
||||||
if m.Name == s.config.NodeName {
|
if m.Name == s.config.NodeName {
|
||||||
return nil
|
return nil
|
||||||
|
@ -534,7 +534,7 @@ func (s *Server) joinConsulServer(m serf.Member, parts *server_details.ServerDet
|
||||||
if parts.Bootstrap {
|
if parts.Bootstrap {
|
||||||
members := s.serfLAN.Members()
|
members := s.serfLAN.Members()
|
||||||
for _, member := range members {
|
for _, member := range members {
|
||||||
valid, p := server_details.IsConsulServer(member)
|
valid, p := agent.IsConsulServer(member)
|
||||||
if valid && member.Name != m.Name && p.Bootstrap {
|
if valid && member.Name != m.Name && p.Bootstrap {
|
||||||
s.logger.Printf("[ERR] consul: '%v' and '%v' are both in bootstrap mode. Only one node should be in bootstrap mode, not adding Raft peer.", m.Name, member.Name)
|
s.logger.Printf("[ERR] consul: '%v' and '%v' are both in bootstrap mode. Only one node should be in bootstrap mode, not adding Raft peer.", m.Name, member.Name)
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -3,7 +3,7 @@ package consul
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/consul/server_details"
|
"github.com/hashicorp/consul/consul/agent"
|
||||||
"github.com/hashicorp/serf/serf"
|
"github.com/hashicorp/serf/serf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ func (md *lanMergeDelegate) NotifyMerge(members []*serf.Member) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ok, parts := server_details.IsConsulServer(*m)
|
ok, parts := agent.IsConsulServer(*m)
|
||||||
if ok && parts.Datacenter != md.dc {
|
if ok && parts.Datacenter != md.dc {
|
||||||
return fmt.Errorf("Member '%s' part of wrong datacenter '%s'",
|
return fmt.Errorf("Member '%s' part of wrong datacenter '%s'",
|
||||||
m.Name, parts.Datacenter)
|
m.Name, parts.Datacenter)
|
||||||
|
@ -42,7 +42,7 @@ type wanMergeDelegate struct {
|
||||||
|
|
||||||
func (md *wanMergeDelegate) NotifyMerge(members []*serf.Member) error {
|
func (md *wanMergeDelegate) NotifyMerge(members []*serf.Member) error {
|
||||||
for _, m := range members {
|
for _, m := range members {
|
||||||
ok, _ := server_details.IsConsulServer(*m)
|
ok, _ := agent.IsConsulServer(*m)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("Member '%s' is not a server", m.Name)
|
return fmt.Errorf("Member '%s' is not a server", m.Name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/consul/server_details"
|
"github.com/hashicorp/consul/consul/agent"
|
||||||
"github.com/hashicorp/consul/tlsutil"
|
"github.com/hashicorp/consul/tlsutil"
|
||||||
"github.com/hashicorp/net-rpc-msgpackrpc"
|
"github.com/hashicorp/net-rpc-msgpackrpc"
|
||||||
"github.com/hashicorp/yamux"
|
"github.com/hashicorp/yamux"
|
||||||
|
@ -408,7 +408,7 @@ func (p *ConnPool) RPC(dc string, addr net.Addr, version int, method string, arg
|
||||||
|
|
||||||
// PingConsulServer sends a Status.Ping message to the specified server and
|
// PingConsulServer sends a Status.Ping message to the specified server and
|
||||||
// returns true if healthy, false if an error occurred
|
// returns true if healthy, false if an error occurred
|
||||||
func (p *ConnPool) PingConsulServer(s *server_details.ServerDetails) (bool, error) {
|
func (p *ConnPool) PingConsulServer(s *agent.Server) (bool, error) {
|
||||||
// Get a usable client
|
// Get a usable client
|
||||||
conn, sc, err := p.getClient(s.Datacenter, s.Addr, s.Version)
|
conn, sc, err := p.getClient(s.Datacenter, s.Addr, s.Version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/consul/server_details"
|
"github.com/hashicorp/consul/consul/agent"
|
||||||
"github.com/hashicorp/serf/serf"
|
"github.com/hashicorp/serf/serf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ func (s *Server) localEvent(event serf.UserEvent) {
|
||||||
// lanNodeJoin is used to handle join events on the LAN pool.
|
// lanNodeJoin is used to handle join events on the LAN pool.
|
||||||
func (s *Server) lanNodeJoin(me serf.MemberEvent) {
|
func (s *Server) lanNodeJoin(me serf.MemberEvent) {
|
||||||
for _, m := range me.Members {
|
for _, m := range me.Members {
|
||||||
ok, parts := server_details.IsConsulServer(m)
|
ok, parts := agent.IsConsulServer(m)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ func (s *Server) lanNodeJoin(me serf.MemberEvent) {
|
||||||
// wanNodeJoin is used to handle join events on the WAN pool.
|
// wanNodeJoin is used to handle join events on the WAN pool.
|
||||||
func (s *Server) wanNodeJoin(me serf.MemberEvent) {
|
func (s *Server) wanNodeJoin(me serf.MemberEvent) {
|
||||||
for _, m := range me.Members {
|
for _, m := range me.Members {
|
||||||
ok, parts := server_details.IsConsulServer(m)
|
ok, parts := agent.IsConsulServer(m)
|
||||||
if !ok {
|
if !ok {
|
||||||
s.logger.Printf("[WARN] consul: non-server in WAN pool: %s", m.Name)
|
s.logger.Printf("[WARN] consul: non-server in WAN pool: %s", m.Name)
|
||||||
continue
|
continue
|
||||||
|
@ -210,7 +210,7 @@ func (s *Server) maybeBootstrap() {
|
||||||
members := s.serfLAN.Members()
|
members := s.serfLAN.Members()
|
||||||
addrs := make([]string, 0)
|
addrs := make([]string, 0)
|
||||||
for _, member := range members {
|
for _, member := range members {
|
||||||
valid, p := server_details.IsConsulServer(member)
|
valid, p := agent.IsConsulServer(member)
|
||||||
if !valid {
|
if !valid {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ func (s *Server) maybeBootstrap() {
|
||||||
// lanNodeFailed is used to handle fail events on the LAN pool.
|
// lanNodeFailed is used to handle fail events on the LAN pool.
|
||||||
func (s *Server) lanNodeFailed(me serf.MemberEvent) {
|
func (s *Server) lanNodeFailed(me serf.MemberEvent) {
|
||||||
for _, m := range me.Members {
|
for _, m := range me.Members {
|
||||||
ok, parts := server_details.IsConsulServer(m)
|
ok, parts := agent.IsConsulServer(m)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ func (s *Server) lanNodeFailed(me serf.MemberEvent) {
|
||||||
// wanNodeFailed is used to handle fail events on the WAN pool.
|
// wanNodeFailed is used to handle fail events on the WAN pool.
|
||||||
func (s *Server) wanNodeFailed(me serf.MemberEvent) {
|
func (s *Server) wanNodeFailed(me serf.MemberEvent) {
|
||||||
for _, m := range me.Members {
|
for _, m := range me.Members {
|
||||||
ok, parts := server_details.IsConsulServer(m)
|
ok, parts := agent.IsConsulServer(m)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/acl"
|
"github.com/hashicorp/consul/acl"
|
||||||
"github.com/hashicorp/consul/consul/server_details"
|
"github.com/hashicorp/consul/consul/agent"
|
||||||
"github.com/hashicorp/consul/consul/state"
|
"github.com/hashicorp/consul/consul/state"
|
||||||
"github.com/hashicorp/consul/tlsutil"
|
"github.com/hashicorp/consul/tlsutil"
|
||||||
"github.com/hashicorp/raft"
|
"github.com/hashicorp/raft"
|
||||||
|
@ -98,7 +98,7 @@ type Server struct {
|
||||||
|
|
||||||
// localConsuls is used to track the known consuls
|
// localConsuls is used to track the known consuls
|
||||||
// in the local datacenter. Used to do leader forwarding.
|
// in the local datacenter. Used to do leader forwarding.
|
||||||
localConsuls map[string]*server_details.ServerDetails
|
localConsuls map[string]*agent.Server
|
||||||
localLock sync.RWMutex
|
localLock sync.RWMutex
|
||||||
|
|
||||||
// Logger uses the provided LogOutput
|
// Logger uses the provided LogOutput
|
||||||
|
@ -120,7 +120,7 @@ type Server struct {
|
||||||
|
|
||||||
// remoteConsuls is used to track the known consuls in
|
// remoteConsuls is used to track the known consuls in
|
||||||
// remote datacenters. Used to do DC forwarding.
|
// remote datacenters. Used to do DC forwarding.
|
||||||
remoteConsuls map[string][]*server_details.ServerDetails
|
remoteConsuls map[string][]*agent.Server
|
||||||
remoteLock sync.RWMutex
|
remoteLock sync.RWMutex
|
||||||
|
|
||||||
// rpcListener is used to listen for incoming connections
|
// rpcListener is used to listen for incoming connections
|
||||||
|
@ -217,10 +217,10 @@ func NewServer(config *Config) (*Server, error) {
|
||||||
connPool: NewPool(config.LogOutput, serverRPCCache, serverMaxStreams, tlsWrap),
|
connPool: NewPool(config.LogOutput, serverRPCCache, serverMaxStreams, tlsWrap),
|
||||||
eventChLAN: make(chan serf.Event, 256),
|
eventChLAN: make(chan serf.Event, 256),
|
||||||
eventChWAN: make(chan serf.Event, 256),
|
eventChWAN: make(chan serf.Event, 256),
|
||||||
localConsuls: make(map[string]*server_details.ServerDetails),
|
localConsuls: make(map[string]*agent.Server),
|
||||||
logger: logger,
|
logger: logger,
|
||||||
reconcileCh: make(chan serf.Member, 32),
|
reconcileCh: make(chan serf.Member, 32),
|
||||||
remoteConsuls: make(map[string][]*server_details.ServerDetails),
|
remoteConsuls: make(map[string][]*agent.Server),
|
||||||
rpcServer: rpc.NewServer(),
|
rpcServer: rpc.NewServer(),
|
||||||
rpcTLS: incomingTLS,
|
rpcTLS: incomingTLS,
|
||||||
tombstoneGC: gc,
|
tombstoneGC: gc,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// Package servers provides a Manager interface for Manager managed
|
// Package servers provides a Manager interface for Manager managed
|
||||||
// server_details.ServerDetails objects. The servers package manages servers
|
// agent.Server objects. The servers package manages servers from a Consul
|
||||||
// from a Consul client's perspective (i.e. a list of servers that a client
|
// client's perspective (i.e. a list of servers that a client talks with for
|
||||||
// talks with for RPCs). The servers package does not provide any API
|
// RPCs). The servers package does not provide any API guarantees and should
|
||||||
// guarantees and should be called only by `hashicorp/consul`.
|
// be called only by `hashicorp/consul`.
|
||||||
package servers
|
package servers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -12,7 +12,7 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/consul/server_details"
|
"github.com/hashicorp/consul/consul/agent"
|
||||||
"github.com/hashicorp/consul/lib"
|
"github.com/hashicorp/consul/lib"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ type ConsulClusterInfo interface {
|
||||||
// Pinger is an interface wrapping client.ConnPool to prevent a
|
// Pinger is an interface wrapping client.ConnPool to prevent a
|
||||||
// cyclic import dependency
|
// cyclic import dependency
|
||||||
type Pinger interface {
|
type Pinger interface {
|
||||||
PingConsulServer(server *server_details.ServerDetails) (bool, error)
|
PingConsulServer(s *agent.Server) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// serverList is a local copy of the struct used to maintain the list of
|
// serverList is a local copy of the struct used to maintain the list of
|
||||||
|
@ -72,7 +72,7 @@ type Pinger interface {
|
||||||
type serverList struct {
|
type serverList struct {
|
||||||
// servers tracks the locally known servers. List membership is
|
// servers tracks the locally known servers. List membership is
|
||||||
// maintained by Serf.
|
// maintained by Serf.
|
||||||
servers []*server_details.ServerDetails
|
servers []*agent.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
|
@ -108,7 +108,7 @@ type Manager struct {
|
||||||
// begin seeing use after the rebalance timer fires or enough servers fail
|
// begin seeing use after the rebalance timer fires or enough servers fail
|
||||||
// organically. If the server is already known, merge the new server
|
// organically. If the server is already known, merge the new server
|
||||||
// details.
|
// details.
|
||||||
func (m *Manager) AddServer(server *server_details.ServerDetails) {
|
func (m *Manager) AddServer(s *agent.Server) {
|
||||||
m.listLock.Lock()
|
m.listLock.Lock()
|
||||||
defer m.listLock.Unlock()
|
defer m.listLock.Unlock()
|
||||||
l := m.getServerList()
|
l := m.getServerList()
|
||||||
|
@ -116,13 +116,13 @@ func (m *Manager) AddServer(server *server_details.ServerDetails) {
|
||||||
// Check if this server is known
|
// Check if this server is known
|
||||||
found := false
|
found := false
|
||||||
for idx, existing := range l.servers {
|
for idx, existing := range l.servers {
|
||||||
if existing.Name == server.Name {
|
if existing.Name == s.Name {
|
||||||
newServers := make([]*server_details.ServerDetails, len(l.servers))
|
newServers := make([]*agent.Server, len(l.servers))
|
||||||
copy(newServers, l.servers)
|
copy(newServers, l.servers)
|
||||||
|
|
||||||
// Overwrite the existing server details in order to
|
// Overwrite the existing server details in order to
|
||||||
// possibly update metadata (e.g. server version)
|
// possibly update metadata (e.g. server version)
|
||||||
newServers[idx] = server
|
newServers[idx] = s
|
||||||
|
|
||||||
l.servers = newServers
|
l.servers = newServers
|
||||||
found = true
|
found = true
|
||||||
|
@ -132,9 +132,9 @@ func (m *Manager) AddServer(server *server_details.ServerDetails) {
|
||||||
|
|
||||||
// Add to the list if not known
|
// Add to the list if not known
|
||||||
if !found {
|
if !found {
|
||||||
newServers := make([]*server_details.ServerDetails, len(l.servers), len(l.servers)+1)
|
newServers := make([]*agent.Server, len(l.servers), len(l.servers)+1)
|
||||||
copy(newServers, l.servers)
|
copy(newServers, l.servers)
|
||||||
newServers = append(newServers, server)
|
newServers = append(newServers, s)
|
||||||
l.servers = newServers
|
l.servers = newServers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,13 +149,13 @@ func (m *Manager) AddServer(server *server_details.ServerDetails) {
|
||||||
// less desirable than just returning the next server in the firing line. If
|
// less desirable than just returning the next server in the firing line. If
|
||||||
// the next server fails, it will fail fast enough and cycleServer will be
|
// the next server fails, it will fail fast enough and cycleServer will be
|
||||||
// called again.
|
// called again.
|
||||||
func (l *serverList) cycleServer() (servers []*server_details.ServerDetails) {
|
func (l *serverList) cycleServer() (servers []*agent.Server) {
|
||||||
numServers := len(l.servers)
|
numServers := len(l.servers)
|
||||||
if numServers < 2 {
|
if numServers < 2 {
|
||||||
return servers // No action required
|
return servers // No action required
|
||||||
}
|
}
|
||||||
|
|
||||||
newServers := make([]*server_details.ServerDetails, 0, numServers)
|
newServers := make([]*agent.Server, 0, numServers)
|
||||||
newServers = append(newServers, l.servers[1:]...)
|
newServers = append(newServers, l.servers[1:]...)
|
||||||
newServers = append(newServers, l.servers[0])
|
newServers = append(newServers, l.servers[0])
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ func (l *serverList) cycleServer() (servers []*server_details.ServerDetails) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeServerByKey performs an inline removal of the first matching server
|
// removeServerByKey performs an inline removal of the first matching server
|
||||||
func (l *serverList) removeServerByKey(targetKey *server_details.Key) {
|
func (l *serverList) removeServerByKey(targetKey *agent.Key) {
|
||||||
for i, s := range l.servers {
|
for i, s := range l.servers {
|
||||||
if targetKey.Equal(s.Key()) {
|
if targetKey.Equal(s.Key()) {
|
||||||
copy(l.servers[i:], l.servers[i+1:])
|
copy(l.servers[i:], l.servers[i+1:])
|
||||||
|
@ -188,7 +188,7 @@ func (l *serverList) shuffleServers() {
|
||||||
// server list. If the server at the front of the list has failed or fails
|
// server list. If the server at the front of the list has failed or fails
|
||||||
// during an RPC call, it is rotated to the end of the list. If there are no
|
// during an RPC call, it is rotated to the end of the list. If there are no
|
||||||
// servers available, return nil.
|
// servers available, return nil.
|
||||||
func (m *Manager) FindServer() *server_details.ServerDetails {
|
func (m *Manager) FindServer() *agent.Server {
|
||||||
l := m.getServerList()
|
l := m.getServerList()
|
||||||
numServers := len(l.servers)
|
numServers := len(l.servers)
|
||||||
if numServers == 0 {
|
if numServers == 0 {
|
||||||
|
@ -225,14 +225,14 @@ func New(logger *log.Logger, shutdownCh chan struct{}, clusterInfo ConsulCluster
|
||||||
m.shutdownCh = shutdownCh
|
m.shutdownCh = shutdownCh
|
||||||
|
|
||||||
l := serverList{}
|
l := serverList{}
|
||||||
l.servers = make([]*server_details.ServerDetails, 0)
|
l.servers = make([]*agent.Server, 0)
|
||||||
m.saveServerList(l)
|
m.saveServerList(l)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyFailedServer marks the passed in server as "failed" by rotating it
|
// NotifyFailedServer marks the passed in server as "failed" by rotating it
|
||||||
// to the end of the server list.
|
// to the end of the server list.
|
||||||
func (m *Manager) NotifyFailedServer(server *server_details.ServerDetails) {
|
func (m *Manager) NotifyFailedServer(s *agent.Server) {
|
||||||
l := m.getServerList()
|
l := m.getServerList()
|
||||||
|
|
||||||
// If the server being failed is not the first server on the list,
|
// If the server being failed is not the first server on the list,
|
||||||
|
@ -241,7 +241,7 @@ func (m *Manager) NotifyFailedServer(server *server_details.ServerDetails) {
|
||||||
// the server to the end of the list.
|
// the server to the end of the list.
|
||||||
|
|
||||||
// Only rotate the server list when there is more than one server
|
// Only rotate the server list when there is more than one server
|
||||||
if len(l.servers) > 1 && l.servers[0] == server &&
|
if len(l.servers) > 1 && l.servers[0] == s &&
|
||||||
// Use atomic.CAS to emulate a TryLock().
|
// Use atomic.CAS to emulate a TryLock().
|
||||||
atomic.CompareAndSwapInt32(&m.notifyFailedBarrier, 0, 1) {
|
atomic.CompareAndSwapInt32(&m.notifyFailedBarrier, 0, 1) {
|
||||||
defer atomic.StoreInt32(&m.notifyFailedBarrier, 0)
|
defer atomic.StoreInt32(&m.notifyFailedBarrier, 0)
|
||||||
|
@ -252,7 +252,7 @@ func (m *Manager) NotifyFailedServer(server *server_details.ServerDetails) {
|
||||||
defer m.listLock.Unlock()
|
defer m.listLock.Unlock()
|
||||||
l = m.getServerList()
|
l = m.getServerList()
|
||||||
|
|
||||||
if len(l.servers) > 1 && l.servers[0] == server {
|
if len(l.servers) > 1 && l.servers[0] == s {
|
||||||
l.servers = l.cycleServer()
|
l.servers = l.cycleServer()
|
||||||
m.saveServerList(l)
|
m.saveServerList(l)
|
||||||
}
|
}
|
||||||
|
@ -261,10 +261,9 @@ func (m *Manager) NotifyFailedServer(server *server_details.ServerDetails) {
|
||||||
|
|
||||||
// NumServers takes out an internal "read lock" and returns the number of
|
// NumServers takes out an internal "read lock" and returns the number of
|
||||||
// servers. numServers includes both healthy and unhealthy servers.
|
// servers. numServers includes both healthy and unhealthy servers.
|
||||||
func (m *Manager) NumServers() (numServers int) {
|
func (m *Manager) NumServers() int {
|
||||||
l := m.getServerList()
|
l := m.getServerList()
|
||||||
numServers = len(l.servers)
|
return len(l.servers)
|
||||||
return numServers
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RebalanceServers shuffles the list of servers on this agent. The server
|
// RebalanceServers shuffles the list of servers on this agent. The server
|
||||||
|
@ -355,14 +354,14 @@ func (m *Manager) reconcileServerList(l *serverList) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
type targetServer struct {
|
type targetServer struct {
|
||||||
server *server_details.ServerDetails
|
server *agent.Server
|
||||||
|
|
||||||
// 'b' == both
|
// 'b' == both
|
||||||
// 'o' == original
|
// 'o' == original
|
||||||
// 'n' == new
|
// 'n' == new
|
||||||
state byte
|
state byte
|
||||||
}
|
}
|
||||||
mergedList := make(map[server_details.Key]*targetServer, len(l.servers))
|
mergedList := make(map[agent.Key]*targetServer, len(l.servers))
|
||||||
for _, s := range l.servers {
|
for _, s := range l.servers {
|
||||||
mergedList[*s.Key()] = &targetServer{server: s, state: 'o'}
|
mergedList[*s.Key()] = &targetServer{server: s, state: 'o'}
|
||||||
}
|
}
|
||||||
|
@ -404,15 +403,15 @@ func (m *Manager) reconcileServerList(l *serverList) bool {
|
||||||
|
|
||||||
// RemoveServer takes out an internal write lock and removes a server from
|
// RemoveServer takes out an internal write lock and removes a server from
|
||||||
// the server list.
|
// the server list.
|
||||||
func (m *Manager) RemoveServer(server *server_details.ServerDetails) {
|
func (m *Manager) RemoveServer(s *agent.Server) {
|
||||||
m.listLock.Lock()
|
m.listLock.Lock()
|
||||||
defer m.listLock.Unlock()
|
defer m.listLock.Unlock()
|
||||||
l := m.getServerList()
|
l := m.getServerList()
|
||||||
|
|
||||||
// Remove the server if known
|
// Remove the server if known
|
||||||
for i, _ := range l.servers {
|
for i, _ := range l.servers {
|
||||||
if l.servers[i].Name == server.Name {
|
if l.servers[i].Name == s.Name {
|
||||||
newServers := make([]*server_details.ServerDetails, 0, len(l.servers)-1)
|
newServers := make([]*agent.Server, 0, len(l.servers)-1)
|
||||||
newServers = append(newServers, l.servers[:i]...)
|
newServers = append(newServers, l.servers[:i]...)
|
||||||
newServers = append(newServers, l.servers[i+1:]...)
|
newServers = append(newServers, l.servers[i+1:]...)
|
||||||
l.servers = newServers
|
l.servers = newServers
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/consul/server_details"
|
"github.com/hashicorp/consul/consul/agent"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -31,7 +31,7 @@ type fauxConnPool struct {
|
||||||
failPct float64
|
failPct float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *fauxConnPool) PingConsulServer(server *server_details.ServerDetails) (bool, error) {
|
func (cp *fauxConnPool) PingConsulServer(server *agent.Server) (bool, error) {
|
||||||
var success bool
|
var success bool
|
||||||
successProb := rand.Float64()
|
successProb := rand.Float64()
|
||||||
if successProb > cp.failPct {
|
if successProb > cp.failPct {
|
||||||
|
@ -63,14 +63,14 @@ func testManagerFailProb(failPct float64) (m *Manager) {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (l *serverList) cycleServer() (servers []*server_details.ServerDetails) {
|
// func (l *serverList) cycleServer() (servers []*agent.Server) {
|
||||||
func TestManagerInternal_cycleServer(t *testing.T) {
|
func TestManagerInternal_cycleServer(t *testing.T) {
|
||||||
m := testManager()
|
m := testManager()
|
||||||
l := m.getServerList()
|
l := m.getServerList()
|
||||||
|
|
||||||
server0 := &server_details.ServerDetails{Name: "server1"}
|
server0 := &agent.Server{Name: "server1"}
|
||||||
server1 := &server_details.ServerDetails{Name: "server2"}
|
server1 := &agent.Server{Name: "server2"}
|
||||||
server2 := &server_details.ServerDetails{Name: "server3"}
|
server2 := &agent.Server{Name: "server3"}
|
||||||
l.servers = append(l.servers, server0, server1, server2)
|
l.servers = append(l.servers, server0, server1, server2)
|
||||||
m.saveServerList(l)
|
m.saveServerList(l)
|
||||||
|
|
||||||
|
@ -166,11 +166,11 @@ func test_reconcileServerList(maxServers int) (bool, error) {
|
||||||
const failPct = 0.5
|
const failPct = 0.5
|
||||||
m := testManagerFailProb(failPct)
|
m := testManagerFailProb(failPct)
|
||||||
|
|
||||||
var failedServers, healthyServers []*server_details.ServerDetails
|
var failedServers, healthyServers []*agent.Server
|
||||||
for i := 0; i < maxServers; i++ {
|
for i := 0; i < maxServers; i++ {
|
||||||
nodeName := fmt.Sprintf("s%02d", i)
|
nodeName := fmt.Sprintf("s%02d", i)
|
||||||
|
|
||||||
node := &server_details.ServerDetails{Name: nodeName}
|
node := &agent.Server{Name: nodeName}
|
||||||
// Add 66% of servers to Manager
|
// Add 66% of servers to Manager
|
||||||
if rand.Float64() > 0.33 {
|
if rand.Float64() > 0.33 {
|
||||||
m.AddServer(node)
|
m.AddServer(node)
|
||||||
|
@ -230,7 +230,7 @@ func test_reconcileServerList(maxServers int) (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
resultingServerMap := make(map[server_details.Key]bool)
|
resultingServerMap := make(map[agent.Key]bool)
|
||||||
for _, s := range m.getServerList().servers {
|
for _, s := range m.getServerList().servers {
|
||||||
resultingServerMap[*s.Key()] = true
|
resultingServerMap[*s.Key()] = true
|
||||||
}
|
}
|
||||||
|
@ -302,7 +302,7 @@ func TestManagerInternal_refreshServerRebalanceTimer(t *testing.T) {
|
||||||
m := New(logger, shutdownCh, &fauxSerf{numNodes: s.numNodes}, &fauxConnPool{})
|
m := New(logger, shutdownCh, &fauxSerf{numNodes: s.numNodes}, &fauxConnPool{})
|
||||||
for i := 0; i < s.numServers; i++ {
|
for i := 0; i < s.numServers; i++ {
|
||||||
nodeName := fmt.Sprintf("s%02d", i)
|
nodeName := fmt.Sprintf("s%02d", i)
|
||||||
m.AddServer(&server_details.ServerDetails{Name: nodeName})
|
m.AddServer(&agent.Server{Name: nodeName})
|
||||||
}
|
}
|
||||||
|
|
||||||
d := m.refreshServerRebalanceTimer()
|
d := m.refreshServerRebalanceTimer()
|
||||||
|
@ -323,7 +323,7 @@ func TestManagerInternal_saveServerList(t *testing.T) {
|
||||||
t.Fatalf("Manager.saveServerList failed to load init config")
|
t.Fatalf("Manager.saveServerList failed to load init config")
|
||||||
}
|
}
|
||||||
|
|
||||||
newServer := new(server_details.ServerDetails)
|
newServer := new(agent.Server)
|
||||||
l.servers = append(l.servers, newServer)
|
l.servers = append(l.servers, newServer)
|
||||||
m.saveServerList(l)
|
m.saveServerList(l)
|
||||||
}()
|
}()
|
||||||
|
@ -339,7 +339,7 @@ func TestManagerInternal_saveServerList(t *testing.T) {
|
||||||
|
|
||||||
// Verify mutation w/o a save doesn't alter the original
|
// Verify mutation w/o a save doesn't alter the original
|
||||||
func() {
|
func() {
|
||||||
newServer := new(server_details.ServerDetails)
|
newServer := new(agent.Server)
|
||||||
l := m.getServerList()
|
l := m.getServerList()
|
||||||
l.servers = append(l.servers, newServer)
|
l.servers = append(l.servers, newServer)
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/consul/server_details"
|
"github.com/hashicorp/consul/consul/agent"
|
||||||
"github.com/hashicorp/consul/consul/servers"
|
"github.com/hashicorp/consul/consul/servers"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ type fauxConnPool struct {
|
||||||
failPct float64
|
failPct float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *fauxConnPool) PingConsulServer(server *server_details.ServerDetails) (bool, error) {
|
func (cp *fauxConnPool) PingConsulServer(server *agent.Server) (bool, error) {
|
||||||
var success bool
|
var success bool
|
||||||
successProb := rand.Float64()
|
successProb := rand.Float64()
|
||||||
if successProb > cp.failPct {
|
if successProb > cp.failPct {
|
||||||
|
@ -64,7 +64,7 @@ func testManagerFailProb(failPct float64) (m *servers.Manager) {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (m *Manager) AddServer(server *server_details.ServerDetails) {
|
// func (m *Manager) AddServer(server *agent.Server) {
|
||||||
func TestServers_AddServer(t *testing.T) {
|
func TestServers_AddServer(t *testing.T) {
|
||||||
m := testManager()
|
m := testManager()
|
||||||
var num int
|
var num int
|
||||||
|
@ -73,7 +73,7 @@ func TestServers_AddServer(t *testing.T) {
|
||||||
t.Fatalf("Expected zero servers to start")
|
t.Fatalf("Expected zero servers to start")
|
||||||
}
|
}
|
||||||
|
|
||||||
s1 := &server_details.ServerDetails{Name: "s1"}
|
s1 := &agent.Server{Name: "s1"}
|
||||||
m.AddServer(s1)
|
m.AddServer(s1)
|
||||||
num = m.NumServers()
|
num = m.NumServers()
|
||||||
if num != 1 {
|
if num != 1 {
|
||||||
|
@ -86,7 +86,7 @@ func TestServers_AddServer(t *testing.T) {
|
||||||
t.Fatalf("Expected one server (still)")
|
t.Fatalf("Expected one server (still)")
|
||||||
}
|
}
|
||||||
|
|
||||||
s2 := &server_details.ServerDetails{Name: "s2"}
|
s2 := &agent.Server{Name: "s2"}
|
||||||
m.AddServer(s2)
|
m.AddServer(s2)
|
||||||
num = m.NumServers()
|
num = m.NumServers()
|
||||||
if num != 2 {
|
if num != 2 {
|
||||||
|
@ -94,7 +94,7 @@ func TestServers_AddServer(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (m *Manager) FindServer() (server *server_details.ServerDetails) {
|
// func (m *Manager) FindServer() (server *agent.Server) {
|
||||||
func TestServers_FindServer(t *testing.T) {
|
func TestServers_FindServer(t *testing.T) {
|
||||||
m := testManager()
|
m := testManager()
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ func TestServers_FindServer(t *testing.T) {
|
||||||
t.Fatalf("Expected nil return")
|
t.Fatalf("Expected nil return")
|
||||||
}
|
}
|
||||||
|
|
||||||
m.AddServer(&server_details.ServerDetails{Name: "s1"})
|
m.AddServer(&agent.Server{Name: "s1"})
|
||||||
if m.NumServers() != 1 {
|
if m.NumServers() != 1 {
|
||||||
t.Fatalf("Expected one server")
|
t.Fatalf("Expected one server")
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ func TestServers_FindServer(t *testing.T) {
|
||||||
t.Fatalf("Expected s1 server (still)")
|
t.Fatalf("Expected s1 server (still)")
|
||||||
}
|
}
|
||||||
|
|
||||||
m.AddServer(&server_details.ServerDetails{Name: "s2"})
|
m.AddServer(&agent.Server{Name: "s2"})
|
||||||
if m.NumServers() != 2 {
|
if m.NumServers() != 2 {
|
||||||
t.Fatalf("Expected two servers")
|
t.Fatalf("Expected two servers")
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ func TestServers_New(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (m *Manager) NotifyFailedServer(server *server_details.ServerDetails) {
|
// func (m *Manager) NotifyFailedServer(server *agent.Server) {
|
||||||
func TestServers_NotifyFailedServer(t *testing.T) {
|
func TestServers_NotifyFailedServer(t *testing.T) {
|
||||||
m := testManager()
|
m := testManager()
|
||||||
|
|
||||||
|
@ -161,8 +161,8 @@ func TestServers_NotifyFailedServer(t *testing.T) {
|
||||||
t.Fatalf("Expected zero servers to start")
|
t.Fatalf("Expected zero servers to start")
|
||||||
}
|
}
|
||||||
|
|
||||||
s1 := &server_details.ServerDetails{Name: "s1"}
|
s1 := &agent.Server{Name: "s1"}
|
||||||
s2 := &server_details.ServerDetails{Name: "s2"}
|
s2 := &agent.Server{Name: "s2"}
|
||||||
|
|
||||||
// Try notifying for a server that is not managed by Manager
|
// Try notifying for a server that is not managed by Manager
|
||||||
m.NotifyFailedServer(s1)
|
m.NotifyFailedServer(s1)
|
||||||
|
@ -215,7 +215,7 @@ func TestServers_NumServers(t *testing.T) {
|
||||||
t.Fatalf("Expected zero servers to start")
|
t.Fatalf("Expected zero servers to start")
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &server_details.ServerDetails{}
|
s := &agent.Server{}
|
||||||
m.AddServer(s)
|
m.AddServer(s)
|
||||||
num = m.NumServers()
|
num = m.NumServers()
|
||||||
if num != 1 {
|
if num != 1 {
|
||||||
|
@ -234,7 +234,7 @@ func TestServers_RebalanceServers(t *testing.T) {
|
||||||
// Make a huge list of nodes.
|
// Make a huge list of nodes.
|
||||||
for i := 0; i < maxServers; i++ {
|
for i := 0; i < maxServers; i++ {
|
||||||
nodeName := fmt.Sprintf("s%02d", i)
|
nodeName := fmt.Sprintf("s%02d", i)
|
||||||
m.AddServer(&server_details.ServerDetails{Name: nodeName})
|
m.AddServer(&agent.Server{Name: nodeName})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep track of how many unique shuffles we get.
|
// Keep track of how many unique shuffles we get.
|
||||||
|
@ -260,7 +260,7 @@ func TestServers_RebalanceServers(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (m *Manager) RemoveServer(server *server_details.ServerDetails) {
|
// func (m *Manager) RemoveServer(server *agent.Server) {
|
||||||
func TestManager_RemoveServer(t *testing.T) {
|
func TestManager_RemoveServer(t *testing.T) {
|
||||||
const nodeNameFmt = "s%02d"
|
const nodeNameFmt = "s%02d"
|
||||||
m := testManager()
|
m := testManager()
|
||||||
|
@ -271,21 +271,21 @@ func TestManager_RemoveServer(t *testing.T) {
|
||||||
|
|
||||||
// Test removing server before its added
|
// Test removing server before its added
|
||||||
nodeName := fmt.Sprintf(nodeNameFmt, 1)
|
nodeName := fmt.Sprintf(nodeNameFmt, 1)
|
||||||
s1 := &server_details.ServerDetails{Name: nodeName}
|
s1 := &agent.Server{Name: nodeName}
|
||||||
m.RemoveServer(s1)
|
m.RemoveServer(s1)
|
||||||
m.AddServer(s1)
|
m.AddServer(s1)
|
||||||
|
|
||||||
nodeName = fmt.Sprintf(nodeNameFmt, 2)
|
nodeName = fmt.Sprintf(nodeNameFmt, 2)
|
||||||
s2 := &server_details.ServerDetails{Name: nodeName}
|
s2 := &agent.Server{Name: nodeName}
|
||||||
m.RemoveServer(s2)
|
m.RemoveServer(s2)
|
||||||
m.AddServer(s2)
|
m.AddServer(s2)
|
||||||
|
|
||||||
const maxServers = 19
|
const maxServers = 19
|
||||||
servers := make([]*server_details.ServerDetails, maxServers)
|
servers := make([]*agent.Server, maxServers)
|
||||||
// Already added two servers above
|
// Already added two servers above
|
||||||
for i := maxServers; i > 2; i-- {
|
for i := maxServers; i > 2; i-- {
|
||||||
nodeName := fmt.Sprintf(nodeNameFmt, i)
|
nodeName := fmt.Sprintf(nodeNameFmt, i)
|
||||||
server := &server_details.ServerDetails{Name: nodeName}
|
server := &agent.Server{Name: nodeName}
|
||||||
servers = append(servers, server)
|
servers = append(servers, server)
|
||||||
m.AddServer(server)
|
m.AddServer(server)
|
||||||
}
|
}
|
||||||
|
@ -299,7 +299,7 @@ func TestManager_RemoveServer(t *testing.T) {
|
||||||
t.Fatalf("Expected %d servers, received %d", maxServers, m.NumServers())
|
t.Fatalf("Expected %d servers, received %d", maxServers, m.NumServers())
|
||||||
}
|
}
|
||||||
|
|
||||||
findServer := func(server *server_details.ServerDetails) bool {
|
findServer := func(server *agent.Server) bool {
|
||||||
for i := m.NumServers(); i > 0; i-- {
|
for i := m.NumServers(); i > 0; i-- {
|
||||||
s := m.FindServer()
|
s := m.FindServer()
|
||||||
if s == server {
|
if s == server {
|
||||||
|
@ -310,7 +310,7 @@ func TestManager_RemoveServer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedNumServers := maxServers
|
expectedNumServers := maxServers
|
||||||
removedServers := make([]*server_details.ServerDetails, 0, maxServers)
|
removedServers := make([]*agent.Server, 0, maxServers)
|
||||||
|
|
||||||
// Remove servers from the front of the list
|
// Remove servers from the front of the list
|
||||||
for i := 3; i > 0; i-- {
|
for i := 3; i > 0; i-- {
|
||||||
|
|
Loading…
Reference in New Issue