Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(436)

Delta Between Two Patch Sets: state/api/apiclient.go

Issue 8716043: Make AddServiceUnits API call return unit names
Left Patch Set: Created 10 years, 11 months ago
Right Patch Set: Make AddServiceUnits API call return unit names Created 10 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « cmd/juju/addunit.go ('k') | state/api/params/params.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package api 1 package api
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "launchpad.net/juju-core/charm" 5 "launchpad.net/juju-core/charm"
6 "launchpad.net/juju-core/constraints" 6 "launchpad.net/juju-core/constraints"
7 "launchpad.net/juju-core/log" 7 "launchpad.net/juju-core/log"
8 "launchpad.net/juju-core/state/api/params" 8 "launchpad.net/juju-core/state/api/params"
9 "launchpad.net/tomb" 9 "launchpad.net/tomb"
10 "strings" 10 "strings"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 return &s, nil 49 return &s, nil
50 } 50 }
51 51
52 // ServiceSet sets configuration options on a service. 52 // ServiceSet sets configuration options on a service.
53 func (c *Client) ServiceSet(service string, options map[string]string) error { 53 func (c *Client) ServiceSet(service string, options map[string]string) error {
54 p := params.ServiceSet{ 54 p := params.ServiceSet{
55 ServiceName: service, 55 ServiceName: service,
56 Options: options, 56 Options: options,
57 } 57 }
58 » err := c.st.client.Call("Client", "", "ServiceSet", p, nil) 58 » return c.st.call("Client", "", "ServiceSet", p, nil)
59 » return clientError(err)
60 } 59 }
61 60
62 // Resolved clears errors on a unit. 61 // Resolved clears errors on a unit.
63 func (c *Client) Resolved(unit string, retry bool) error { 62 func (c *Client) Resolved(unit string, retry bool) error {
64 p := params.Resolved{ 63 p := params.Resolved{
65 UnitName: unit, 64 UnitName: unit,
66 Retry: retry, 65 Retry: retry,
67 } 66 }
68 » err := c.st.client.Call("Client", "", "Resolved", p, nil) 67 » return c.st.call("Client", "", "Resolved", p, nil)
69 » return clientError(err)
70 } 68 }
71 69
72 // ServiceSetYAML sets configuration options on a service 70 // ServiceSetYAML sets configuration options on a service
73 // given options in YAML format. 71 // given options in YAML format.
74 func (c *Client) ServiceSetYAML(service string, yaml string) error { 72 func (c *Client) ServiceSetYAML(service string, yaml string) error {
75 p := params.ServiceSetYAML{ 73 p := params.ServiceSetYAML{
76 ServiceName: service, 74 ServiceName: service,
77 Config: yaml, 75 Config: yaml,
78 } 76 }
79 » err := c.st.client.Call("Client", "", "ServiceSetYAML", p, nil) 77 » return c.st.call("Client", "", "ServiceSetYAML", p, nil)
80 » return clientError(err)
81 } 78 }
82 79
83 // ServiceGet returns the configuration for the named service. 80 // ServiceGet returns the configuration for the named service.
84 func (c *Client) ServiceGet(service string) (*params.ServiceGetResults, error) { 81 func (c *Client) ServiceGet(service string) (*params.ServiceGetResults, error) {
85 var results params.ServiceGetResults 82 var results params.ServiceGetResults
86 params := params.ServiceGet{ServiceName: service} 83 params := params.ServiceGet{ServiceName: service}
87 » err := c.st.client.Call("Client", "", "ServiceGet", params, &results) 84 » err := c.st.call("Client", "", "ServiceGet", params, &results)
88 » if err != nil { 85 » return &results, err
89 » » return nil, clientError(err)
90 » }
91 » return &results, nil
92 } 86 }
93 87
94 // AddRelation adds a relation between the specified endpoints and returns the r elation info. 88 // AddRelation adds a relation between the specified endpoints and returns the r elation info.
95 func (c *Client) AddRelation(endpoints ...string) (*params.AddRelationResults, e rror) { 89 func (c *Client) AddRelation(endpoints ...string) (*params.AddRelationResults, e rror) {
96 var addRelRes params.AddRelationResults 90 var addRelRes params.AddRelationResults
97 params := params.AddRelation{Endpoints: endpoints} 91 params := params.AddRelation{Endpoints: endpoints}
98 » err := c.st.client.Call("Client", "", "AddRelation", params, &addRelRes) 92 » err := c.st.call("Client", "", "AddRelation", params, &addRelRes)
99 » if err != nil { 93 » return &addRelRes, err
100 » » return nil, clientError(err)
101 » }
102 » return &addRelRes, nil
103 } 94 }
104 95
105 // DestroyRelation removes the relation between the specified endpoints. 96 // DestroyRelation removes the relation between the specified endpoints.
106 func (c *Client) DestroyRelation(endpoints ...string) error { 97 func (c *Client) DestroyRelation(endpoints ...string) error {
107 params := params.DestroyRelation{Endpoints: endpoints} 98 params := params.DestroyRelation{Endpoints: endpoints}
108 » err := c.st.client.Call("Client", "", "DestroyRelation", params, nil) 99 » return c.st.call("Client", "", "DestroyRelation", params, nil)
109 » return clientError(err)
110 } 100 }
111 101
112 // ServiceExpose changes the juju-managed firewall to expose any ports that 102 // ServiceExpose changes the juju-managed firewall to expose any ports that
113 // were also explicitly marked by units as open. 103 // were also explicitly marked by units as open.
114 func (c *Client) ServiceExpose(service string) error { 104 func (c *Client) ServiceExpose(service string) error {
115 params := params.ServiceExpose{ServiceName: service} 105 params := params.ServiceExpose{ServiceName: service}
116 » err := c.st.client.Call("Client", "", "ServiceExpose", params, nil) 106 » return c.st.call("Client", "", "ServiceExpose", params, nil)
117 » return clientError(err)
118 } 107 }
119 108
120 // ServiceUnexpose changes the juju-managed firewall to unexpose any ports that 109 // ServiceUnexpose changes the juju-managed firewall to unexpose any ports that
121 // were also explicitly marked by units as open. 110 // were also explicitly marked by units as open.
122 func (c *Client) ServiceUnexpose(service string) error { 111 func (c *Client) ServiceUnexpose(service string) error {
123 params := params.ServiceUnexpose{ServiceName: service} 112 params := params.ServiceUnexpose{ServiceName: service}
124 » err := c.st.client.Call("Client", "", "ServiceUnexpose", params, nil) 113 » return c.st.call("Client", "", "ServiceUnexpose", params, nil)
125 » return clientError(err)
126 } 114 }
127 115
128 // ServiceDeploy obtains the charm, either locally or from the charm store, 116 // ServiceDeploy obtains the charm, either locally or from the charm store,
129 // and deploys it. 117 // and deploys it.
130 func (c *Client) ServiceDeploy(charmUrl string, serviceName string, numUnits int , configYAML string, cons constraints.Value) error { 118 func (c *Client) ServiceDeploy(charmUrl string, serviceName string, numUnits int , configYAML string, cons constraints.Value) error {
131 params := params.ServiceDeploy{ 119 params := params.ServiceDeploy{
132 ServiceName: serviceName, 120 ServiceName: serviceName,
133 CharmUrl: charmUrl, 121 CharmUrl: charmUrl,
134 NumUnits: numUnits, 122 NumUnits: numUnits,
135 // BUG(lp:1162122): ConfigYAML has no tests. 123 // BUG(lp:1162122): ConfigYAML has no tests.
136 ConfigYAML: configYAML, 124 ConfigYAML: configYAML,
137 Constraints: cons, 125 Constraints: cons,
138 } 126 }
139 » err := c.st.client.Call("Client", "", "ServiceDeploy", params, nil) 127 » return c.st.call("Client", "", "ServiceDeploy", params, nil)
140 » if err != nil {
141 » » return clientError(err)
142 » }
143 » return nil
144 } 128 }
145 129
146 // AddServiceUnits adds a given number of units to a service. 130 // AddServiceUnits adds a given number of units to a service.
147 func (c *Client) AddServiceUnits(service string, numUnits int) ([]string, error) { 131 func (c *Client) AddServiceUnits(service string, numUnits int) ([]string, error) {
148 args := params.AddServiceUnits{ 132 args := params.AddServiceUnits{
149 ServiceName: service, 133 ServiceName: service,
150 NumUnits: numUnits, 134 NumUnits: numUnits,
151 } 135 }
152 results := new(params.AddServiceUnitsResults) 136 results := new(params.AddServiceUnitsResults)
153 » err := c.st.client.Call("Client", "", "AddServiceUnits", args, results) 137 » err := c.st.call("Client", "", "AddServiceUnits", args, results)
rog 2013/04/12 17:37:18 if you use c.st.call, you won't need to return cli
dimitern 2013/04/12 18:01:09 +1
frankban 2013/04/15 09:54:02 Done here.
154 » return results.Units, clientError(err) 138 » return results.Units, err
155 } 139 }
156 140
157 // DestroyServiceUnits decreases the number of units dedicated to a service. 141 // DestroyServiceUnits decreases the number of units dedicated to a service.
158 func (c *Client) DestroyServiceUnits(unitNames []string) error { 142 func (c *Client) DestroyServiceUnits(unitNames []string) error {
159 params := params.DestroyServiceUnits{unitNames} 143 params := params.DestroyServiceUnits{unitNames}
160 » err := c.st.client.Call("Client", "", "DestroyServiceUnits", params, nil ) 144 » return c.st.call("Client", "", "DestroyServiceUnits", params, nil)
161 » return clientError(err)
162 } 145 }
163 146
164 // ServiceDestroy destroys a given service. 147 // ServiceDestroy destroys a given service.
165 func (c *Client) ServiceDestroy(service string) error { 148 func (c *Client) ServiceDestroy(service string) error {
166 params := params.ServiceDestroy{ 149 params := params.ServiceDestroy{
167 ServiceName: service, 150 ServiceName: service,
168 } 151 }
169 » return clientError(c.st.client.Call("Client", "", "ServiceDestroy", para ms, nil)) 152 » return c.st.call("Client", "", "ServiceDestroy", params, nil)
170 } 153 }
171 154
172 // GetServiceConstraints returns the constraints for the given service. 155 // GetServiceConstraints returns the constraints for the given service.
173 func (c *Client) GetServiceConstraints(service string) (constraints.Value, error ) { 156 func (c *Client) GetServiceConstraints(service string) (constraints.Value, error ) {
174 results := new(params.GetServiceConstraintsResults) 157 results := new(params.GetServiceConstraintsResults)
175 » err := c.st.client.Call("Client", "", "GetServiceConstraints", params.Ge tServiceConstraints{service}, results) 158 » err := c.st.call("Client", "", "GetServiceConstraints", params.GetServic eConstraints{service}, results)
176 » return results.Constraints, clientError(err) 159 » return results.Constraints, err
177 } 160 }
178 161
179 // SetServiceConstraints specifies the constraints for the given service. 162 // SetServiceConstraints specifies the constraints for the given service.
180 func (c *Client) SetServiceConstraints(service string, constraints constraints.V alue) error { 163 func (c *Client) SetServiceConstraints(service string, constraints constraints.V alue) error {
181 params := params.SetServiceConstraints{ 164 params := params.SetServiceConstraints{
182 ServiceName: service, 165 ServiceName: service,
183 Constraints: constraints, 166 Constraints: constraints,
184 } 167 }
185 » return clientError(c.st.client.Call("Client", "", "SetServiceConstraints ", params, nil)) 168 » return c.st.call("Client", "", "SetServiceConstraints", params, nil)
186 } 169 }
187 170
188 // CharmInfo holds information about a charm. 171 // CharmInfo holds information about a charm.
189 type CharmInfo struct { 172 type CharmInfo struct {
190 Revision int 173 Revision int
191 URL string 174 URL string
192 Config *charm.Config 175 Config *charm.Config
193 Meta *charm.Meta 176 Meta *charm.Meta
194 } 177 }
195 178
196 // CharmInfo returns information about the requested charm. 179 // CharmInfo returns information about the requested charm.
197 func (c *Client) CharmInfo(charmURL string) (*CharmInfo, error) { 180 func (c *Client) CharmInfo(charmURL string) (*CharmInfo, error) {
198 args := params.CharmInfo{CharmURL: charmURL} 181 args := params.CharmInfo{CharmURL: charmURL}
199 info := new(CharmInfo) 182 info := new(CharmInfo)
200 » err := c.st.client.Call("Client", "", "CharmInfo", args, info) 183 » if err := c.st.call("Client", "", "CharmInfo", args, info); err != nil {
201 » if err != nil { 184 » » return nil, err
202 » » return nil, clientError(err)
203 } 185 }
204 return info, nil 186 return info, nil
205 } 187 }
206 188
207 // EnvironmentInfo holds information about the Juju environment. 189 // EnvironmentInfo holds information about the Juju environment.
208 type EnvironmentInfo struct { 190 type EnvironmentInfo struct {
209 DefaultSeries string 191 DefaultSeries string
210 ProviderType string 192 ProviderType string
211 Name string 193 Name string
212 } 194 }
213 195
214 // EnvironmentInfo returns details about the Juju environment. 196 // EnvironmentInfo returns details about the Juju environment.
215 func (c *Client) EnvironmentInfo() (*EnvironmentInfo, error) { 197 func (c *Client) EnvironmentInfo() (*EnvironmentInfo, error) {
216 info := new(EnvironmentInfo) 198 info := new(EnvironmentInfo)
217 » err := c.st.client.Call("Client", "", "EnvironmentInfo", nil, info) 199 » err := c.st.call("Client", "", "EnvironmentInfo", nil, info)
218 » return info, clientError(err) 200 » return info, err
219 } 201 }
220 202
221 // AllWatcher holds information allowing us to get Deltas describing changes 203 // AllWatcher holds information allowing us to get Deltas describing changes
222 // to the entire environment. 204 // to the entire environment.
223 type AllWatcher struct { 205 type AllWatcher struct {
224 client *Client 206 client *Client
225 id *string 207 id *string
226 } 208 }
227 209
228 func newAllWatcher(client *Client, id *string) *AllWatcher { 210 func newAllWatcher(client *Client, id *string) *AllWatcher {
229 return &AllWatcher{client, id} 211 return &AllWatcher{client, id}
230 } 212 }
231 213
232 func (watcher *AllWatcher) Next() ([]params.Delta, error) { 214 func (watcher *AllWatcher) Next() ([]params.Delta, error) {
233 info := new(params.AllWatcherNextResults) 215 info := new(params.AllWatcherNextResults)
234 » err := watcher.client.st.client.Call("AllWatcher", *watcher.id, "Next", nil, info) 216 » err := watcher.client.st.call("AllWatcher", *watcher.id, "Next", nil, in fo)
235 » return info.Deltas, clientError(err) 217 » return info.Deltas, err
236 } 218 }
237 219
238 func (watcher *AllWatcher) Stop() error { 220 func (watcher *AllWatcher) Stop() error {
239 » return clientError( 221 » return watcher.client.st.call("AllWatcher", *watcher.id, "Stop", nil, ni l)
240 » » watcher.client.st.client.Call("AllWatcher", *watcher.id, "Stop", nil, nil))
241 } 222 }
242 223
243 // WatchAll holds the id of the newly-created AllWatcher. 224 // WatchAll holds the id of the newly-created AllWatcher.
244 type WatchAll struct { 225 type WatchAll struct {
245 AllWatcherId string 226 AllWatcherId string
246 } 227 }
247 228
248 // WatchAll returns an AllWatcher, from which you can request the Next 229 // WatchAll returns an AllWatcher, from which you can request the Next
249 // collection of Deltas. 230 // collection of Deltas.
250 func (c *Client) WatchAll() (*AllWatcher, error) { 231 func (c *Client) WatchAll() (*AllWatcher, error) {
251 info := new(WatchAll) 232 info := new(WatchAll)
252 » err := c.st.client.Call("Client", "", "WatchAll", nil, info) 233 » if err := c.st.call("Client", "", "WatchAll", nil, info); err != nil {
253 » if err != nil { 234 » » return nil, err
254 » » return nil, clientError(err)
255 } 235 }
256 return newAllWatcher(c, &info.AllWatcherId), nil 236 return newAllWatcher(c, &info.AllWatcherId), nil
257 } 237 }
258 238
259 // GetAnnotations returns annotations that have been set on the given entity. 239 // GetAnnotations returns annotations that have been set on the given entity.
260 func (c *Client) GetAnnotations(tag string) (map[string]string, error) { 240 func (c *Client) GetAnnotations(tag string) (map[string]string, error) {
261 args := params.GetAnnotations{tag} 241 args := params.GetAnnotations{tag}
262 ann := new(params.GetAnnotationsResults) 242 ann := new(params.GetAnnotationsResults)
263 » err := c.st.client.Call("Client", "", "GetAnnotations", args, ann) 243 » err := c.st.call("Client", "", "GetAnnotations", args, ann)
264 » if err != nil { 244 » return ann.Annotations, err
265 » » return nil, clientError(err)
266 » }
267 » return ann.Annotations, nil
268 } 245 }
269 246
270 // SetAnnotations sets the annotation pairs on the given entity. 247 // SetAnnotations sets the annotation pairs on the given entity.
271 // Currently annotations are supported on machines, services, 248 // Currently annotations are supported on machines, services,
272 // units and the environment itself. 249 // units and the environment itself.
273 func (c *Client) SetAnnotations(tag string, pairs map[string]string) error { 250 func (c *Client) SetAnnotations(tag string, pairs map[string]string) error {
274 args := params.SetAnnotations{tag, pairs} 251 args := params.SetAnnotations{tag, pairs}
275 » err := c.st.client.Call("Client", "", "SetAnnotations", args, nil) 252 » return c.st.call("Client", "", "SetAnnotations", args, nil)
276 » if err != nil {
277 » » return clientError(err)
278 » }
279 » return nil
280 } 253 }
281 254
282 // Machine returns a reference to the machine with the given id. 255 // Machine returns a reference to the machine with the given id.
283 func (st *State) Machine(id string) (*Machine, error) { 256 func (st *State) Machine(id string) (*Machine, error) {
284 m := &Machine{ 257 m := &Machine{
285 st: st, 258 st: st,
286 id: id, 259 id: id,
287 } 260 }
288 if err := m.Refresh(); err != nil { 261 if err := m.Refresh(); err != nil {
289 return nil, err 262 return nil, err
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 // Tag values returned by any other entities from the same state. 452 // Tag values returned by any other entities from the same state.
480 func (u *Unit) Tag() string { 453 func (u *Unit) Tag() string {
481 return UnitTag(u.name) 454 return UnitTag(u.name)
482 } 455 }
483 456
484 // DeployerTag returns the tag of the agent responsible for deploying 457 // DeployerTag returns the tag of the agent responsible for deploying
485 // the unit. If no such entity can be determined, false is returned. 458 // the unit. If no such entity can be determined, false is returned.
486 func (u *Unit) DeployerTag() (string, bool) { 459 func (u *Unit) DeployerTag() (string, bool) {
487 return u.doc.DeployerTag, u.doc.DeployerTag != "" 460 return u.doc.DeployerTag, u.doc.DeployerTag != ""
488 } 461 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b