LEFT | RIGHT |
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "fmt" | 4 "fmt" |
5 "launchpad.net/juju-core/downloader" | 5 "launchpad.net/juju-core/downloader" |
6 "launchpad.net/juju-core/environs" | 6 "launchpad.net/juju-core/environs" |
7 "launchpad.net/juju-core/log" | 7 "launchpad.net/juju-core/log" |
8 "launchpad.net/juju-core/state" | 8 "launchpad.net/juju-core/state" |
9 "launchpad.net/juju-core/state/watcher" | 9 "launchpad.net/juju-core/state/watcher" |
10 "launchpad.net/juju-core/version" | 10 "launchpad.net/juju-core/version" |
11 "launchpad.net/juju-core/worker" | 11 "launchpad.net/juju-core/worker" |
12 "launchpad.net/tomb" | 12 "launchpad.net/tomb" |
13 "os" | 13 "os" |
14 ) | |
15 | |
16 // testing hooks | |
17 var ( | |
18 // invalidVersion is called when an invalid version has been proposed. | |
19 invalidVersion = func() {} | |
20 // sameVersion is called when a version has been proposed, but | |
21 // only the same version can be found. | |
22 sameVersion = func() {} | |
23 ) | 14 ) |
24 | 15 |
25 // An Upgrader observes the version information for an agent in the | 16 // An Upgrader observes the version information for an agent in the |
26 // environment state, and handles the downloading and unpacking of | 17 // environment state, and handles the downloading and unpacking of |
27 // new versions of the juju tools when necessary. | 18 // new versions of the juju tools when necessary. |
28 // | 19 // |
29 // When a new version is available Wait and Stop return UpgradedError. | 20 // When a new version is available Wait and Stop return UpgradedError. |
30 type Upgrader struct { | 21 type Upgrader struct { |
31 tomb tomb.Tomb | 22 tomb tomb.Tomb |
32 st *state.State | 23 st *state.State |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 binary.Number = vers | 131 binary.Number = vers |
141 | 132 |
142 if tools, err := environs.ReadTools(binary); err == nil
{ | 133 if tools, err := environs.ReadTools(binary); err == nil
{ |
143 // The tools have already been downloaded, so us
e them. | 134 // The tools have already been downloaded, so us
e them. |
144 return &UpgradedError{tools} | 135 return &UpgradedError{tools} |
145 } | 136 } |
146 // TODO(rog) add support for environs.DevVersion | 137 // TODO(rog) add support for environs.DevVersion |
147 tools, err := environs.FindTools(environ, binary, enviro
ns.CompatVersion) | 138 tools, err := environs.FindTools(environ, binary, enviro
ns.CompatVersion) |
148 if err != nil { | 139 if err != nil { |
149 log.Printf("upgrader: error finding tools for %v
: %v", binary, err) | 140 log.Printf("upgrader: error finding tools for %v
: %v", binary, err) |
150 invalidVersion() | |
151 // TODO(rog): poll until tools become available. | 141 // TODO(rog): poll until tools become available. |
152 break | 142 break |
153 } | 143 } |
154 if tools.Binary != binary { | 144 if tools.Binary != binary { |
155 if tools.Number == version.Current.Number { | 145 if tools.Number == version.Current.Number { |
156 // TODO(rog): poll until tools become av
ailable. | 146 // TODO(rog): poll until tools become av
ailable. |
157 log.Printf("upgrader: version %v request
ed but no newer version found", binary) | 147 log.Printf("upgrader: version %v request
ed but no newer version found", binary) |
158 sameVersion() | |
159 break | 148 break |
160 } | 149 } |
161 log.Printf("upgrader: cannot find exact tools ma
tch for %s; using %s instead", binary, tools.Binary) | 150 log.Printf("upgrader: cannot find exact tools ma
tch for %s; using %s instead", binary, tools.Binary) |
162 } | 151 } |
163 download = downloader.New(tools.URL, "") | 152 download = downloader.New(tools.URL, "") |
164 downloadTools = tools | 153 downloadTools = tools |
165 downloadDone = download.Done() | 154 downloadDone = download.Done() |
166 case status := <-downloadDone: | 155 case status := <-downloadDone: |
167 tools := downloadTools | 156 tools := downloadTools |
168 download, downloadTools, downloadDone = nil, nil, nil | 157 download, downloadTools, downloadDone = nil, nil, nil |
(...skipping 10 matching lines...) Expand all Loading... |
179 log.Printf("upgrader: cannot unpack %v tools: %v
", tools.Binary, err) | 168 log.Printf("upgrader: cannot unpack %v tools: %v
", tools.Binary, err) |
180 break | 169 break |
181 } | 170 } |
182 return &UpgradedError{tools} | 171 return &UpgradedError{tools} |
183 case <-u.tomb.Dying(): | 172 case <-u.tomb.Dying(): |
184 return nil | 173 return nil |
185 } | 174 } |
186 } | 175 } |
187 panic("not reached") | 176 panic("not reached") |
188 } | 177 } |
LEFT | RIGHT |