From a9d4e2357ef4a6c5819d5ade0cc36ad6074d5dc3 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Fri, 18 Apr 2014 17:17:12 -0700 Subject: [PATCH] consul: Switch to RPCInfo --- consul/catalog_endpoint.go | 12 ++++++------ consul/health_endpoint.go | 8 ++++---- consul/kvs_endpoint.go | 6 +++--- consul/rpc.go | 3 ++- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/consul/catalog_endpoint.go b/consul/catalog_endpoint.go index e288229937..52fbb46de3 100644 --- a/consul/catalog_endpoint.go +++ b/consul/catalog_endpoint.go @@ -14,7 +14,7 @@ type Catalog struct { // Register is used register that a node is providing a given service. func (c *Catalog) Register(args *structs.RegisterRequest, reply *struct{}) error { - if done, err := c.srv.forward("Catalog.Register", args.Datacenter, args, reply); done { + if done, err := c.srv.forward("Catalog.Register", args, args, reply); done { return err } defer metrics.MeasureSince([]string{"consul", "catalog", "register"}, time.Now()) @@ -55,7 +55,7 @@ func (c *Catalog) Register(args *structs.RegisterRequest, reply *struct{}) error // Deregister is used to remove a service registration for a given node. func (c *Catalog) Deregister(args *structs.DeregisterRequest, reply *struct{}) error { - if done, err := c.srv.forward("Catalog.Deregister", args.Datacenter, args, reply); done { + if done, err := c.srv.forward("Catalog.Deregister", args, args, reply); done { return err } defer metrics.MeasureSince([]string{"consul", "catalog", "deregister"}, time.Now()) @@ -91,7 +91,7 @@ func (c *Catalog) ListDatacenters(args *struct{}, reply *[]string) error { // ListNodes is used to query the nodes in a DC func (c *Catalog) ListNodes(args *structs.DCSpecificRequest, reply *structs.IndexedNodes) error { - if done, err := c.srv.forward("Catalog.ListNodes", args.Datacenter, args, reply); done { + if done, err := c.srv.forward("Catalog.ListNodes", args, args, reply); done { return err } @@ -107,7 +107,7 @@ func (c *Catalog) ListNodes(args *structs.DCSpecificRequest, reply *structs.Inde // ListServices is used to query the services in a DC func (c *Catalog) ListServices(args *structs.DCSpecificRequest, reply *structs.IndexedServices) error { - if done, err := c.srv.forward("Catalog.ListServices", args.Datacenter, args, reply); done { + if done, err := c.srv.forward("Catalog.ListServices", args, args, reply); done { return err } @@ -123,7 +123,7 @@ func (c *Catalog) ListServices(args *structs.DCSpecificRequest, reply *structs.I // ServiceNodes returns all the nodes registered as part of a service func (c *Catalog) ServiceNodes(args *structs.ServiceSpecificRequest, reply *structs.IndexedServiceNodes) error { - if done, err := c.srv.forward("Catalog.ServiceNodes", args.Datacenter, args, reply); done { + if done, err := c.srv.forward("Catalog.ServiceNodes", args, args, reply); done { return err } @@ -160,7 +160,7 @@ func (c *Catalog) ServiceNodes(args *structs.ServiceSpecificRequest, reply *stru // NodeServices returns all the services registered as part of a node func (c *Catalog) NodeServices(args *structs.NodeSpecificRequest, reply *structs.IndexedNodeServices) error { - if done, err := c.srv.forward("Catalog.NodeServices", args.Datacenter, args, reply); done { + if done, err := c.srv.forward("Catalog.NodeServices", args, args, reply); done { return err } diff --git a/consul/health_endpoint.go b/consul/health_endpoint.go index f1428c43f7..421d4b8862 100644 --- a/consul/health_endpoint.go +++ b/consul/health_endpoint.go @@ -14,7 +14,7 @@ type Health struct { // ChecksInState is used to get all the checks in a given state func (h *Health) ChecksInState(args *structs.ChecksInStateRequest, reply *structs.IndexedHealthChecks) error { - if done, err := h.srv.forward("Health.ChecksInState", args.Datacenter, args, reply); done { + if done, err := h.srv.forward("Health.ChecksInState", args, args, reply); done { return err } @@ -31,7 +31,7 @@ func (h *Health) ChecksInState(args *structs.ChecksInStateRequest, // NodeChecks is used to get all the checks for a node func (h *Health) NodeChecks(args *structs.NodeSpecificRequest, reply *structs.IndexedHealthChecks) error { - if done, err := h.srv.forward("Health.NodeChecks", args.Datacenter, args, reply); done { + if done, err := h.srv.forward("Health.NodeChecks", args, args, reply); done { return err } @@ -54,7 +54,7 @@ func (h *Health) ServiceChecks(args *structs.ServiceSpecificRequest, } // Potentially forward - if done, err := h.srv.forward("Health.ServiceChecks", args.Datacenter, args, reply); done { + if done, err := h.srv.forward("Health.ServiceChecks", args, args, reply); done { return err } @@ -70,7 +70,7 @@ func (h *Health) ServiceChecks(args *structs.ServiceSpecificRequest, // ServiceNodes returns all the nodes registered as part of a service including health info func (h *Health) ServiceNodes(args *structs.ServiceSpecificRequest, reply *structs.IndexedCheckServiceNodes) error { - if done, err := h.srv.forward("Health.ServiceNodes", args.Datacenter, args, reply); done { + if done, err := h.srv.forward("Health.ServiceNodes", args, args, reply); done { return err } diff --git a/consul/kvs_endpoint.go b/consul/kvs_endpoint.go index 0e884524f3..57f3e49956 100644 --- a/consul/kvs_endpoint.go +++ b/consul/kvs_endpoint.go @@ -15,7 +15,7 @@ type KVS struct { // Apply is used to apply a KVS request to the data store. This should // only be used for operations that modify the data func (k *KVS) Apply(args *structs.KVSRequest, reply *bool) error { - if done, err := k.srv.forward("KVS.Apply", args.Datacenter, args, reply); done { + if done, err := k.srv.forward("KVS.Apply", args, args, reply); done { return err } defer metrics.MeasureSince([]string{"consul", "kvs", "apply"}, time.Now()) @@ -44,7 +44,7 @@ func (k *KVS) Apply(args *structs.KVSRequest, reply *bool) error { // Get is used to lookup a single key func (k *KVS) Get(args *structs.KeyRequest, reply *structs.IndexedDirEntries) error { - if done, err := k.srv.forward("KVS.Get", args.Datacenter, args, reply); done { + if done, err := k.srv.forward("KVS.Get", args, args, reply); done { return err } @@ -76,7 +76,7 @@ func (k *KVS) Get(args *structs.KeyRequest, reply *structs.IndexedDirEntries) er // List is used to list all keys with a given prefix func (k *KVS) List(args *structs.KeyRequest, reply *structs.IndexedDirEntries) error { - if done, err := k.srv.forward("KVS.List", args.Datacenter, args, reply); done { + if done, err := k.srv.forward("KVS.List", args, args, reply); done { return err } diff --git a/consul/rpc.go b/consul/rpc.go index cb4185a3dc..831a5a9df9 100644 --- a/consul/rpc.go +++ b/consul/rpc.go @@ -134,8 +134,9 @@ func (s *Server) handleConsulConn(conn net.Conn) { // forward is used to forward to a remote DC or to forward to the local leader // Returns a bool of if forwarding was performed, as well as any error -func (s *Server) forward(method, dc string, args interface{}, reply interface{}) (bool, error) { +func (s *Server) forward(method string, info structs.RPCInfo, args interface{}, reply interface{}) (bool, error) { // Handle DC forwarding + dc := info.RequestDatacenter() if dc != s.config.Datacenter { err := s.forwardDC(method, dc, args, reply) return true, err