|
@@ -2,9 +2,10 @@ package main
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
- //"errors"
|
|
|
|
|
|
|
+ "fmt"
|
|
|
"github.com/coreos/etcd/store"
|
|
"github.com/coreos/etcd/store"
|
|
|
"github.com/coreos/go-raft"
|
|
"github.com/coreos/go-raft"
|
|
|
|
|
+ "path"
|
|
|
"time"
|
|
"time"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -120,6 +121,10 @@ func (c *JoinCommand) CommandName() string {
|
|
|
func (c *JoinCommand) Apply(raftServer *raft.Server) (interface{}, error) {
|
|
func (c *JoinCommand) Apply(raftServer *raft.Server) (interface{}, error) {
|
|
|
err := raftServer.AddPeer(c.Name)
|
|
err := raftServer.AddPeer(c.Name)
|
|
|
addMachine(c.Name, c.Hostname, c.RaftPort, c.ClientPort)
|
|
addMachine(c.Name, c.Hostname, c.RaftPort, c.ClientPort)
|
|
|
|
|
+ nodeName := fmt.Sprintf("%s%d", "node", raftServer.CommitIndex())
|
|
|
|
|
+ key := path.Join("machines", nodeName)
|
|
|
|
|
+ value := fmt.Sprintf("%s,%d,%d", c.Hostname, c.RaftPort, c.ClientPort)
|
|
|
|
|
+ etcdStore.Set(key, value, time.Unix(0, 0), raftServer.CommitIndex())
|
|
|
return []byte("join success"), err
|
|
return []byte("join success"), err
|
|
|
}
|
|
}
|
|
|
|
|
|