github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/worker/uniter/operation/failaction.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package operation 5 6 import ( 7 "fmt" 8 ) 9 10 type failAction struct { 11 actionId string 12 callbacks Callbacks 13 name string 14 RequiresMachineLock 15 } 16 17 // String is part of the Operation interface. 18 func (fa *failAction) String() string { 19 return fmt.Sprintf("fail action %s", fa.actionId) 20 } 21 22 // Prepare is part of the Operation interface. 23 func (fa *failAction) Prepare(state State) (*State, error) { 24 return stateChange{ 25 Kind: RunAction, 26 Step: Pending, 27 ActionId: &fa.actionId, 28 Hook: state.Hook, 29 }.apply(state), nil 30 } 31 32 // Execute is part of the Operation interface. 33 func (fa *failAction) Execute(state State) (*State, error) { 34 if err := fa.callbacks.FailAction(fa.actionId, "action terminated"); err != nil { 35 return nil, err 36 } 37 38 return stateChange{ 39 Kind: RunAction, 40 Step: Done, 41 ActionId: &fa.actionId, 42 Hook: state.Hook, 43 }.apply(state), nil 44 } 45 46 // Commit preserves the recorded hook, and returns a neutral state. 47 // Commit is part of the Operation interface. 48 func (fa *failAction) Commit(state State) (*State, error) { 49 return stateChange{ 50 Kind: continuationKind(state), 51 Step: Pending, 52 Hook: state.Hook, 53 }.apply(state), nil 54 }