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