本文整理匯總了Golang中github.com/docker/swarmkit/api.StoreAction類的典型用法代碼示例。如果您正苦於以下問題:Golang StoreAction類的具體用法?Golang StoreAction怎麽用?Golang StoreAction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了StoreAction類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
func init() {
register(ObjectStoreConfig{
Name: tableNode,
Table: &memdb.TableSchema{
Name: tableNode,
Indexes: map[string]*memdb.IndexSchema{
indexID: {
Name: indexID,
Unique: true,
Indexer: nodeIndexerByID{},
},
// TODO(aluzzardi): Use `indexHostname` instead.
indexName: {
Name: indexName,
AllowMissing: true,
Indexer: nodeIndexerByHostname{},
},
indexRole: {
Name: indexRole,
Indexer: nodeIndexerByRole{},
},
indexMembership: {
Name: indexMembership,
Indexer: nodeIndexerByMembership{},
},
},
},
Save: func(tx ReadTx, snapshot *api.StoreSnapshot) error {
var err error
snapshot.Nodes, err = FindNodes(tx, All)
return err
},
Restore: func(tx Tx, snapshot *api.StoreSnapshot) error {
nodes, err := FindNodes(tx, All)
if err != nil {
return err
}
for _, n := range nodes {
if err := DeleteNode(tx, n.ID); err != nil {
return err
}
}
for _, n := range snapshot.Nodes {
if err := CreateNode(tx, n); err != nil {
return err
}
}
return nil
},
ApplyStoreAction: func(tx Tx, sa *api.StoreAction) error {
switch v := sa.Target.(type) {
case *api.StoreAction_Node:
obj := v.Node
switch sa.Action {
case api.StoreActionKindCreate:
return CreateNode(tx, obj)
case api.StoreActionKindUpdate:
return UpdateNode(tx, obj)
case api.StoreActionKindRemove:
return DeleteNode(tx, obj.ID)
}
}
return errUnknownStoreAction
},
NewStoreAction: func(c state.Event) (api.StoreAction, error) {
var sa api.StoreAction
switch v := c.(type) {
case state.EventCreateNode:
sa.Action = api.StoreActionKindCreate
sa.Target = &api.StoreAction_Node{
Node: v.Node,
}
case state.EventUpdateNode:
sa.Action = api.StoreActionKindUpdate
sa.Target = &api.StoreAction_Node{
Node: v.Node,
}
case state.EventDeleteNode:
sa.Action = api.StoreActionKindRemove
sa.Target = &api.StoreAction_Node{
Node: v.Node,
}
default:
return api.StoreAction{}, errUnknownStoreAction
}
return sa, nil
},
})
}
示例2: init
func init() {
register(ObjectStoreConfig{
Name: tableNetwork,
Table: &memdb.TableSchema{
Name: tableNetwork,
Indexes: map[string]*memdb.IndexSchema{
indexID: {
Name: indexID,
Unique: true,
Indexer: networkIndexerByID{},
},
indexName: {
Name: indexName,
Unique: true,
Indexer: networkIndexerByName{},
},
},
},
Save: func(tx ReadTx, snapshot *api.StoreSnapshot) error {
var err error
snapshot.Networks, err = FindNetworks(tx, All)
return err
},
Restore: func(tx Tx, snapshot *api.StoreSnapshot) error {
networks, err := FindNetworks(tx, All)
if err != nil {
return err
}
for _, n := range networks {
if err := DeleteNetwork(tx, n.ID); err != nil {
return err
}
}
for _, n := range snapshot.Networks {
if err := CreateNetwork(tx, n); err != nil {
return err
}
}
return nil
},
ApplyStoreAction: func(tx Tx, sa *api.StoreAction) error {
switch v := sa.Target.(type) {
case *api.StoreAction_Network:
obj := v.Network
switch sa.Action {
case api.StoreActionKindCreate:
return CreateNetwork(tx, obj)
case api.StoreActionKindUpdate:
return UpdateNetwork(tx, obj)
case api.StoreActionKindRemove:
return DeleteNetwork(tx, obj.ID)
}
}
return errUnknownStoreAction
},
NewStoreAction: func(c state.Event) (api.StoreAction, error) {
var sa api.StoreAction
switch v := c.(type) {
case state.EventCreateNetwork:
sa.Action = api.StoreActionKindCreate
sa.Target = &api.StoreAction_Network{
Network: v.Network,
}
case state.EventUpdateNetwork:
sa.Action = api.StoreActionKindUpdate
sa.Target = &api.StoreAction_Network{
Network: v.Network,
}
case state.EventDeleteNetwork:
sa.Action = api.StoreActionKindRemove
sa.Target = &api.StoreAction_Network{
Network: v.Network,
}
default:
return api.StoreAction{}, errUnknownStoreAction
}
return sa, nil
},
})
}
示例3: init
func init() {
register(ObjectStoreConfig{
Name: tableTask,
Table: &memdb.TableSchema{
Name: tableTask,
Indexes: map[string]*memdb.IndexSchema{
indexID: {
Name: indexID,
Unique: true,
Indexer: taskIndexerByID{},
},
indexName: {
Name: indexName,
AllowMissing: true,
Indexer: taskIndexerByName{},
},
indexServiceID: {
Name: indexServiceID,
AllowMissing: true,
Indexer: taskIndexerByServiceID{},
},
indexNodeID: {
Name: indexNodeID,
AllowMissing: true,
Indexer: taskIndexerByNodeID{},
},
indexSlot: {
Name: indexSlot,
AllowMissing: true,
Indexer: taskIndexerBySlot{},
},
indexDesiredState: {
Name: indexDesiredState,
Indexer: taskIndexerByDesiredState{},
},
},
},
Save: func(tx ReadTx, snapshot *api.StoreSnapshot) error {
var err error
snapshot.Tasks, err = FindTasks(tx, All)
return err
},
Restore: func(tx Tx, snapshot *api.StoreSnapshot) error {
tasks, err := FindTasks(tx, All)
if err != nil {
return err
}
for _, t := range tasks {
if err := DeleteTask(tx, t.ID); err != nil {
return err
}
}
for _, t := range snapshot.Tasks {
if err := CreateTask(tx, t); err != nil {
return err
}
}
return nil
},
ApplyStoreAction: func(tx Tx, sa *api.StoreAction) error {
switch v := sa.Target.(type) {
case *api.StoreAction_Task:
obj := v.Task
switch sa.Action {
case api.StoreActionKindCreate:
return CreateTask(tx, obj)
case api.StoreActionKindUpdate:
return UpdateTask(tx, obj)
case api.StoreActionKindRemove:
return DeleteTask(tx, obj.ID)
}
}
return errUnknownStoreAction
},
NewStoreAction: func(c state.Event) (api.StoreAction, error) {
var sa api.StoreAction
switch v := c.(type) {
case state.EventCreateTask:
sa.Action = api.StoreActionKindCreate
sa.Target = &api.StoreAction_Task{
Task: v.Task,
}
case state.EventUpdateTask:
sa.Action = api.StoreActionKindUpdate
sa.Target = &api.StoreAction_Task{
Task: v.Task,
}
case state.EventDeleteTask:
sa.Action = api.StoreActionKindRemove
sa.Target = &api.StoreAction_Task{
Task: v.Task,
}
default:
return api.StoreAction{}, errUnknownStoreAction
}
return sa, nil
},
})
}