client

package
v0.7.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2017 License: MPL-2.0 Imports: 55 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReasonNoRestartsAllowed   = "Policy allows no restarts"
	ReasonUnrecoverableErrror = "Error was unrecoverable"
	ReasonWithinPolicy        = "Restart within policy"
	ReasonDelay               = "Exceeded allowed attempts, applying a delay"
)
View Source
const (

	// DefaultMaxTemplateEventRate is the default maximum rate at which a
	// template event should be fired.
	DefaultMaxTemplateEventRate = 3 * time.Second
)
View Source
const (
	// MB is a constant which converts values in bytes to MB
	MB = 1024 * 1024
)

Variables

This section is empty.

Functions

func NewTokenFuture added in v0.5.0

func NewTokenFuture() *tokenFuture

NewTokenFuture returns a new token future without any token set

Types

type AllocCounter added in v0.6.0

type AllocCounter interface {
	NumAllocs() int
}

AllocCounter is used by AllocGarbageCollector to discover how many allocations a node has and is generally fulfilled by the Client.

type AllocGarbageCollector added in v0.5.2

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

AllocGarbageCollector garbage collects terminated allocations on a node

func NewAllocGarbageCollector added in v0.5.2

func NewAllocGarbageCollector(logger *log.Logger, statsCollector stats.NodeStatsCollector, ac AllocCounter, config *GCConfig) *AllocGarbageCollector

NewAllocGarbageCollector returns a garbage collector for terminated allocations on a node. Must call Run() in a goroutine enable periodic garbage collection.

func (*AllocGarbageCollector) Collect added in v0.5.2

func (a *AllocGarbageCollector) Collect(allocID string) error

Collect garbage collects a single allocation on a node

func (*AllocGarbageCollector) CollectAll added in v0.5.2

func (a *AllocGarbageCollector) CollectAll() error

CollectAll garbage collects all termianated allocations on a node

func (*AllocGarbageCollector) MakeRoomFor added in v0.5.2

func (a *AllocGarbageCollector) MakeRoomFor(allocations []*structs.Allocation) error

MakeRoomFor garbage collects enough number of allocations in the terminal state to make room for new allocations

func (*AllocGarbageCollector) MarkForCollection added in v0.5.2

func (a *AllocGarbageCollector) MarkForCollection(ar *AllocRunner)

MarkForCollection starts tracking an allocation for Garbage Collection

func (*AllocGarbageCollector) Remove added in v0.5.2

func (a *AllocGarbageCollector) Remove(ar *AllocRunner)

Remove removes an alloc runner without garbage collecting it

func (*AllocGarbageCollector) Run added in v0.6.0

func (a *AllocGarbageCollector) Run()

Run the periodic garbage collector.

func (*AllocGarbageCollector) Stop added in v0.5.2

func (a *AllocGarbageCollector) Stop()

type AllocRunner

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

AllocRunner is used to wrap an allocation and provide the execution context.

func NewAllocRunner

func NewAllocRunner(logger *log.Logger, config *config.Config, stateDB *bolt.DB, updater AllocStateUpdater,
	alloc *structs.Allocation, vaultClient vaultclient.VaultClient, consulClient ConsulServiceAPI,
	prevAlloc prevAllocWatcher) *AllocRunner

NewAllocRunner is used to create a new allocation context

func (*AllocRunner) Alloc

func (r *AllocRunner) Alloc() *structs.Allocation

Alloc returns the associated allocation

func (*AllocRunner) Destroy

func (r *AllocRunner) Destroy()

Destroy is used to indicate that the allocation context should be destroyed

func (*AllocRunner) DestroyContext

func (r *AllocRunner) DestroyContext() error

DestroyContext is used to destroy the context

func (*AllocRunner) DestroyState

func (r *AllocRunner) DestroyState() error

DestroyState is used to cleanup after ourselves

func (*AllocRunner) GetAllocDir added in v0.5.0

func (r *AllocRunner) GetAllocDir() *allocdir.AllocDir

GetAllocDir returns the alloc dir for the alloc runner

func (*AllocRunner) GetListener added in v0.6.1

