<commit_before>// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package uniter

import (
	"github.com/juju/errors"
	"gopkg.in/juju/charm.v6-unstable/hooks"

	"github.com/juju/juju/apiserver/params"
	"github.com/juju/juju/worker/uniter/hook"
	"github.com/juju/juju/worker/uniter/operation"
	"github.com/juju/juju/worker/uniter/remotestate"
	"github.com/juju/juju/worker/uniter/resolver"
)

// ResolverConfig defines configuration for the uniter resolver.
type ResolverConfig struct {
	ClearResolved       func() error
	ReportHookError     func(hook.Info) error
	FixDeployer         func() error
	StartRetryHookTimer func()
	StopRetryHookTimer  func()
	Leadership          resolver.Resolver
	Actions             resolver.Resolver
	Relations           resolver.Resolver
	Storage             resolver.Resolver
	Commands            resolver.Resolver
}

type uniterResolver struct {
	config                ResolverConfig
	retryHookTimerStarted bool
}

func NewUniterResolver(cfg ResolverConfig) resolver.Resolver {
	return &uniterResolver{cfg}
}

func (s *uniterResolver) NextOp(
	localState resolver.LocalState,
	remoteState remotestate.Snapshot,
	opFactory operation.Factory,
) (operation.Operation, error) {

	if remoteState.Life == params.Dead || localState.Stopped {
		return nil, resolver.ErrTerminate
	}

	if localState.Kind == operation.Upgrade {
		if localState.Conflicted {
			return s.nextOpConflicted(localState, remoteState, opFactory)
		}
		logger.Infof("resuming charm upgrade")
		return opFactory.NewUpgrade(localState.CharmURL)
	}

	if localState.Restart {
		// We've just run the upgrade op, which will change the
		// unit's charm URL. We need to restart the resolver
		// loop so that we start watching the correct events.
		return nil, resolver.ErrRestart
	}

	if localState.Kind == operation.Continue {<commit_msg>worker/uniter: Readded comment accidentally removed during rebase<commit_after>// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package uniter

import (
	"github.com/juju/errors"
	"gopkg.in/juju/charm.v6-unstable/hooks"

	"github.com/juju/juju/apiserver/params"
	"github.com/juju/juju/worker/uniter/hook"
	"github.com/juju/juju/worker/uniter/operation"
	"github.com/juju/juju/worker/uniter/remotestate"
	"github.com/juju/juju/worker/uniter/resolver"
)

// ResolverConfig defines configuration for the uniter resolver.
type ResolverConfig struct {
	ClearResolved       func() error
	ReportHookError     func(hook.Info) error
	FixDeployer         func() error
	StartRetryHookTimer func()
	StopRetryHookTimer  func()
	Leadership          resolver.Resolver
	Actions             resolver.Resolver
	Relations           resolver.Resolver
	Storage             resolver.Resolver
	Commands            resolver.Resolver
}

type uniterResolver struct {
	config                ResolverConfig
	retryHookTimerStarted bool
}

// NewUniterResolver returns a new resolver.Resolver for the uniter.
func NewUniterResolver(cfg ResolverConfig) resolver.Resolver {
	return &uniterResolver{cfg}
}

func (s *uniterResolver) NextOp(
	localState resolver.LocalState,
	remoteState remotestate.Snapshot,
	opFactory operation.Factory,
) (operation.Operation, error) {

	if remoteState.Life == params.Dead || localState.Stopped {
		return nil, resolver.ErrTerminate
	}

	if localState.Kind == operation.Upgrade {
		if localState.Conflicted {
			return s.nextOpConflicted(localState, remoteState, opFactory)
		}
		logger.Infof("resuming charm upgrade")
		return opFactory.NewUpgrade(localState.CharmURL)
	}

	if localState.Restart {
		// We've just run the upgrade op, which will change the
		// unit's charm URL. We need to restart the resolver
		// loop so that we start watching the correct events.
		return nil, resolver.ErrRestart
	}

	if localState.Kind == operation.Continue {
{'fraction_non_alphanumeric': 0.08731593903384138, 'fraction_numerical': 0.003099974166881943, 'mean_word_length': 3.750920245398773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3797226', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1212, 'n_words': 292}