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

Side by Side Diff: cmd/jujud/unit.go

Issue 6561063: cmd/jujud: implement uniter upgrade
Patch Set: cmd/jujud: implement uniter upgrade Created 12 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:
View unified diff | Download patch
OLDNEW
1 package main 1 package main
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "launchpad.net/gnuflag" 5 "launchpad.net/gnuflag"
6 "launchpad.net/juju-core/cmd" 6 "launchpad.net/juju-core/cmd"
7 "launchpad.net/juju-core/environs"
7 "launchpad.net/juju-core/log" 8 "launchpad.net/juju-core/log"
8 "launchpad.net/juju-core/state" 9 "launchpad.net/juju-core/state"
9 "launchpad.net/juju-core/worker/uniter" 10 "launchpad.net/juju-core/worker/uniter"
10 "launchpad.net/tomb" 11 "launchpad.net/tomb"
11 "time" 12 "time"
12 ) 13 )
13 14
14 // UnitAgent is a cmd.Command responsible for running a unit agent. 15 // UnitAgent is a cmd.Command responsible for running a unit agent.
15 type UnitAgent struct { 16 type UnitAgent struct {
16 tomb tomb.Tomb 17 tomb tomb.Tomb
(...skipping 25 matching lines...) Expand all
42 // Stop stops the unit agent. 43 // Stop stops the unit agent.
43 func (a *UnitAgent) Stop() error { 44 func (a *UnitAgent) Stop() error {
44 a.tomb.Kill(nil) 45 a.tomb.Kill(nil)
45 return a.tomb.Wait() 46 return a.tomb.Wait()
46 } 47 }
47 48
48 // Run runs a unit agent. 49 // Run runs a unit agent.
49 func (a *UnitAgent) Run(ctx *cmd.Context) error { 50 func (a *UnitAgent) Run(ctx *cmd.Context) error {
50 defer a.tomb.Done() 51 defer a.tomb.Done()
51 for a.tomb.Err() == tomb.ErrStillAlive { 52 for a.tomb.Err() == tomb.ErrStillAlive {
52 » » err := a.runOnce() 53 » » unit, err := a.runOnce()
fwereade 2012/09/28 08:32:19 As discussed, the unit belongs only with the Upgra
rog 2012/09/28 12:06:32 Done.
53 » » log.Printf("uniter error: %v", err) 54 » » if ug, ok := err.(*UpgradedError); ok {
55 » » » tools, err1 := environs.ChangeAgentTools(a.Conf.DataDir, unit.PathKey(), ug.Binary)
56 » » » if err1 == nil {
57 » » » » log.Printf("exiting to upgrade to %v from %q", t ools.Binary, tools.URL)
niemeyer 2012/09/27 17:07:53 ("exiting to upgrade from %v to %v (%q)", version.
rog 2012/09/28 12:06:32 done. the upgraded error now includes this informa
58 » » » » // Return and let upstart deal with the restart.
59 » » » » return nil
60 » » » }
61 » » » err = err1
62 » » }
niemeyer 2012/09/27 17:07:53 log.Printf("uniter error: %v", err)
rog 2012/09/28 12:06:32 done (omitting the "error" which should be self ev
54 select { 63 select {
55 case <-a.tomb.Dying(): 64 case <-a.tomb.Dying():
56 a.tomb.Kill(err) 65 a.tomb.Kill(err)
57 case <-time.After(retryDelay): 66 case <-time.After(retryDelay):
58 » » » log.Printf("rerunning uniter") 67 » » » log.Printf("rerunning uniter after error: %v", err)
niemeyer 2012/09/27 17:07:53 The original logging with "rerunning uniter" still
rog 2012/09/28 12:06:32 Done.
59 } 68 }
60 } 69 }
61 return a.tomb.Err() 70 return a.tomb.Err()
62 } 71 }
63 72
64 // runOnce runs a uniter once. 73 // runOnce runs a uniter once.
65 func (a *UnitAgent) runOnce() error { 74 func (a *UnitAgent) runOnce() (*state.Unit, error) {
66 st, err := state.Open(&a.Conf.StateInfo) 75 st, err := state.Open(&a.Conf.StateInfo)
67 if err != nil { 76 if err != nil {
68 » » return err 77 » » return nil, err
69 } 78 }
70 defer st.Close() 79 defer st.Close()
71 » u, err := uniter.NewUniter(st, a.UnitName, a.Conf.DataDir) 80 » unit, err := st.Unit(a.UnitName)
72 if err != nil { 81 if err != nil {
73 » » return err 82 » » return nil, err
74 } 83 }
fwereade 2012/09/28 08:32:19 As discussed live, please use ErrDead (and use tha
rog 2012/09/28 12:06:32 Done.
75 » return runTasks(a.tomb.Dying(), u) 84 » return unit, runTasks(a.tomb.Dying(),
85 » » uniter.NewUniter(st, unit.Name(), a.Conf.DataDir),
fwereade 2012/09/28 08:32:19 I'm OK with the Uniter change though :).
86 » » NewUpgrader(st, unit, a.Conf.DataDir),
87 » )
76 } 88 }
OLDNEW
« no previous file with comments | « [revision details] ('k') | environs/jujutest/livetests.go » ('j') | worker/uniter/modes.go » ('J')

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