add new node to /machines
parent
fba1ba0b85
commit
69f8b8693d
|
@ -2,9 +2,10 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
//"errors"
|
||||
"fmt"
|
||||
"github.com/coreos/etcd/store"
|
||||
"github.com/coreos/go-raft"
|
||||
"path"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -120,6 +121,10 @@ func (c *JoinCommand) CommandName() string {
|
|||
func (c *JoinCommand) Apply(raftServer *raft.Server) (interface{}, error) {
|
||||
err := raftServer.AddPeer(c.Name)
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -4,4 +4,5 @@ package store
|
|||
var keywords = map[string]bool{
|
||||
"/acoounts": true,
|
||||
"/ephemeralNodes": true,
|
||||
"/machines": true,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue