Left: | ||
Right: |
OLD | NEW |
---|---|
1 package state | 1 package state |
2 | 2 |
3 import ( | 3 import ( |
4 "fmt" | 4 "fmt" |
5 "labix.org/v2/mgo" | 5 "labix.org/v2/mgo" |
6 "labix.org/v2/mgo/txn" | 6 "labix.org/v2/mgo/txn" |
7 "launchpad.net/juju-core/state/presence" | 7 "launchpad.net/juju-core/state/presence" |
8 "launchpad.net/juju-core/trivial" | 8 "launchpad.net/juju-core/trivial" |
9 "strconv" | 9 "strconv" |
10 "time" | 10 "time" |
11 ) | 11 ) |
12 | 12 |
13 // Machine represents the state of a machine. | 13 // Machine represents the state of a machine. |
14 type Machine struct { | 14 type Machine struct { |
15 st *State | 15 st *State |
16 doc machineDoc | 16 doc machineDoc |
17 } | 17 } |
18 | 18 |
19 // machineDoc represents the internal state of a machine in MongoDB. | 19 // machineDoc represents the internal state of a machine in MongoDB. |
20 type machineDoc struct { | 20 type machineDoc struct { |
21 Id int `bson:"_id"` | 21 Id int `bson:"_id"` |
22 InstanceId string | 22 InstanceId string |
23 Principals []string | 23 Principals []string |
24 Life Life | 24 Life Life |
25 Tools *Tools `bson:",omitempty"` | 25 Tools *Tools `bson:",omitempty"` |
26 TxnRevno int64 `bson:"txn-revno"` | 26 TxnRevno int64 `bson:"txn-revno"` |
27 Workers []WorkerKind | |
27 } | 28 } |
28 | 29 |
29 func newMachine(st *State, doc *machineDoc) *Machine { | 30 func newMachine(st *State, doc *machineDoc) *Machine { |
30 return &Machine{st: st, doc: *doc} | 31 return &Machine{st: st, doc: *doc} |
31 } | 32 } |
32 | 33 |
33 // Id returns the machine id. | 34 // Id returns the machine id. |
34 func (m *Machine) Id() int { | 35 func (m *Machine) Id() int { |
35 return m.doc.Id | 36 return m.doc.Id |
36 } | 37 } |
37 | 38 |
38 // globalKey returns the global database key for the machine. | 39 // globalKey returns the global database key for the machine. |
39 func (m *Machine) globalKey() string { | 40 func (m *Machine) globalKey() string { |
40 return "m#" + m.String() | 41 return "m#" + m.String() |
41 } | 42 } |
42 | 43 |
43 // Life returns whether the machine is Alive, Dying or Dead. | 44 // Life returns whether the machine is Alive, Dying or Dead. |
44 func (m *Machine) Life() Life { | 45 func (m *Machine) Life() Life { |
45 return m.doc.Life | 46 return m.doc.Life |
46 } | 47 } |
47 | 48 |
49 // Workers returns the workers that the machine agent is configured | |
niemeyer
2012/09/27 19:39:47
// Workers returns the workers that the machine ag
rog
2012/09/28 12:45:53
Done.
| |
50 // to run. | |
51 func (m *Machine) Workers() []WorkerKind { | |
52 return m.doc.Workers | |
53 } | |
54 | |
48 // AgentTools returns the tools that the agent is currently running. | 55 // AgentTools returns the tools that the agent is currently running. |
49 // It returns a *NotFoundError if the tools have not yet been set. | 56 // It returns a *NotFoundError if the tools have not yet been set. |
50 func (m *Machine) AgentTools() (*Tools, error) { | 57 func (m *Machine) AgentTools() (*Tools, error) { |
51 if m.doc.Tools == nil { | 58 if m.doc.Tools == nil { |
52 return nil, notFound("agent tools for machine %v", m) | 59 return nil, notFound("agent tools for machine %v", m) |
53 } | 60 } |
54 tools := *m.doc.Tools | 61 tools := *m.doc.Tools |
55 return &tools, nil | 62 return &tools, nil |
56 } | 63 } |
57 | 64 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 return fmt.Errorf("cannot set instance id of machine %s: %v", m, onAbort(err, errNotAlive)) | 203 return fmt.Errorf("cannot set instance id of machine %s: %v", m, onAbort(err, errNotAlive)) |
197 } | 204 } |
198 m.doc.InstanceId = id | 205 m.doc.InstanceId = id |
199 return nil | 206 return nil |
200 } | 207 } |
201 | 208 |
202 // String returns a unique description of this machine. | 209 // String returns a unique description of this machine. |
203 func (m *Machine) String() string { | 210 func (m *Machine) String() string { |
204 return strconv.Itoa(m.doc.Id) | 211 return strconv.Itoa(m.doc.Id) |
205 } | 212 } |
OLD | NEW |