2013-12-11 22:04:44 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
2013-12-24 20:43:34 +00:00
|
|
|
"fmt"
|
2014-02-20 23:16:26 +00:00
|
|
|
"time"
|
2014-12-01 04:05:15 +00:00
|
|
|
|
|
|
|
"github.com/armon/go-metrics"
|
pkg refactor
command/agent/* -> agent/*
command/consul/* -> agent/consul/*
command/agent/command{,_test}.go -> command/agent{,_test}.go
command/base/command.go -> command/base.go
command/base/* -> command/*
commands.go -> command/commands.go
The script which did the refactor is:
(
cd $GOPATH/src/github.com/hashicorp/consul
git mv command/agent/command.go command/agent.go
git mv command/agent/command_test.go command/agent_test.go
git mv command/agent/flag_slice_value{,_test}.go command/
git mv command/agent .
git mv command/base/command.go command/base.go
git mv command/base/config_util{,_test}.go command/
git mv commands.go command/
git mv consul agent
rmdir command/base/
gsed -i -e 's|package agent|package command|' command/agent{,_test}.go
gsed -i -e 's|package agent|package command|' command/flag_slice_value{,_test}.go
gsed -i -e 's|package base|package command|' command/base.go command/config_util{,_test}.go
gsed -i -e 's|package main|package command|' command/commands.go
gsed -i -e 's|base.Command|BaseCommand|' command/commands.go
gsed -i -e 's|agent.Command|AgentCommand|' command/commands.go
gsed -i -e 's|\tCommand:|\tBaseCommand:|' command/commands.go
gsed -i -e 's|base\.||' command/commands.go
gsed -i -e 's|command\.||' command/commands.go
gsed -i -e 's|command|c|' main.go
gsed -i -e 's|range Commands|range command.Commands|' main.go
gsed -i -e 's|Commands: Commands|Commands: command.Commands|' main.go
gsed -i -e 's|base\.BoolValue|BoolValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.DurationValue|DurationValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.StringValue|StringValue|' command/operator_autopilot_set.go
gsed -i -e 's|base\.UintValue|UintValue|' command/operator_autopilot_set.go
gsed -i -e 's|\bCommand\b|BaseCommand|' command/base.go
gsed -i -e 's|BaseCommand Options|Command Options|' command/base.go
gsed -i -e 's|base.Command|BaseCommand|' command/*.go
gsed -i -e 's|c\.Command|c.BaseCommand|g' command/*.go
gsed -i -e 's|\tCommand:|\tBaseCommand:|' command/*_test.go
gsed -i -e 's|base\.||' command/*_test.go
gsed -i -e 's|\bCommand\b|AgentCommand|' command/agent{,_test}.go
gsed -i -e 's|cmd.AgentCommand|cmd.BaseCommand|' command/agent.go
gsed -i -e 's|cli.AgentCommand = new(Command)|cli.Command = new(AgentCommand)|' command/agent_test.go
gsed -i -e 's|exec.AgentCommand|exec.Command|' command/agent_test.go
gsed -i -e 's|exec.BaseCommand|exec.Command|' command/agent_test.go
gsed -i -e 's|NewTestAgent|agent.NewTestAgent|' command/agent_test.go
gsed -i -e 's|= TestConfig|= agent.TestConfig|' command/agent_test.go
gsed -i -e 's|: RetryJoin|: agent.RetryJoin|' command/agent_test.go
gsed -i -e 's|\.\./\.\./|../|' command/config_util_test.go
gsed -i -e 's|\bverifyUniqueListeners|VerifyUniqueListeners|' agent/config{,_test}.go command/agent.go
gsed -i -e 's|\bserfLANKeyring\b|SerfLANKeyring|g' agent/{agent,keyring,testagent}.go command/agent.go
gsed -i -e 's|\bserfWANKeyring\b|SerfWANKeyring|g' agent/{agent,keyring,testagent}.go command/agent.go
gsed -i -e 's|\bNewAgent\b|agent.New|g' command/agent{,_test}.go
gsed -i -e 's|\bNewAgent|New|' agent/{acl_test,agent,testagent}.go
gsed -i -e 's|\bAgent\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bBool\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bDefaultConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bDevConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bMergeConfig\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bReadConfigPaths\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bParseMetaPair\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bSerfLANKeyring\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|\bSerfWANKeyring\b|agent.&|g' command/agent{,_test}.go
gsed -i -e 's|circonus\.agent|circonus|g' command/agent{,_test}.go
gsed -i -e 's|logger\.agent|logger|g' command/agent{,_test}.go
gsed -i -e 's|metrics\.agent|metrics|g' command/agent{,_test}.go
gsed -i -e 's|// agent.Agent|// agent|' command/agent{,_test}.go
gsed -i -e 's|a\.agent\.Config|a.Config|' command/agent{,_test}.go
gsed -i -e 's|agent\.AppendSliceValue|AppendSliceValue|' command/{configtest,validate}.go
gsed -i -e 's|consul/consul|agent/consul|' GNUmakefile
gsed -i -e 's|\.\./test|../../test|' agent/consul/server_test.go
# fix imports
f=$(grep -rl 'github.com/hashicorp/consul/command/agent' * | grep '\.go')
gsed -i -e 's|github.com/hashicorp/consul/command/agent|github.com/hashicorp/consul/agent|' $f
goimports -w $f
f=$(grep -rl 'github.com/hashicorp/consul/consul' * | grep '\.go')
gsed -i -e 's|github.com/hashicorp/consul/consul|github.com/hashicorp/consul/agent/consul|' $f
goimports -w $f
goimports -w command/*.go main.go
)
2017-06-09 22:28:28 +00:00
|
|
|
"github.com/hashicorp/consul/agent/consul/state"
|
|
|
|
"github.com/hashicorp/consul/agent/consul/structs"
|
2017-05-15 20:10:36 +00:00
|
|
|
"github.com/hashicorp/consul/ipaddr"
|
2016-06-06 20:19:31 +00:00
|
|
|
"github.com/hashicorp/consul/types"
|
2017-01-20 07:36:50 +00:00
|
|
|
"github.com/hashicorp/go-memdb"
|
2017-01-18 22:26:42 +00:00
|
|
|
"github.com/hashicorp/go-uuid"
|
2013-12-11 22:04:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Catalog endpoint is used to manipulate the service catalog
|
|
|
|
type Catalog struct {
|
2013-12-11 22:57:40 +00:00
|
|
|
srv *Server
|
2013-12-11 22:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Register is used register that a node is providing a given service.
|
2013-12-19 20:03:57 +00:00
|
|
|
func (c *Catalog) Register(args *structs.RegisterRequest, reply *struct{}) error {
|
2014-04-19 00:17:12 +00:00
|
|
|
if done, err := c.srv.forward("Catalog.Register", args, args, reply); done {
|
2013-12-11 22:04:44 +00:00
|
|
|
return err
|
|
|
|
}
|
2014-02-20 23:16:26 +00:00
|
|
|
defer metrics.MeasureSince([]string{"consul", "catalog", "register"}, time.Now())
|
2013-12-11 22:04:44 +00:00
|
|
|
|
2016-12-09 00:01:01 +00:00
|
|
|
// Verify the args.
|
2013-12-24 20:43:34 +00:00
|
|
|
if args.Node == "" || args.Address == "" {
|
|
|
|
return fmt.Errorf("Must provide node and address")
|
|
|
|
}
|
2017-01-18 22:26:42 +00:00
|
|
|
if args.ID != "" {
|
|
|
|
if _, err := uuid.ParseUUID(string(args.ID)); err != nil {
|
|
|
|
return fmt.Errorf("Bad node ID: %v", err)
|
|
|
|
}
|
|
|
|
}
|
2013-12-24 20:43:34 +00:00
|
|
|
|
2016-12-08 01:58:23 +00:00
|
|
|
// Fetch the ACL token, if any.
|
|
|
|
acl, err := c.srv.resolveToken(args.Token)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-12-09 00:01:01 +00:00
|
|
|
// Handle a service registration.
|
2014-01-08 21:39:40 +00:00
|
|
|
if args.Service != nil {
|
|
|
|
// If no service id, but service name, use default
|
|
|
|
if args.Service.ID == "" && args.Service.Service != "" {
|
|
|
|
args.Service.ID = args.Service.Service
|
|
|
|
}
|
|
|
|
|
2016-12-09 00:01:01 +00:00
|
|
|
// Verify ServiceName provided if ID.
|
2014-01-08 21:39:40 +00:00
|
|
|
if args.Service.ID != "" && args.Service.Service == "" {
|
|
|
|
return fmt.Errorf("Must provide service name with ID")
|
|
|
|
}
|
2014-12-01 04:05:15 +00:00
|
|
|
|
2017-05-08 16:34:45 +00:00
|
|
|
// Check the service address here and in the agent endpoint
|
|
|
|
// since service registration isn't sychronous.
|
2017-05-15 20:10:36 +00:00
|
|
|
if ipaddr.IsAny(args.Service.Address) {
|
2017-05-08 16:34:45 +00:00
|
|
|
return fmt.Errorf("Invalid service address")
|
|
|
|
}
|
|
|
|
|
2016-12-08 01:58:23 +00:00
|
|
|
// Apply the ACL policy if any. The 'consul' service is excluded
|
|
|
|
// since it is managed automatically internally (that behavior
|
2016-12-09 00:01:01 +00:00
|
|
|
// is going away after version 0.8). We check this same policy
|
|
|
|
// later if version 0.8 is enabled, so we can eventually just
|
|
|
|
// delete this and do all the ACL checks down there.
|
2017-07-14 05:33:47 +00:00
|
|
|
if args.Service.Service != structs.ConsulServiceName {
|
2016-12-08 01:58:23 +00:00
|
|
|
if acl != nil && !acl.ServiceWrite(args.Service.Service) {
|
2017-04-21 00:02:42 +00:00
|
|
|
return errPermissionDenied
|
2014-12-01 04:05:15 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-06 22:18:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 00:01:01 +00:00
|
|
|
// Move the old format single check into the slice, and fixup IDs.
|
2014-01-08 21:39:40 +00:00
|
|
|
if args.Check != nil {
|
2015-01-14 01:52:17 +00:00
|
|
|
args.Checks = append(args.Checks, args.Check)
|
|
|
|
args.Check = nil
|
|
|
|
}
|
|
|
|
for _, check := range args.Checks {
|
|
|
|
if check.CheckID == "" && check.Name != "" {
|
2016-06-06 20:19:31 +00:00
|
|
|
check.CheckID = types.CheckID(check.Name)
|
2014-01-08 21:39:40 +00:00
|
|
|
}
|
2015-01-14 01:52:17 +00:00
|
|
|
if check.Node == "" {
|
|
|
|
check.Node = args.Node
|
2014-01-08 21:39:40 +00:00
|
|
|
}
|
2014-01-06 22:18:38 +00:00
|
|
|
}
|
|
|
|
|
2016-12-09 00:01:01 +00:00
|
|
|
// Check the complete register request against the given ACL policy.
|
2016-12-10 03:15:44 +00:00
|
|
|
if acl != nil && c.srv.config.ACLEnforceVersion8 {
|
2016-12-09 00:01:01 +00:00
|
|
|
state := c.srv.fsm.State()
|
2017-01-20 07:36:50 +00:00
|
|
|
_, ns, err := state.NodeServices(nil, args.Node)
|
2016-12-09 00:01:01 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Node lookup failed: %v", err)
|
|
|
|
}
|
|
|
|
if err := vetRegisterWithACL(acl, args, ns); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-27 07:15:21 +00:00
|
|
|
resp, err := c.srv.raftApply(structs.RegisterRequestType, args)
|
2013-12-11 22:04:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-03-27 07:15:21 +00:00
|
|
|
if respErr, ok := resp.(error); ok {
|
|
|
|
return respErr
|
|
|
|
}
|
2013-12-11 22:04:44 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deregister is used to remove a service registration for a given node.
|
2013-12-19 20:03:57 +00:00
|
|
|
func (c *Catalog) Deregister(args *structs.DeregisterRequest, reply *struct{}) error {
|
2014-04-19 00:17:12 +00:00
|
|
|
if done, err := c.srv.forward("Catalog.Deregister", args, args, reply); done {
|
2013-12-11 23:34:10 +00:00
|
|
|
return err
|
|
|
|
}
|
2014-02-20 23:16:26 +00:00
|
|
|
defer metrics.MeasureSince([]string{"consul", "catalog", "deregister"}, time.Now())
|
2013-12-11 23:34:10 +00:00
|
|
|
|
2013-12-24 20:43:34 +00:00
|
|
|
// Verify the args
|
|
|
|
if args.Node == "" {
|
|
|
|
return fmt.Errorf("Must provide node")
|
|
|
|
}
|
|
|
|
|
2016-12-10 03:15:44 +00:00
|
|
|
// Fetch the ACL token, if any.
|
|
|
|
acl, err := c.srv.resolveToken(args.Token)
|
2013-12-11 23:34:10 +00:00
|
|
|
if err != nil {
|
2016-12-10 03:15:44 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the complete deregister request against the given ACL policy.
|
|
|
|
if acl != nil && c.srv.config.ACLEnforceVersion8 {
|
|
|
|
state := c.srv.fsm.State()
|
|
|
|
|
|
|
|
var ns *structs.NodeService
|
|
|
|
if args.ServiceID != "" {
|
|
|
|
_, ns, err = state.NodeService(args.Node, args.ServiceID)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Service lookup failed: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var nc *structs.HealthCheck
|
|
|
|
if args.CheckID != "" {
|
|
|
|
_, nc, err = state.NodeCheck(args.Node, args.CheckID)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Check lookup failed: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := vetDeregisterWithACL(acl, args, ns, nc); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := c.srv.raftApply(structs.DeregisterRequestType, args); err != nil {
|
2013-12-11 23:34:10 +00:00
|
|
|
return err
|
|
|
|
}
|
2013-12-11 22:04:44 +00:00
|
|
|
return nil
|
|
|
|
}
|
2013-12-12 18:35:50 +00:00
|
|
|
|
|
|
|
// ListDatacenters is used to query for the list of known datacenters
|
|
|
|
func (c *Catalog) ListDatacenters(args *struct{}, reply *[]string) error {
|
2017-03-14 05:56:24 +00:00
|
|
|
dcs, err := c.srv.router.GetDatacentersByDistance()
|
2015-11-07 06:14:45 +00:00
|
|
|
if err != nil {
|
2015-07-24 19:53:50 +00:00
|
|
|
return err
|
2015-07-02 22:36:59 +00:00
|
|
|
}
|
2014-06-06 21:12:40 +00:00
|
|
|
|
2013-12-12 18:35:50 +00:00
|
|
|
*reply = dcs
|
|
|
|
return nil
|
|
|
|
}
|
2013-12-12 18:48:36 +00:00
|
|
|
|
|
|
|
// ListNodes is used to query the nodes in a DC
|
2014-02-05 19:00:43 +00:00
|
|
|
func (c *Catalog) ListNodes(args *structs.DCSpecificRequest, reply *structs.IndexedNodes) error {
|
2014-04-19 00:17:12 +00:00
|
|
|
if done, err := c.srv.forward("Catalog.ListNodes", args, args, reply); done {
|
2013-12-12 18:48:36 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-01-20 07:36:50 +00:00
|
|
|
return c.srv.blockingQuery(
|
2015-10-12 07:42:09 +00:00
|
|
|
&args.QueryOptions,
|
2014-04-21 18:04:52 +00:00
|
|
|
&reply.QueryMeta,
|
2017-04-21 00:46:29 +00:00
|
|
|
func(ws memdb.WatchSet, state *state.Store) error {
|
2017-01-06 01:21:56 +00:00
|
|
|
var index uint64
|
|
|
|
var nodes structs.Nodes
|
|
|
|
var err error
|
2017-01-11 19:41:12 +00:00
|
|
|
if len(args.NodeMetaFilters) > 0 {
|
2017-01-20 07:36:50 +00:00
|
|
|
index, nodes, err = state.NodesByMeta(ws, args.NodeMetaFilters)
|
2017-01-06 01:21:56 +00:00
|
|
|
} else {
|
2017-01-20 07:36:50 +00:00
|
|
|
index, nodes, err = state.Nodes(ws)
|
2017-01-06 01:21:56 +00:00
|
|
|
}
|
2015-10-12 07:42:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
reply.Index, reply.Nodes = index, nodes
|
2016-12-11 00:00:11 +00:00
|
|
|
if err := c.srv.filterACL(args.Token, reply); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-07-02 22:36:59 +00:00
|
|
|
return c.srv.sortNodesByDistanceFrom(args.Source, reply.Nodes)
|
2014-02-05 19:00:43 +00:00
|
|
|
})
|
2013-12-12 18:48:36 +00:00
|
|
|
}
|
2013-12-12 19:07:14 +00:00
|
|
|
|
|
|
|
// ListServices is used to query the services in a DC
|
2014-02-05 19:00:43 +00:00
|
|
|
func (c *Catalog) ListServices(args *structs.DCSpecificRequest, reply *structs.IndexedServices) error {
|
2014-04-19 00:17:12 +00:00
|
|
|
if done, err := c.srv.forward("Catalog.ListServices", args, args, reply); done {
|
2013-12-12 19:07:14 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-01-20 07:36:50 +00:00
|
|
|
return c.srv.blockingQuery(
|
2015-10-12 07:42:09 +00:00
|
|
|
&args.QueryOptions,
|
2014-04-21 18:04:52 +00:00
|
|
|
&reply.QueryMeta,
|
2017-04-21 00:46:29 +00:00
|
|
|
func(ws memdb.WatchSet, state *state.Store) error {
|
2017-01-09 19:21:49 +00:00
|
|
|
var index uint64
|
|
|
|
var services structs.Services
|
|
|
|
var err error
|
2017-01-11 19:41:12 +00:00
|
|
|
if len(args.NodeMetaFilters) > 0 {
|
2017-01-20 07:36:50 +00:00
|
|
|
index, services, err = state.ServicesByNodeMeta(ws, args.NodeMetaFilters)
|
2017-01-09 19:21:49 +00:00
|
|
|
} else {
|
2017-01-20 07:36:50 +00:00
|
|
|
index, services, err = state.Services(ws)
|
2017-01-09 19:21:49 +00:00
|
|
|
}
|
2015-10-12 07:42:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
reply.Index, reply.Services = index, services
|
2015-06-11 19:48:38 +00:00
|
|
|
return c.srv.filterACL(args.Token, reply)
|
2014-02-05 19:00:43 +00:00
|
|
|
})
|
2013-12-12 19:07:14 +00:00
|
|
|
}
|
2013-12-12 19:37:19 +00:00
|
|
|
|
|
|
|
// ServiceNodes returns all the nodes registered as part of a service
|
2014-02-05 19:10:10 +00:00
|
|
|
func (c *Catalog) ServiceNodes(args *structs.ServiceSpecificRequest, reply *structs.IndexedServiceNodes) error {
|
2014-04-19 00:17:12 +00:00
|
|
|
if done, err := c.srv.forward("Catalog.ServiceNodes", args, args, reply); done {
|
2013-12-12 19:37:19 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:43:34 +00:00
|
|
|
// Verify the arguments
|
|
|
|
if args.ServiceName == "" {
|
|
|
|
return fmt.Errorf("Must provide service name")
|
|
|
|
}
|
|
|
|
|
2017-01-20 07:36:50 +00:00
|
|
|
err := c.srv.blockingQuery(
|
2015-10-12 07:42:09 +00:00
|
|
|
&args.QueryOptions,
|
2014-04-21 18:04:52 +00:00
|
|
|
&reply.QueryMeta,
|
2017-04-21 00:46:29 +00:00
|
|
|
func(ws memdb.WatchSet, state *state.Store) error {
|
2015-10-12 07:42:09 +00:00
|
|
|
var index uint64
|
|
|
|
var services structs.ServiceNodes
|
|
|
|
var err error
|
2014-02-05 19:10:10 +00:00
|
|
|
if args.TagFilter {
|
2017-01-20 07:36:50 +00:00
|
|
|
index, services, err = state.ServiceTagNodes(ws, args.ServiceName, args.ServiceTag)
|
2014-02-05 19:10:10 +00:00
|
|
|
} else {
|
2017-01-20 07:36:50 +00:00
|
|
|
index, services, err = state.ServiceNodes(ws, args.ServiceName)
|
2015-10-12 07:42:09 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2014-02-05 19:10:10 +00:00
|
|
|
}
|
2015-10-12 07:42:09 +00:00
|
|
|
reply.Index, reply.ServiceNodes = index, services
|
2017-01-14 01:08:43 +00:00
|
|
|
if len(args.NodeMetaFilters) > 0 {
|
|
|
|
var filtered structs.ServiceNodes
|
|
|
|
for _, service := range services {
|
|
|
|
if structs.SatisfiesMetaFilters(service.NodeMeta, args.NodeMetaFilters) {
|
|
|
|
filtered = append(filtered, service)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reply.ServiceNodes = filtered
|
|
|
|
}
|
2015-06-30 21:25:40 +00:00
|
|
|
if err := c.srv.filterACL(args.Token, reply); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-07-02 22:36:59 +00:00
|
|
|
return c.srv.sortNodesByDistanceFrom(args.Source, reply.ServiceNodes)
|
2014-02-05 19:10:10 +00:00
|
|
|
})
|
2014-04-04 21:55:44 +00:00
|
|
|
|
|
|
|
// Provide some metrics
|
|
|
|
if err == nil {
|
|
|
|
metrics.IncrCounter([]string{"consul", "catalog", "service", "query", args.ServiceName}, 1)
|
|
|
|
if args.ServiceTag != "" {
|
|
|
|
metrics.IncrCounter([]string{"consul", "catalog", "service", "query-tag", args.ServiceName, args.ServiceTag}, 1)
|
|
|
|
}
|
|
|
|
if len(reply.ServiceNodes) == 0 {
|
|
|
|
metrics.IncrCounter([]string{"consul", "catalog", "service", "not-found", args.ServiceName}, 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err
|
2013-12-12 19:37:19 +00:00
|
|
|
}
|
2013-12-12 19:46:25 +00:00
|
|
|
|
|
|
|
// NodeServices returns all the services registered as part of a node
|
2014-02-05 19:10:10 +00:00
|
|
|
func (c *Catalog) NodeServices(args *structs.NodeSpecificRequest, reply *structs.IndexedNodeServices) error {
|
2014-04-19 00:17:12 +00:00
|
|
|
if done, err := c.srv.forward("Catalog.NodeServices", args, args, reply); done {
|
2013-12-12 19:46:25 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:43:34 +00:00
|
|
|
// Verify the arguments
|
|
|
|
if args.Node == "" {
|
|
|
|
return fmt.Errorf("Must provide node")
|
|
|
|
}
|
|
|
|
|
2017-01-20 07:36:50 +00:00
|
|
|
return c.srv.blockingQuery(
|
2015-10-12 07:42:09 +00:00
|
|
|
&args.QueryOptions,
|
2014-04-21 18:04:52 +00:00
|
|
|
&reply.QueryMeta,
|
2017-04-21 00:46:29 +00:00
|
|
|
func(ws memdb.WatchSet, state *state.Store) error {
|
2017-01-20 07:36:50 +00:00
|
|
|
index, services, err := state.NodeServices(ws, args.Node)
|
2015-10-12 07:42:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-12-10 05:04:00 +00:00
|
|
|
|
2015-10-12 07:42:09 +00:00
|
|
|
reply.Index, reply.NodeServices = index, services
|
2015-06-11 19:48:38 +00:00
|
|
|
return c.srv.filterACL(args.Token, reply)
|
2014-02-05 19:10:10 +00:00
|
|
|
})
|
2013-12-12 19:46:25 +00:00
|
|
|
}
|