Commit Graph

618 Commits

Author SHA1 Message Date
Sean Chittenden
aff951ca4e Always create a consul.Syncer. Use a default Consul Config if necessary. 2016-06-10 15:55:27 -04:00
Sean Chittenden
61a36a6d54 Commit miss, bump to 5s 2016-06-10 15:54:39 -04:00
Sean Chittenden
dbdebcad80 golint(1) police 2016-06-10 15:54:39 -04:00
Sean Chittenden
a423f07d63 Stash client and server registration behind consul.auto_register 2016-06-10 15:54:39 -04:00
Sean Chittenden
5757e50243 Only return the Client's server addresses, never mix-in server peers 2016-06-10 15:54:39 -04:00
Sean Chittenden
c426b8501c Hand wave over the syncer tests atm, these will be fixed shortly. 2016-06-10 15:54:39 -04:00
Sean Chittenden
69aa8e8195 Don't spam the consul if Consul is not available.
Log once when Consul goes away, and log when Consul comes back.
2016-06-10 15:54:39 -04:00
Sean Chittenden
05e713cfca Skip nil check for agent's consulSyncer is always not nil 2016-06-10 15:54:39 -04:00
Sean Chittenden
f7b2949f11 Properly cover Syncer attributes with the registryLock.
trackedServices, delegateChecks, trackedChecks, and checkRunners
should all be covered.  This lock needs to be reasonably narrow and
can't use defer due to possible recursive locking concerns further
downstream from the call sites.
2016-06-10 15:54:39 -04:00
Sean Chittenden
27f6ffd83d On Syncer Shutdown, remove all services that match a Syncer's prefix. 2016-06-10 15:54:39 -04:00
Sean Chittenden
7d060c20d7 Sync checks with Consul by comparing the AgentCheckReg w/ ConsulService
The source of truth is the local Nomad Agent.  Any checks are not local that
have a matching prefix are removed.  Changed checks are re-registered
and missing checks are re-added.
2016-06-10 15:54:39 -04:00
Sean Chittenden
19f765eb05 Sync services with Consul by comparing the AgentServiceReg w/ ConsulService
The source of truth is the local Nomad Agent.  Any services not local that
have a matching prefix are removed.  Changed services are re-registered
and missing services are re-added.
2016-06-10 15:54:39 -04:00
Sean Chittenden
d1ab21f2f7 Generate and sync Consul ServiceIDs consistently 2016-06-10 15:54:39 -04:00
Sean Chittenden
5913acfd69 Rename runChecks to consulAvailable
Apologies in advance for the variable thrash, the fingerprinter is
no longer used to gate whether or not Consul is available any more.
2016-06-10 15:54:39 -04:00
Sean Chittenden
d87c697c87 Update Syncer.Run() to call SyncServices(). 2016-06-10 15:54:39 -04:00
Sean Chittenden
8be79cf28c Add "Service Groups" to the Syncer.
Now the right way to register services with the Syncer is to call
`SetServices(groupName, []*services)`.  This was required to allow
the Syncer to sync either the Client, Server, or Both using a
single Syncer.
2016-06-10 15:54:39 -04:00
Sean Chittenden
a4f605a789 Initialize Consul for the Nomad Agent in a more uniform way.
Decompose Client and Server registration into `setupClient()` and
`setupServer()`, respectively.
2016-06-10 15:54:39 -04:00
Sean Chittenden
802a8c459c Rename command/agent/consul/sync.go to syncer.go 2016-06-10 15:54:39 -04:00
Sean Chittenden
7ad5cd571c Begin leveraging the Agent-level consul.Syncer 2016-06-10 15:54:39 -04:00
Sean Chittenden
54838b9eba Rename structs.Task's Service attribute to ConsulService 2016-06-10 15:54:39 -04:00
Sean Chittenden
b6a2ec2db8 Remove Syncer.registerService()
This call is obsolete by a future commit that changes the canonical
source of truth to be consul.AgentServiceRegistration structs, which
means it is not necessary to construct AgentServiceRegistration
objects every time a registration is made, we just reuse the existing
object.
2016-06-10 15:54:39 -04:00
Sean Chittenden
57c2c819e8 Move package client/consul/sync to command/agent/consul.
This has been done to allow the Server and Client to reuse the same
Syncer because the Agent may be running Client, Server, or both
simultaneously and we only want one Syncer object alive in the agent.
2016-06-10 15:54:39 -04:00
Sean Chittenden
74e691cab1 Change the API signature of Syncer.SyncServices().
SyncServices() immediately attempts to sync whatever information
the process has with Consul.  Previously this method would take an
argument of the exclusive list of services that should exist,
however this is not condusive to having a Nomad Client and Nomad
Server share the same consul.Syncer.
2016-06-10 15:54:39 -04:00
Sean Chittenden
acb3d58b82 Refine Nomad's Consul port handling.
Previously this would immediately default to '127.0.0.1' if the
config was set to `:some-port-number`.  Now it uses the BindAddr
if available.  Also, if the `port` option is set to just a port`
number (e.g. '1234'), attempt to parse the port number by itself
to allow statically configured ports to work, even when no host is
specified.
2016-06-10 15:54:39 -04:00
Sean Chittenden
1352f7f0e6 Change client/consul.NewSyncer() to accept a shutdown channel
In addition to the API changing, consul.Syncer can now be signaled
to shutdown via the Shutdown() method, which will call the Run()'ing
sync task to exit gracefully.
2016-06-10 15:54:39 -04:00
Sean Chittenden
ab434b4079 Fix typo in comment 2016-06-10 15:50:11 -04:00
Sean Chittenden
503c6a996f Fix test TestClientConfigCommand_UpdateServers()
Now that hostnames are validated on input, switch to IPs since they
bypass DNS resolution.
2016-06-10 15:50:11 -04:00
Sean Chittenden
f03765814e Add some trace-level logging for /v1/agent/servers when writing
This endpoint shouldn't be hit often, but this could be useful in
logs down the road.
2016-06-10 15:50:11 -04:00
Sean Chittenden
37e7038a27 Fix config_parse_test to reflect that consul.addr does not exist.
`consul.address` does, but not `consul.addr`.
2016-06-10 15:50:11 -04:00
Sean Chittenden
a55395678f Fix tests for client.TestAgent_ServerConfig
Add similar logic in Agent `serverConfig()` to set up the
`serverSerfAddr` the same as `serverHttpAddr` and `serverRpcAddr`.
2016-06-10 15:50:11 -04:00
Sean Chittenden
ed30876186 Change the endpoint for /v1/agent/servers and fix tests.
When an agent is running a server, the list of servers includes the
Raft peers.  When the agent is running a client (which is always the
case?), include a list of the servers found in the Client's RpcProxy.
Dedupe and provide a unique list back to the caller.
2016-06-10 15:50:11 -04:00
Sean Chittenden
b9f230b7b2 Move client.DefaultConfig() to client/config.DefaultConfig()
Resolves an import cycle in testing and is more appropriate because
the default should reside next to its struct definition.
2016-06-10 15:50:11 -04:00
Sean Chittenden
b2357598ba Register the serf service with the Nomad server service.
This will be unused in this PR.
2016-06-10 15:50:11 -04:00
Sean Chittenden
6b8a9b435c Update the nomad_server_service default from nomad-server to just nomad. 2016-06-10 15:50:11 -04:00
Sean Chittenden
d6769f59f7 Create a weak decoder to parse time.Duration.
Hat tip to Alex for pointing this out (vs patching mapstructure)
2016-06-10 15:50:11 -04:00
Sean Chittenden
ca0f2d982d Nuke a.consulConfig in favor of a.consul.Config 2016-06-10 15:50:11 -04:00
Sean Chittenden
3d22c22bf5 Remove types.ShutdownChannel and replace with chan struct{} 2016-06-10 15:50:11 -04:00
Sean Chittenden
4d47eedd58 Teach Client to reuse an Agent's consulSyncer.
"There can be only one."
2016-06-10 15:50:11 -04:00
Sean Chittenden
bc86e897ed Register two services each for clients and servers, http and rpc.
In order to give clients a fighting chance to talk to the right port,
differentiate RPC services from HTTP services by registering two
services with different tags.  This yields
`rpc.nomad-server.service.consul` and
`http.nomad-server.service.consul` which is immensely more useful to
clients attempting to bootstrap their world.
2016-06-10 15:50:11 -04:00
Sean Chittenden
ce8c03d708 Advertise the server's RPC endpoint, not its HTTP endpoint.
Rename c.serverRpcAddr to serverRpcAddr.  This will be broken out
into in additional set of services in a subsequent commit.
2016-06-10 15:50:11 -04:00
Sean Chittenden
7cdf0edcfe Rename the package from client/rpc_proxy to client/rpcproxy
Also rename `NewRpcProxy()` to just `New()` to avoid package stutter.
2016-06-10 15:50:11 -04:00
Sean Chittenden
1fa43a09dd Reduce all forms of ConsulConfig down to a single struct
nomad/structs/config/consul.go's ConsulConfig is the canonical definition
for all things Consul now.
2016-06-10 15:50:11 -04:00
Sean Chittenden
4d30c98aa6 Rename consulConfig to consulAgentConfig 2016-06-10 15:50:11 -04:00
Sean Chittenden
5e0d76f7ce Rename client/config/config's ConsulConfig to ConsulAgentConfig
A follow up commit to the previous rename.  More to come.
2016-06-10 15:50:11 -04:00
Sean Chittenden
e6397da738 Centralize the creation of a consul/api.Config struct.
While documented, the consul.timeout parameter wasn't ever set
except one-off in the Consul fingerprinter.
2016-06-10 15:50:11 -04:00
Sean Chittenden
71dde1b584 Reconcile consul's address configuration section.
There were conflicting directives previously, both consul.addr and
consul.address were required to achieve the desired behavior.  The
documentation said `consul.address` was the canonical name for the
parameter, so consolidate configuration parameters to `consul.address`.
2016-06-10 15:50:11 -04:00
Sean Chittenden
05bbbd2d55 Reconcile renamed structures during rebase 2016-06-10 15:50:11 -04:00
Sean Chittenden
c159e77fe3 An Agent's consulSyncer is always not nil now. 2016-06-10 15:50:11 -04:00
Sean Chittenden
89d48c8e82 Revise Agent.syncAgentServicesWithConsul()'s interface
Reduce down to its lowest common helper function denominator.
2016-06-10 15:50:11 -04:00
Sean Chittenden
8da18b60f3 Alpha sort config keys for Consul 2016-06-10 15:50:11 -04:00