Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1382)

Delta Between Two Patch Sets: worker/machiner/machiner.go

Issue 6501106: environs: remove VarDir global
Left Patch Set: environs: remove VarDir global Created 11 years, 6 months ago
Right Patch Set: environs: remove VarDir global Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « worker/machiner/export_test.go ('k') | worker/machiner/machiner_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package machiner 1 package machiner
2 2
3 import ( 3 import (
4 "launchpad.net/juju-core/container" 4 "launchpad.net/juju-core/container"
5 "launchpad.net/juju-core/log" 5 "launchpad.net/juju-core/log"
6 "launchpad.net/juju-core/state" 6 "launchpad.net/juju-core/state"
7 "launchpad.net/juju-core/state/watcher" 7 "launchpad.net/juju-core/state/watcher"
8 "launchpad.net/tomb" 8 "launchpad.net/tomb"
9 ) 9 )
10 10
11 // NewMachiner starts a machine agent running that 11 // NewMachiner starts a machine agent running that
12 // deploys agents in the given directory. 12 // deploys agents in the given directory.
13 // The Machiner dies when it encounters an error. 13 // The Machiner dies when it encounters an error.
14 func NewMachiner(machine *state.Machine, varDir string) *Machiner { 14 func NewMachiner(machine *state.Machine, dataDir string) *Machiner {
15 » cont := &container.Simple{VarDir: varDir} 15 » cont := &container.Simple{DataDir: dataDir}
16 return newMachiner(machine, cont) 16 return newMachiner(machine, cont)
17 } 17 }
18 18
19 func newMachiner(machine *state.Machine, cont container.Container) *Machiner { 19 func newMachiner(machine *state.Machine, cont container.Container) *Machiner {
20 » m := &Machiner{container: cont} 20 » m := &Machiner{localContainer: cont}
21 go m.loop(machine) 21 go m.loop(machine)
22 return m 22 return m
23 } 23 }
24 24
25 // Machiner represents a running machine agent. 25 // Machiner represents a running machine agent.
26 type Machiner struct { 26 type Machiner struct {
27 » tomb tomb.Tomb 27 » tomb tomb.Tomb
28 » container container.Container 28 » localContainer container.Container
fwereade 2012/09/10 06:58:30 Wait, what? A machiner can only deploy to one cont
rog 2012/09/10 19:53:10 When LXC is added, we'll probably have "localConta
niemeyer 2012/09/11 18:35:21 This is true, but the decision is made considering
rog 2012/09/12 16:46:17 reverted after discussion on line.
29 } 29 }
30 30
31 func (m *Machiner) loop(machine *state.Machine) { 31 func (m *Machiner) loop(machine *state.Machine) {
32 defer m.tomb.Done() 32 defer m.tomb.Done()
33 w := machine.WatchUnits() 33 w := machine.WatchUnits()
34 defer watcher.Stop(w, &m.tomb) 34 defer watcher.Stop(w, &m.tomb)
35 35
36 // TODO read initial units, check if they're running 36 // TODO read initial units, check if they're running
37 // and restart them if not. Also track units so 37 // and restart them if not. Also track units so
38 // that we don't deploy units that are already running. 38 // that we don't deploy units that are already running.
39 for { 39 for {
40 select { 40 select {
41 case <-m.tomb.Dying(): 41 case <-m.tomb.Dying():
42 return 42 return
43 case change, ok := <-w.Changes(): 43 case change, ok := <-w.Changes():
44 if !ok { 44 if !ok {
45 m.tomb.Kill(watcher.MustErr(w)) 45 m.tomb.Kill(watcher.MustErr(w))
46 return 46 return
47 } 47 }
48 for _, u := range change.Removed { 48 for _, u := range change.Removed {
49 if u.IsPrincipal() { 49 if u.IsPrincipal() {
50 » » » » » if err := m.container.Destroy(u); err != nil { 50 » » » » » if err := m.localContainer.Destroy(u); e rr != nil {
51 log.Printf("cannot destroy unit %s: %v", u.Name(), err) 51 log.Printf("cannot destroy unit %s: %v", u.Name(), err)
52 } 52 }
53 } 53 }
54 } 54 }
55 for _, u := range change.Added { 55 for _, u := range change.Added {
56 if u.IsPrincipal() { 56 if u.IsPrincipal() {
57 » » » » » if err := m.container.Deploy(u); err != nil { 57 » » » » » if err := m.localContainer.Deploy(u); er r != nil {
58 // TODO put unit into a queue to retry the deploy. 58 // TODO put unit into a queue to retry the deploy.
59 log.Printf("cannot deploy unit % s: %v", u.Name(), err) 59 log.Printf("cannot deploy unit % s: %v", u.Name(), err)
60 } 60 }
61 } 61 }
62 } 62 }
63 } 63 }
64 } 64 }
65 } 65 }
66 66
67 // Wait waits until the Machiner has died, and returns the error encountered. 67 // Wait waits until the Machiner has died, and returns the error encountered.
68 func (m *Machiner) Wait() error { 68 func (m *Machiner) Wait() error {
69 return m.tomb.Wait() 69 return m.tomb.Wait()
70 } 70 }
71 71
72 // Stop terminates the Machiner and returns any error that it encountered. 72 // Stop terminates the Machiner and returns any error that it encountered.
73 func (m *Machiner) Stop() error { 73 func (m *Machiner) Stop() error {
74 m.tomb.Kill(nil) 74 m.tomb.Kill(nil)
75 return m.tomb.Wait() 75 return m.tomb.Wait()
76 } 76 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b