Index: cmd/jujud/upgrade.go |
=== modified file 'cmd/jujud/upgrade.go' |
--- cmd/jujud/upgrade.go 2012-08-21 15:54:02 +0000 |
+++ cmd/jujud/upgrade.go 2012-09-05 16:21:29 +0000 |
@@ -8,6 +8,7 @@ |
"launchpad.net/juju-core/state" |
"launchpad.net/juju-core/state/watcher" |
"launchpad.net/juju-core/version" |
+ "launchpad.net/juju-core/worker" |
"launchpad.net/tomb" |
"os" |
) |
@@ -19,6 +20,7 @@ |
// When a new version is available Wait and Stop return UpgradedError. |
type Upgrader struct { |
tomb tomb.Tomb |
+ st *state.State |
agentName string |
agentState AgentState |
} |
@@ -38,15 +40,12 @@ |
type AgentState interface { |
// SetAgentTools sets the tools that the agent is currently running. |
SetAgentTools(tools *state.Tools) error |
- |
- // WatchProposedAgentTools watches the tools that the agent is |
- // currently proposed to run. |
- WatchProposedAgentTools() *state.AgentToolsWatcher |
} |
// NewUpgrader returns a new Upgrader watching the given agent. |
-func NewUpgrader(agentName string, agentState AgentState) *Upgrader { |
+func NewUpgrader(st *state.State, agentName string, agentState AgentState) *Upgrader { |
u := &Upgrader{ |
+ st: st, |
agentName: agentName, |
agentState: agentState, |
} |
@@ -83,9 +82,14 @@ |
return err |
} |
- w := u.agentState.WatchProposedAgentTools() |
+ w := u.st.WatchEnvironConfig() |
defer watcher.Stop(w, &u.tomb) |
+ environ, err := worker.WaitForEnviron(w, u.tomb.Dying()) |
+ if err != nil { |
+ return err |
+ } |
+ |
// TODO(rog) retry downloads when they fail. |
var ( |
download *downloader.Download |
@@ -98,13 +102,19 @@ |
// hangs up) another change to the proposed tools can |
// potentially fix things. |
select { |
- case tools, ok := <-w.Changes(): |
+ case cfg, ok := <-w.Changes(): |
if !ok { |
return watcher.MustErr(w) |
} |
+ err := environ.SetConfig(cfg) |
+ if err != nil { |
+ log.Printf("provisioner loaded invalid environment configuration: %v", err) |
+ // continue on, because the version number is still significant. |
+ } |
+ vers := cfg.AgentVersion() |
if download != nil { |
// There's a download in progress, stop it if we need to. |
- if *tools == *downloadTools { |
+ if vers == downloadTools.Number { |
// We are already downloading the requested tools. |
break |
} |
@@ -114,13 +124,31 @@ |
} |
// Ignore the proposed tools if they haven't been set yet |
// or we're already running the proposed version. |
- if tools.URL == "" || *tools == *currentTools { |
+ if vers == version.Current.Number { |
break |
} |
- if tools, err := environs.ReadTools(tools.Binary); err == nil { |
+ binary := version.Current |
+ binary.Number = vers |
+ |
+ if tools, err := environs.ReadTools(binary); err == nil { |
// The tools have already been downloaded, so use them. |
return &UpgradedError{tools} |
} |
+ // TODO(rog) add support for environs.DevVersion |
+ tools, err := environs.FindTools(environ, binary, environs.CompatVersion) |
+ if err != nil { |
+ log.Printf("upgrader: error finding tools for %v: %v", binary, err) |
+ // TODO(rog): poll until tools become available. |
+ break |
+ } |
+ if tools.Binary != binary { |
+ if tools.Number == version.Current.Number { |
+ // TODO(rog): poll until tools become available. |
+ log.Printf("upgrader: version %v requested but no newer version found", binary) |
+ break |
+ } |
+ log.Printf("upgrader: cannot find exact tools match for %s; using %s instead", binary, tools.Binary) |
+ } |
download = downloader.New(tools.URL, "") |
downloadTools = tools |
downloadDone = download.Done() |