consul: Adding Raft rpc endpoint

This commit is contained in:
Armon Dadgar 2013-12-09 14:49:07 -08:00
parent a2eb514206
commit 1a9a51c5c2
2 changed files with 38 additions and 0 deletions

35
consul/raft_endpoint.go Normal file
View File

@ -0,0 +1,35 @@
package consul
import (
"net"
)
// Raft endpoint is used to manipulate the Raft subsystem
type Raft struct {
server *Server
}
func (r *Raft) Apply(args []byte, reply *struct{}) error {
future := r.server.raft.Apply(args, 0)
return future.Error()
}
func (r *Raft) AddPeer(args string, reply *struct{}) error {
peer, err := net.ResolveTCPAddr("tcp", args)
if err != nil {
r.server.logger.Printf("[ERR] Failed to parse peer: %v", err)
return err
}
future := r.server.raft.AddPeer(peer)
return future.Error()
}
func (r *Raft) RemovePeer(args string, reply *struct{}) error {
peer, err := net.ResolveTCPAddr("tcp", args)
if err != nil {
r.server.logger.Printf("[ERR] Failed to parse peer: %v", err)
return err
}
future := r.server.raft.AddPeer(peer)
return future.Error()
}

View File

@ -201,6 +201,9 @@ func (s *Server) setupRaft() error {
// setupRPC is used to setup the RPC listener
func (s *Server) setupRPC() error {
// Register the handlers
s.rpcServer.Register(&Raft{server: s})
list, err := net.Listen("tcp", s.config.RPCAddr)
if err != nil {
return err