state

package
v0.0.0-...-92c8ec3 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2016 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package state provides interfaces to work with swarm cluster state.

The primary interface is Store, which abstracts storage of this cluster state. Store exposes a transactional interface for both reads and writes. To perform a read transaction, View accepts a callback function that it will invoke with a ReadTx object that gives it a consistent view of the state. Similarly, Update accepts a callback function that it will invoke with a Tx object that allows reads and writes to happen without interference from other transactions.

This is an example of making an update to a Store:

err := store.Update(func(tx state.Tx) {
	if err := tx.Nodes().Update(newNode); err != nil {
		reutrn err
	}
	return nil
})
if err != nil {
	return fmt.Errorf("transaction failed: %v", err)
}

WatchableStore is a version of Store that exposes watch functionality. These expose a publish/subscribe queue where code can subscribe to changes of interest. This can be combined with the ViewAndWatch function to "fork" a store, by making a snapshot and then applying future changes to keep the copy in sync. This approach lets consumers of the data use their own data structures and implement their own concurrency strategies. It can lead to more efficient code because data consumers don't necessarily have to lock the main data store if they are maintaining their own copies of the state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClusterCheckID

func ClusterCheckID(v1, v2 *api.Cluster) bool

ClusterCheckID is a ClusterCheckFunc for matching volume IDs.

func NetworkCheckID

func NetworkCheckID(n1, n2 *api.Network) bool

NetworkCheckID is a NetworkCheckFunc for matching network IDs.

func NodeCheckID

func NodeCheckID(n1, n2 *api.Node) bool

NodeCheckID is a NodeCheckFunc for matching node IDs.

func NodeCheckState

func NodeCheckState(n1, n2 *api.Node) bool

NodeCheckState is a NodeCheckFunc for matching node state.

func ServiceCheckID

func ServiceCheckID(j1, j2 *api.Service) bool

ServiceCheckID is a ServiceCheckFunc for matching service IDs.

func TaskCheckID

func TaskCheckID(t1, t2 *api.Task) bool

TaskCheckID is a TaskCheckFunc for matching task IDs.

func TaskCheckNodeID

func TaskCheckNodeID(t1, t2 *api.Task) bool

TaskCheckNodeID is a TaskCheckFunc for matching node IDs.

func TaskCheckStateGreaterThan

func TaskCheckStateGreaterThan(t1, t2 *api.Task) bool

TaskCheckStateGreaterThan is a TaskCheckFunc for checking task state.

func Watch

func Watch(queue *watch.Queue, specifiers ...Event) (eventq chan events.Event, cancel func())

Watch takes a variable number of events to match against. The subscriber will receive events that match any of the arguments passed to Watch.

Examples:

// subscribe to all events Watch(q)

// subscribe to all UpdateTask events Watch(q, EventUpdateTask{})

// subscribe to all task-related events Watch(q, EventUpdateTask{}, EventCreateTask{}, EventDeleteTask{})

// subscribe to UpdateTask for node 123 Watch(q, EventUpdateTask{Task: &api.Task{NodeID: 123},

Checks: []TaskCheckFunc{TaskCheckNodeID}})

// subscribe to UpdateTask for node 123, as well as CreateTask // for node 123 that also has ServiceID set to "abc" Watch(q, EventUpdateTask{Task: &api.Task{NodeID: 123},

                Checks: []TaskCheckFunc{TaskCheckNodeID}},
EventCreateTask{Task: &api.Task{NodeID: 123, ServiceID: "abc"},
                Checks: []TaskCheckFunc{TaskCheckNodeID,
                                        func(t1, t2 *api.Task) bool {
                                                return t1.ServiceID == t2.ServiceID
                                        }}})

Types

type ClusterCheckFunc

type ClusterCheckFunc func(v1, v2 *api.Cluster) bool

ClusterCheckFunc is the type of function used to perform filtering checks on api.Cluster structures.

type Event

type Event interface {
	// contains filtered or unexported methods
}

Event is the type used for events passed over watcher channels, and also the type used to specify filtering in calls to Watch.

type EventCommit

type EventCommit struct{}

EventCommit delineates a transaction boundary.

type EventCreateCluster

type EventCreateCluster struct {
	Cluster *api.Cluster
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []ClusterCheckFunc
}

EventCreateCluster is the type used to put CreateCluster events on the publish/subscribe queue and filter these events in calls to Watch.

type EventCreateNetwork

type EventCreateNetwork struct {
	Network *api.Network
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []NetworkCheckFunc
}

