Unexport state from the cluster package
This commit is contained in:
parent
9ddcbb7914
commit
d85fb84398
|
@ -23,14 +23,14 @@ type Cluster struct {
|
|||
ml *memberlist.Memberlist
|
||||
mlConfig *memberlist.Config
|
||||
localNode common.Node
|
||||
state *State
|
||||
state *state
|
||||
events chan memberlist.NodeEvent
|
||||
}
|
||||
|
||||
// New is used to create a new Cluster instance
|
||||
// The returned instance is ready to be updated with the local node settings then joined
|
||||
func New(init bool, clusterKey []byte, bindAddr string, bindPort int, useIPAsName bool) (*Cluster, error) {
|
||||
state := &State{}
|
||||
state := &state{}
|
||||
if !init {
|
||||
loadState(state)
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ func (c *Cluster) setupDelegate() {
|
|||
c.mlConfig.Events = &memberlist.ChannelEventDelegate{Ch: c.events}
|
||||
}
|
||||
|
||||
func computeClusterKey(state *State, clusterKey []byte) ([]byte, error) {
|
||||
func computeClusterKey(state *state, clusterKey []byte) ([]byte, error) {
|
||||
if len(clusterKey) == 0 {
|
||||
clusterKey = state.ClusterKey
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
// State keeps track of information needed to rejoin the cluster
|
||||
type State struct {
|
||||
type state struct {
|
||||
ClusterKey []byte
|
||||
Nodes []common.Node
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ func (c *Cluster) saveState() error {
|
|||
return ioutil.WriteFile(statePath, stateOut, 0600)
|
||||
}
|
||||
|
||||
func loadState(cs *State) {
|
||||
func loadState(cs *state) {
|
||||
content, err := ioutil.ReadFile(statePath)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
|
@ -41,7 +41,7 @@ func loadState(cs *State) {
|
|||
}
|
||||
|
||||
// avoid partially unmarshalled content by using a temp var
|
||||
csTmp := &State{}
|
||||
csTmp := &state{}
|
||||
if err := json.Unmarshal(content, csTmp); err != nil {
|
||||
logrus.Warnf("could not decode state: %s", err)
|
||||
} else {
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/costela/wesher/common"
|
||||
)
|
||||
|
||||
func Test_State_Save_Load(t *testing.T) {
|
||||
func Test_state_save_soad(t *testing.T) {
|
||||
key := "abcdefghijklmnopqrstuvwxyzABCDEF"
|
||||
node := common.Node{
|
||||
Name: "node",
|
||||
|
@ -16,14 +16,14 @@ func Test_State_Save_Load(t *testing.T) {
|
|||
}
|
||||
|
||||
cluster := Cluster{
|
||||
state: &State{
|
||||
state: &state{
|
||||
ClusterKey: []byte(key),
|
||||
Nodes: []common.Node{node},
|
||||
},
|
||||
}
|
||||
|
||||
cluster.saveState()
|
||||
loaded := &State{}
|
||||
loaded := &state{}
|
||||
loadState(loaded)
|
||||
|
||||
if !reflect.DeepEqual(cluster.state, loaded) {
|
||||
|
|
Loading…
Reference in New Issue