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 { return 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 ¶
- func ClusterCheckID(v1, v2 *api.Cluster) bool
- func Matcher(specifiers ...Event) events.MatcherFunc
- func NetworkCheckID(n1, n2 *api.Network) bool
- func NodeCheckID(n1, n2 *api.Node) bool
- func NodeCheckState(n1, n2 *api.Node) bool
- func SecretCheckID(v1, v2 *api.Secret) bool
- func ServiceCheckID(j1, j2 *api.Service) bool
- func TaskCheckID(t1, t2 *api.Task) bool
- func TaskCheckNodeID(t1, t2 *api.Task) bool
- func TaskCheckServiceID(t1, t2 *api.Task) bool
- func TaskCheckStateGreaterThan(t1, t2 *api.Task) bool
- func Watch(queue *watch.Queue, specifiers ...Event) (eventq chan events.Event, cancel func())
- type ClusterCheckFunc
- type Event
- type EventCommit
- type EventCreateCluster
- type EventCreateNetwork
- type EventCreateNode
- type EventCreateSecret
- type EventCreateService
- type EventCreateTask
- type EventDeleteCluster
- type EventDeleteNetwork
- type EventDeleteNode
- type EventDeleteSecret
- type EventDeleteService
- type EventDeleteTask
- type EventUpdateCluster
- type EventUpdateNetwork
- type EventUpdateNode
- type EventUpdateSecret
- type EventUpdateService
- type EventUpdateTask
- type NetworkCheckFunc
- type NodeCheckFunc
- type Proposer
- type SecretCheckFunc
- type ServiceCheckFunc
- type TaskCheckFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClusterCheckID ¶
ClusterCheckID is a ClusterCheckFunc for matching volume IDs.
func Matcher ¶
func Matcher(specifiers ...Event) events.MatcherFunc
Matcher returns an events.Matcher that matches the specifiers with OR logic.
func NetworkCheckID ¶
NetworkCheckID is a NetworkCheckFunc for matching network IDs.
func NodeCheckID ¶
NodeCheckID is a NodeCheckFunc for matching node IDs.
func NodeCheckState ¶
NodeCheckState is a NodeCheckFunc for matching node state.
func SecretCheckID ¶
SecretCheckID is a SecretCheckFunc for matching volume IDs.
func ServiceCheckID ¶
ServiceCheckID is a ServiceCheckFunc for matching service IDs.
func TaskCheckID ¶
TaskCheckID is a TaskCheckFunc for matching task IDs.
func TaskCheckNodeID ¶
TaskCheckNodeID is a TaskCheckFunc for matching node IDs.
func TaskCheckServiceID ¶
TaskCheckServiceID is a TaskCheckFunc for matching service IDs.
func TaskCheckStateGreaterThan ¶
TaskCheckStateGreaterThan is a TaskCheckFunc for checking task state.
func Watch ¶
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 ¶
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 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 EventCreateSecret ¶
type EventCreateSecret struct { Secret *api.Secret // 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 []SecretCheckFunc }
EventCreateSecret is the type used to put CreateSecret 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 EventDeleteSecret ¶
type EventDeleteSecret struct { Secret *api.Secret // 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 []SecretCheckFunc }
EventDeleteSecret is the type used to put DeleteSecret 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 EventUpdateSecret ¶
type EventUpdateSecret struct { Secret *api.Secret // 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 []SecretCheckFunc }
EventUpdateSecret is the type used to put UpdateSecret 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 ¶
NetworkCheckFunc is the type of function used to perform filtering checks on api.Service structures.
type NodeCheckFunc ¶
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 SecretCheckFunc ¶
SecretCheckFunc is the type of function used to perform filtering checks on api.Secret structures.
type ServiceCheckFunc ¶
ServiceCheckFunc is the type of function used to perform filtering checks on api.Service structures.
type TaskCheckFunc ¶
TaskCheckFunc is the type of function used to perform filtering checks on api.Task structures.