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

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/conv2state/converter.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
import (
7
7
        "github.com/juju/errors"
8
 
        "github.com/juju/loggo"
9
8
        "github.com/juju/names"
10
9
 
11
 
        apimachiner "github.com/juju/juju/api/machiner"
 
10
        "github.com/juju/juju/api/machiner"
12
11
        "github.com/juju/juju/apiserver/params"
13
12
        "github.com/juju/juju/state/multiwatcher"
14
13
        "github.com/juju/juju/watcher"
15
14
)
16
15
 
17
 
var logger = loggo.GetLogger("juju.worker.conv2state")
18
 
 
19
16
// New returns a new notify watch handler that will convert the given machine &
20
17
// agent to a controller.
21
 
func New(m *apimachiner.State, agent Agent) watcher.NotifyHandler {
 
18
func New(m *machiner.State, agent Agent) watcher.NotifyHandler {
22
19
        return &converter{machiner: wrapper{m}, agent: agent}
23
20
}
24
21
 
26
23
// state machine.
27
24
type converter struct {
28
25
        agent    Agent
29
 
        machiner machiner
30
 
        machine  machine
 
26
        machiner interface {
 
27
                Machine(tag names.MachineTag) (machine, error)
 
28
        }
 
29
        machine machine
31
30
}
32
31
 
33
32
// Agent is an interface that can have its password set and be told to restart.
36
35
        Tag() names.Tag
37
36
}
38
37
 
39
 
// machiner is a type that creates machines from a tag.
40
 
type machiner interface {
41
 
        Machine(tag names.MachineTag) (machine, error)
42
 
}
43
 
 
44
38
// machine is a type that has a list of jobs and can be watched.
45
39
type machine interface {
46
40
        Jobs() (*params.JobsResult, error)
50
44
// wrapper is a wrapper around api/machiner.State to match the (local) machiner
51
45
// interface.
52
46
type wrapper struct {
53
 
        m *apimachiner.State
 
47
        m *machiner.State
54
48
}
55
49
 
56
50
// Machines implements machiner.Machine and returns a machine from the wrapper