github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/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  	"github.com/juju/juju/worker/uniter/remotestate"
    10  )
    11  
    12  type failAction struct {
    13  	actionId  string
    14  	callbacks Callbacks
    15  	RequiresMachineLock
    16  }
    17  
    18  // String is part of the Operation interface.
    19  func (fa *failAction) String() string {
    20  	return fmt.Sprintf("fail action %s", fa.actionId)
    21  }
    22  
    23  // Prepare is part of the Operation interface.
    24  func (fa *failAction) Prepare(state State) (*State, error) {
    25  	return stateChange{
    26  		Kind:     RunAction,
    27  		Step:     Pending,
    28  		ActionId: &fa.actionId,
    29  		Hook:     state.Hook,
    30  	}.apply(state), nil
    31  }
    32  
    33  // Execute is part of the Operation interface.
    34  func (fa *failAction) Execute(state State) (*State, error) {
    35  	if err := fa.callbacks.FailAction(fa.actionId, "action terminated"); err != nil {
    36  		return nil, err
    37  	}
    38  
    39  	return stateChange{
    40  		Kind:     RunAction,
    41  		Step:     Done,
    42  		ActionId: &fa.actionId,
    43  		Hook:     state.Hook,
    44  	}.apply(state), nil
    45  }
    46  
    47  // Commit preserves the recorded hook, and returns a neutral state.
    48  // Commit is part of the Operation interface.
    49  func (fa *failAction) Commit(state State) (*State, error) {
    50  	return stateChange{
    51  		Kind: continuationKind(state),
    52  		Step: Pending,
    53  		Hook: state.Hook,
    54  	}.apply(state), nil
    55  }
    56  
    57  // RemoteStateChanged is called when the remote state changed during execution
    58  // of the operation.
    59  func (fa *failAction) RemoteStateChanged(snapshot remotestate.Snapshot) {
    60  }