consul

package
v0.6.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2017 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

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"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentAPI added in v0.6.0

type AgentAPI interface {
	Services() (map[string]*api.AgentService, error)
	Checks() (map[string]*api.AgentCheck, error)
	CheckRegister(check *api.AgentCheckRegistration) error
	CheckDeregister(checkID string) 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 CatalogAPI added in v0.6.0

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 MockCatalog added in v0.6.0

type MockCatalog struct {
	// contains filtered or unexported fields
}

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

func NewMockCatalog added in v0.6.0

func NewMockCatalog(l *log.Logger) *MockCatalog

func (*MockCatalog) Datacenters added in v0.6.0

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

func (*MockCatalog) Service added in v0.6.0

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

type ServiceClient added in v0.6.0

type ServiceClient struct {
	// contains filtered or unexported fields
}

ServiceClient handles task and agent service registration with Consul.

func NewServiceClient added in v0.6.0

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

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

func (*ServiceClient) Checks added in v0.6.0

func (c *ServiceClient) Checks(a *structs.Allocation) ([]*api.AgentCheck, error)

Checks returns the checks registered against the agent for the given allocation.

func (*ServiceClient) RegisterAgent added in v0.6.0

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 added in v0.6.0

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

RegisterTask with Consul. Adds all sevice 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 asynchrously (see Run).

func (*ServiceClient) RemoveTask added in v0.6.0

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

RemoveTask from Consul. Removes all service entries and checks.

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

func (*ServiceClient) Run added in v0.6.0

func (c *ServiceClient) Run()

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

func (*ServiceClient) Shutdown added in v0.6.0

func (c *ServiceClient) Shutdown() error

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

func (*ServiceClient) UpdateTask added in v0.6.0

func (c *ServiceClient) UpdateTask(allocID string, existing, newTask *structs.Task, 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.

Jump to

Keyboard shortcuts

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