func (r *AllocRunner) GetListener() *cstructs.AllocListener

GetListener returns a listener for updates broadcast by this alloc runner. Callers are responsible for calling Close on their Listener.

func (*AllocRunner) IsMigrating added in v0.6.1

func (r *AllocRunner) IsMigrating() bool

IsMigrating returns true if this alloc is migrating data from a previous allocation.

func (*AllocRunner) IsWaiting added in v0.6.1

func (r *AllocRunner) IsWaiting() bool

IsWaiting returns true if this alloc is waiting on a previous allocation to terminate.

func (*AllocRunner) LatestAllocStats added in v0.4.0

func (r *AllocRunner) LatestAllocStats(taskFilter string) (*cstructs.AllocResourceUsage, error)

LatestAllocStats returns the latest allocation stats. If the optional taskFilter is set the allocation stats will only include the given task.

func (*AllocRunner) RestoreState

func (r *AllocRunner) RestoreState() error

RestoreState is used to restore the state of the alloc runner

func (*AllocRunner) Run

func (r *AllocRunner) Run()

Run is a long running goroutine used to manage an allocation

func (*AllocRunner) SaveState

func (r *AllocRunner) SaveState() error

SaveState is used to snapshot the state of the alloc runner if the fullSync is marked as false only the state of the Alloc Runner is snapshotted. If fullSync is marked as true, we snapshot all the Task Runners associated with the Alloc

func (*AllocRunner) StatsReporter added in v0.4.0

func (r *AllocRunner) StatsReporter() AllocStatsReporter

StatsReporter returns an interface to query resource usage statistics of an allocation

func (*AllocRunner) Update

func (r *AllocRunner) Update(update *structs.Allocation)

Update is used to update the allocation of the context

func (*AllocRunner) WaitCh added in v0.1.2

func (r *AllocRunner) WaitCh() <-chan struct{}

WaitCh returns a channel to wait for termination

type AllocStateUpdater

type AllocStateUpdater func(alloc *structs.Allocation)

AllocStateUpdater is used to update the status of an allocation

type AllocStatsReporter added in v0.4.0

type AllocStatsReporter interface {
	LatestAllocStats(taskFilter string) (*cstructs.AllocResourceUsage, error)
}

type Client

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

Client is used to implement the client interaction with Nomad. Clients are expected to register as a schedulable node to the servers, and to run allocations as determined by the servers.

func NewClient

func NewClient(cfg *config.Config, consulCatalog consul.CatalogAPI, consulService ConsulServiceAPI, logger *log.Logger) (*Client, error)

NewClient is used to create a new client from the given configuration

func (*Client) CollectAllAllocs added in v0.5.2

func (c *Client) CollectAllAllocs() error

CollectAllAllocs garbage collects all allocations on a node in the terminal state

func (*Client) CollectAllocation added in v0.5.2

func (c *Client) CollectAllocation(allocID string) error

CollectAllocation garbage collects a single allocation

func (*Client) Datacenter added in v0.4.0

func (c *Client) Datacenter() string

Datacenter returns the datacenter for the given client

func (*Client) GetAllocFS added in v0.3.0

func (c *Client) GetAllocFS(allocID string) (allocdir.AllocDirFS, error)

GetAllocFS returns the AllocFS interface for the alloc dir of an allocation

func (*Client) GetAllocStats added in v0.4.0

func (c *Client) GetAllocStats(allocID string) (AllocStatsReporter, error)

func (*Client) GetClientAlloc added in v0.5.6

func (c *Client) GetClientAlloc(allocID string) (*structs.Allocation, error)

GetClientAlloc returns the allocation from the client

func (*Client) GetServers added in v0.5.0

func (c *Client) GetServers() []string

GetServers returns the list of nomad servers this client is aware of.

func (*Client) LatestHostStats added in v0.4.0

func (c *Client) LatestHostStats() *stats.HostStats

HostStats returns all the stats related to a Nomad client

func (*Client) Leave

func (c *Client) Leave() error

Leave is used to prepare the client to leave the cluster

func (*Client) Node

func (c *Client) Node() *structs.Node

Node returns the locally registered node

