github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/worker/uniter/op_plumbing.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package uniter 5 6 import ( 7 "github.com/juju/names" 8 "gopkg.in/juju/charm.v5" 9 "gopkg.in/juju/charm.v5/hooks" 10 11 "github.com/juju/juju/worker/uniter/hook" 12 "github.com/juju/juju/worker/uniter/operation" 13 ) 14 15 // creator exists primarily to make the implementation of the Mode funcs more 16 // readable -- the general pattern is to switch to get a creator func (which 17 // doesn't allow for the possibility of error) and then to pass the chosen 18 // creator down to runOperation (which can then consistently create and run 19 // all the operations in the same way). 20 type creator func(factory operation.Factory) (operation.Operation, error) 21 22 // The following creator functions are all just dumb plumbing to support the 23 // Mode funcs. 24 25 func newInstallOp(charmURL *charm.URL) creator { 26 return func(factory operation.Factory) (operation.Operation, error) { 27 return factory.NewInstall(charmURL) 28 } 29 } 30 31 func newUpgradeOp(charmURL *charm.URL) creator { 32 return func(factory operation.Factory) (operation.Operation, error) { 33 return factory.NewUpgrade(charmURL) 34 } 35 } 36 37 func newRevertUpgradeOp(charmURL *charm.URL) creator { 38 return func(factory operation.Factory) (operation.Operation, error) { 39 return factory.NewRevertUpgrade(charmURL) 40 } 41 } 42 43 func newResolvedUpgradeOp(charmURL *charm.URL) creator { 44 return func(factory operation.Factory) (operation.Operation, error) { 45 return factory.NewResolvedUpgrade(charmURL) 46 } 47 } 48 49 func newSimpleRunHookOp(kind hooks.Kind) creator { 50 return func(factory operation.Factory) (operation.Operation, error) { 51 return factory.NewRunHook(hook.Info{Kind: kind}) 52 } 53 } 54 55 func newRunHookOp(hookInfo hook.Info) creator { 56 return func(factory operation.Factory) (operation.Operation, error) { 57 return factory.NewRunHook(hookInfo) 58 } 59 } 60 61 func newRetryHookOp(hookInfo hook.Info) creator { 62 return func(factory operation.Factory) (operation.Operation, error) { 63 return factory.NewRetryHook(hookInfo) 64 } 65 } 66 67 func newSkipHookOp(hookInfo hook.Info) creator { 68 return func(factory operation.Factory) (operation.Operation, error) { 69 return factory.NewSkipHook(hookInfo) 70 } 71 } 72 73 func newCommandsOp(args operation.CommandArgs, sendResponse operation.CommandResponseFunc) creator { 74 return func(factory operation.Factory) (operation.Operation, error) { 75 return factory.NewCommands(args, sendResponse) 76 } 77 } 78 79 func newActionOp(actionId string) creator { 80 return func(factory operation.Factory) (operation.Operation, error) { 81 return factory.NewAction(actionId) 82 } 83 } 84 85 func newUpdateRelationsOp(ids []int) creator { 86 return func(factory operation.Factory) (operation.Operation, error) { 87 return factory.NewUpdateRelations(ids) 88 } 89 } 90 91 func newUpdateStorageOp(tags []names.StorageTag) creator { 92 return func(factory operation.Factory) (operation.Operation, error) { 93 return factory.NewUpdateStorage(tags) 94 } 95 } 96 97 func newAcceptLeadershipOp() creator { 98 return func(factory operation.Factory) (operation.Operation, error) { 99 return factory.NewAcceptLeadership() 100 } 101 } 102 103 func newResignLeadershipOp() creator { 104 return func(factory operation.Factory) (operation.Operation, error) { 105 return factory.NewResignLeadership() 106 } 107 }