本文整理汇总了Golang中github.com/juju/juju/worker/uniter/remotestate.RemoteStateWatcher.RemoteStateChanged方法的典型用法代码示例。如果您正苦于以下问题:Golang RemoteStateWatcher.RemoteStateChanged方法的具体用法?Golang RemoteStateWatcher.RemoteStateChanged怎么用?Golang RemoteStateWatcher.RemoteStateChanged使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/worker/uniter/remotestate.RemoteStateWatcher
的用法示例。
在下文中一共展示了RemoteStateWatcher.RemoteStateChanged方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: loop
//.........这里部分代码省略.........
// the "Continue" state, which indicates that
// there is nothing to do and we're not in an
// error state.
return nil
}
return setAgentStatus(u, status.StatusIdle, "", nil)
}
clearResolved := func() error {
if err := u.unit.ClearResolved(); err != nil {
return errors.Trace(err)
}
watcher.ClearResolvedMode()
return nil
}
for {
if err = restartWatcher(); err != nil {
err = errors.Annotate(err, "(re)starting watcher")
break
}
uniterResolver := NewUniterResolver(ResolverConfig{
ClearResolved: clearResolved,
ReportHookError: u.reportHookError,
FixDeployer: u.deployer.Fix,
ShouldRetryHooks: u.hookRetryStrategy.ShouldRetry,
StartRetryHookTimer: retryHookTimer.Start,
StopRetryHookTimer: retryHookTimer.Reset,
Actions: actions.NewResolver(),
Leadership: uniterleadership.NewResolver(),
Relations: relation.NewRelationsResolver(u.relations),
Storage: storage.NewResolver(u.storage),
Commands: runcommands.NewCommandsResolver(
u.commands, watcher.CommandCompleted,
),
})
// We should not do anything until there has been a change
// to the remote state. The watcher will trigger at least
// once initially.
select {
case <-u.catacomb.Dying():
return u.catacomb.ErrDying()
case <-watcher.RemoteStateChanged():
}
localState := resolver.LocalState{
CharmURL: charmURL,
CharmModifiedVersion: charmModifiedVersion,
}
for err == nil {
err = resolver.Loop(resolver.LoopConfig{
Resolver: uniterResolver,
Watcher: watcher,
Executor: u.operationExecutor,
Factory: u.operationFactory,
Abort: u.catacomb.Dying(),
OnIdle: onIdle,
CharmDirGuard: u.charmDirGuard,
}, &localState)
switch cause := errors.Cause(err); cause {
case nil:
// Loop back around.
case resolver.ErrLoopAborted:
err = u.catacomb.ErrDying()
case operation.ErrNeedsReboot:
err = worker.ErrRebootMachine
case operation.ErrHookFailed:
// Loop back around. The resolver can tell that it is in
// an error state by inspecting the operation state.
err = nil
case resolver.ErrTerminate:
err = u.terminate()
case resolver.ErrRestart:
// make sure we update the two values used above in
// creating LocalState.
charmURL = localState.CharmURL
charmModifiedVersion = localState.CharmModifiedVersion
// leave err assigned, causing loop to break
default:
// We need to set conflicted from here, because error
// handling is outside of the resolver's control.
if operation.IsDeployConflictError(cause) {
localState.Conflicted = true
err = setAgentStatus(u, status.StatusError, "upgrade failed", nil)
} else {
reportAgentError(u, "resolver loop error", err)
}
}
}
if errors.Cause(err) != resolver.ErrRestart {
break
}
}
logger.Infof("unit %q shutting down: %s", u.unit, err)
return err
}
示例2: loop
//.........这里部分代码省略.........
defer watcherMu.Unlock()
if watcher != nil {
return watcher.Stop()
}
return nil
})
onIdle := func() error {
opState := u.operationExecutor.State()
if opState.Kind != operation.Continue {
// We should only set idle status if we're in
// the "Continue" state, which indicates that
// there is nothing to do and we're not in an
// error state.
return nil
}
return setAgentStatus(u, params.StatusIdle, "", nil)
}
clearResolved := func() error {
if err := u.unit.ClearResolved(); err != nil {
return errors.Trace(err)
}
watcher.ClearResolvedMode()
return nil
}
for {
if err = restartWatcher(); err != nil {
err = errors.Annotate(err, "(re)starting watcher")
break
}
uniterResolver := &uniterResolver{
clearResolved: clearResolved,
reportHookError: u.reportHookError,
fixDeployer: u.deployer.Fix,
actionsResolver: actions.NewResolver(),
leadershipResolver: uniterleadership.NewResolver(),
relationsResolver: relation.NewRelationsResolver(u.relations),
storageResolver: storage.NewResolver(u.storage),
}
// We should not do anything until there has been a change
// to the remote state. The watcher will trigger at least
// once initially.
select {
case <-u.tomb.Dying():
return tomb.ErrDying
case <-watcher.RemoteStateChanged():
}
localState := resolver.LocalState{CharmURL: charmURL}
for err == nil {
err = resolver.Loop(resolver.LoopConfig{
Resolver: uniterResolver,
Watcher: watcher,
Executor: u.operationExecutor,
Factory: u.operationFactory,
Dying: u.tomb.Dying(),
OnIdle: onIdle,
CharmDirLocker: u.charmDirLocker,
}, &localState)
switch cause := errors.Cause(err); cause {
case nil:
// Loop back around.
case tomb.ErrDying:
err = tomb.ErrDying
case operation.ErrNeedsReboot:
err = worker.ErrRebootMachine
case operation.ErrHookFailed:
// Loop back around. The resolver can tell that it is in
// an error state by inspecting the operation state.
err = nil
case resolver.ErrTerminate:
err = u.terminate()
case resolver.ErrRestart:
charmURL = localState.CharmURL
// leave err assigned, causing loop to break
default:
// We need to set conflicted from here, because error
// handling is outside of the resolver's control.
if operation.IsDeployConflictError(cause) {
localState.Conflicted = true
err = setAgentStatus(u, params.StatusError, "upgrade failed", nil)
} else {
reportAgentError(u, "resolver loop error", err)
}
}
}
if errors.Cause(err) != resolver.ErrRestart {
break
}
}
logger.Infof("unit %q shutting down: %s", u.unit, err)
return err
}