mirror of https://github.com/status-im/consul.git
agent: Adding reload RPC command
This commit is contained in:
parent
8bdfd8c7b2
commit
253037a3e7
|
@ -50,6 +50,7 @@ const (
|
|||
monitorCommand = "monitor"
|
||||
leaveCommand = "leave"
|
||||
statsCommand = "stats"
|
||||
reloadCommand = "reload"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -156,6 +157,7 @@ type AgentRPC struct {
|
|||
listener net.Listener
|
||||
logger *log.Logger
|
||||
logWriter *logWriter
|
||||
reloadCh chan struct{}
|
||||
stop bool
|
||||
stopCh chan struct{}
|
||||
}
|
||||
|
@ -211,6 +213,7 @@ func NewAgentRPC(agent *Agent, listener net.Listener,
|
|||
listener: listener,
|
||||
logger: log.New(logOutput, "", log.LstdFlags),
|
||||
logWriter: logWriter,
|
||||
reloadCh: make(chan struct{}, 1),
|
||||
stopCh: make(chan struct{}),
|
||||
}
|
||||
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
|
||||
func (i *AgentRPC) listen() {
|
||||
for {
|
||||
|
@ -361,6 +370,9 @@ func (i *AgentRPC) handleRequest(client *rpcClient, reqHeader *requestHeader) er
|
|||
case statsCommand:
|
||||
return i.handleStats(client, seq)
|
||||
|
||||
case reloadCommand:
|
||||
return i.handleReload(client, seq)
|
||||
|
||||
default:
|
||||
respHeader := responseHeader{Seq: seq, Error: unsupportedCommand}
|
||||
client.Send(&respHeader, nil)
|
||||
|
@ -559,6 +571,18 @@ func (i *AgentRPC) handleStats(client *rpcClient, seq uint64) error {
|
|||
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
|
||||
func errToString(err error) string {
|
||||
if err == nil {
|
||||
|
|
Loading…
Reference in New Issue