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

Side by Side Diff: worker/machiner/machiner.go

Issue 8667043: various: unify machine and unit status types (Closed)
Patch Set: various: unify machine and unit status types Created 10 years, 11 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:
View unified diff | Download patch
« no previous file with comments | « state/unit_test.go ('k') | worker/machiner/machiner_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package machiner 1 package machiner
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
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/api/params" 7 "launchpad.net/juju-core/state/api/params"
8 "launchpad.net/juju-core/state/watcher" 8 "launchpad.net/juju-core/state/watcher"
9 "launchpad.net/juju-core/worker" 9 "launchpad.net/juju-core/worker"
10 "launchpad.net/tomb" 10 "launchpad.net/tomb"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 // Announce our presence to the world. 54 // Announce our presence to the world.
55 pinger, err := m.SetAgentAlive() 55 pinger, err := m.SetAgentAlive()
56 if err != nil { 56 if err != nil {
57 return err 57 return err
58 } 58 }
59 defer watcher.Stop(pinger, &mr.tomb) 59 defer watcher.Stop(pinger, &mr.tomb)
60 log.Debugf("worker/machiner: agent for machine %q is now alive", m) 60 log.Debugf("worker/machiner: agent for machine %q is now alive", m)
61 61
62 // Mark the machine as started and log it. 62 // Mark the machine as started and log it.
63 » if err := m.SetStatus(params.MachineStarted, ""); err != nil { 63 » if err := m.SetStatus(params.StatusStarted, ""); err != nil {
64 return err 64 return err
65 } 65 }
66 log.Noticef("worker/machiner: machine %q started", m) 66 log.Noticef("worker/machiner: machine %q started", m)
67 67
68 w := m.Watch() 68 w := m.Watch()
69 defer watcher.Stop(w, &mr.tomb) 69 defer watcher.Stop(w, &mr.tomb)
70 for { 70 for {
71 select { 71 select {
72 case <-mr.tomb.Dying(): 72 case <-mr.tomb.Dying():
73 return tomb.ErrDying 73 return tomb.ErrDying
74 case <-w.Changes(): 74 case <-w.Changes():
75 if err := m.Refresh(); state.IsNotFound(err) { 75 if err := m.Refresh(); state.IsNotFound(err) {
76 return worker.ErrTerminateAgent 76 return worker.ErrTerminateAgent
77 } else if err != nil { 77 } else if err != nil {
78 return err 78 return err
79 } 79 }
80 if m.Life() != state.Alive { 80 if m.Life() != state.Alive {
81 log.Debugf("worker/machiner: machine %q is now % s", m, m.Life()) 81 log.Debugf("worker/machiner: machine %q is now % s", m, m.Life())
82 » » » » if err := m.SetStatus(params.MachineStopped, "") ; err != nil { 82 » » » » if err := m.SetStatus(params.StatusStopped, ""); err != nil {
83 return err 83 return err
84 } 84 }
85 // If the machine is Dying, it has no units, 85 // If the machine is Dying, it has no units,
86 // and can be safely set to Dead. 86 // and can be safely set to Dead.
87 if err := m.EnsureDead(); err != nil { 87 if err := m.EnsureDead(); err != nil {
88 return err 88 return err
89 } 89 }
90 log.Noticef("worker/machiner: machine %q shuttin g down", m) 90 log.Noticef("worker/machiner: machine %q shuttin g down", m)
91 return worker.ErrTerminateAgent 91 return worker.ErrTerminateAgent
92 } 92 }
93 } 93 }
94 } 94 }
95 panic("unreachable") 95 panic("unreachable")
96 } 96 }
OLDNEW
« no previous file with comments | « state/unit_test.go ('k') | worker/machiner/machiner_test.go » ('j') | no next file with comments »

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