From 4f4b4b0f3ed1ee86991254e1ef86ef67fed2c94b Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Fri, 20 Feb 2015 15:45:06 -0800 Subject: [PATCH 1/2] agent: write API's on /v1/agent block for anti-entropy --- command/agent/agent_endpoint.go | 54 ++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/command/agent/agent_endpoint.go b/command/agent/agent_endpoint.go index 544dbdee1..78299c78a 100644 --- a/command/agent/agent_endpoint.go +++ b/command/agent/agent_endpoint.go @@ -98,30 +98,50 @@ func (s *HTTPServer) AgentRegisterCheck(resp http.ResponseWriter, req *http.Requ } // Add the check - return nil, s.agent.AddCheck(health, chkType, true) + if err := s.agent.AddCheck(health, chkType, true); err != nil { + return nil, err + } + s.syncChanges() + return nil, nil } func (s *HTTPServer) AgentDeregisterCheck(resp http.ResponseWriter, req *http.Request) (interface{}, error) { checkID := strings.TrimPrefix(req.URL.Path, "/v1/agent/check/deregister/") - return nil, s.agent.RemoveCheck(checkID, true) + if err := s.agent.RemoveCheck(checkID, true); err != nil { + return nil, err + } + s.syncChanges() + return nil, nil } func (s *HTTPServer) AgentCheckPass(resp http.ResponseWriter, req *http.Request) (interface{}, error) { checkID := strings.TrimPrefix(req.URL.Path, "/v1/agent/check/pass/") note := req.URL.Query().Get("note") - return nil, s.agent.UpdateCheck(checkID, structs.HealthPassing, note) + if err := s.agent.UpdateCheck(checkID, structs.HealthPassing, note); err != nil { + return nil, err + } + s.syncChanges() + return nil, nil } func (s *HTTPServer) AgentCheckWarn(resp http.ResponseWriter, req *http.Request) (interface{}, error) { checkID := strings.TrimPrefix(req.URL.Path, "/v1/agent/check/warn/") note := req.URL.Query().Get("note") - return nil, s.agent.UpdateCheck(checkID, structs.HealthWarning, note) + if err := s.agent.UpdateCheck(checkID, structs.HealthWarning, note); err != nil { + return nil, err + } + s.syncChanges() + return nil, nil } func (s *HTTPServer) AgentCheckFail(resp http.ResponseWriter, req *http.Request) (interface{}, error) { checkID := strings.TrimPrefix(req.URL.Path, "/v1/agent/check/fail/") note := req.URL.Query().Get("note") - return nil, s.agent.UpdateCheck(checkID, structs.HealthCritical, note) + if err := s.agent.UpdateCheck(checkID, structs.HealthCritical, note); err != nil { + return nil, err + } + s.syncChanges() + return nil, nil } func (s *HTTPServer) AgentRegisterService(resp http.ResponseWriter, req *http.Request) (interface{}, error) { @@ -180,12 +200,20 @@ func (s *HTTPServer) AgentRegisterService(resp http.ResponseWriter, req *http.Re } // Add the check - return nil, s.agent.AddService(ns, chkTypes, true) + if err := s.agent.AddService(ns, chkTypes, true); err != nil { + return nil, err + } + s.syncChanges() + return nil, nil } func (s *HTTPServer) AgentDeregisterService(resp http.ResponseWriter, req *http.Request) (interface{}, error) { serviceID := strings.TrimPrefix(req.URL.Path, "/v1/agent/service/deregister/") - return nil, s.agent.RemoveService(serviceID, true) + if err := s.agent.RemoveService(serviceID, true); err != nil { + return nil, err + } + s.syncChanges() + return nil, nil } func (s *HTTPServer) AgentServiceMaintenance(resp http.ResponseWriter, req *http.Request) (interface{}, error) { @@ -233,7 +261,7 @@ func (s *HTTPServer) AgentServiceMaintenance(resp http.ResponseWriter, req *http return nil, nil } } - + s.syncChanges() return nil, nil } @@ -265,5 +293,15 @@ func (s *HTTPServer) AgentNodeMaintenance(resp http.ResponseWriter, req *http.Re } else { s.agent.DisableNodeMaintenance() } + s.syncChanges() return nil, nil } + +// syncChanges is a helper function which wraps a blocking call to sync +// services and checks to the server. If the operation fails, we only +// only warn because the write did succeed and anti-entropy will sync later. +func (s *HTTPServer) syncChanges() { + if err := s.agent.state.syncChanges(); err != nil { + s.logger.Printf("[ERR] agent: failed to sync changes: %v", err) + } +} From bb85d6f331cc4bb643f1cd003628050a94b75ced Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Mon, 23 Feb 2015 10:43:15 -0800 Subject: [PATCH 2/2] website: document -recursor arg for agent cli --- website/source/docs/agent/options.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/source/docs/agent/options.html.markdown b/website/source/docs/agent/options.html.markdown index 1a4810258..1da22770f 100644 --- a/website/source/docs/agent/options.html.markdown +++ b/website/source/docs/agent/options.html.markdown @@ -155,6 +155,10 @@ The options below are all specified on the command-line. version. This should be set only when [upgrading](/docs/upgrading.html). You can view the protocol versions supported by Consul by running `consul -v`. +* `-recursor` - Specifies the address of an upstream DNS + server. This option may be provided multiple times, and is functionally + equivalent to the [`recursors` configuration option](#recursors). + * `-rejoin` - When provided, Consul will ignore a previous leave and attempt to rejoin the cluster when starting. By default, Consul treats leave as a permanent intent and does not attempt to join the cluster again when starting. This flag