func (*Client) NodeID added in v0.7.0

func (c *Client) NodeID() string

NodeID returns the node ID for the given client

func (*Client) NumAllocs added in v0.6.0

func (c *Client) NumAllocs() int

NumAllocs returns the number of allocs this client has. Used to fulfill the AllocCounter interface for the GC.

func (*Client) RPC

func (c *Client) RPC(method string, args interface{}, reply interface{}) error

RPC is used to forward an RPC call to a nomad server, or fail if no servers.

func (*Client) RPCMajorVersion added in v0.4.0

func (c *Client) RPCMajorVersion() int

RPCMajorVersion returns the structs.ApiMajorVersion supported by the client.

func (*Client) RPCMinorVersion added in v0.4.0

func (c *Client) RPCMinorVersion() int

RPCMinorVersion returns the structs.ApiMinorVersion supported by the client.

func (*Client) Region added in v0.4.0

func (c *Client) Region() string

Region returns the region for the given client

func (*Client) ResolveToken added in v0.7.0

func (c *Client) ResolveToken(secretID string) (*acl.ACL, error)

ResolveToken is used to translate an ACL Token Secret ID into an ACL object, nil if ACLs are disabled, or an error.

func (*Client) SetServers

func (c *Client) SetServers(servers []string) error

SetServers sets a new list of nomad servers to connect to. As long as one server is resolvable no error is returned.

func (*Client) Shutdown

func (c *Client) Shutdown() error

Shutdown is used to tear down the client

func (*Client) Stats

func (c *Client) Stats() map[string]map[string]string

Stats is used to return statistics for debugging and insight for various sub-systems

func (*Client) StatsReporter added in v0.4.0

func (c *Client) StatsReporter() ClientStatsReporter

StatsReporter exposes the various APIs related resource usage of a Nomad client

func (*Client) ValidateMigrateToken added in v0.7.0

func (c *Client) ValidateMigrateToken(allocID, migrateToken string) bool

ValidateMigrateToken verifies that a token is for a specific client and allocation, and has been created by a trusted party that has privileged knowledge of the client's secret identifier

type ClientStatsReporter added in v0.4.0

type ClientStatsReporter interface {
	// GetAllocStats returns the AllocStatsReporter for the passed allocation.
	// If it does not exist an error is reported.
	GetAllocStats(allocID string) (AllocStatsReporter, error)

	// LatestHostStats returns the latest resource usage stats for the host
	LatestHostStats() *stats.HostStats
}

ClientStatsReporter exposes all the APIs related to resource usage of a Nomad Client

type ConsulServiceAPI added in v0.6.0

type ConsulServiceAPI interface {
	RegisterTask(allocID string, task *structs.Task, restarter consul.TaskRestarter, exec driver.ScriptExecutor, net *cstructs.DriverNetwork) error
	RemoveTask(allocID string, task *structs.Task)
	UpdateTask(allocID string, existing, newTask *structs.Task, restart consul.TaskRestarter, exec driver.ScriptExecutor, net *cstructs.DriverNetwork) error
	AllocRegistrations(allocID string) (*consul.AllocRegistration, error)
}

ConsulServiceAPI is the interface the Nomad Client uses to register and remove services and checks from Consul.

type GCAlloc added in v0.5.2

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

GCAlloc wraps an allocation runner and an index enabling it to be used within a PQ

type GCAllocPQImpl added in v0.5.2

type GCAllocPQImpl []*GCAlloc

func (GCAllocPQImpl) Len added in v0.5.2

func (pq GCAllocPQImpl) Len() int

func (GCAllocPQImpl) Less added in v0.5.2

func (pq GCAllocPQImpl) Less(i, j int) bool

func (*GCAllocPQImpl) Pop added in v0.5.2

func (pq *GCAllocPQImpl) Pop() interface{}

func (*GCAllocPQImpl) Push added in v0.5.2

func (pq *GCAllocPQImpl) Push(x interface{})

func (GCAllocPQImpl) Swap added in v0.5.2

func (pq GCAllocPQImpl) Swap(i, j int)

type GCConfig added in v0.5.4

