Version: v0.8.3 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2018 License: MPL-2.0 Imports: 17 Imported by: 0




View Source
const (

	// DefaultQueryWaitDuration is the max duration the Consul Agent will
	// spend waiting for a response from a Consul Query.
	DefaultQueryWaitDuration = 2 * time.Second

	// ServiceTagHTTP is the tag assigned to HTTP services
	ServiceTagHTTP = "http"

	// ServiceTagRPC is the tag assigned to RPC services
	ServiceTagRPC = "rpc"

	// ServiceTagSerf is the tag assigned to Serf services
	ServiceTagSerf = "serf"


This section is empty.


This section is empty.


type AgentAPI

type AgentAPI interface {
	Services() (map[string]*api.AgentService, error)
	Checks() (map[string]*api.AgentCheck, error)
	CheckRegister(check *api.AgentCheckRegistration) error
	CheckDeregister(checkID string) error
	Self() (map[string]map[string]interface{}, error)
	ServiceRegister(service *api.AgentServiceRegistration) error
	ServiceDeregister(serviceID string) error
	UpdateTTL(id, output, status string) error

AgentAPI is the consul/api.Agent API used by Nomad.

type AllocRegistration

type AllocRegistration struct {
	// Tasks maps the name of a task to its registered services and checks
	Tasks map[string]*TaskRegistration

AllocRegistration holds the status of services registered for a particular allocations by task.

func (*AllocRegistration) NumChecks

func (a *AllocRegistration) NumChecks() int

NumChecks returns the number of registered checks

func (*AllocRegistration) NumServices

func (a *AllocRegistration) NumServices() int

NumServices returns the number of registered services

type CatalogAPI

type CatalogAPI interface {
	Datacenters() ([]string, error)
	Service(service, tag string, q *api.QueryOptions) ([]*api.CatalogService, *api.QueryMeta, error)

CatalogAPI is the consul/api.Catalog API used by Nomad.

type ChecksAPI

type ChecksAPI interface {
	// Checks returns a list of all checks.
	Checks() (map[string]*api.AgentCheck, error)

ChecksAPI is the part of the Consul API the checkWatcher requires.

type MockAgent

type MockAgent struct {
	// contains filtered or unexported fields

MockAgent is a fake in-memory Consul backend for ServiceClient.

func NewMockAgent

func NewMockAgent() *MockAgent

NewMockAgent that returns all checks as passing.

func (*MockAgent) CheckDeregister

func (c *MockAgent) CheckDeregister(checkID string) error

func (*MockAgent) CheckRegister

func (c *MockAgent) CheckRegister(check *api.AgentCheckRegistration) error

func (*MockAgent) CheckRegs

func (c *MockAgent) CheckRegs() []*api.AgentCheckRegistration

CheckRegs returns the raw AgentCheckRegistrations registered with this mock agent.

func (*MockAgent) Checks

func (c *MockAgent) Checks() (map[string]*api.AgentCheck, error)

Checks implements the Agent API Checks method.

func (*MockAgent) Self

func (c *MockAgent) Self() (map[string]map[string]interface{}, error)

func (*MockAgent) ServiceDeregister

func (c *MockAgent) ServiceDeregister(serviceID string) error

func (*MockAgent) ServiceRegister

func (c *MockAgent) ServiceRegister(service *api.AgentServiceRegistration) error

func (*MockAgent) Services

func (c *MockAgent) Services() (map[string]*api.AgentService, error)

func (*MockAgent) SetStatus

func (c *MockAgent) SetStatus(s string) string

SetStatus that Checks() should return. Returns old status value.

func (*MockAgent) UpdateTTL

func (c *MockAgent) UpdateTTL(id string, output string, status string) error

type MockCatalog

type MockCatalog struct {
	// contains filtered or unexported fields

MockCatalog can be used for testing where the CatalogAPI is needed.

func NewMockCatalog

func NewMockCatalog(l *log.Logger) *MockCatalog

func (*MockCatalog) Datacenters

func (m *MockCatalog) Datacenters() ([]string, error)

func (*MockCatalog) Service

func (m *MockCatalog) Service(service, tag string, q *api.QueryOptions) ([]*api.CatalogService, *api.QueryMeta, error)

type ServiceClient

type ServiceClient struct {
	// contains filtered or unexported fields

ServiceClient handles task and agent service registration with Consul.

func NewServiceClient

func NewServiceClient(consulClient AgentAPI, logger *log.Logger) *ServiceClient

NewServiceClient creates a new Consul ServiceClient from an existing Consul API Client and logger.

func (*ServiceClient) AllocRegistrations

func (c *ServiceClient) AllocRegistrations(allocID string) (*AllocRegistration, error)

AllocRegistrations returns the registrations for the given allocation. If the allocation has no reservations, the response is a nil object.

func (*ServiceClient) RegisterAgent

func (c *ServiceClient) RegisterAgent(role string, services []*structs.Service) error

RegisterAgent registers Nomad agents (client or server). The Service.PortLabel should be a literal port to be parsed with SplitHostPort. Script checks are not supported and will return an error. Registration is asynchronous.

Agents will be deregistered when Shutdown is called.

func (*ServiceClient) RegisterTask

func (c *ServiceClient) RegisterTask(allocID string, task *structs.Task, restarter TaskRestarter, exec driver.ScriptExecutor, net *cstructs.DriverNetwork) error

RegisterTask with Consul. Adds all service entries and checks to Consul. If exec is nil and a script check exists an error is returned.

If the service IP is set it used as the address in the service registration. Checks will always use the IP from the Task struct (host's IP).

Actual communication with Consul is done asynchronously (see Run).

func (*ServiceClient) RemoveTask

func (c *ServiceClient) RemoveTask(allocID string, task *structs.Task)

RemoveTask from Consul. Removes all service entries and checks.

Actual communication with Consul is done asynchronously (see Run).

func (*ServiceClient) Run

func (c *ServiceClient) Run()

Run the Consul main loop which retries operations against Consul. It should be called exactly once.

func (*ServiceClient) Shutdown

func (c *ServiceClient) Shutdown() error

Shutdown the Consul client. Update running task registrations and deregister agent from Consul. On first call blocks up to shutdownWait before giving up on syncing operations.

func (*ServiceClient) UpdateTask

func (c *ServiceClient) UpdateTask(allocID string, existing, newTask *structs.Task, restarter TaskRestarter, exec driver.ScriptExecutor, net *cstructs.DriverNetwork) error

UpdateTask in Consul. Does not alter the service if only checks have changed.

DriverNetwork must not change between invocations for the same allocation.

type ServiceRegistration

type ServiceRegistration struct {

	// Service is the AgentService registered in Consul.
	Service *api.AgentService

	// Checks is the status of the registered checks.
	Checks []*api.AgentCheck
	// contains filtered or unexported fields

ServiceRegistration holds the status of a registered Consul Service and its Checks.

type TaskRegistration

type TaskRegistration struct {
	Services map[string]*ServiceRegistration

TaskRegistration holds the status of services registered for a particular task.

type TaskRestarter

type TaskRestarter interface {
	Restart(source, reason string, failure bool)

TaskRestarter allows the checkWatcher to restart tasks.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL