mirror of https://github.com/hashicorp/consul
agent: Adding reload RPC command
parent
8bdfd8c7b2
commit
253037a3e7
|
@ -50,6 +50,7 @@ const (
|
||||||
monitorCommand = "monitor"
|
monitorCommand = "monitor"
|
||||||
leaveCommand = "leave"
|
leaveCommand = "leave"
|
||||||
statsCommand = "stats"
|
statsCommand = "stats"
|
||||||
|
reloadCommand = "reload"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -156,6 +157,7 @@ type AgentRPC struct {
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
logWriter *logWriter
|
logWriter *logWriter
|
||||||
|
reloadCh chan struct{}
|
||||||
stop bool
|
stop bool
|
||||||
stopCh chan struct{}
|
stopCh chan struct{}
|
||||||
}
|
}
|
||||||
|
@ -211,6 +213,7 @@ func NewAgentRPC(agent *Agent, listener net.Listener,
|
||||||
listener: listener,
|
listener: listener,
|
||||||
logger: log.New(logOutput, "", log.LstdFlags),
|
logger: log.New(logOutput, "", log.LstdFlags),
|
||||||
logWriter: logWriter,
|
logWriter: logWriter,
|
||||||
|
reloadCh: make(chan struct{}, 1),
|
||||||
stopCh: make(chan struct{}),
|
stopCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
go rpc.listen()
|
go rpc.listen()
|
||||||
|
@ -236,6 +239,12 @@ func (i *AgentRPC) Shutdown() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReloadCh returns a channel that can be watched for
|
||||||
|
// when a reload is being triggered.
|
||||||
|
func (i *AgentRPC) ReloadCh() <-chan struct{} {
|
||||||
|
return i.reloadCh
|
||||||
|
}
|
||||||
|
|
||||||
// listen is a long running routine that listens for new clients
|
// listen is a long running routine that listens for new clients
|
||||||
func (i *AgentRPC) listen() {
|
func (i *AgentRPC) listen() {
|
||||||
for {
|
for {
|
||||||
|
@ -361,6 +370,9 @@ func (i *AgentRPC) handleRequest(client *rpcClient, reqHeader *requestHeader) er
|
||||||
case statsCommand:
|
case statsCommand:
|
||||||
return i.handleStats(client, seq)
|
return i.handleStats(client, seq)
|
||||||
|
|
||||||
|
case reloadCommand:
|
||||||
|
return i.handleReload(client, seq)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
respHeader := responseHeader{Seq: seq, Error: unsupportedCommand}
|
respHeader := responseHeader{Seq: seq, Error: unsupportedCommand}
|
||||||
client.Send(&respHeader, nil)
|
client.Send(&respHeader, nil)
|
||||||
|
@ -559,6 +571,18 @@ func (i *AgentRPC) handleStats(client *rpcClient, seq uint64) error {
|
||||||
return client.Send(&header, resp)
|
return client.Send(&header, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *AgentRPC) handleReload(client *rpcClient, seq uint64) error {
|
||||||
|
// Push to the reload channel
|
||||||
|
select {
|
||||||
|
case i.reloadCh <- struct{}{}:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always succeed
|
||||||
|
resp := responseHeader{Seq: seq, Error: ""}
|
||||||
|
return client.Send(&resp, nil)
|
||||||
|
}
|
||||||
|
|
||||||
// Used to convert an error to a string representation
|
// Used to convert an error to a string representation
|
||||||
func errToString(err error) string {
|
func errToString(err error) string {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
Loading…
Reference in New Issue