agent

package
v0.0.0-...-3e31364 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed is returned when an operation fails because the resource is closed.
	ErrClosed = errors.New("agent: closed")
)

Functions

func DeleteTask

func DeleteTask(tx *bolt.Tx, id string) error

DeleteTask completely removes the task from the database.

func GetTask

func GetTask(tx *bolt.Tx, id string) (*api.Task, error)

GetTask retrieves the task with id from the datastore.

func GetTaskStatus

func GetTaskStatus(tx *bolt.Tx, id string) (*api.TaskStatus, error)

GetTaskStatus returns the current status for the task.

func InitDB

func InitDB(db *bolt.DB) error

InitDB prepares a database for writing task data.

Proper buckets will be created if they don't already exist.

func NewDependencyManager

func NewDependencyManager() exec.DependencyManager

NewDependencyManager creates a dependency manager object that wraps objects which provide access to various dependency types.

func PutTask

func PutTask(tx *bolt.Tx, task *api.Task) error

PutTask places the task into the database.

func PutTaskStatus

func PutTaskStatus(tx *bolt.Tx, id string, status *api.TaskStatus) error

PutTaskStatus updates the status for the task with id.

func Restrict

func Restrict(dependencies exec.DependencyManager, t *api.Task) exec.DependencyGetter

Restrict provides getters that only allows access to the dependencies referenced by the task.

func SetTaskAssignment

func SetTaskAssignment(tx *bolt.Tx, id string, assigned bool) error

SetTaskAssignment sets the current assignment state.

func TaskAssigned

func TaskAssigned(tx *bolt.Tx, id string) bool

TaskAssigned returns true if the task is assigned to the node.

func WalkTaskStatus

func WalkTaskStatus(tx *bolt.Tx, fn func(id string, status *api.TaskStatus) error) error

WalkTaskStatus calls fn for the status of each task.

func WalkTasks

func WalkTasks(tx *bolt.Tx, fn func(task *api.Task) error) error

WalkTasks walks all tasks in the datastore.

Types

type Agent

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

Agent implements the primary node functionality for a member of a swarm cluster. The primary functionality is to run and report on the status of tasks assigned to the node.

func New

func New(config *Config) (*Agent, error)

New returns a new agent, ready for task dispatch.

func (*Agent) Err

func (a *Agent) Err(ctx context.Context) error

Err returns the error that caused the agent to shutdown or nil. Err blocks until the agent is fully shutdown.

func (*Agent) Leave

func (a *Agent) Leave(ctx context.Context) error

Leave instructs the agent to leave the cluster. This method will shutdown assignment processing and remove all assignments from the node. Leave blocks until worker has finished closing all task managers or agent is closed.

func (*Agent) Publisher

func (a *Agent) Publisher(ctx context.Context, subscriptionID string) (exec.LogPublisher, func(), error)

Publisher returns a LogPublisher for the given subscription as well as a cancel function that should be called when the log stream is completed.

func (*Agent) Ready

func (a *Agent) Ready() <-chan struct{}

Ready returns a channel that will be closed when agent first becomes ready.

func (*Agent) ResourceAllocator

func (a *Agent) ResourceAllocator() ResourceAllocator

ResourceAllocator provides an interface to access resource allocation methods such as AttachNetwork and DetachNetwork.

func (*Agent) Start

func (a *Agent) Start(ctx context.Context) error

Start begins execution of the agent in the provided context, if not already started.

Start returns an error if the agent has already started.

func (*Agent) Stop

func (a *Agent) Stop(ctx context.Context) error

Stop shuts down the agent, blocking until full shutdown. If the agent is not started, Stop will block until the agent has fully shutdown.

func (*Agent) UpdateTaskStatus

func (a *Agent) UpdateTaskStatus(ctx context.Context, taskID string, status *api.TaskStatus) error

UpdateTaskStatus attempts to send a task status update over the current session, blocking until the operation is completed.

If an error is returned, the operation should be retried.

type Config

