~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/uniter/operation/failaction.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}