consul: Switch to RPCInfo

This commit is contained in:
Armon Dadgar 2014-04-18 17:17:12 -07:00
parent cea8a4f9f2
commit a9d4e2357e
4 changed files with 15 additions and 14 deletions

View File

@ -14,7 +14,7 @@ type Catalog struct {
// Register is used register that a node is providing a given service. // Register is used register that a node is providing a given service.
func (c *Catalog) Register(args *structs.RegisterRequest, reply *struct{}) error { 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 return err
} }
defer metrics.MeasureSince([]string{"consul", "catalog", "register"}, time.Now()) 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. // Deregister is used to remove a service registration for a given node.
func (c *Catalog) Deregister(args *structs.DeregisterRequest, reply *struct{}) error { 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 return err
} }
defer metrics.MeasureSince([]string{"consul", "catalog", "deregister"}, time.Now()) 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 // ListNodes is used to query the nodes in a DC
func (c *Catalog) ListNodes(args *structs.DCSpecificRequest, reply *structs.IndexedNodes) error { 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 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 // ListServices is used to query the services in a DC
func (c *Catalog) ListServices(args *structs.DCSpecificRequest, reply *structs.IndexedServices) error { 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 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 // ServiceNodes returns all the nodes registered as part of a service
func (c *Catalog) ServiceNodes(args *structs.ServiceSpecificRequest, reply *structs.IndexedServiceNodes) error { 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 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 // NodeServices returns all the services registered as part of a node
func (c *Catalog) NodeServices(args *structs.NodeSpecificRequest, reply *structs.IndexedNodeServices) error { 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 return err
} }

View File

@ -14,7 +14,7 @@ type Health struct {
// ChecksInState is used to get all the checks in a given state // ChecksInState is used to get all the checks in a given state
func (h *Health) ChecksInState(args *structs.ChecksInStateRequest, func (h *Health) ChecksInState(args *structs.ChecksInStateRequest,
reply *structs.IndexedHealthChecks) error { 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 return err
} }
@ -31,7 +31,7 @@ func (h *Health) ChecksInState(args *structs.ChecksInStateRequest,
// NodeChecks is used to get all the checks for a node // NodeChecks is used to get all the checks for a node
func (h *Health) NodeChecks(args *structs.NodeSpecificRequest, func (h *Health) NodeChecks(args *structs.NodeSpecificRequest,
reply *structs.IndexedHealthChecks) error { 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 return err
} }
@ -54,7 +54,7 @@ func (h *Health) ServiceChecks(args *structs.ServiceSpecificRequest,
} }
// Potentially forward // 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 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 // 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 { 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 return err
} }

View File

@ -15,7 +15,7 @@ type KVS struct {
// Apply is used to apply a KVS request to the data store. This should // Apply is used to apply a KVS request to the data store. This should
// only be used for operations that modify the data // only be used for operations that modify the data
func (k *KVS) Apply(args *structs.KVSRequest, reply *bool) error { 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 return err
} }
defer metrics.MeasureSince([]string{"consul", "kvs", "apply"}, time.Now()) 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 // Get is used to lookup a single key
func (k *KVS) Get(args *structs.KeyRequest, reply *structs.IndexedDirEntries) error { 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 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 // List is used to list all keys with a given prefix
func (k *KVS) List(args *structs.KeyRequest, reply *structs.IndexedDirEntries) error { 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 return err
} }

View File

@ -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 // 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 // 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 // Handle DC forwarding
dc := info.RequestDatacenter()
if dc != s.config.Datacenter { if dc != s.config.Datacenter {
err := s.forwardDC(method, dc, args, reply) err := s.forwardDC(method, dc, args, reply)
return true, err return true, err