type Config struct {
	// Hostname the name of host for agent instance.
	Hostname string

	// ConnBroker provides a connection broker for retrieving gRPC
	// connections to managers.
	ConnBroker *connectionbroker.Broker

	// Executor specifies the executor to use for the agent.
	Executor exec.Executor

	// DB used for task storage. Must be open for the lifetime of the agent.
	DB *bolt.DB

	// NotifyNodeChange channel receives new node changes from session messages.
	NotifyNodeChange chan<- *NodeChanges

	// NotifyTLSChange channel sends new TLS information changes, which can cause a session to restart
	NotifyTLSChange <-chan events.Event

	// Credentials is credentials for grpc connection to manager.
	Credentials credentials.TransportCredentials

	// NodeTLSInfo contains the starting node TLS info to bootstrap into the agent
	NodeTLSInfo *api.NodeTLSInfo

	// SessionTracker, if provided, will have its SessionClosed and SessionError methods called
	// when sessions close and error.
	SessionTracker SessionTracker

	// FIPS returns whether the node is FIPS-enabled
	FIPS bool
}

Config provides values for an Agent.

type NodeChanges

type NodeChanges struct {
	Node     *api.Node
	RootCert []byte
}

NodeChanges encapsulates changes that should be made to the node as per session messages from the dispatcher

type ResourceAllocator

type ResourceAllocator interface {
	// AttachNetwork creates a network attachment in the manager
	// given a target network and a unique ID representing the
	// connecting entity and optionally a list of ipv4/ipv6
	// addresses to be assigned to the attachment. AttachNetwork
	// returns a unique ID for the attachment if successful or an
	// error in case of failure.
	AttachNetwork(ctx context.Context, id, target string, addresses []string) (string, error)

	// DetachNetworks deletes a network attachment for the passed
	// attachment ID. The attachment ID is obtained from a
	// previous AttachNetwork call.
	DetachNetwork(ctx context.Context, aID string) error
}

ResourceAllocator is an interface to allocate resource such as network attachments from a worker node.

type SessionTracker

type SessionTracker interface {
	// SessionClosed is called whenever a session is closed - if the function errors, the agent
	// will exit with the returned error.  Otherwise the agent can continue and rebuild a new session.
	SessionClosed() error

	// SessionError is called whenever a session errors
	SessionError(err error)

	// SessionEstablished is called whenever a session is established
	SessionEstablished()
}

A SessionTracker gets notified when sessions close and error

type StatusReporter

type StatusReporter interface {
	UpdateTaskStatus(ctx context.Context, taskID string, status *api.TaskStatus) error
}

StatusReporter receives updates to task status. Method may be called concurrently, so implementations should be goroutine-safe.

type Worker

type Worker interface {
	// Init prepares the worker for task assignment.
	Init(ctx context.Context) error

	// Close performs worker cleanup when no longer needed.
	//
	// It is not safe to call any worker function after that.
	Close()

	// Assign assigns a complete set of tasks and configs/secrets to a
	// worker. Any items not included in this set will be removed.
	Assign(ctx context.Context, assignments []*api.AssignmentChange) error

	// Updates updates an incremental set of tasks or configs/secrets of
	// the worker. Any items not included either in added or removed will
	// remain untouched.
	Update(ctx context.Context, assignments []*api.AssignmentChange) error

	// Listen to updates about tasks controlled by the worker. When first
	// called, the reporter will receive all updates for all tasks controlled
	// by the worker.
	//
	// The listener will be removed if the context is cancelled.
	Listen(ctx context.Context, reporter StatusReporter)

	// Report resends the status of all tasks controlled by this worker.
	Report(ctx context.Context, reporter StatusReporter)

	// Subscribe to log messages matching the subscription.
	Subscribe(ctx context.Context, subscription *api.SubscriptionMessage) error

	// Wait blocks until all task managers have closed
	Wait(ctx context.Context) error
}

Worker implements the core task management logic and persistence. It coordinates the set of assignments with the executor.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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