本文整理汇总了Golang中github.com/juju/juju/worker/uniter/remotestate.RemoteStateWatcher.ClearResolvedMode方法的典型用法代码示例。如果您正苦于以下问题:Golang RemoteStateWatcher.ClearResolvedMode方法的具体用法?Golang RemoteStateWatcher.ClearResolvedMode怎么用?Golang RemoteStateWatcher.ClearResolvedMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/worker/uniter/remotestate.RemoteStateWatcher
的用法示例。
在下文中一共展示了RemoteStateWatcher.ClearResolvedMode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: loop
//.........这里部分代码省略.........
remotestate.WatcherConfig{
State: remotestate.NewAPIState(u.st),
LeadershipTracker: u.leadershipTracker,
UnitTag: unitTag,
UpdateStatusChannel: u.updateStatusAt,
CommandChannel: u.commandChannel,
RetryHookChannel: retryHookChan,
})
if err != nil {
return errors.Trace(err)
}
if err := u.catacomb.Add(watcher); err != nil {
return errors.Trace(err)
}
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, 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():
示例2: loop
func (u *Uniter) loop(unitTag names.UnitTag) (err error) {
if err := u.init(unitTag); err != nil {
if err == worker.ErrTerminateAgent {
return err
}
return fmt.Errorf("failed to initialize uniter for %q: %v", unitTag, err)
}
logger.Infof("unit %q started", u.unit)
// Install is a special case, as it must run before there
// is any remote state, and before the remote state watcher
// is started.
var charmURL *corecharm.URL
opState := u.operationExecutor.State()
if opState.Kind == operation.Install {
logger.Infof("resuming charm install")
op, err := u.operationFactory.NewInstall(opState.CharmURL)
if err != nil {
return errors.Trace(err)
}
if err := u.operationExecutor.Run(op); err != nil {
return errors.Trace(err)
}
charmURL = opState.CharmURL
} else {
curl, err := u.unit.CharmURL()
if err != nil {
return errors.Trace(err)
}
charmURL = curl
}
var (
watcher *remotestate.RemoteStateWatcher
watcherMu sync.Mutex
)
restartWatcher := func() error {
watcherMu.Lock()
defer watcherMu.Unlock()
if watcher != nil {
if err := watcher.Stop(); err != nil {
return errors.Trace(err)
}
}
var err error
watcher, err = remotestate.NewWatcher(
remotestate.WatcherConfig{
State: remotestate.NewAPIState(u.st),
LeadershipTracker: u.leadershipTracker,
UnitTag: unitTag,
UpdateStatusChannel: u.updateStatusAt,
})
if err != nil {
return errors.Trace(err)
}
// Stop the uniter if the watcher fails. The watcher may be
// stopped cleanly, so only kill the tomb if the error is
// non-nil.
go func(w *remotestate.RemoteStateWatcher) {
if err := w.Wait(); err != nil {
u.tomb.Kill(err)
}
}(watcher)
return nil
}
// watcher may be replaced, so use a closure.
u.addCleanup(func() error {
watcherMu.Lock()
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 {
//.........这里部分代码省略.........