Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2012, 2013 Canonical Ltd. | 1 // Copyright 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package upgrader | 4 package upgrader |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 | 8 |
9 "launchpad.net/juju-core/agent/tools" | |
9 "launchpad.net/juju-core/state/api/common" | 10 "launchpad.net/juju-core/state/api/common" |
10 "launchpad.net/juju-core/state/api/params" | 11 "launchpad.net/juju-core/state/api/params" |
11 "launchpad.net/juju-core/state/api/watcher" | 12 "launchpad.net/juju-core/state/api/watcher" |
12 ) | 13 ) |
13 | 14 |
14 // State provides access to an upgrader worker's view of the state. | 15 // State provides access to an upgrader worker's view of the state. |
15 type State struct { | 16 type State struct { |
16 caller common.Caller | 17 caller common.Caller |
17 } | 18 } |
18 | 19 |
19 // NewState returns a version of the state that provides functionality | 20 // NewState returns a version of the state that provides functionality |
20 // required by the upgrader worker. | 21 // required by the upgrader worker. |
21 func NewState(caller common.Caller) *State { | 22 func NewState(caller common.Caller) *State { |
22 return &State{caller} | 23 return &State{caller} |
23 } | 24 } |
24 | 25 |
25 func (st *State) SetTools(tools params.AgentTools) error { | 26 func (st *State) SetTools(tag string, tools *tools.Tools) error { |
dimitern
2013/07/25 09:14:33
doc comment?
rog
2013/07/25 11:18:34
Done.
| |
26 » var results params.SetAgentToolsResults | 27 » var results params.ErrorResults |
27 » args := params.SetAgentTools{ | 28 » args := params.SetAgentsTools{ |
28 » » AgentTools: []params.AgentTools{tools}, | 29 » » AgentTools: []params.SetAgentTools{{ |
30 » » » Tag: tag, | |
31 » » » Tools: tools, | |
32 » » }}, | |
29 } | 33 } |
30 err := st.caller.Call("Upgrader", "", "SetTools", args, &results) | 34 err := st.caller.Call("Upgrader", "", "SetTools", args, &results) |
31 if err != nil { | 35 if err != nil { |
32 // TODO: Not directly tested | 36 // TODO: Not directly tested |
33 return err | 37 return err |
34 } | 38 } |
35 » if len(results.Results) != 1 { | 39 » return results.OneError() |
36 » » return fmt.Errorf("expected one result, got %d", len(results.Res ults)) | |
37 » } | |
38 » result := results.Results[0] | |
39 » if result.Tag != tools.Tag { | |
40 » » // TODO: Not directly tested | |
41 » » return fmt.Errorf("server returned tag that did not match: got % q expected %q", | |
42 » » » result.Tag, tools.Tag) | |
43 » } | |
44 » if err := result.Error; err != nil { | |
45 » » return err | |
46 » } | |
47 » return nil | |
48 } | 40 } |
49 | 41 |
50 func (st *State) Tools(tag string) (*params.AgentTools, error) { | 42 func (st *State) Tools(tag string) (*tools.Tools, error) { |
51 var results params.AgentToolsResults | 43 var results params.AgentToolsResults |
52 args := params.Entities{ | 44 args := params.Entities{ |
53 Entities: []params.Entity{{Tag: tag}}, | 45 Entities: []params.Entity{{Tag: tag}}, |
54 } | 46 } |
55 err := st.caller.Call("Upgrader", "", "Tools", args, &results) | 47 err := st.caller.Call("Upgrader", "", "Tools", args, &results) |
56 if err != nil { | 48 if err != nil { |
57 // TODO: Not directly tested | 49 // TODO: Not directly tested |
58 return nil, err | 50 return nil, err |
59 } | 51 } |
60 » if len(results.Tools) != 1 { | 52 » if len(results.Results) != 1 { |
61 // TODO: Not directly tested | 53 // TODO: Not directly tested |
62 » » return nil, fmt.Errorf("expected one result, got %d", len(result s.Tools)) | 54 » » return nil, fmt.Errorf("expected one result, got %d", len(result s.Results)) |
63 } | 55 } |
64 » tools := results.Tools[0] | 56 » result := results.Results[0] |
65 » if err := tools.Error; err != nil { | 57 » if err := result.Error; err != nil { |
66 return nil, err | 58 return nil, err |
67 } | 59 } |
68 » if tools.AgentTools.Tag != tag { | 60 » return result.Tools, nil |
69 » » // TODO: Not directly tested | |
70 » » return nil, fmt.Errorf("server returned tag that did not match: got %q expected %q", | |
71 » » » tools.AgentTools.Tag, tag) | |
72 » } | |
73 » return &tools.AgentTools, nil | |
74 } | 61 } |
75 | 62 |
76 func (st *State) WatchAPIVersion(agentTag string) (*watcher.NotifyWatcher, error ) { | 63 func (st *State) WatchAPIVersion(agentTag string) (*watcher.NotifyWatcher, error ) { |
77 var results params.NotifyWatchResults | 64 var results params.NotifyWatchResults |
78 args := params.Entities{ | 65 args := params.Entities{ |
79 Entities: []params.Entity{{Tag: agentTag}}, | 66 Entities: []params.Entity{{Tag: agentTag}}, |
80 } | 67 } |
81 err := st.caller.Call("Upgrader", "", "WatchAPIVersion", args, &results) | 68 err := st.caller.Call("Upgrader", "", "WatchAPIVersion", args, &results) |
82 if err != nil { | 69 if err != nil { |
83 // TODO: Not directly tested | 70 // TODO: Not directly tested |
84 return nil, err | 71 return nil, err |
85 } | 72 } |
86 if len(results.Results) != 1 { | 73 if len(results.Results) != 1 { |
87 // TODO: Not directly tested | 74 // TODO: Not directly tested |
88 return nil, fmt.Errorf("expected one result, got %d", len(result s.Results)) | 75 return nil, fmt.Errorf("expected one result, got %d", len(result s.Results)) |
89 } | 76 } |
90 result := results.Results[0] | 77 result := results.Results[0] |
91 if result.Error != nil { | 78 if result.Error != nil { |
92 // TODO: Not directly tested | 79 // TODO: Not directly tested |
93 return nil, result.Error | 80 return nil, result.Error |
94 } | 81 } |
95 w := watcher.NewNotifyWatcher(st.caller, result) | 82 w := watcher.NewNotifyWatcher(st.caller, result) |
96 return w, nil | 83 return w, nil |
97 } | 84 } |
OLD | NEW |