Documentation ¶
Index ¶
- Variables
- func DeleteTask(tx *bolt.Tx, id string) error
- func GetTask(tx *bolt.Tx, id string) (*api.Task, error)
- func GetTaskStatus(tx *bolt.Tx, id string) (*api.TaskStatus, error)
- func InitDB(db *bolt.DB) error
- func PutTask(tx *bolt.Tx, task *api.Task) error
- func PutTaskStatus(tx *bolt.Tx, id string, status *api.TaskStatus) error
- func SetTaskAssignment(tx *bolt.Tx, id string, assigned bool) error
- func TaskAssigned(tx *bolt.Tx, id string) bool
- func WalkTaskStatus(tx *bolt.Tx, fn func(id string, status *api.TaskStatus) error) error
- func WalkTasks(tx *bolt.Tx, fn func(task *api.Task) error) error
- type Agent
- type Config
- type Node
- func (n *Node) Agent() *Agent
- func (n *Node) CertificateRequested() <-chan struct{}
- func (n *Node) Err(ctx context.Context) error
- func (n *Node) ListenControlSocket(ctx context.Context) <-chan *grpc.ClientConn
- func (n *Node) Manager() *manager.Manager
- func (n *Node) NodeID() string
- func (n *Node) NodeMembership() api.NodeSpec_Membership
- func (n *Node) Ready() <-chan struct{}
- func (n *Node) Remotes() []api.Peer
- func (n *Node) Start(ctx context.Context) error
- func (n *Node) Stop(ctx context.Context) error
- type NodeConfig
- type StatusReporter
- type Worker
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClosed is returned when an operation fails because the resource is closed. ErrClosed = errors.New("agent: closed") )
Functions ¶
func DeleteTask ¶
DeleteTask completely removes the task from the database.
func GetTaskStatus ¶
GetTaskStatus returns the current status for the task.
func InitDB ¶
InitDB prepares a database for writing task data.
Proper buckets will be created if they don't already exist.
func PutTaskStatus ¶
PutTaskStatus updates the status for the task with id.
func SetTaskAssignment ¶
SetTaskAssignment sets the current assignment state.
func TaskAssigned ¶
TaskAssigned returns true if the task is assigned to the node.
func WalkTaskStatus ¶
WalkTaskStatus calls fn for the status of each task.
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 (*Agent) Err ¶
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 ¶
Start begins execution of the agent in the provided context, if not already started.
func (*Agent) Stop ¶
Stop shuts down the agent, blocking until full shutdown. If the agent is not started, Stop will block until Started.
func (*Agent) UpdateTaskStatus ¶
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 ¶
Node implements the primary node functionality for a member of a swarm cluster. Node handles workloads and may also run as a manager.
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 ¶
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) 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.
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.