type GCConfig struct {
	// MaxAllocs is the maximum number of allocations to track before a GC
	// is triggered.
	MaxAllocs           int
	DiskUsageThreshold  float64
	InodeUsageThreshold float64
	Interval            time.Duration
	ReservedDiskMB      int
	ParallelDestroys    int
}

GCConfig allows changing the behaviour of the garbage collector

type IndexedGCAllocPQ added in v0.5.2

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

IndexedGCAllocPQ is an indexed PQ which maintains a list of allocation runner based on their termination time.

func NewIndexedGCAllocPQ added in v0.5.2

func NewIndexedGCAllocPQ() *IndexedGCAllocPQ

func (*IndexedGCAllocPQ) Length added in v0.5.2

func (i *IndexedGCAllocPQ) Length() int

func (*IndexedGCAllocPQ) Pop added in v0.5.2

func (i *IndexedGCAllocPQ) Pop() *GCAlloc

func (*IndexedGCAllocPQ) Push added in v0.5.2

func (i *IndexedGCAllocPQ) Push(ar *AllocRunner)

Push an alloc runner into the GC queue

func (*IndexedGCAllocPQ) Remove added in v0.5.2

func (i *IndexedGCAllocPQ) Remove(allocID string) (*GCAlloc, error)

type RestartTracker added in v0.3.0

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

func (*RestartTracker) GetReason added in v0.3.2

func (r *RestartTracker) GetReason() string

GetReason returns a human-readable description for the last state returned by GetState.

func (*RestartTracker) GetState added in v0.3.1

func (r *RestartTracker) GetState() (string, time.Duration)

GetState returns the tasks next state given the set exit code and start error. One of the following states are returned:

  • TaskRestarting - Task should be restarted
  • TaskNotRestarting - Task should not be restarted and has exceeded its restart policy.
  • TaskTerminated - Task has terminated successfully and does not need a restart.

If TaskRestarting is returned, the duration is how long to wait until starting the task again.

func (*RestartTracker) SetPolicy added in v0.3.0

func (r *RestartTracker) SetPolicy(policy *structs.RestartPolicy)

SetPolicy updates the policy used to determine restarts.

func (*RestartTracker) SetRestartTriggered added in v0.5.0

func (r *RestartTracker) SetRestartTriggered(failure bool) *RestartTracker

SetRestartTriggered is used to mark that the task has been signalled to be restarted. Setting the failure to true restarts according to the restart policy. When failure is false the task is restarted without considering the restart policy.

func (*RestartTracker) SetStartError added in v0.3.1

func (r *RestartTracker) SetStartError(err error) *RestartTracker

SetStartError is used to mark the most recent start error. If starting was successful the error should be nil.

func (*RestartTracker) SetWaitResult added in v0.3.1

func (r *RestartTracker) SetWaitResult(res *dstructs.WaitResult) *RestartTracker

SetWaitResult is used to mark the most recent wait result.

type SignalEvent added in v0.5.0

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

SignalEvent is a tuple of the signal and the event generating it

type TaskHooks added in v0.5.0

type TaskHooks interface {
	// Restart is used to restart the task
	Restart(source, reason string, failure bool)

	// Signal is used to signal the task
	Signal(source, reason string, s os.Signal) error

	// UnblockStart is used to unblock the starting of the task. This should be
	// called after prestart work is completed
	UnblockStart(source string)

	// Kill is used to kill the task because of the passed error. If fail is set
	// to true, the task is marked as failed
	Kill(source, reason string, fail bool)

	// EmitEvent is used to emit an event to be stored in the tasks events.
	EmitEvent(source, message string)
}

TaskHooks is an interface which provides hooks into the tasks life-cycle

type TaskRunner

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

TaskRunner is used to wrap a task within an allocation and provide the execution context.

func NewTaskRunner

func NewTaskRunner(logger *log.Logger, config *config.Config,
	stateDB *bolt.DB, updater TaskStateUpdater, taskDir *allocdir.TaskDir,
	alloc *structs.Allocation, task *structs.Task,
	vaultClient vaultclient.VaultClient, consulClient ConsulServiceAPI) *TaskRunner

