Merge lp:~thumper/juju-core/common-api-env-watcher into lp:~go-bot/juju-core/trunk
- common-api-env-watcher
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Tim Penhey |
Approved revision: | no longer in the source branch. |
Merged at revision: | 2243 |
Proposed branch: | lp:~thumper/juju-core/common-api-env-watcher |
Merge into: | lp:~go-bot/juju-core/trunk |
Diff against target: |
522 lines (+111/-75) 14 files modified
state/api/agent/state.go (+3/-3) state/api/base/caller.go (+1/-1) state/api/charmrevisionupdater/updater.go (+3/-3) state/api/common/environwatcher.go (+56/-0) state/api/common/life.go (+2/-1) state/api/deployer/deployer.go (+3/-2) state/api/firewaller/firewaller.go (+3/-2) state/api/keyupdater/authorisedkeys.go (+3/-3) state/api/logger/logger.go (+3/-3) state/api/machiner/machiner.go (+3/-2) state/api/provisioner/provisioner.go (+18/-43) state/api/uniter/uniter.go (+3/-2) state/api/upgrader/upgrader.go (+3/-3) state/api/watcher/watcher.go (+7/-7) |
To merge this branch: | bzr merge lp:~thumper/juju-core/common-api-env-watcher |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email:
|
Commit message
Refactor client side api to have common behaviour
The apiserver components have a common packge that
enables other end points to share the implementation
of some common facilities.
The api client side should also have this common
behaviour.
This branch starts this with the environ watcher
and getter for the provisioner. This will be used
by the Uniter in the next branch.
In order to reduce import cycles the common.Caller
interface had to be moved. It was either that or to
have the common code in a different package. I
decided that it was better to have the same package
name for the common code on both the client and
server side for the api, so common.Caller becomes
base.Caller.
Description of the change
Refactor client side api to have common behaviour
The apiserver components have a common packge that
enables other end points to share the implementation
of some common facilities.
The api client side should also have this common
behaviour.
This branch starts this with the environ watcher
and getter for the provisioner. This will be used
by the Uniter in the next branch.
In order to reduce import cycles the common.Caller
interface had to be moved. It was either that or to
have the common code in a different package. I
decided that it was better to have the same package
name for the common code on both the client and
server side for the api, so common.Caller becomes
base.Caller.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Tim Penhey (thumper) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ian Booth (wallyworld) wrote : | # |
LGTM with tweaks
https:/
File state/api/
https:/
state/api/
doc comment
https:/
state/api/
perhaps facadeName?
https:/
state/api/
string, caller base.Caller) *EnvironWatcher {
ditto
https:/
File state/api/
https:/
state/api/
"Provisioner"
lower case please, no need to export
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Go Bot (go-bot) wrote : | # |
Attempt to merge into lp:juju-core failed due to conflicts:
text conflict in state/api/
text conflict in state/api/
text conflict in state/api/
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~thumper/juju-core/common-api-env-watcher into lp:juju-core failed. Below is the output from the failed tests.
# launchpad.
state/api/
state/api/
# launchpad.
state/api/
# launchpad.
state/api/
state/api/
# launchpad.
state/api/
state/api/
Preview Diff
1 | === modified file 'state/api/agent/state.go' | |||
2 | --- state/api/agent/state.go 2013-10-01 10:00:26 +0000 | |||
3 | +++ state/api/agent/state.go 2014-01-23 00:09:43 +0000 | |||
4 | @@ -7,18 +7,18 @@ | |||
5 | 7 | "fmt" | 7 | "fmt" |
6 | 8 | 8 | ||
7 | 9 | "launchpad.net/juju-core/instance" | 9 | "launchpad.net/juju-core/instance" |
9 | 10 | "launchpad.net/juju-core/state/api/common" | 10 | "launchpad.net/juju-core/state/api/base" |
10 | 11 | "launchpad.net/juju-core/state/api/params" | 11 | "launchpad.net/juju-core/state/api/params" |
11 | 12 | ) | 12 | ) |
12 | 13 | 13 | ||
13 | 14 | // State provides access to an agent's view of the state. | 14 | // State provides access to an agent's view of the state. |
14 | 15 | type State struct { | 15 | type State struct { |
16 | 16 | caller common.Caller | 16 | caller base.Caller |
17 | 17 | } | 17 | } |
18 | 18 | 18 | ||
19 | 19 | // NewState returns a version of the state that provides functionality | 19 | // NewState returns a version of the state that provides functionality |
20 | 20 | // required by agent code. | 20 | // required by agent code. |
22 | 21 | func NewState(caller common.Caller) *State { | 21 | func NewState(caller base.Caller) *State { |
23 | 22 | return &State{caller} | 22 | return &State{caller} |
24 | 23 | } | 23 | } |
25 | 24 | 24 | ||
26 | 25 | 25 | ||
27 | === added directory 'state/api/base' | |||
28 | === renamed file 'state/api/common/interfaces.go' => 'state/api/base/caller.go' | |||
29 | --- state/api/common/interfaces.go 2013-06-06 09:56:00 +0000 | |||
30 | +++ state/api/base/caller.go 2014-01-23 00:09:43 +0000 | |||
31 | @@ -1,7 +1,7 @@ | |||
32 | 1 | // Copyright 2012, 2013 Canonical Ltd. | 1 | // Copyright 2012, 2013 Canonical Ltd. |
33 | 2 | // Licensed under the AGPLv3, see LICENCE file for details. | 2 | // Licensed under the AGPLv3, see LICENCE file for details. |
34 | 3 | 3 | ||
36 | 4 | package common | 4 | package base |
37 | 5 | 5 | ||
38 | 6 | // Caller is implemented by the client-facing State object. | 6 | // Caller is implemented by the client-facing State object. |
39 | 7 | type Caller interface { | 7 | type Caller interface { |
40 | 8 | 8 | ||
41 | === modified file 'state/api/charmrevisionupdater/updater.go' | |||
42 | --- state/api/charmrevisionupdater/updater.go 2014-01-15 07:23:28 +0000 | |||
43 | +++ state/api/charmrevisionupdater/updater.go 2014-01-23 00:09:43 +0000 | |||
44 | @@ -4,17 +4,17 @@ | |||
45 | 4 | package charmrevisionupdater | 4 | package charmrevisionupdater |
46 | 5 | 5 | ||
47 | 6 | import ( | 6 | import ( |
49 | 7 | "launchpad.net/juju-core/state/api/common" | 7 | "launchpad.net/juju-core/state/api/base" |
50 | 8 | "launchpad.net/juju-core/state/api/params" | 8 | "launchpad.net/juju-core/state/api/params" |
51 | 9 | ) | 9 | ) |
52 | 10 | 10 | ||
53 | 11 | // State provides access to a worker's view of the state. | 11 | // State provides access to a worker's view of the state. |
54 | 12 | type State struct { | 12 | type State struct { |
56 | 13 | caller common.Caller | 13 | caller base.Caller |
57 | 14 | } | 14 | } |
58 | 15 | 15 | ||
59 | 16 | // NewState returns a version of the state that provides functionality required by the worker. | 16 | // NewState returns a version of the state that provides functionality required by the worker. |
61 | 17 | func NewState(caller common.Caller) *State { | 17 | func NewState(caller base.Caller) *State { |
62 | 18 | return &State{caller} | 18 | return &State{caller} |
63 | 19 | } | 19 | } |
64 | 20 | 20 | ||
65 | 21 | 21 | ||
66 | === added file 'state/api/common/environwatcher.go' | |||
67 | --- state/api/common/environwatcher.go 1970-01-01 00:00:00 +0000 | |||
68 | +++ state/api/common/environwatcher.go 2014-01-23 00:09:43 +0000 | |||
69 | @@ -0,0 +1,56 @@ | |||
70 | 1 | // Copyright 2014 Canonical Ltd. | ||
71 | 2 | // Licensed under the AGPLv3, see LICENCE file for details. | ||
72 | 3 | |||
73 | 4 | package common | ||
74 | 5 | |||
75 | 6 | import ( | ||
76 | 7 | "launchpad.net/juju-core/environs/config" | ||
77 | 8 | "launchpad.net/juju-core/state/api/base" | ||
78 | 9 | "launchpad.net/juju-core/state/api/params" | ||
79 | 10 | "launchpad.net/juju-core/state/api/watcher" | ||
80 | 11 | ) | ||
81 | 12 | |||
82 | 13 | // EnvironWatcher provides common client side api functions | ||
83 | 14 | // to call into the apiserver.common.EnvironWatcher. | ||
84 | 15 | type EnvironWatcher struct { | ||
85 | 16 | façadeName string | ||
86 | 17 | caller base.Caller | ||
87 | 18 | } | ||
88 | 19 | |||
89 | 20 | // NewEnvironWatcher creates a EnvironWatcher on the specified façade, | ||
90 | 21 | // and uses this name when calling through the caller. | ||
91 | 22 | func NewEnvironWatcher(façadeName string, caller base.Caller) *EnvironWatcher { | ||
92 | 23 | return &EnvironWatcher{façadeName, caller} | ||
93 | 24 | } | ||
94 | 25 | |||
95 | 26 | // WatchForEnvironConfigChanges return a NotifyWatcher waiting for the | ||
96 | 27 | // environment configuration to change. | ||
97 | 28 | func (e *EnvironWatcher) WatchForEnvironConfigChanges() (watcher.NotifyWatcher, error) { | ||
98 | 29 | var result params.NotifyWatchResult | ||
99 | 30 | err := e.caller.Call(e.façadeName, "", "WatchForEnvironConfigChanges", nil, &result) | ||
100 | 31 | if err != nil { | ||
101 | 32 | return nil, err | ||
102 | 33 | } | ||
103 | 34 | if err := result.Error; err != nil { | ||
104 | 35 | return nil, result.Error | ||
105 | 36 | } | ||
106 | 37 | w := watcher.NewNotifyWatcher(e.caller, result) | ||
107 | 38 | return w, nil | ||
108 | 39 | } | ||
109 | 40 | |||
110 | 41 | // EnvironConfig returns the current environment configuration. | ||
111 | 42 | func (e *EnvironWatcher) EnvironConfig() (*config.Config, error) { | ||
112 | 43 | var result params.EnvironConfigResult | ||
113 | 44 | err := e.caller.Call(e.façadeName, "", "EnvironConfig", nil, &result) | ||
114 | 45 | if err != nil { | ||
115 | 46 | return nil, err | ||
116 | 47 | } | ||
117 | 48 | if err := result.Error; err != nil { | ||
118 | 49 | return nil, err | ||
119 | 50 | } | ||
120 | 51 | conf, err := config.New(config.NoDefaults, result.Config) | ||
121 | 52 | if err != nil { | ||
122 | 53 | return nil, err | ||
123 | 54 | } | ||
124 | 55 | return conf, nil | ||
125 | 56 | } | ||
126 | 0 | 57 | ||
127 | === modified file 'state/api/common/life.go' | |||
128 | --- state/api/common/life.go 2014-01-22 22:36:32 +0000 | |||
129 | +++ state/api/common/life.go 2014-01-23 00:09:43 +0000 | |||
130 | @@ -6,12 +6,13 @@ | |||
131 | 6 | import ( | 6 | import ( |
132 | 7 | "fmt" | 7 | "fmt" |
133 | 8 | 8 | ||
134 | 9 | "launchpad.net/juju-core/state/api/base" | ||
135 | 9 | "launchpad.net/juju-core/state/api/params" | 10 | "launchpad.net/juju-core/state/api/params" |
136 | 10 | ) | 11 | ) |
137 | 11 | 12 | ||
138 | 12 | // Life requests the life cycle of the given entity from the given | 13 | // Life requests the life cycle of the given entity from the given |
139 | 13 | // server-side API facade via the given caller. | 14 | // server-side API facade via the given caller. |
141 | 14 | func Life(caller Caller, facadeName, tag string) (params.Life, error) { | 15 | func Life(caller base.Caller, facadeName, tag string) (params.Life, error) { |
142 | 15 | var result params.LifeResults | 16 | var result params.LifeResults |
143 | 16 | args := params.Entities{ | 17 | args := params.Entities{ |
144 | 17 | Entities: []params.Entity{{Tag: tag}}, | 18 | Entities: []params.Entity{{Tag: tag}}, |
145 | 18 | 19 | ||
146 | === modified file 'state/api/deployer/deployer.go' | |||
147 | --- state/api/deployer/deployer.go 2014-01-22 22:36:32 +0000 | |||
148 | +++ state/api/deployer/deployer.go 2014-01-23 00:09:43 +0000 | |||
149 | @@ -4,18 +4,19 @@ | |||
150 | 4 | package deployer | 4 | package deployer |
151 | 5 | 5 | ||
152 | 6 | import ( | 6 | import ( |
153 | 7 | "launchpad.net/juju-core/state/api/base" | ||
154 | 7 | "launchpad.net/juju-core/state/api/common" | 8 | "launchpad.net/juju-core/state/api/common" |
155 | 8 | "launchpad.net/juju-core/state/api/params" | 9 | "launchpad.net/juju-core/state/api/params" |
156 | 9 | ) | 10 | ) |
157 | 10 | 11 | ||
158 | 11 | // State provides access to the deployer worker's idea of the state. | 12 | // State provides access to the deployer worker's idea of the state. |
159 | 12 | type State struct { | 13 | type State struct { |
161 | 13 | caller common.Caller | 14 | caller base.Caller |
162 | 14 | } | 15 | } |
163 | 15 | 16 | ||
164 | 16 | // NewState creates a new State instance that makes API calls | 17 | // NewState creates a new State instance that makes API calls |
165 | 17 | // through the given caller. | 18 | // through the given caller. |
167 | 18 | func NewState(caller common.Caller) *State { | 19 | func NewState(caller base.Caller) *State { |
168 | 19 | return &State{caller} | 20 | return &State{caller} |
169 | 20 | } | 21 | } |
170 | 21 | 22 | ||
171 | 22 | 23 | ||
172 | === modified file 'state/api/firewaller/firewaller.go' | |||
173 | --- state/api/firewaller/firewaller.go 2014-01-22 22:36:32 +0000 | |||
174 | +++ state/api/firewaller/firewaller.go 2014-01-23 00:09:43 +0000 | |||
175 | @@ -5,6 +5,7 @@ | |||
176 | 5 | 5 | ||
177 | 6 | import ( | 6 | import ( |
178 | 7 | "launchpad.net/juju-core/environs/config" | 7 | "launchpad.net/juju-core/environs/config" |
179 | 8 | "launchpad.net/juju-core/state/api/base" | ||
180 | 8 | "launchpad.net/juju-core/state/api/common" | 9 | "launchpad.net/juju-core/state/api/common" |
181 | 9 | "launchpad.net/juju-core/state/api/params" | 10 | "launchpad.net/juju-core/state/api/params" |
182 | 10 | "launchpad.net/juju-core/state/api/watcher" | 11 | "launchpad.net/juju-core/state/api/watcher" |
183 | @@ -12,11 +13,11 @@ | |||
184 | 12 | 13 | ||
185 | 13 | // State provides access to the Firewaller API facade. | 14 | // State provides access to the Firewaller API facade. |
186 | 14 | type State struct { | 15 | type State struct { |
188 | 15 | caller common.Caller | 16 | caller base.Caller |
189 | 16 | } | 17 | } |
190 | 17 | 18 | ||
191 | 18 | // NewState creates a new client-side Firewaller facade. | 19 | // NewState creates a new client-side Firewaller facade. |
193 | 19 | func NewState(caller common.Caller) *State { | 20 | func NewState(caller base.Caller) *State { |
194 | 20 | return &State{caller} | 21 | return &State{caller} |
195 | 21 | } | 22 | } |
196 | 22 | 23 | ||
197 | 23 | 24 | ||
198 | === modified file 'state/api/keyupdater/authorisedkeys.go' | |||
199 | --- state/api/keyupdater/authorisedkeys.go 2013-12-09 11:40:27 +0000 | |||
200 | +++ state/api/keyupdater/authorisedkeys.go 2014-01-23 00:09:43 +0000 | |||
201 | @@ -6,18 +6,18 @@ | |||
202 | 6 | import ( | 6 | import ( |
203 | 7 | "fmt" | 7 | "fmt" |
204 | 8 | 8 | ||
206 | 9 | "launchpad.net/juju-core/state/api/common" | 9 | "launchpad.net/juju-core/state/api/base" |
207 | 10 | "launchpad.net/juju-core/state/api/params" | 10 | "launchpad.net/juju-core/state/api/params" |
208 | 11 | "launchpad.net/juju-core/state/api/watcher" | 11 | "launchpad.net/juju-core/state/api/watcher" |
209 | 12 | ) | 12 | ) |
210 | 13 | 13 | ||
211 | 14 | // State provides access to a worker's view of the state. | 14 | // State provides access to a worker's view of the state. |
212 | 15 | type State struct { | 15 | type State struct { |
214 | 16 | caller common.Caller | 16 | caller base.Caller |
215 | 17 | } | 17 | } |
216 | 18 | 18 | ||
217 | 19 | // NewState returns a version of the state that provides functionality required by the worker. | 19 | // NewState returns a version of the state that provides functionality required by the worker. |
219 | 20 | func NewState(caller common.Caller) *State { | 20 | func NewState(caller base.Caller) *State { |
220 | 21 | return &State{caller} | 21 | return &State{caller} |
221 | 22 | } | 22 | } |
222 | 23 | 23 | ||
223 | 24 | 24 | ||
224 | === modified file 'state/api/logger/logger.go' | |||
225 | --- state/api/logger/logger.go 2013-09-13 04:27:17 +0000 | |||
226 | +++ state/api/logger/logger.go 2014-01-23 00:09:43 +0000 | |||
227 | @@ -6,19 +6,19 @@ | |||
228 | 6 | import ( | 6 | import ( |
229 | 7 | "fmt" | 7 | "fmt" |
230 | 8 | 8 | ||
232 | 9 | "launchpad.net/juju-core/state/api/common" | 9 | "launchpad.net/juju-core/state/api/base" |
233 | 10 | "launchpad.net/juju-core/state/api/params" | 10 | "launchpad.net/juju-core/state/api/params" |
234 | 11 | "launchpad.net/juju-core/state/api/watcher" | 11 | "launchpad.net/juju-core/state/api/watcher" |
235 | 12 | ) | 12 | ) |
236 | 13 | 13 | ||
237 | 14 | // State provides access to an logger worker's view of the state. | 14 | // State provides access to an logger worker's view of the state. |
238 | 15 | type State struct { | 15 | type State struct { |
240 | 16 | caller common.Caller | 16 | caller base.Caller |
241 | 17 | } | 17 | } |
242 | 18 | 18 | ||
243 | 19 | // NewState returns a version of the state that provides functionality | 19 | // NewState returns a version of the state that provides functionality |
244 | 20 | // required by the logger worker. | 20 | // required by the logger worker. |
246 | 21 | func NewState(caller common.Caller) *State { | 21 | func NewState(caller base.Caller) *State { |
247 | 22 | return &State{caller} | 22 | return &State{caller} |
248 | 23 | } | 23 | } |
249 | 24 | 24 | ||
250 | 25 | 25 | ||
251 | === modified file 'state/api/machiner/machiner.go' | |||
252 | --- state/api/machiner/machiner.go 2014-01-22 22:36:32 +0000 | |||
253 | +++ state/api/machiner/machiner.go 2014-01-23 00:09:43 +0000 | |||
254 | @@ -4,17 +4,18 @@ | |||
255 | 4 | package machiner | 4 | package machiner |
256 | 5 | 5 | ||
257 | 6 | import ( | 6 | import ( |
258 | 7 | "launchpad.net/juju-core/state/api/base" | ||
259 | 7 | "launchpad.net/juju-core/state/api/common" | 8 | "launchpad.net/juju-core/state/api/common" |
260 | 8 | "launchpad.net/juju-core/state/api/params" | 9 | "launchpad.net/juju-core/state/api/params" |
261 | 9 | ) | 10 | ) |
262 | 10 | 11 | ||
263 | 11 | // State provides access to the Machiner API facade. | 12 | // State provides access to the Machiner API facade. |
264 | 12 | type State struct { | 13 | type State struct { |
266 | 13 | caller common.Caller | 14 | caller base.Caller |
267 | 14 | } | 15 | } |
268 | 15 | 16 | ||
269 | 16 | // NewState creates a new client-side Machiner facade. | 17 | // NewState creates a new client-side Machiner facade. |
271 | 17 | func NewState(caller common.Caller) *State { | 18 | func NewState(caller base.Caller) *State { |
272 | 18 | return &State{caller} | 19 | return &State{caller} |
273 | 19 | } | 20 | } |
274 | 20 | 21 | ||
275 | 21 | 22 | ||
276 | === modified file 'state/api/provisioner/provisioner.go' | |||
277 | --- state/api/provisioner/provisioner.go 2014-01-22 22:36:32 +0000 | |||
278 | +++ state/api/provisioner/provisioner.go 2014-01-23 00:09:43 +0000 | |||
279 | @@ -6,26 +6,33 @@ | |||
280 | 6 | import ( | 6 | import ( |
281 | 7 | "fmt" | 7 | "fmt" |
282 | 8 | 8 | ||
284 | 9 | "launchpad.net/juju-core/environs/config" | 9 | "launchpad.net/juju-core/state/api/base" |
285 | 10 | "launchpad.net/juju-core/state/api/common" | 10 | "launchpad.net/juju-core/state/api/common" |
286 | 11 | "launchpad.net/juju-core/state/api/params" | 11 | "launchpad.net/juju-core/state/api/params" |
287 | 12 | "launchpad.net/juju-core/state/api/watcher" | 12 | "launchpad.net/juju-core/state/api/watcher" |
288 | 13 | "launchpad.net/juju-core/tools" | 13 | "launchpad.net/juju-core/tools" |
289 | 14 | ) | 14 | ) |
290 | 15 | 15 | ||
291 | 16 | const provisioner = "Provisioner" | ||
292 | 17 | |||
293 | 16 | // State provides access to the Machiner API facade. | 18 | // State provides access to the Machiner API facade. |
294 | 17 | type State struct { | 19 | type State struct { |
296 | 18 | caller common.Caller | 20 | *common.EnvironWatcher |
297 | 21 | |||
298 | 22 | caller base.Caller | ||
299 | 19 | } | 23 | } |
300 | 20 | 24 | ||
301 | 21 | // NewState creates a new client-side Machiner facade. | 25 | // NewState creates a new client-side Machiner facade. |
304 | 22 | func NewState(caller common.Caller) *State { | 26 | func NewState(caller base.Caller) *State { |
305 | 23 | return &State{caller} | 27 | return &State{ |
306 | 28 | EnvironWatcher: common.NewEnvironWatcher(provisioner, caller), | ||
307 | 29 | |||
308 | 30 | caller: caller} | ||
309 | 24 | } | 31 | } |
310 | 25 | 32 | ||
311 | 26 | // machineLife requests the lifecycle of the given machine from the server. | 33 | // machineLife requests the lifecycle of the given machine from the server. |
312 | 27 | func (st *State) machineLife(tag string) (params.Life, error) { | 34 | func (st *State) machineLife(tag string) (params.Life, error) { |
314 | 28 | return common.Life(st.caller, "Provisioner", tag) | 35 | return common.Life(st.caller, provisioner, tag) |
315 | 29 | } | 36 | } |
316 | 30 | 37 | ||
317 | 31 | // Machine provides access to methods of a state.Machine through the facade. | 38 | // Machine provides access to methods of a state.Machine through the facade. |
318 | @@ -41,44 +48,12 @@ | |||
319 | 41 | }, nil | 48 | }, nil |
320 | 42 | } | 49 | } |
321 | 43 | 50 | ||
322 | 44 | // WatchForEnvironConfigChanges return a NotifyWatcher waiting for the | ||
323 | 45 | // environment configuration to change. | ||
324 | 46 | func (st *State) WatchForEnvironConfigChanges() (watcher.NotifyWatcher, error) { | ||
325 | 47 | var result params.NotifyWatchResult | ||
326 | 48 | err := st.caller.Call("Provisioner", "", "WatchForEnvironConfigChanges", nil, &result) | ||
327 | 49 | if err != nil { | ||
328 | 50 | return nil, err | ||
329 | 51 | } | ||
330 | 52 | if err := result.Error; err != nil { | ||
331 | 53 | return nil, result.Error | ||
332 | 54 | } | ||
333 | 55 | w := watcher.NewNotifyWatcher(st.caller, result) | ||
334 | 56 | return w, nil | ||
335 | 57 | } | ||
336 | 58 | |||
337 | 59 | // EnvironConfig returns the current environment configuration. | ||
338 | 60 | func (st *State) EnvironConfig() (*config.Config, error) { | ||
339 | 61 | var result params.EnvironConfigResult | ||
340 | 62 | err := st.caller.Call("Provisioner", "", "EnvironConfig", nil, &result) | ||
341 | 63 | if err != nil { | ||
342 | 64 | return nil, err | ||
343 | 65 | } | ||
344 | 66 | if err := result.Error; err != nil { | ||
345 | 67 | return nil, err | ||
346 | 68 | } | ||
347 | 69 | conf, err := config.New(config.NoDefaults, result.Config) | ||
348 | 70 | if err != nil { | ||
349 | 71 | return nil, err | ||
350 | 72 | } | ||
351 | 73 | return conf, nil | ||
352 | 74 | } | ||
353 | 75 | |||
354 | 76 | // WatchEnvironMachines returns a StringsWatcher that notifies of | 51 | // WatchEnvironMachines returns a StringsWatcher that notifies of |
355 | 77 | // changes to the lifecycles of the machines (but not containers) in | 52 | // changes to the lifecycles of the machines (but not containers) in |
356 | 78 | // the current environment. | 53 | // the current environment. |
357 | 79 | func (st *State) WatchEnvironMachines() (watcher.StringsWatcher, error) { | 54 | func (st *State) WatchEnvironMachines() (watcher.StringsWatcher, error) { |
358 | 80 | var result params.StringsWatchResult | 55 | var result params.StringsWatchResult |
360 | 81 | err := st.caller.Call("Provisioner", "", "WatchEnvironMachines", nil, &result) | 56 | err := st.caller.Call(provisioner, "", "WatchEnvironMachines", nil, &result) |
361 | 82 | if err != nil { | 57 | if err != nil { |
362 | 83 | return nil, err | 58 | return nil, err |
363 | 84 | } | 59 | } |
364 | @@ -92,7 +67,7 @@ | |||
365 | 92 | // StateAddresses returns the list of addresses used to connect to the state. | 67 | // StateAddresses returns the list of addresses used to connect to the state. |
366 | 93 | func (st *State) StateAddresses() ([]string, error) { | 68 | func (st *State) StateAddresses() ([]string, error) { |
367 | 94 | var result params.StringsResult | 69 | var result params.StringsResult |
369 | 95 | err := st.caller.Call("Provisioner", "", "StateAddresses", nil, &result) | 70 | err := st.caller.Call(provisioner, "", "StateAddresses", nil, &result) |
370 | 96 | if err != nil { | 71 | if err != nil { |
371 | 97 | return nil, err | 72 | return nil, err |
372 | 98 | } | 73 | } |
373 | @@ -102,7 +77,7 @@ | |||
374 | 102 | // APIAddresses returns the list of addresses used to connect to the API. | 77 | // APIAddresses returns the list of addresses used to connect to the API. |
375 | 103 | func (st *State) APIAddresses() ([]string, error) { | 78 | func (st *State) APIAddresses() ([]string, error) { |
376 | 104 | var result params.StringsResult | 79 | var result params.StringsResult |
378 | 105 | err := st.caller.Call("Provisioner", "", "APIAddresses", nil, &result) | 80 | err := st.caller.Call(provisioner, "", "APIAddresses", nil, &result) |
379 | 106 | if err != nil { | 81 | if err != nil { |
380 | 107 | return nil, err | 82 | return nil, err |
381 | 108 | } | 83 | } |
382 | @@ -112,7 +87,7 @@ | |||
383 | 112 | // CACert returns the certificate used to validate the state connection. | 87 | // CACert returns the certificate used to validate the state connection. |
384 | 113 | func (st *State) CACert() ([]byte, error) { | 88 | func (st *State) CACert() ([]byte, error) { |
385 | 114 | var result params.BytesResult | 89 | var result params.BytesResult |
387 | 115 | err := st.caller.Call("Provisioner", "", "CACert", nil, &result) | 90 | err := st.caller.Call(provisioner, "", "CACert", nil, &result) |
388 | 116 | if err != nil { | 91 | if err != nil { |
389 | 117 | return nil, err | 92 | return nil, err |
390 | 118 | } | 93 | } |
391 | @@ -125,7 +100,7 @@ | |||
392 | 125 | args := params.Entities{ | 100 | args := params.Entities{ |
393 | 126 | Entities: []params.Entity{{Tag: tag}}, | 101 | Entities: []params.Entity{{Tag: tag}}, |
394 | 127 | } | 102 | } |
396 | 128 | err := st.caller.Call("Provisioner", "", "Tools", args, &results) | 103 | err := st.caller.Call(provisioner, "", "Tools", args, &results) |
397 | 129 | if err != nil { | 104 | if err != nil { |
398 | 130 | // TODO: Not directly tested | 105 | // TODO: Not directly tested |
399 | 131 | return nil, err | 106 | return nil, err |
400 | @@ -144,6 +119,6 @@ | |||
401 | 144 | // ContainerConfig returns information from the environment config that are | 119 | // ContainerConfig returns information from the environment config that are |
402 | 145 | // needed for container cloud-init. | 120 | // needed for container cloud-init. |
403 | 146 | func (st *State) ContainerConfig() (result params.ContainerConfig, err error) { | 121 | func (st *State) ContainerConfig() (result params.ContainerConfig, err error) { |
405 | 147 | err = st.caller.Call("Provisioner", "", "ContainerConfig", nil, &result) | 122 | err = st.caller.Call(provisioner, "", "ContainerConfig", nil, &result) |
406 | 148 | return result, err | 123 | return result, err |
407 | 149 | } | 124 | } |
408 | 150 | 125 | ||
409 | === modified file 'state/api/uniter/uniter.go' | |||
410 | --- state/api/uniter/uniter.go 2014-01-22 22:36:32 +0000 | |||
411 | +++ state/api/uniter/uniter.go 2014-01-23 00:09:43 +0000 | |||
412 | @@ -8,19 +8,20 @@ | |||
413 | 8 | 8 | ||
414 | 9 | "launchpad.net/juju-core/charm" | 9 | "launchpad.net/juju-core/charm" |
415 | 10 | "launchpad.net/juju-core/names" | 10 | "launchpad.net/juju-core/names" |
416 | 11 | "launchpad.net/juju-core/state/api/base" | ||
417 | 11 | "launchpad.net/juju-core/state/api/common" | 12 | "launchpad.net/juju-core/state/api/common" |
418 | 12 | "launchpad.net/juju-core/state/api/params" | 13 | "launchpad.net/juju-core/state/api/params" |
419 | 13 | ) | 14 | ) |
420 | 14 | 15 | ||
421 | 15 | // State provides access to the Uniter API facade. | 16 | // State provides access to the Uniter API facade. |
422 | 16 | type State struct { | 17 | type State struct { |
424 | 17 | caller common.Caller | 18 | caller base.Caller |
425 | 18 | // unitTag contains the authenticated unit's tag. | 19 | // unitTag contains the authenticated unit's tag. |
426 | 19 | unitTag string | 20 | unitTag string |
427 | 20 | } | 21 | } |
428 | 21 | 22 | ||
429 | 22 | // NewState creates a new client-side Uniter facade. | 23 | // NewState creates a new client-side Uniter facade. |
431 | 23 | func NewState(caller common.Caller, authTag string) *State { | 24 | func NewState(caller base.Caller, authTag string) *State { |
432 | 24 | return &State{caller, authTag} | 25 | return &State{caller, authTag} |
433 | 25 | } | 26 | } |
434 | 26 | 27 | ||
435 | 27 | 28 | ||
436 | === modified file 'state/api/upgrader/upgrader.go' | |||
437 | --- state/api/upgrader/upgrader.go 2013-10-03 12:18:41 +0000 | |||
438 | +++ state/api/upgrader/upgrader.go 2014-01-23 00:09:43 +0000 | |||
439 | @@ -6,7 +6,7 @@ | |||
440 | 6 | import ( | 6 | import ( |
441 | 7 | "fmt" | 7 | "fmt" |
442 | 8 | 8 | ||
444 | 9 | "launchpad.net/juju-core/state/api/common" | 9 | "launchpad.net/juju-core/state/api/base" |
445 | 10 | "launchpad.net/juju-core/state/api/params" | 10 | "launchpad.net/juju-core/state/api/params" |
446 | 11 | "launchpad.net/juju-core/state/api/watcher" | 11 | "launchpad.net/juju-core/state/api/watcher" |
447 | 12 | "launchpad.net/juju-core/tools" | 12 | "launchpad.net/juju-core/tools" |
448 | @@ -15,12 +15,12 @@ | |||
449 | 15 | 15 | ||
450 | 16 | // State provides access to an upgrader worker's view of the state. | 16 | // State provides access to an upgrader worker's view of the state. |
451 | 17 | type State struct { | 17 | type State struct { |
453 | 18 | caller common.Caller | 18 | caller base.Caller |
454 | 19 | } | 19 | } |
455 | 20 | 20 | ||
456 | 21 | // NewState returns a version of the state that provides functionality | 21 | // NewState returns a version of the state that provides functionality |
457 | 22 | // required by the upgrader worker. | 22 | // required by the upgrader worker. |
459 | 23 | func NewState(caller common.Caller) *State { | 23 | func NewState(caller base.Caller) *State { |
460 | 24 | return &State{caller} | 24 | return &State{caller} |
461 | 25 | } | 25 | } |
462 | 26 | 26 | ||
463 | 27 | 27 | ||
464 | === modified file 'state/api/watcher/watcher.go' | |||
465 | --- state/api/watcher/watcher.go 2013-12-05 03:42:25 +0000 | |||
466 | +++ state/api/watcher/watcher.go 2014-01-23 00:09:43 +0000 | |||
467 | @@ -9,7 +9,7 @@ | |||
468 | 9 | "launchpad.net/tomb" | 9 | "launchpad.net/tomb" |
469 | 10 | 10 | ||
470 | 11 | "launchpad.net/juju-core/log" | 11 | "launchpad.net/juju-core/log" |
472 | 12 | "launchpad.net/juju-core/state/api/common" | 12 | "launchpad.net/juju-core/state/api/base" |
473 | 13 | "launchpad.net/juju-core/state/api/params" | 13 | "launchpad.net/juju-core/state/api/params" |
474 | 14 | ) | 14 | ) |
475 | 15 | 15 | ||
476 | @@ -114,14 +114,14 @@ | |||
477 | 114 | // It does not send content for those changes. | 114 | // It does not send content for those changes. |
478 | 115 | type notifyWatcher struct { | 115 | type notifyWatcher struct { |
479 | 116 | commonWatcher | 116 | commonWatcher |
481 | 117 | caller common.Caller | 117 | caller base.Caller |
482 | 118 | notifyWatcherId string | 118 | notifyWatcherId string |
483 | 119 | out chan struct{} | 119 | out chan struct{} |
484 | 120 | } | 120 | } |
485 | 121 | 121 | ||
486 | 122 | // If an API call returns a NotifyWatchResult, you can use this to turn it into | 122 | // If an API call returns a NotifyWatchResult, you can use this to turn it into |
487 | 123 | // a local Watcher. | 123 | // a local Watcher. |
489 | 124 | func NewNotifyWatcher(caller common.Caller, result params.NotifyWatchResult) NotifyWatcher { | 124 | func NewNotifyWatcher(caller base.Caller, result params.NotifyWatchResult) NotifyWatcher { |
490 | 125 | w := ¬ifyWatcher{ | 125 | w := ¬ifyWatcher{ |
491 | 126 | caller: caller, | 126 | caller: caller, |
492 | 127 | notifyWatcherId: result.NotifyWatcherId, | 127 | notifyWatcherId: result.NotifyWatcherId, |
493 | @@ -172,12 +172,12 @@ | |||
494 | 172 | // The content of the changes is a list of strings. | 172 | // The content of the changes is a list of strings. |
495 | 173 | type stringsWatcher struct { | 173 | type stringsWatcher struct { |
496 | 174 | commonWatcher | 174 | commonWatcher |
498 | 175 | caller common.Caller | 175 | caller base.Caller |
499 | 176 | stringsWatcherId string | 176 | stringsWatcherId string |
500 | 177 | out chan []string | 177 | out chan []string |
501 | 178 | } | 178 | } |
502 | 179 | 179 | ||
504 | 180 | func NewStringsWatcher(caller common.Caller, result params.StringsWatchResult) StringsWatcher { | 180 | func NewStringsWatcher(caller base.Caller, result params.StringsWatchResult) StringsWatcher { |
505 | 181 | w := &stringsWatcher{ | 181 | w := &stringsWatcher{ |
506 | 182 | caller: caller, | 182 | caller: caller, |
507 | 183 | stringsWatcherId: result.StringsWatcherId, | 183 | stringsWatcherId: result.StringsWatcherId, |
508 | @@ -230,12 +230,12 @@ | |||
509 | 230 | // those units known to have entered. | 230 | // those units known to have entered. |
510 | 231 | type relationUnitsWatcher struct { | 231 | type relationUnitsWatcher struct { |
511 | 232 | commonWatcher | 232 | commonWatcher |
513 | 233 | caller common.Caller | 233 | caller base.Caller |
514 | 234 | relationUnitsWatcherId string | 234 | relationUnitsWatcherId string |
515 | 235 | out chan params.RelationUnitsChange | 235 | out chan params.RelationUnitsChange |
516 | 236 | } | 236 | } |
517 | 237 | 237 | ||
519 | 238 | func NewRelationUnitsWatcher(caller common.Caller, result params.RelationUnitsWatchResult) RelationUnitsWatcher { | 238 | func NewRelationUnitsWatcher(caller base.Caller, result params.RelationUnitsWatchResult) RelationUnitsWatcher { |
520 | 239 | w := &relationUnitsWatcher{ | 239 | w := &relationUnitsWatcher{ |
521 | 240 | caller: caller, | 240 | caller: caller, |
522 | 241 | relationUnitsWatcherId: result.RelationUnitsWatcherId, | 241 | relationUnitsWatcherId: result.RelationUnitsWatcherId, |
Reviewers: mp+202766_ code.launchpad. net,
Message:
Please take a look.
Description:
Refactor client side api to have common behaviour
The apiserver components have a common packge that
enables other end points to share the implementation
of some common facilities.
The api client side should also have this common
behaviour.
This branch starts this with the environ watcher
and getter for the provisioner. This will be used
by the Uniter in the next branch.
In order to reduce import cycles the common.Caller
interface had to be moved. It was either that or to
have the common code in a different package. I
decided that it was better to have the same package
name for the common code on both the client and
server side for the api, so common.Caller becomes
base.Caller.
https:/ /code.launchpad .net/~thumper/ juju-core/ common- api-env- watcher/ +merge/ 202766
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/52610045/
Affected files (+104, -75 lines): agent/state. go base/caller. go charmrevisionup dater/updater. go common/ environwatcher. go deployer/ deployer. go keyupdater/ authorisedkeys. go logger/ logger. go machiner/ machiner. go provisioner/ provisioner. go uniter/ uniter. go upgrader/ upgrader. go watcher/ watcher. go
A [revision details]
M state/api/
M state/api/
M state/api/
A state/api/
M state/api/
M state/api/
M state/api/
M state/api/
M state/api/
M state/api/
M state/api/
M state/api/