Merge lp:~axwalk/juju-core/remove-1.16-client-support into lp:~go-bot/juju-core/trunk
- remove-1.16-client-support
- Merge into trunk
Proposed by
Andrew Wilkins
Status: | Merged |
---|---|
Approved by: | Andrew Wilkins |
Approved revision: | no longer in the source branch. |
Merged at revision: | 2580 |
Proposed branch: | lp:~axwalk/juju-core/remove-1.16-client-support |
Merge into: | lp:~go-bot/juju-core/trunk |
Diff against target: |
1021 lines (+21/-669) 13 files modified
cmd/juju/addmachine.go (+6/-58) cmd/juju/common.go (+0/-15) cmd/juju/constraints.go (+1/-43) cmd/juju/deploy.go (+0/-78) cmd/juju/destroymachine.go (+3/-28) cmd/juju/environment.go (+2/-71) cmd/juju/set.go (+1/-36) cmd/juju/status.go (+0/-16) cmd/juju/unset.go (+1/-35) cmd/juju/upgradecharm.go (+0/-81) cmd/juju/upgradejuju.go (+0/-96) environs/manual/provisioner.go (+7/-69) state/statecmd/destroymachines.go (+0/-43) |
To merge this branch: | bzr merge lp:~axwalk/juju-core/remove-1.16-client-support |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+214504@code.launchpad.net |
Commit message
Remove 1.16 support code
This drops most of the 1.16 support code from
the client-side. There's more to remove, this
is just a start.
Description of the change
Remove 1.16 support code
This drops most of the 1.16 support code from
the client-side. There's more to remove, this
is just a start.
To post a comment you must log in.
Revision history for this message
Andrew Wilkins (axwalk) wrote : | # |
Revision history for this message
Ian Booth (wallyworld) wrote : | # |
LGTM. Woohoo!
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'cmd/juju/addmachine.go' |
2 | --- cmd/juju/addmachine.go 2014-04-03 04:46:51 +0000 |
3 | +++ cmd/juju/addmachine.go 2014-04-07 10:13:32 +0000 |
4 | @@ -12,12 +12,10 @@ |
5 | "launchpad.net/juju-core/cmd" |
6 | "launchpad.net/juju-core/cmd/envcmd" |
7 | "launchpad.net/juju-core/constraints" |
8 | - "launchpad.net/juju-core/environs/config" |
9 | "launchpad.net/juju-core/environs/manual" |
10 | "launchpad.net/juju-core/instance" |
11 | "launchpad.net/juju-core/juju" |
12 | "launchpad.net/juju-core/names" |
13 | - "launchpad.net/juju-core/state" |
14 | "launchpad.net/juju-core/state/api/params" |
15 | ) |
16 | |
17 | @@ -114,46 +112,6 @@ |
18 | return err |
19 | } |
20 | |
21 | -// addMachine1dot16 runs Client.AddMachines using a direct DB connection to maintain |
22 | -// compatibility with an API server running 1.16 or older (when AddMachines |
23 | -// was not available). This fallback can be removed when we no longer maintain |
24 | -// 1.16 compatibility. |
25 | -// This was copied directly from the code in AddMachineCommand.Run in 1.16 |
26 | -func (c *AddMachineCommand) addMachine1dot16() (string, error) { |
27 | - conn, err := juju.NewConnFromName(c.EnvName) |
28 | - if err != nil { |
29 | - return "", err |
30 | - } |
31 | - defer conn.Close() |
32 | - |
33 | - series := c.Series |
34 | - if series == "" { |
35 | - conf, err := conn.State.EnvironConfig() |
36 | - if err != nil { |
37 | - return "", err |
38 | - } |
39 | - series = config.PreferredSeries(conf) |
40 | - } |
41 | - template := state.MachineTemplate{ |
42 | - Series: series, |
43 | - Constraints: c.Constraints, |
44 | - Jobs: []state.MachineJob{state.JobHostUnits}, |
45 | - } |
46 | - var m *state.Machine |
47 | - switch { |
48 | - case c.ContainerType == "": |
49 | - m, err = conn.State.AddOneMachine(template) |
50 | - case c.MachineId != "": |
51 | - m, err = conn.State.AddMachineInsideMachine(template, c.MachineId, c.ContainerType) |
52 | - default: |
53 | - m, err = conn.State.AddMachineInsideNewMachine(template, template, c.ContainerType) |
54 | - } |
55 | - if err != nil { |
56 | - return "", err |
57 | - } |
58 | - return m.String(), err |
59 | -} |
60 | - |
61 | func (c *AddMachineCommand) Run(ctx *cmd.Context) error { |
62 | if c.SSHHost != "" { |
63 | args := manual.ProvisionMachineArgs{ |
64 | @@ -181,25 +139,15 @@ |
65 | Jobs: []params.MachineJob{params.JobHostUnits}, |
66 | } |
67 | results, err := client.AddMachines([]params.AddMachineParams{machineParams}) |
68 | - var machineId string |
69 | - if params.IsCodeNotImplemented(err) { |
70 | - logger.Infof("AddMachines not supported by the API server, " + |
71 | - "falling back to 1.16 compatibility mode (direct DB access)") |
72 | - machineId, err = c.addMachine1dot16() |
73 | - } else if err != nil { |
74 | - return err |
75 | - } else { |
76 | - // Currently, only one machine is added, but in future there may be several added in one call. |
77 | - machineInfo := results[0] |
78 | - var machineErr *params.Error |
79 | - machineId, machineErr = machineInfo.Machine, machineInfo.Error |
80 | - if machineErr != nil { |
81 | - err = machineErr |
82 | - } |
83 | - } |
84 | if err != nil { |
85 | return err |
86 | } |
87 | + // Currently, only one machine is added, but in future there may be several added in one call. |
88 | + machineInfo := results[0] |
89 | + if machineInfo.Error != nil { |
90 | + return machineInfo.Error |
91 | + } |
92 | + machineId := machineInfo.Machine |
93 | if c.ContainerType == "" { |
94 | logger.Infof("created machine %v", machineId) |
95 | } else { |
96 | |
97 | === modified file 'cmd/juju/common.go' |
98 | --- cmd/juju/common.go 2014-04-03 15:55:07 +0000 |
99 | +++ cmd/juju/common.go 2014-04-07 10:13:32 +0000 |
100 | @@ -69,18 +69,3 @@ |
101 | } |
102 | return &charm.URL{Reference: ref, Series: series}, nil |
103 | } |
104 | - |
105 | -// resolveCharmURL1dot16 returns a resolved charm URL for older state servers |
106 | -// that do not support ResolveCharm. The default series "precise" is |
107 | -// appropriate for these environments. |
108 | -func resolveCharmURL1dot16(url string, conf *config.Config) (*charm.URL, error) { |
109 | - ref, series, err := charm.ParseReference(url) |
110 | - if err != nil { |
111 | - return nil, err |
112 | - } |
113 | - |
114 | - if series == "" { |
115 | - series = config.PreferredSeries(conf) |
116 | - } |
117 | - return &charm.URL{Reference: ref, Series: series}, err |
118 | -} |
119 | |
120 | === modified file 'cmd/juju/constraints.go' |
121 | --- cmd/juju/constraints.go 2014-04-01 04:53:43 +0000 |
122 | +++ cmd/juju/constraints.go 2014-04-07 10:13:32 +0000 |
123 | @@ -13,7 +13,6 @@ |
124 | "launchpad.net/juju-core/constraints" |
125 | "launchpad.net/juju-core/juju" |
126 | "launchpad.net/juju-core/names" |
127 | - "launchpad.net/juju-core/state/api/params" |
128 | ) |
129 | |
130 | const getConstraintsDoc = ` |
131 | @@ -93,21 +92,6 @@ |
132 | return cmd.CheckEmpty(args) |
133 | } |
134 | |
135 | -// getEnvironConstraints1dot16 uses direct DB access to get the Environment |
136 | -// constraints against an API server running 1.16 or older (when GetEnvironmentConstraints |
137 | -// was not available). This fallback can be removed when we no longer maintain |
138 | -// 1.16 compatibility. |
139 | -// This only does the GetEnvironmentConstraints portion of Run, since |
140 | -// GetServiceConstraints was already implemented. |
141 | -func (c *GetConstraintsCommand) getEnvironConstraints1dot16() (constraints.Value, error) { |
142 | - conn, err := juju.NewConnFromName(c.EnvName) |
143 | - if err != nil { |
144 | - return constraints.Value{}, err |
145 | - } |
146 | - defer conn.Close() |
147 | - return conn.State.EnvironConstraints() |
148 | -} |
149 | - |
150 | func (c *GetConstraintsCommand) Run(ctx *cmd.Context) error { |
151 | apiclient, err := juju.NewAPIClientFromName(c.EnvName) |
152 | if err != nil { |
153 | @@ -118,11 +102,6 @@ |
154 | var cons constraints.Value |
155 | if c.ServiceName == "" { |
156 | cons, err = apiclient.GetEnvironmentConstraints() |
157 | - if params.IsCodeNotImplemented(err) { |
158 | - logger.Infof("GetEnvironmentConstraints not supported by the API server, " + |
159 | - "falling back to 1.16 compatibility mode (direct DB access)") |
160 | - cons, err = c.getEnvironConstraints1dot16() |
161 | - } |
162 | } else { |
163 | cons, err = apiclient.GetServiceConstraints(c.ServiceName) |
164 | } |
165 | @@ -166,21 +145,6 @@ |
166 | return err |
167 | } |
168 | |
169 | -// setEnvironConstraints1dot16 uses direct DB access to get the Environment |
170 | -// constraints against an API server running 1.16 or older (when SetEnvironmentConstraints |
171 | -// was not available). This fallback can be removed when we no longer maintain |
172 | -// 1.16 compatibility. |
173 | -// This only does the SetEnvironmentConstraints portion of Run, since |
174 | -// SetServiceConstraints was already implemented. |
175 | -func (c *SetConstraintsCommand) setEnvironConstraints1dot16() error { |
176 | - conn, err := juju.NewConnFromName(c.EnvName) |
177 | - if err != nil { |
178 | - return err |
179 | - } |
180 | - defer conn.Close() |
181 | - return conn.State.SetEnvironConstraints(c.Constraints) |
182 | -} |
183 | - |
184 | func (c *SetConstraintsCommand) Run(_ *cmd.Context) (err error) { |
185 | apiclient, err := juju.NewAPIClientFromName(c.EnvName) |
186 | if err != nil { |
187 | @@ -188,13 +152,7 @@ |
188 | } |
189 | defer apiclient.Close() |
190 | if c.ServiceName == "" { |
191 | - err = apiclient.SetEnvironmentConstraints(c.Constraints) |
192 | - if params.IsCodeNotImplemented(err) { |
193 | - logger.Infof("SetEnvironmentConstraints not supported by the API server, " + |
194 | - "falling back to 1.16 compatibility mode (direct DB access)") |
195 | - err = c.setEnvironConstraints1dot16() |
196 | - } |
197 | - return err |
198 | + return apiclient.SetEnvironmentConstraints(c.Constraints) |
199 | } |
200 | return apiclient.SetServiceConstraints(c.ServiceName, c.Constraints) |
201 | } |
202 | |
203 | === modified file 'cmd/juju/deploy.go' |
204 | --- cmd/juju/deploy.go 2014-04-03 04:46:51 +0000 |
205 | +++ cmd/juju/deploy.go 2014-04-07 10:13:32 +0000 |
206 | @@ -142,11 +142,6 @@ |
207 | defer client.Close() |
208 | |
209 | attrs, err := client.EnvironmentGet() |
210 | - if params.IsCodeNotImplemented(err) { |
211 | - logger.Infof("EnvironmentGet not supported by the API server, " + |
212 | - "falling back to 1.16 compatibility mode (direct DB access)") |
213 | - return c.run1dot16(ctx) |
214 | - } |
215 | if err != nil { |
216 | return err |
217 | } |
218 | @@ -249,79 +244,6 @@ |
219 | return err |
220 | } |
221 | |
222 | -// run1dot16 implements the deploy command in 1.16 compatibility mode, |
223 | -// with direct state access. Remove this when support for 1.16 is |
224 | -// dropped. |
225 | -func (c *DeployCommand) run1dot16(ctx *cmd.Context) error { |
226 | - conn, err := juju.NewConnFromName(c.EnvName) |
227 | - if err != nil { |
228 | - return err |
229 | - } |
230 | - defer conn.Close() |
231 | - conf, err := conn.State.EnvironConfig() |
232 | - if err != nil { |
233 | - return err |
234 | - } |
235 | - |
236 | - curl, err := resolveCharmURL1dot16(c.CharmName, conf) |
237 | - if err != nil { |
238 | - return err |
239 | - } |
240 | - |
241 | - repo, err := charm.InferRepository(curl.Reference, c.RepoPath) |
242 | - if err != nil { |
243 | - return err |
244 | - } |
245 | - repo = config.SpecializeCharmRepo(repo, conf) |
246 | - |
247 | - // TODO(fwereade) it's annoying to roundtrip the bytes through the client |
248 | - // here, but it's the original behaviour and not convenient to change. |
249 | - // PutCharm will always be required in some form for local charms; and we |
250 | - // will need an EnsureStoreCharm method somewhere that gets the state.Charm |
251 | - // for use in the following checks. |
252 | - ch, err := conn.PutCharm(curl, repo, c.BumpRevision) |
253 | - if err != nil { |
254 | - return err |
255 | - } |
256 | - numUnits := c.NumUnits |
257 | - if ch.Meta().Subordinate { |
258 | - if !constraints.IsEmpty(&c.Constraints) { |
259 | - return errors.New("cannot use --constraints with subordinate service") |
260 | - } |
261 | - if numUnits == 1 && c.ToMachineSpec == "" { |
262 | - numUnits = 0 |
263 | - } else { |
264 | - return errors.New("cannot use --num-units or --to with subordinate service") |
265 | - } |
266 | - } |
267 | - |
268 | - serviceName := c.ServiceName |
269 | - if serviceName == "" { |
270 | - serviceName = ch.Meta().Name |
271 | - } |
272 | - var settings charm.Settings |
273 | - if c.Config.Path != "" { |
274 | - configYAML, err := c.Config.Read(ctx) |
275 | - if err != nil { |
276 | - return err |
277 | - } |
278 | - settings, err = ch.Config().ParseSettingsYAML(configYAML, serviceName) |
279 | - if err != nil { |
280 | - return err |
281 | - } |
282 | - } |
283 | - _, err = juju.DeployService(conn.State, |
284 | - juju.DeployServiceParams{ |
285 | - ServiceName: serviceName, |
286 | - Charm: ch, |
287 | - NumUnits: numUnits, |
288 | - ConfigSettings: settings, |
289 | - Constraints: c.Constraints, |
290 | - ToMachineSpec: c.ToMachineSpec, |
291 | - }) |
292 | - return err |
293 | -} |
294 | - |
295 | // addCharmViaAPI calls the appropriate client API calls to add the |
296 | // given charm URL to state. Also displays the charm URL of the added |
297 | // charm on stdout. |
298 | |
299 | === modified file 'cmd/juju/destroymachine.go' |
300 | --- cmd/juju/destroymachine.go 2014-04-01 04:53:43 +0000 |
301 | +++ cmd/juju/destroymachine.go 2014-04-07 10:13:32 +0000 |
302 | @@ -12,8 +12,6 @@ |
303 | "launchpad.net/juju-core/cmd/envcmd" |
304 | "launchpad.net/juju-core/juju" |
305 | "launchpad.net/juju-core/names" |
306 | - "launchpad.net/juju-core/state/api/params" |
307 | - "launchpad.net/juju-core/state/statecmd" |
308 | ) |
309 | |
310 | // DestroyMachineCommand causes an existing machine to be destroyed. |
311 | @@ -62,21 +60,6 @@ |
312 | return nil |
313 | } |
314 | |
315 | -func (c *DestroyMachineCommand) run1dot16() error { |
316 | - if c.Force { |
317 | - return fmt.Errorf("destroy-machine --force is not supported in Juju servers older than 1.16.4") |
318 | - } |
319 | - conn, err := juju.NewConnFromName(c.EnvName) |
320 | - if err != nil { |
321 | - return err |
322 | - } |
323 | - defer conn.Close() |
324 | - // TODO: When this run1dot16 code is removed, we should remove the |
325 | - // method in state as well (as long as add-machine also no longer |
326 | - // needs it.) |
327 | - return statecmd.DestroyMachines1dot16(conn.State, c.MachineIds...) |
328 | -} |
329 | - |
330 | func (c *DestroyMachineCommand) Run(_ *cmd.Context) error { |
331 | apiclient, err := juju.NewAPIClientFromName(c.EnvName) |
332 | if err != nil { |
333 | @@ -84,15 +67,7 @@ |
334 | } |
335 | defer apiclient.Close() |
336 | if c.Force { |
337 | - err = apiclient.ForceDestroyMachines(c.MachineIds...) |
338 | - } else { |
339 | - err = apiclient.DestroyMachines(c.MachineIds...) |
340 | - } |
341 | - // Juju 1.16.3 and older did not have DestroyMachines as an API command. |
342 | - if params.IsCodeNotImplemented(err) { |
343 | - logger.Infof("DestroyMachines not supported by the API server, " + |
344 | - "falling back to <=1.16.3 compatibility") |
345 | - return c.run1dot16() |
346 | - } |
347 | - return err |
348 | + return apiclient.ForceDestroyMachines(c.MachineIds...) |
349 | + } |
350 | + return apiclient.DestroyMachines(c.MachineIds...) |
351 | } |
352 | |
353 | === modified file 'cmd/juju/environment.go' |
354 | --- cmd/juju/environment.go 2014-04-01 14:31:22 +0000 |
355 | +++ cmd/juju/environment.go 2014-04-07 10:13:32 +0000 |
356 | @@ -12,7 +12,6 @@ |
357 | "launchpad.net/juju-core/cmd" |
358 | "launchpad.net/juju-core/cmd/envcmd" |
359 | "launchpad.net/juju-core/juju" |
360 | - "launchpad.net/juju-core/state/api/params" |
361 | ) |
362 | |
363 | // GetEnvironmentCommand is able to output either the entire environment or |
364 | @@ -59,26 +58,6 @@ |
365 | return |
366 | } |
367 | |
368 | -// environmentGet1dot16 runs matches client.EnvironmentGet using a direct DB |
369 | -// connection to maintain compatibility with an API server running 1.16 or |
370 | -// older (when EnvironmentGet was not available). This fallback can be removed |
371 | -// when we no longer maintain 1.16 compatibility. |
372 | -func (c *GetEnvironmentCommand) environmentGet1dot16() (map[string]interface{}, error) { |
373 | - conn, err := juju.NewConnFromName(c.EnvName) |
374 | - if err != nil { |
375 | - return nil, err |
376 | - } |
377 | - defer conn.Close() |
378 | - |
379 | - // Get the existing environment config from the state. |
380 | - config, err := conn.State.EnvironConfig() |
381 | - if err != nil { |
382 | - return nil, err |
383 | - } |
384 | - attrs := config.AllAttrs() |
385 | - return attrs, nil |
386 | -} |
387 | - |
388 | func (c *GetEnvironmentCommand) Run(ctx *cmd.Context) error { |
389 | client, err := juju.NewAPIClientFromName(c.EnvName) |
390 | if err != nil { |
391 | @@ -87,11 +66,6 @@ |
392 | defer client.Close() |
393 | |
394 | attrs, err := client.EnvironmentGet() |
395 | - if params.IsCodeNotImplemented(err) { |
396 | - logger.Infof("EnvironmentGet not supported by the API server, " + |
397 | - "falling back to 1.16 compatibility mode (direct DB access)") |
398 | - attrs, err = c.environmentGet1dot16() |
399 | - } |
400 | if err != nil { |
401 | return err |
402 | } |
403 | @@ -159,36 +133,13 @@ |
404 | return nil |
405 | } |
406 | |
407 | -// run1dot16 runs matches client.EnvironmentSet using a direct DB |
408 | -// connection to maintain compatibility with an API server running 1.16 or |
409 | -// older (when EnvironmentSet was not available). This fallback can be removed |
410 | -// when we no longer maintain 1.16 compatibility. |
411 | -// This content was copied from SetEnvironmentCommand.Run in 1.16 |
412 | -func (c *SetEnvironmentCommand) run1dot16() error { |
413 | - conn, err := juju.NewConnFromName(c.EnvName) |
414 | - if err != nil { |
415 | - return err |
416 | - } |
417 | - defer conn.Close() |
418 | - |
419 | - // Update state config with new values |
420 | - return conn.State.UpdateEnvironConfig(c.values, nil, nil) |
421 | -} |
422 | - |
423 | func (c *SetEnvironmentCommand) Run(ctx *cmd.Context) error { |
424 | client, err := juju.NewAPIClientFromName(c.EnvName) |
425 | if err != nil { |
426 | return err |
427 | } |
428 | defer client.Close() |
429 | - |
430 | - err = client.EnvironmentSet(c.values) |
431 | - if params.IsCodeNotImplemented(err) { |
432 | - logger.Infof("EnvironmentSet not supported by the API server, " + |
433 | - "falling back to 1.16 compatibility mode (direct DB access)") |
434 | - err = c.run1dot16() |
435 | - } |
436 | - return err |
437 | + return client.EnvironmentSet(c.values) |
438 | } |
439 | |
440 | // UnsetEnvironment |
441 | @@ -228,31 +179,11 @@ |
442 | return nil |
443 | } |
444 | |
445 | -// run1dot16 runs matches client.EnvironmentUnset using a direct DB |
446 | -// connection to maintain compatibility with an API server running 1.16 or |
447 | -// older (when EnvironmentUnset was not available). This fallback can be removed |
448 | -// when we no longer maintain 1.16 compatibility. |
449 | -func (c *UnsetEnvironmentCommand) run1dot16() error { |
450 | - conn, err := juju.NewConnFromName(c.EnvName) |
451 | - if err != nil { |
452 | - return err |
453 | - } |
454 | - defer conn.Close() |
455 | - return conn.State.UpdateEnvironConfig(nil, c.keys, nil) |
456 | -} |
457 | - |
458 | func (c *UnsetEnvironmentCommand) Run(ctx *cmd.Context) error { |
459 | client, err := juju.NewAPIClientFromName(c.EnvName) |
460 | if err != nil { |
461 | return err |
462 | } |
463 | defer client.Close() |
464 | - |
465 | - err = client.EnvironmentUnset(c.keys...) |
466 | - if params.IsCodeNotImplemented(err) { |
467 | - logger.Infof("EnvironmentUnset not supported by the API server, " + |
468 | - "falling back to 1.16 compatibility mode (direct DB access)") |
469 | - err = c.run1dot16() |
470 | - } |
471 | - return err |
472 | + return client.EnvironmentUnset(c.keys...) |
473 | } |
474 | |
475 | === modified file 'cmd/juju/set.go' |
476 | --- cmd/juju/set.go 2014-04-01 04:53:43 +0000 |
477 | +++ cmd/juju/set.go 2014-04-07 10:13:32 +0000 |
478 | @@ -13,7 +13,6 @@ |
479 | "launchpad.net/juju-core/cmd" |
480 | "launchpad.net/juju-core/cmd/envcmd" |
481 | "launchpad.net/juju-core/juju" |
482 | - "launchpad.net/juju-core/state/api/params" |
483 | ) |
484 | |
485 | // SetCommand updates the configuration of a service. |
486 | @@ -64,34 +63,6 @@ |
487 | return nil |
488 | } |
489 | |
490 | -// serviceSet1dot16 does the final ServiceSet step using direct DB access |
491 | -// compatibility with an API server running 1.16 or older (when ServiceUnset |
492 | -// was not available). This fallback can be removed when we no longer maintain |
493 | -// 1.16 compatibility. |
494 | -// This was copied directly from the code in SetCommand.Run in 1.16 |
495 | -func (c *SetCommand) serviceSet1dot16() error { |
496 | - conn, err := juju.NewConnFromName(c.EnvName) |
497 | - if err != nil { |
498 | - return err |
499 | - } |
500 | - defer conn.Close() |
501 | - service, err := conn.State.Service(c.ServiceName) |
502 | - if err != nil { |
503 | - return err |
504 | - } |
505 | - ch, _, err := service.Charm() |
506 | - if err != nil { |
507 | - return err |
508 | - } |
509 | - // We don't need the multiple logic here, because that should have |
510 | - // already been taken care of by the API code (which *was* in 1.16). |
511 | - settings, err := ch.Config().ParseSettingsStrings(c.SettingsStrings) |
512 | - if err != nil { |
513 | - return err |
514 | - } |
515 | - return service.UpdateConfigSettings(settings) |
516 | -} |
517 | - |
518 | // Run updates the configuration of a service. |
519 | func (c *SetCommand) Run(ctx *cmd.Context) error { |
520 | api, err := juju.NewAPIClientFromName(c.EnvName) |
521 | @@ -109,13 +80,7 @@ |
522 | } else if len(c.SettingsStrings) == 0 { |
523 | return nil |
524 | } |
525 | - err = api.ServiceSet(c.ServiceName, c.SettingsStrings) |
526 | - if params.IsCodeNotImplemented(err) { |
527 | - logger.Infof("NewServiceSetForClientAPI not supported by the API server, " + |
528 | - "falling back to 1.16 compatibility mode (direct DB access)") |
529 | - err = c.serviceSet1dot16() |
530 | - } |
531 | - return err |
532 | + return api.ServiceSet(c.ServiceName, c.SettingsStrings) |
533 | } |
534 | |
535 | // parse parses the option k=v strings into a map of options to be |
536 | |
537 | === modified file 'cmd/juju/status.go' |
538 | --- cmd/juju/status.go 2014-04-01 04:53:43 +0000 |
539 | +++ cmd/juju/status.go 2014-04-07 10:13:32 +0000 |
540 | @@ -68,16 +68,6 @@ |
541 | %v |
542 | ` |
543 | |
544 | -func (c *StatusCommand) getStatus1dot16() (*api.Status, error) { |
545 | - conn, err := juju.NewConnFromName(c.EnvName) |
546 | - if err != nil { |
547 | - return nil, fmt.Errorf(connectionError, c.EnvName, err) |
548 | - } |
549 | - defer conn.Close() |
550 | - |
551 | - return statecmd.Status(conn, c.patterns) |
552 | -} |
553 | - |
554 | func (c *StatusCommand) Run(ctx *cmd.Context) error { |
555 | // Just verify the pattern validity client side, do not use the matcher |
556 | _, err := statecmd.NewUnitMatcher(c.patterns) |
557 | @@ -91,12 +81,6 @@ |
558 | defer apiclient.Close() |
559 | |
560 | status, err := apiclient.Status(c.patterns) |
561 | - if params.IsCodeNotImplemented(err) { |
562 | - logger.Infof("Status not supported by the API server, " + |
563 | - "falling back to 1.16 compatibility mode " + |
564 | - "(direct DB access)") |
565 | - status, err = c.getStatus1dot16() |
566 | - } |
567 | // Display any error, but continue to print status if some was returned |
568 | if err != nil { |
569 | fmt.Fprintf(ctx.Stderr, "%v\n", err) |
570 | |
571 | === modified file 'cmd/juju/unset.go' |
572 | --- cmd/juju/unset.go 2014-04-01 04:53:43 +0000 |
573 | +++ cmd/juju/unset.go 2014-04-07 10:13:32 +0000 |
574 | @@ -8,11 +8,9 @@ |
575 | |
576 | "launchpad.net/gnuflag" |
577 | |
578 | - "launchpad.net/juju-core/charm" |
579 | "launchpad.net/juju-core/cmd" |
580 | "launchpad.net/juju-core/cmd/envcmd" |
581 | "launchpad.net/juju-core/juju" |
582 | - "launchpad.net/juju-core/state/api/params" |
583 | ) |
584 | |
585 | // UnsetCommand sets configuration values of a service back |
586 | @@ -58,32 +56,6 @@ |
587 | return nil |
588 | } |
589 | |
590 | -// run1dot16 runs 'juju unset' using a direct DB connection to maintain |
591 | -// compatibility with an API server running 1.16 or older (when ServiceUnset |
592 | -// was not available). This fallback can be removed when we no longer maintain |
593 | -// 1.16 compatibility. |
594 | -// This was copied directly from the code in UnsetCommand.Run in 1.16 |
595 | -func (c *UnsetCommand) run1dot16() error { |
596 | - conn, err := juju.NewConnFromName(c.EnvName) |
597 | - if err != nil { |
598 | - return err |
599 | - } |
600 | - defer conn.Close() |
601 | - service, err := conn.State.Service(c.ServiceName) |
602 | - if err != nil { |
603 | - return err |
604 | - } |
605 | - if len(c.Options) > 0 { |
606 | - settings := make(charm.Settings) |
607 | - for _, option := range c.Options { |
608 | - settings[option] = nil |
609 | - } |
610 | - return service.UpdateConfigSettings(settings) |
611 | - } else { |
612 | - return nil |
613 | - } |
614 | -} |
615 | - |
616 | // Run resets the configuration of a service. |
617 | func (c *UnsetCommand) Run(ctx *cmd.Context) error { |
618 | apiclient, err := juju.NewAPIClientFromName(c.EnvName) |
619 | @@ -91,11 +63,5 @@ |
620 | return err |
621 | } |
622 | defer apiclient.Close() |
623 | - err = apiclient.ServiceUnset(c.ServiceName, c.Options) |
624 | - if params.IsCodeNotImplemented(err) { |
625 | - logger.Infof("ServiceUnset not supported by the API server, " + |
626 | - "falling back to 1.16 compatibility mode (direct DB access)") |
627 | - err = c.run1dot16() |
628 | - } |
629 | - return err |
630 | + return apiclient.ServiceUnset(c.ServiceName, c.Options) |
631 | } |
632 | |
633 | === modified file 'cmd/juju/upgradecharm.go' |
634 | --- cmd/juju/upgradecharm.go 2014-04-03 15:05:14 +0000 |
635 | +++ cmd/juju/upgradecharm.go 2014-04-07 10:13:32 +0000 |
636 | @@ -16,7 +16,6 @@ |
637 | "launchpad.net/juju-core/environs/config" |
638 | "launchpad.net/juju-core/juju" |
639 | "launchpad.net/juju-core/names" |
640 | - "launchpad.net/juju-core/state/api/params" |
641 | ) |
642 | |
643 | // UpgradeCharm is responsible for upgrading a service's charm. |
644 | @@ -115,10 +114,6 @@ |
645 | } |
646 | defer client.Close() |
647 | oldURL, err := client.ServiceGetCharmURL(c.ServiceName) |
648 | - if params.IsCodeNotImplemented(err) { |
649 | - logger.Infof("ServiceGetCharmURL is not implemented by the API server, switching to 1.16 compatibility mode (direct DB connection).") |
650 | - return c.run1dot16(ctx) |
651 | - } |
652 | if err != nil { |
653 | return err |
654 | } |
655 | @@ -178,79 +173,3 @@ |
656 | |
657 | return client.ServiceSetCharm(c.ServiceName, addedURL.String(), c.Force) |
658 | } |
659 | - |
660 | -// run1dot16 perfoms the charm upgrade using a 1.16 compatible code |
661 | -// path, with a direct state connection. Remove once the support for |
662 | -// 1.16 is dropped. |
663 | -func (c *UpgradeCharmCommand) run1dot16(ctx *cmd.Context) error { |
664 | - conn, err := juju.NewConnFromName(c.EnvName) |
665 | - if err != nil { |
666 | - return err |
667 | - } |
668 | - defer conn.Close() |
669 | - service, err := conn.State.Service(c.ServiceName) |
670 | - if err != nil { |
671 | - return err |
672 | - } |
673 | - |
674 | - conf, err := conn.State.EnvironConfig() |
675 | - if err != nil { |
676 | - return err |
677 | - } |
678 | - |
679 | - oldURL, _ := service.CharmURL() |
680 | - var newURL *charm.URL |
681 | - if c.SwitchURL != "" { |
682 | - // A new charm URL was explicitly specified. |
683 | - newURL, err = resolveCharmURL1dot16(c.SwitchURL, conf) |
684 | - if err != nil { |
685 | - return err |
686 | - } |
687 | - } else { |
688 | - // No new URL specified, but revision might have been. |
689 | - newURL = oldURL.WithRevision(c.Revision) |
690 | - } |
691 | - |
692 | - repo, err := charm.InferRepository(newURL.Reference, ctx.AbsPath(c.RepoPath)) |
693 | - if err != nil { |
694 | - return err |
695 | - } |
696 | - repo = config.SpecializeCharmRepo(repo, conf) |
697 | - |
698 | - // If no explicit revision was set with either SwitchURL |
699 | - // or Revision flags, discover the latest. |
700 | - explicitRevision := true |
701 | - if newURL.Revision == -1 { |
702 | - explicitRevision = false |
703 | - latest, err := charm.Latest(repo, newURL) |
704 | - if err != nil { |
705 | - return err |
706 | - } |
707 | - newURL = newURL.WithRevision(latest) |
708 | - } |
709 | - bumpRevision := false |
710 | - if *newURL == *oldURL { |
711 | - if explicitRevision { |
712 | - return fmt.Errorf("already running specified charm %q", newURL) |
713 | - } |
714 | - // Only try bumping the revision when necessary (local dir charm). |
715 | - if _, isLocal := repo.(*charm.LocalRepository); !isLocal { |
716 | - // TODO(dimitern): If the --force flag is set to something |
717 | - // different to before, we might actually want to allow this |
718 | - // case (and the other error below). LP bug #1174287 |
719 | - return fmt.Errorf("already running latest charm %q", newURL) |
720 | - } |
721 | - // This is a local repository. |
722 | - if ch, err := repo.Get(newURL); err != nil { |
723 | - return err |
724 | - } else if _, bumpRevision = ch.(*charm.Dir); !bumpRevision { |
725 | - // Only bump the revision when it's a directory. |
726 | - return fmt.Errorf("cannot increment revision of charm %q: not a directory", newURL) |
727 | - } |
728 | - } |
729 | - sch, err := conn.PutCharm(newURL, repo, bumpRevision) |
730 | - if err != nil { |
731 | - return err |
732 | - } |
733 | - return service.SetCharm(sch, c.Force) |
734 | -} |
735 | |
736 | === modified file 'cmd/juju/upgradejuju.go' |
737 | --- cmd/juju/upgradejuju.go 2014-04-01 04:53:43 +0000 |
738 | +++ cmd/juju/upgradejuju.go 2014-04-07 10:13:32 +0000 |
739 | @@ -16,10 +16,8 @@ |
740 | "launchpad.net/juju-core/environs" |
741 | "launchpad.net/juju-core/environs/bootstrap" |
742 | "launchpad.net/juju-core/environs/config" |
743 | - "launchpad.net/juju-core/environs/storage" |
744 | "launchpad.net/juju-core/environs/sync" |
745 | envtools "launchpad.net/juju-core/environs/tools" |
746 | - "launchpad.net/juju-core/errors" |
747 | "launchpad.net/juju-core/juju" |
748 | "launchpad.net/juju-core/state/api" |
749 | "launchpad.net/juju-core/state/api/params" |
750 | @@ -132,9 +130,6 @@ |
751 | |
752 | // Determine the version to upgrade to, uploading tools if necessary. |
753 | attrs, err := client.EnvironmentGet() |
754 | - if params.IsCodeNotImplemented(err) { |
755 | - return c.run1dot16() |
756 | - } |
757 | if err != nil { |
758 | return err |
759 | } |
760 | @@ -372,94 +367,3 @@ |
761 | } |
762 | return vers |
763 | } |
764 | - |
765 | -// run1dot16 implements the command without access to the API. This is |
766 | -// needed for compatibility, so 1.16 can be upgraded to newer |
767 | -// releases. It should be removed in 1.18. |
768 | -func (c *UpgradeJujuCommand) run1dot16() error { |
769 | - logger.Warningf("running in 1.16 compatibility mode") |
770 | - conn, err := juju.NewConnFromName(c.EnvName) |
771 | - if err != nil { |
772 | - return err |
773 | - } |
774 | - defer conn.Close() |
775 | - defer func() { |
776 | - if err == errUpToDate { |
777 | - logger.Infof(err.Error()) |
778 | - err = nil |
779 | - } |
780 | - }() |
781 | - |
782 | - // Determine the version to upgrade to, uploading tools if necessary. |
783 | - env := conn.Environ |
784 | - cfg, err := conn.State.EnvironConfig() |
785 | - if err != nil { |
786 | - return err |
787 | - } |
788 | - context, err := c.initVersions1dot16(cfg, env) |
789 | - if err != nil { |
790 | - return err |
791 | - } |
792 | - if c.UploadTools { |
793 | - series := bootstrap.SeriesToUpload(cfg, c.Series) |
794 | - if err := context.uploadTools1dot16(env.Storage(), series); err != nil { |
795 | - return err |
796 | - } |
797 | - } |
798 | - if err := context.validate(); err != nil { |
799 | - return err |
800 | - } |
801 | - logger.Infof("upgrade version chosen: %s", context.chosen) |
802 | - logger.Infof("available tools: %s", context.tools) |
803 | - |
804 | - if err := conn.State.SetEnvironAgentVersion(context.chosen); err != nil { |
805 | - return err |
806 | - } |
807 | - logger.Infof("started upgrade to %s", context.chosen) |
808 | - return nil |
809 | -} |
810 | - |
811 | -func (c *UpgradeJujuCommand) initVersions1dot16(cfg *config.Config, env environs.Environ) (*upgradeContext, error) { |
812 | - agent, ok := cfg.AgentVersion() |
813 | - if !ok { |
814 | - // Can't happen. In theory. |
815 | - return nil, fmt.Errorf("incomplete environment configuration") |
816 | - } |
817 | - if c.Version == agent { |
818 | - return nil, errUpToDate |
819 | - } |
820 | - client := version.Current.Number |
821 | - available, err := envtools.FindTools(env, client.Major, -1, coretools.Filter{}, envtools.DoNotAllowRetry) |
822 | - if err != nil { |
823 | - if !errors.IsNotFoundError(err) { |
824 | - return nil, err |
825 | - } |
826 | - if !c.UploadTools { |
827 | - // No tools found and we shouldn't upload any, so if we are not asking for a |
828 | - // major upgrade, pretend there is no more recent version available. |
829 | - if c.Version == version.Zero && agent.Major == client.Major { |
830 | - return nil, errUpToDate |
831 | - } |
832 | - return nil, err |
833 | - } |
834 | - } |
835 | - return &upgradeContext{ |
836 | - agent: agent, |
837 | - client: client, |
838 | - chosen: c.Version, |
839 | - tools: available, |
840 | - }, nil |
841 | -} |
842 | - |
843 | -func (context *upgradeContext) uploadTools1dot16(storage storage.Storage, series []string) error { |
844 | - if context.chosen == version.Zero { |
845 | - context.chosen = context.client |
846 | - } |
847 | - context.chosen = uploadVersion(context.chosen, context.tools) |
848 | - uploaded, err := sync.Upload(storage, &context.chosen, series...) |
849 | - if err != nil { |
850 | - return err |
851 | - } |
852 | - context.tools = coretools.List{uploaded} |
853 | - return nil |
854 | -} |
855 | |
856 | === modified file 'environs/manual/provisioner.go' |
857 | --- environs/manual/provisioner.go 2014-04-01 04:15:17 +0000 |
858 | +++ environs/manual/provisioner.go 2014-04-07 10:13:32 +0000 |
859 | @@ -21,7 +21,6 @@ |
860 | "launchpad.net/juju-core/state" |
861 | "launchpad.net/juju-core/state/api" |
862 | "launchpad.net/juju-core/state/api/params" |
863 | - "launchpad.net/juju-core/state/statecmd" |
864 | "launchpad.net/juju-core/tools" |
865 | "launchpad.net/juju-core/utils" |
866 | "launchpad.net/juju-core/utils/shell" |
867 | @@ -72,34 +71,14 @@ |
868 | if err != nil { |
869 | return "", err |
870 | } |
871 | - // Used for fallback to 1.16 code |
872 | - var stateConn *juju.Conn |
873 | defer func() { |
874 | if machineId != "" && err != nil { |
875 | logger.Errorf("provisioning failed, removing machine %v: %v", machineId, err) |
876 | - // If we have stateConn, then we are in 1.16 |
877 | - // compatibility mode and we should issue |
878 | - // DestroyMachines directly on the state, rather than |
879 | - // via API (because DestroyMachine *also* didn't exist |
880 | - // in 1.16, though it will be in 1.16.5). |
881 | - // TODO: When this compatibility code is removed, we |
882 | - // should remove the method in state as well (as long |
883 | - // as destroy-machine also no longer needs it.) |
884 | - var cleanupErr error |
885 | - if stateConn != nil { |
886 | - cleanupErr = statecmd.DestroyMachines1dot16(stateConn.State, machineId) |
887 | - } else { |
888 | - cleanupErr = client.DestroyMachines(machineId) |
889 | - } |
890 | - if cleanupErr != nil { |
891 | + if cleanupErr := client.DestroyMachines(machineId); cleanupErr != nil { |
892 | logger.Warningf("error cleaning up machine: %s", cleanupErr) |
893 | } |
894 | machineId = "" |
895 | } |
896 | - if stateConn != nil { |
897 | - stateConn.Close() |
898 | - stateConn = nil |
899 | - } |
900 | client.Close() |
901 | }() |
902 | |
903 | @@ -120,35 +99,16 @@ |
904 | |
905 | // Inform Juju that the machine exists. |
906 | machineId, err = recordMachineInState(client, *machineParams) |
907 | - if params.IsCodeNotImplemented(err) { |
908 | - logger.Infof("AddMachines not supported by the API server, " + |
909 | - "falling back to 1.16 compatibility mode (direct DB access)") |
910 | - stateConn, err = juju.NewConnFromName(args.EnvName) |
911 | - if err == nil { |
912 | - machineId, err = recordMachineInState1dot16(stateConn, *machineParams) |
913 | - } |
914 | - } |
915 | if err != nil { |
916 | return "", err |
917 | } |
918 | |
919 | - var provisioningScript string |
920 | - if stateConn == nil { |
921 | - provisioningScript, err = client.ProvisioningScript(params.ProvisioningScriptParams{ |
922 | - MachineId: machineId, |
923 | - Nonce: machineParams.Nonce, |
924 | - }) |
925 | - if err != nil { |
926 | - return "", err |
927 | - } |
928 | - } else { |
929 | - mcfg, err := statecmd.MachineConfig(stateConn.State, machineId, machineParams.Nonce, args.DataDir) |
930 | - if err == nil { |
931 | - provisioningScript, err = ProvisioningScript(mcfg) |
932 | - } |
933 | - if err != nil { |
934 | - return "", err |
935 | - } |
936 | + provisioningScript, err := client.ProvisioningScript(params.ProvisioningScriptParams{ |
937 | + MachineId: machineId, |
938 | + Nonce: machineParams.Nonce, |
939 | + }) |
940 | + if err != nil { |
941 | + return "", err |
942 | } |
943 | |
944 | // Finally, provision the machine agent. |
945 | @@ -194,28 +154,6 @@ |
946 | return outJobs, nil |
947 | } |
948 | |
949 | -func recordMachineInState1dot16( |
950 | - stateConn *juju.Conn, machineParams params.AddMachineParams) (machineId string, err error) { |
951 | - stateJobs, err := convertToStateJobs(machineParams.Jobs) |
952 | - if err != nil { |
953 | - return "", err |
954 | - } |
955 | - template := state.MachineTemplate{ |
956 | - Series: machineParams.Series, |
957 | - Constraints: machineParams.Constraints, |
958 | - InstanceId: machineParams.InstanceId, |
959 | - Jobs: stateJobs, |
960 | - Nonce: machineParams.Nonce, |
961 | - HardwareCharacteristics: machineParams.HardwareCharacteristics, |
962 | - Addresses: machineParams.Addrs, |
963 | - } |
964 | - machine, err := stateConn.State.AddOneMachine(template) |
965 | - if err != nil { |
966 | - return "", err |
967 | - } |
968 | - return machine.Id(), nil |
969 | -} |
970 | - |
971 | // gatherMachineParams collects all the information we know about the machine |
972 | // we are about to provision. It will SSH into that machine as the ubuntu user. |
973 | // The hostname supplied should not include a username. |
974 | |
975 | === removed file 'state/statecmd/destroymachines.go' |
976 | --- state/statecmd/destroymachines.go 2013-12-10 12:24:25 +0000 |
977 | +++ state/statecmd/destroymachines.go 1970-01-01 00:00:00 +0000 |
978 | @@ -1,43 +0,0 @@ |
979 | -// Copyright 2012, 2013 Canonical Ltd. |
980 | -// Licensed under the AGPLv3, see LICENCE file for details. |
981 | - |
982 | -package statecmd |
983 | - |
984 | -import ( |
985 | - "fmt" |
986 | - "strings" |
987 | - |
988 | - "launchpad.net/juju-core/errors" |
989 | - "launchpad.net/juju-core/state" |
990 | -) |
991 | - |
992 | -// DestroyMachines1dot16 destroys the machines with the specified ids. |
993 | -// This is copied from the 1.16.3 code to enable compatibility. It should be |
994 | -// removed when we release a version that goes via the API only (whatever is |
995 | -// after 1.18) |
996 | -func DestroyMachines1dot16(st *state.State, ids ...string) (err error) { |
997 | - var errs []string |
998 | - for _, id := range ids { |
999 | - machine, err := st.Machine(id) |
1000 | - switch { |
1001 | - case errors.IsNotFoundError(err): |
1002 | - err = fmt.Errorf("machine %s does not exist", id) |
1003 | - case err != nil: |
1004 | - case machine.Life() != state.Alive: |
1005 | - continue |
1006 | - default: |
1007 | - err = machine.Destroy() |
1008 | - } |
1009 | - if err != nil { |
1010 | - errs = append(errs, err.Error()) |
1011 | - } |
1012 | - } |
1013 | - if len(errs) == 0 { |
1014 | - return nil |
1015 | - } |
1016 | - msg := "some machines were not destroyed" |
1017 | - if len(errs) == len(ids) { |
1018 | - msg = "no machines were destroyed" |
1019 | - } |
1020 | - return fmt.Errorf("%s: %s", msg, strings.Join(errs, "; ")) |
1021 | -} |
Reviewers: mp+214504_ code.launchpad. net,
Message:
Please take a look.
Description:
Remove 1.16 support code
This drops most of the 1.16 support code from
the client-side. There's more to remove, this
is just a start.
https:/ /code.launchpad .net/~axwalk/ juju-core/ remove- 1.16-client- support/ +merge/ 214504
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/84520046/
Affected files (+23, -669 lines): addmachine. go constraints. go destroymachine. go environment. go juju/upgradecha rm.go upgradejuju. go manual/ provisioner. go destroymachines .go
A [revision details]
M cmd/juju/
M cmd/juju/common.go
M cmd/juju/
M cmd/juju/deploy.go
M cmd/juju/
M cmd/juju/
M cmd/juju/set.go
M cmd/juju/status.go
M cmd/juju/unset.go
cmd/
M cmd/juju/
M environs/
D state/statecmd/