github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/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 "gopkg.in/juju/charm.v4" 8 "gopkg.in/juju/charm.v4/hooks" 9 10 "github.com/juju/juju/worker/uniter/hook" 11 "github.com/juju/juju/worker/uniter/operation" 12 ) 13 14 // creator exists primarily to make the implementation of the Mode funcs more 15 // readable -- the general pattern is to switch to get a creator func (which 16 // doesn't allow for the possibility of error) and then to pass the chosen 17 // creator down to runOperation (which can then consistently create and run 18 // all the operations in the same way). 19 type creator func(factory operation.Factory) (operation.Operation, error) 20 21 // The following creator functions are all just dumb plumbing to support the 22 // Mode funcs. 23 24 func newInstallOp(charmURL *charm.URL) creator { 25 return func(factory operation.Factory) (operation.Operation, error) { 26 return factory.NewInstall(charmURL) 27 } 28 } 29 30 func newUpgradeOp(charmURL *charm.URL) creator { 31 return func(factory operation.Factory) (operation.Operation, error) { 32 return factory.NewUpgrade(charmURL) 33 } 34 } 35 36 func newRevertUpgradeOp(charmURL *charm.URL) creator { 37 return func(factory operation.Factory) (operation.Operation, error) { 38 return factory.NewRevertUpgrade(charmURL) 39 } 40 } 41 42 func newResolvedUpgradeOp(charmURL *charm.URL) creator { 43 return func(factory operation.Factory) (operation.Operation, error) { 44 return factory.NewResolvedUpgrade(charmURL) 45 } 46 } 47 48 func newSimpleRunHookOp(kind hooks.Kind) creator { 49 return func(factory operation.Factory) (operation.Operation, error) { 50 return factory.NewRunHook(hook.Info{Kind: kind}) 51 } 52 } 53 54 func newRunHookOp(hookInfo hook.Info) creator { 55 return func(factory operation.Factory) (operation.Operation, error) { 56 return factory.NewRunHook(hookInfo) 57 } 58 } 59 60 func newRetryHookOp(hookInfo hook.Info) creator { 61 return func(factory operation.Factory) (operation.Operation, error) { 62 return factory.NewRetryHook(hookInfo) 63 } 64 } 65 66 func newSkipHookOp(hookInfo hook.Info) creator { 67 return func(factory operation.Factory) (operation.Operation, error) { 68 return factory.NewSkipHook(hookInfo) 69 } 70 } 71 72 func newCommandsOp(args operation.CommandArgs, sendResponse operation.CommandResponseFunc) creator { 73 return func(factory operation.Factory) (operation.Operation, error) { 74 return factory.NewCommands(args, sendResponse) 75 } 76 } 77 78 func newActionOp(actionId string) creator { 79 return func(factory operation.Factory) (operation.Operation, error) { 80 return factory.NewAction(actionId) 81 } 82 } 83 84 func newUpdateRelationsOp(ids []int) creator { 85 return func(factory operation.Factory) (operation.Operation, error) { 86 return factory.NewUpdateRelations(ids) 87 } 88 }