github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/worker/uniter/upgradecharmprofile/resolver.go (about) 1 // Copyright 2018 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package upgradecharmprofile 5 6 import ( 7 "github.com/juju/loggo" 8 9 "github.com/juju/juju/core/lxdprofile" 10 "github.com/juju/juju/worker/uniter/operation" 11 "github.com/juju/juju/worker/uniter/remotestate" 12 "github.com/juju/juju/worker/uniter/resolver" 13 ) 14 15 var logger = loggo.GetLogger("juju.worker.uniter.upgradecharmprofile") 16 17 type upgradeCharmProfileResolver struct{} 18 19 // NewResolver returns a new upgrade charm profile resolver 20 func NewResolver() resolver.Resolver { 21 return &upgradeCharmProfileResolver{} 22 } 23 24 // NextOp is defined on the Resolver interface. 25 func (l *upgradeCharmProfileResolver) NextOp( 26 localState resolver.LocalState, remoteState remotestate.Snapshot, opFactory operation.Factory, 27 ) (operation.Operation, error) { 28 // Ensure the lxd profile is installed, before we move to upgrading 29 // of the charm. 30 if !lxdprofile.UpgradeStatusTerminal(remoteState.UpgradeCharmProfileStatus) { 31 return nil, resolver.ErrDoNotProceed 32 } 33 // If the upgrade status is in an error state, we should log it out 34 // to the operator. 35 if lxdprofile.UpgradeStatusErrorred(remoteState.UpgradeCharmProfileStatus) { 36 // This is a terminal error for the machine, as we can no longer promise 37 // to deliver the correct lxd profile on the machine; one which the 38 // operator asked for. Instead we need to error out and allow the 39 // operator to update the lxd profile before attempting to re-apply the 40 // charm. 41 if localState.UpgradeCharmProfileStatus == lxdprofile.NotKnownStatus { 42 return nil, resolver.ErrNoOperation 43 } 44 logger.Errorf("error upgrading charm profile: %v", remoteState.UpgradeCharmProfileStatus) 45 return opFactory.NewFinishUpgradeCharmProfile(remoteState.CharmURL) 46 } 47 48 return nil, resolver.ErrNoOperation 49 }