NewTaskRunner is used to create a new task context

func (*TaskRunner) Destroy

func (r *TaskRunner) Destroy(event *structs.TaskEvent)

Destroy is used to indicate that the task context should be destroyed. The event parameter provides a context for the destroy.

func (*TaskRunner) DestroyState

func (r *TaskRunner) DestroyState() error

DestroyState is used to cleanup after ourselves

func (*TaskRunner) EmitEvent added in v0.6.1

func (r *TaskRunner) EmitEvent(source, message string)

func (*TaskRunner) Kill added in v0.5.0

func (r *TaskRunner) Kill(source, reason string, fail bool)

Kill will kill a task and store the error, no longer restarting the task. If fail is set, the task is marked as having failed.

func (*TaskRunner) LatestResourceUsage added in v0.4.0

func (r *TaskRunner) LatestResourceUsage() *cstructs.TaskResourceUsage

LatestResourceUsage returns the last resource utilization datapoint collected

func (*TaskRunner) MarkReceived added in v0.3.2

func (r *TaskRunner) MarkReceived()

MarkReceived marks the task as received.

func (*TaskRunner) Restart added in v0.5.0

func (r *TaskRunner) Restart(source, reason string, failure bool)

Restart will restart the task.

func (*TaskRunner) RestoreState

func (r *TaskRunner) RestoreState() (string, error)

RestoreState is used to restore our state. If a non-empty string is returned the task is restarted with the string as the reason. This is useful for backwards incompatible upgrades that need to restart tasks with a new executor.

func (*TaskRunner) Run

func (r *TaskRunner) Run()

Run is a long running routine used to manage the task

func (*TaskRunner) SaveState

func (r *TaskRunner) SaveState() error

SaveState is used to snapshot our state

func (*TaskRunner) Signal added in v0.5.0

func (r *TaskRunner) Signal(source, reason string, s os.Signal) error

Signal will send a signal to the task

func (*TaskRunner) UnblockStart added in v0.5.0

func (r *TaskRunner) UnblockStart(source string)

UnblockStart unblocks the starting of the task. It currently assumes only consul-template will unblock

func (*TaskRunner) Update

func (r *TaskRunner) Update(update *structs.Allocation)

Update is used to update the task of the context

func (*TaskRunner) WaitCh

func (r *TaskRunner) WaitCh() <-chan struct{}

WaitCh returns a channel to wait for termination

type TaskStateUpdater

type TaskStateUpdater func(taskName, state string, event *structs.TaskEvent, lazySync bool)

TaskStateUpdater is used to signal that tasks state has changed. If lazySync is set the event won't be immediately pushed to the server.

type TaskTemplateManager added in v0.5.0

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

TaskTemplateManager is used to run a set of templates for a given task

func NewTaskTemplateManager added in v0.5.0

func NewTaskTemplateManager(config *TaskTemplateManagerConfig) (*TaskTemplateManager, error)

func (*TaskTemplateManager) Stop added in v0.5.0

func (tm *TaskTemplateManager) Stop()

Stop is used to stop the consul-template runner

type TaskTemplateManagerConfig added in v0.6.1

type TaskTemplateManagerConfig struct {
	// Hooks is used to interact with the task the template manager is being run
	// for
	Hooks TaskHooks

	// Templates is the set of templates we are managing
	Templates []*structs.Template

	// ClientConfig is the Nomad Client configuration
	ClientConfig *config.Config

	// VaultToken is the Vault token for the task.
	VaultToken string

	// TaskDir is the task's directory
	TaskDir string

	// EnvBuilder is the environment variable builder for the task.
	EnvBuilder *env.Builder

	// MaxTemplateEventRate is the maximum rate at which we should emit events.
	MaxTemplateEventRate time.Duration
	// contains filtered or unexported fields
}

TaskTemplateManagerConfig is used to configure an instance of the TaskTemplateManager

func (*TaskTemplateManagerConfig) Validate added in v0.6.1

func (c *TaskTemplateManagerConfig) Validate() error

Validate validates the configuration.

Directories

Path Synopsis
env

Jump to

Keyboard shortcuts

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