Added some docs

This commit is contained in:
Diptanu Choudhury 2016-05-14 00:36:26 -07:00
parent d94e651c6e
commit ecd995b283
3 changed files with 17 additions and 18 deletions

View File

@ -110,8 +110,6 @@ type Config struct {
// Revision is the commit number of the Nomad client
Revision string
ClientServiceName string
// ConsulConfig is the configuration to connect with Consul Agent
ConsulConfig *consul.ConsulConfig
}

View File

@ -22,10 +22,10 @@ type ConsulService struct {
client *consul.Client
availble bool
serviceIdentifier string
delegateChecks map[string]struct{}
serviceIdentifier string // serviceIdentifier is a token which identifies which task/alloc the service belongs to
delegateChecks map[string]struct{} // delegateChecks are the checks that the Nomad client runs and reports to Consul
createCheck func(*structs.ServiceCheck, string) (Check, error)
addrFinder func(string) (string, int)
addrFinder func(portLabel string) (string, int)
trackedServices map[string]*consul.AgentService
trackedChecks map[string]*consul.AgentCheckRegistration
@ -132,7 +132,7 @@ func (c *ConsulService) SetDelegatedChecks(delegateChecks map[string]struct{}, c
return c
}
// SetAddrFinder sets a function to find the host and port for a Service
// SetAddrFinder sets a function to find the host and port for a Service given its port label
func (c *ConsulService) SetAddrFinder(addrFinder func(string) (string, int)) *ConsulService {
c.addrFinder = addrFinder
return c
@ -466,3 +466,9 @@ func (c *ConsulService) runCheck(check Check) {
}
}
}
// generateServiceIdentifier returns a service identifier based on an allocation
// id and task name
func generateServiceIdentifier(allocID string, taskName string) string {
return fmt.Sprintf("%s-%s", taskName, allocID)
}

View File

@ -29,8 +29,8 @@ type Agent struct {
logger *log.Logger
logOutput io.Writer
consulService *consul.ConsulService
consulConfig *consul.ConsulConfig
consulService *consul.ConsulService // consulService registers the Nomad agent with the consul agent
consulConfig *consul.ConsulConfig // consulConfig is the consul configuration the Nomad client uses to connect with Consul agent
serverHTTPAddr string
clientHTTPAddr string
@ -56,6 +56,8 @@ func NewAgent(config *Config, logOutput io.Writer) (*Agent, error) {
shutdownCh: make(chan struct{}),
}
// creating the consul client configuration that both the server and client
// uses
a.createConsulConfig()
if err := a.setupServer(); err != nil {
@ -493,35 +495,28 @@ func (a *Agent) syncAgentServicesWithConsul(clientHttpAddr string, serverHttpAdd
}
a.consulService = cs
var services []*structs.Service
addrs := make(map[string]string)
if a.client != nil && a.config.ConsulConfig.ClientServiceName != "" {
if err != nil {
return err
}
clientService := &structs.Service{
Name: a.config.ConsulConfig.ClientServiceName,
PortLabel: "clienthttpaddr",
PortLabel: clientHttpAddr,
}
addrs["clienthttpaddr"] = clientHttpAddr
services = append(services, clientService)
cs.SetServiceIdentifier("agent-client")
}
if a.server != nil && a.config.ConsulConfig.ServerServiceName != "" {
serverService := &structs.Service{
Name: a.config.ConsulConfig.ServerServiceName,
PortLabel: "serverhttpaddr",
PortLabel: serverHttpAddr,
}
addrs["serverhttpaddr"] = serverHttpAddr
services = append(services, serverService)
cs.SetServiceIdentifier("agent-server")
}
cs.SetAddrFinder(func(portLabel string) (string, int) {
addr := addrs[portLabel]
if addr == "" {
return "", 0
}
host, port, err := net.SplitHostPort(addr)
host, port, err := net.SplitHostPort(portLabel)
if err != nil {
return "", 0
}