agent

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2016 License: Apache-2.0 Imports: 29 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 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 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 id 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) Ready

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

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

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.

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 Started.

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

	// Managers provides the manager backend used by the agent. It will be
	// updated with managers weights as observed by the agent.
	Managers picker.Remotes

	// Conn specifies the client connection Agent will use.
	Conn *grpc.ClientConn

	// Picker is the picker used by Conn.
	// TODO(aaronl): This is only part of the config to allow resetting the
	// GRPC connection. This should be refactored to address the coupling
	// between Conn and Picker.
	Picker *picker.Picker

	// 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

	// NotifyRoleChange channel receives new roles from session messages.
	NotifyRoleChange chan<- api.NodeRole
}

Config provides values for an Agent.

type Node

type Node struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Node implements the primary node functionality for a member of a swarm cluster. Node handles workloads and may also run as a manager.

func NewNode

func NewNode(c *NodeConfig) (*Node, error)

NewNode returns new Node instance.

func (*Node) Agent

func (n *Node) Agent() *Agent

Agent returns agent instance started by node. May be nil.

func (*Node) CertificateRequested

func (n *Node) CertificateRequested() <-chan struct{}

CertificateRequested returns a channel that is closed after node has requested a certificate. After this call a caller can expect calls to NodeID() and `NodeMembership()` to succeed.

func (*Node) Err

func (n *Node) Err(ctx context.Context) error

Err returns the error that caused the node to shutdown or nil. Err blocks until the node has fully shut down.

func (*Node) ListenControlSocket

func (n *Node) ListenControlSocket(ctx context.Context) <-chan *grpc.ClientConn

ListenControlSocket listens changes of a connection for managing the cluster control api

func (*Node) Manager

func (n *Node) Manager() *manager.Manager

Manager returns manager instance started by node. May be nil.

func (*Node) NodeID

func (n *Node) NodeID() string

NodeID returns current node's ID. May be empty if not set.

func (*Node) NodeMembership

func (n *Node) NodeMembership() api.NodeSpec_Membership

NodeMembership returns current node's membership. May be empty if not set.

func (*Node) Ready

func (n *Node) Ready() <-chan struct{}

Ready returns a channel that is closed after node's initialization has completes for the first time.

func (*Node) Remotes

func (n *Node) Remotes() []api.Peer

Remotes returns a list of known peers known to node.

func (*Node) Start

func (n *Node) Start(ctx context.Context) error

Start starts a node instance.

func (*Node) Stop

func (n *Node) Stop(ctx context.Context) error

Stop stops node execution

type NodeConfig

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

	// JoinAddr specifies node that should be used for the initial connection to
	// other manager in cluster. This should be only one address and optional,
	// the actual remotes come from the stored state.
	JoinAddr string

	// StateDir specifies the directory the node uses to keep the state of the
	// remote managers and certificates.
	StateDir string

	// JoinToken is the token to be used on the first certificate request.
	JoinToken string

	// ExternalCAs is a list of CAs to which a manager node
	// will make certificate signing requests for node certificates.
	ExternalCAs []*api.ExternalCA

	// ForceNewCluster creates a new cluster from current raft state.
	ForceNewCluster bool

	// ListenControlAPI specifies address the control API should listen on.
	ListenControlAPI string

	// ListenRemoteAPI specifies the address for the remote API that agents
	// and raft members connect to.
	ListenRemoteAPI string

	// AdvertiseRemoteAPI specifies the address that should be advertised
	// for connections to the remote API (including the raft service).
	AdvertiseRemoteAPI string

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

	// ElectionTick defines the amount of ticks needed without
	// leader to trigger a new election
	ElectionTick uint32

	// HeartbeatTick defines the amount of ticks between each
	// heartbeat sent to other members for health-check purposes
	HeartbeatTick uint32
}

NodeConfig provides values for a Node.

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

	// Assign the set of tasks to the worker. Tasks outside of this set will be
	// removed.
	Assign(ctx context.Context, tasks []*api.Task) 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)
}

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