consul: expose UserEvent from Serf

This commit is contained in:
Armon Dadgar 2014-08-26 18:50:03 -07:00
parent 0f5136f776
commit b1cf52db01
4 changed files with 25 additions and 0 deletions

View File

@ -372,6 +372,15 @@ func (a *Agent) WANMembers() []serf.Member {
}
}
// UserEvent is used to fire an event via the Serf layer on the LAN
func (a *Agent) UserEvent(name string, payload []byte) error {
if a.server != nil {
return a.server.UserEvent(name, payload)
} else {
return a.client.UserEvent(name, payload)
}
}
// StartSync is called once Services and Checks are registered.
// This is called to prevent a race between clients and the anti-entropy routines
func (a *Agent) StartSync() {

View File

@ -201,6 +201,11 @@ func (c *Client) RemoveFailedNode(node string) error {
return c.serf.RemoveFailedNode(node)
}
// UserEvent is used to fire an event via the Serf layer
func (c *Client) UserEvent(name string, payload []byte) error {
return c.serf.UserEvent(userEventName(name), payload, false)
}
// lanEventHandler is used to handle events from the lan Serf cluster
func (c *Client) lanEventHandler() {
for {

View File

@ -1,6 +1,7 @@
package consul
import (
"fmt"
"net"
"strings"
@ -13,6 +14,11 @@ const (
StatusReap = serf.MemberStatus(-1)
)
// userEventName computes the name of a user event
func userEventName(name string) string {
return fmt.Sprintf("consul:event:%s")
}
// lanEventHandler is used to handle events from the lan Serf cluster
func (s *Server) lanEventHandler() {
for {

View File

@ -530,6 +530,11 @@ func (s *Server) RemoveFailedNode(node string) error {
return nil
}
// UserEvent is used to fire an event via the Serf layer on the LAN
func (s *Server) UserEvent(name string, payload []byte) error {
return s.serfLAN.UserEvent(userEventName(name), payload, false)
}
// IsLeader checks if this server is the cluster leader
func (s *Server) IsLeader() bool {
return s.raft.State() == raft.Leader