From 253037a3e764f7387d9c6c87663c91b32d3922e3 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Wed, 11 Jun 2014 10:53:12 -0700 Subject: [PATCH] agent: Adding reload RPC command --- command/agent/rpc.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/command/agent/rpc.go b/command/agent/rpc.go index 63b7a6bce4..2a6960d1a0 100644 --- a/command/agent/rpc.go +++ b/command/agent/rpc.go @@ -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 {