EventCreateNetwork is the type used to put CreateNetwork events on the publish/subscribe queue and filter these events in calls to Watch.

type EventCreateNode

type EventCreateNode struct {
	Node *api.Node
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []NodeCheckFunc
}

EventCreateNode is the type used to put CreateNode events on the publish/subscribe queue and filter these events in calls to Watch.

type EventCreateService

type EventCreateService struct {
	Service *api.Service
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []ServiceCheckFunc
}

EventCreateService is the type used to put CreateService events on the publish/subscribe queue and filter these events in calls to Watch.

type EventCreateTask

type EventCreateTask struct {
	Task *api.Task
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []TaskCheckFunc
}

EventCreateTask is the type used to put CreateTask events on the publish/subscribe queue and filter these events in calls to Watch.

type EventDeleteCluster

type EventDeleteCluster struct {
	Cluster *api.Cluster
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []ClusterCheckFunc
}

EventDeleteCluster is the type used to put DeleteCluster events on the publish/subscribe queue and filter these events in calls to Watch.

type EventDeleteNetwork

type EventDeleteNetwork struct {
	Network *api.Network
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []NetworkCheckFunc
}

EventDeleteNetwork is the type used to put DeleteNetwork events on the publish/subscribe queue and filter these events in calls to Watch.

type EventDeleteNode

type EventDeleteNode struct {
	Node *api.Node
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []NodeCheckFunc
}

EventDeleteNode is the type used to put DeleteNode events on the publish/subscribe queue and filter these events in calls to Watch.

type EventDeleteService

type EventDeleteService struct {
	Service *api.Service
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []ServiceCheckFunc
}

EventDeleteService is the type used to put DeleteService events on the publish/subscribe queue and filter these events in calls to Watch.

type EventDeleteTask

type EventDeleteTask struct {
	Task *api.Task
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []TaskCheckFunc
}

EventDeleteTask is the type used to put DeleteTask events on the publish/subscribe queue and filter these events in calls to Watch.

type EventUpdateCluster

type EventUpdateCluster struct {
	Cluster *api.Cluster
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []ClusterCheckFunc
}

EventUpdateCluster is the type used to put UpdateCluster events on the publish/subscribe queue and filter these events in calls to Watch.

type EventUpdateNetwork

type EventUpdateNetwork struct {
	Network *api.Network
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []NetworkCheckFunc
}

EventUpdateNetwork is the type used to put UpdateNetwork events on the publish/subscribe queue and filter these events in calls to Watch.

type EventUpdateNode

type EventUpdateNode struct {
	Node *api.Node
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []NodeCheckFunc
}

EventUpdateNode is the type used to put DeleteNode events on the publish/subscribe queue and filter these events in calls to Watch.

type EventUpdateService

type EventUpdateService struct {
	Service *api.Service
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []ServiceCheckFunc
}

EventUpdateService is the type used to put UpdateService events on the publish/subscribe queue and filter these events in calls to Watch.

type EventUpdateTask

type EventUpdateTask struct {
	Task *api.Task
	// Checks is a list of functions to call to filter events for a watch
	// stream. They are applied with AND logic. They are only applicable for
	// calls to Watch.
	Checks []TaskCheckFunc
}

EventUpdateTask is the type used to put UpdateTask events on the publish/subscribe queue and filter these events in calls to Watch.

type NetworkCheckFunc

type NetworkCheckFunc func(n1, n2 *api.Network) bool

NetworkCheckFunc is the type of function used to perform filtering checks on api.Service structures.

type NodeCheckFunc

type NodeCheckFunc func(n1, n2 *api.Node) bool

NodeCheckFunc is the type of function used to perform filtering checks on api.Service structures.

type Proposer

type Proposer interface {
	// ProposeValue adds storeAction to the distributed log. If this
	// completes successfully, ProposeValue calls cb to commit the
	// proposed changes. The callback is necessary for the Proposer to make
	// sure that the changes are committed before it interacts further
	// with the store.
	ProposeValue(ctx context.Context, storeAction []*api.StoreAction, cb func()) error
	GetVersion() *api.Version
}

A Proposer can propose actions to a cluster.

type ServiceCheckFunc

type ServiceCheckFunc func(j1, j2 *api.Service) bool

ServiceCheckFunc is the type of function used to perform filtering checks on api.Service structures.

type TaskCheckFunc

type TaskCheckFunc func(t1, t2 *api.Task) bool

TaskCheckFunc is the type of function used to perform filtering checks on api.Task structures.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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