github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/uniter/resolver/interface.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package resolver
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"gopkg.in/juju/charm.v6"
     9  
    10  	"github.com/juju/juju/core/model"
    11  	"github.com/juju/juju/worker/uniter/operation"
    12  	"github.com/juju/juju/worker/uniter/remotestate"
    13  )
    14  
    15  // ErrNoOperation is used to indicate that there are no
    16  // currently pending operations to run.
    17  var ErrNoOperation = errors.New("no operations")
    18  
    19  // ErrWaiting indicates that the resolver loop should
    20  // not execute any more operations until a remote state
    21  // event has occurred.
    22  var ErrWaiting = errors.New("waiting for remote state change")
    23  
    24  // ErrRestart indicates that the resolver loop should
    25  // be restarted with a new remote state watcher.
    26  var ErrRestart = errors.New("restarting resolver")
    27  
    28  // ErrTerminate is used when the unit has been marked
    29  // as dead and so there will never be any more
    30  // operations to run for that unit.
    31  var ErrTerminate = errors.New("terminate resolver")
    32  
    33  // Resolver instances use local (as is) and remote (to be) state
    34  // to provide operations to run in order to progress towards
    35  // the desired state.
    36  type Resolver interface {
    37  	// NextOp returns the next operation to run to reconcile
    38  	// the local state with the remote, desired state. The
    39  	// operations returned must be created using the given
    40  	// operation.Factory.
    41  	//
    42  	// This method must return ErrNoOperation if there are no
    43  	// operations to perform.
    44  	//
    45  	// By returning ErrTerminate, the resolver indicates that
    46  	// it will never have any more operations to perform,
    47  	// and the caller can cease calling.
    48  	NextOp(
    49  		LocalState,
    50  		remotestate.Snapshot,
    51  		operation.Factory,
    52  	) (operation.Operation, error)
    53  }
    54  
    55  // LocalState is a cache of the state of the local unit, as needed by the
    56  // Uniter. It is generally compared to the remote state of the expected state of
    57  // the unit as stored in the controller.
    58  type LocalState struct {
    59  	operation.State
    60  
    61  	// CharmModifiedVersion increases any time the charm,
    62  	// or any part of it, is changed in some way.
    63  	CharmModifiedVersion int
    64  
    65  	// CharmURL reports the currently installed charm URL. This is set
    66  	// by the committing of deploy (install/upgrade) ops.
    67  	CharmURL *charm.URL
    68  
    69  	// Conflicted indicates that the uniter is in a conflicted state,
    70  	// and needs either resolution or a forced upgrade to continue.
    71  	Conflicted bool
    72  
    73  	// Restart indicates that the resolver should exit with ErrRestart
    74  	// at the earliest opportunity.
    75  	Restart bool
    76  
    77  	// UpdateStatusVersion is the version of update status from remotestate.Snapshot
    78  	// for which an update-status hook has been committed.
    79  	UpdateStatusVersion int
    80  
    81  	// RetryHookVersion is the version of hook-retries from
    82  	// remotestate.Snapshot for which a hook has been retried.
    83  	RetryHookVersion int
    84  
    85  	// LeaderSettingsVersion is the version of leader settings from
    86  	// remotestate.Snapshot for which a leader-settings-changed hook has
    87  	// been committed.
    88  	LeaderSettingsVersion int
    89  
    90  	// CompletedActions is the set of actions that have been completed.
    91  	// This is used to prevent us re running actions requested by the
    92  	// controller.
    93  	CompletedActions map[string]struct{}
    94  
    95  	// UpgradeSeriesStatus is the current state of any currently running
    96  	// upgrade series.
    97  	UpgradeSeriesStatus model.UpgradeSeriesStatus
    98  
    99  	// UpgradeCharmProfileStatus is the current state of the upgrade charm
   100  	// profile.
   101  	UpgradeCharmProfileStatus string
   102  }