~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/leadership/manifold.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
        "time"
9
9
 
10
10
        "github.com/juju/errors"
 
11
        "github.com/juju/utils/clock"
11
12
        "gopkg.in/juju/names.v2"
12
13
 
13
14
        "github.com/juju/juju/agent"
22
23
type ManifoldConfig struct {
23
24
        AgentName           string
24
25
        APICallerName       string
 
26
        Clock               clock.Clock
25
27
        LeadershipGuarantee time.Duration
26
28
}
27
29
 
42
44
// named in the supplied config.
43
45
func startFunc(config ManifoldConfig) dependency.StartFunc {
44
46
        return func(context dependency.Context) (worker.Worker, error) {
 
47
                if config.Clock == nil {
 
48
                        return nil, errors.NotValidf("missing Clock")
 
49
                }
45
50
                var agent agent.Agent
46
51
                if err := context.Get(config.AgentName, &agent); err != nil {
47
52
                        return nil, err
50
55
                if err := context.Get(config.APICallerName, &apiCaller); err != nil {
51
56
                        return nil, err
52
57
                }
53
 
                return NewManifoldWorker(agent, apiCaller, config.LeadershipGuarantee)
 
58
                return NewManifoldWorker(agent, apiCaller, config.Clock, config.LeadershipGuarantee)
54
59
        }
55
60
}
56
61
 
58
63
// exists primarily to be patched out via NewManifoldWorker for ease of testing,
59
64
// and is not itself directly tested. It would almost certainly be better to
60
65
// pass the constructor dependencies in as explicit manifold config.
61
 
var NewManifoldWorker = func(agent agent.Agent, apiCaller base.APICaller, guarantee time.Duration) (worker.Worker, error) {
 
66
var NewManifoldWorker = func(agent agent.Agent, apiCaller base.APICaller, clock clock.Clock, guarantee time.Duration) (worker.Worker, error) {
62
67
        tag := agent.CurrentConfig().Tag()
63
68
        unitTag, ok := tag.(names.UnitTag)
64
69
        if !ok {
65
70
                return nil, fmt.Errorf("expected a unit tag; got %q", tag)
66
71
        }
67
72
        claimer := leadership.NewClient(apiCaller)
68
 
        return NewTracker(unitTag, claimer, guarantee), nil
 
73
        return NewTracker(unitTag, claimer, clock, guarantee), nil
69
74
}
70
75
 
71
76
// outputFunc extracts the coreleadership.Tracker from a *Tracker passed in as a Worker.