Merge lp:~benji/juju-core/expose-service-constraints into lp:~juju/juju-core/trunk

Proposed by Benji York
Status: Merged
Merged at revision: 1109
Proposed branch: lp:~benji/juju-core/expose-service-constraints
Merge into: lp:~juju/juju-core/trunk
Diff against target: 128 lines (+57/-4)
6 files modified
cmd/juju/constraints.go (+5/-4)
state/api/apiclient.go (+7/-0)
state/api/params/params.go (+10/-0)
state/apiserver/api_test.go (+11/-0)
state/apiserver/apiserver.go (+5/-0)
state/statecmd/getconstraints.go (+19/-0)
To merge this branch: bzr merge lp:~benji/juju-core/expose-service-constraints
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+157115@code.launchpad.net

Description of the change

Add service constraint fetching to the API

https://codereview.appspot.com/8366043/

To post a comment you must log in.
Revision history for this message
Dimiter Naydenov (dimitern) wrote :

LGTM, modulo a few trivials.

https://codereview.appspot.com/8366043/diff/1/cmd/juju/constraints.go
File cmd/juju/constraints.go (right):

https://codereview.appspot.com/8366043/diff/1/cmd/juju/constraints.go#newcode66
cmd/juju/constraints.go:66: if err != nil {
how about just: if err == nil { cons = results.Constraints }, the if
below will take care of the other case.

https://codereview.appspot.com/8366043/diff/1/state/api/apiclient.go
File state/api/apiclient.go (right):

https://codereview.appspot.com/8366043/diff/1/state/api/apiclient.go#newcode171
state/api/apiclient.go:171: // GetServiceConstraints specifies the
constraints for the given service.
s/specifies/returns/

https://codereview.appspot.com/8366043/diff/1/state/apiserver/apiserver.go
File state/apiserver/apiserver.go (right):

https://codereview.appspot.com/8366043/diff/1/state/apiserver/apiserver.go#newcode374
state/apiserver/apiserver.go:374: // GetServiceConstraints sets the
constraints for a given service.
s/sets/returns/

https://codereview.appspot.com/8366043/diff/1/state/statecmd/getconstraints.go
File state/statecmd/getconstraints.go (right):

https://codereview.appspot.com/8366043/diff/1/state/statecmd/getconstraints.go#newcode11
state/statecmd/getconstraints.go:11: // GetServiceContstraints sets the
constraints for a given service
ditto

https://codereview.appspot.com/8366043/

Revision history for this message
Brad Crittenden (bac) wrote :

The code looks good, except for a few typos, etc.

There is quite a paucity of tests in this branch. Is your reasoning
that the call is just a wrapper around an already well-tested function?

https://codereview.appspot.com/8366043/diff/11001/cmd/juju/constraints.go
File cmd/juju/constraints.go (right):

https://codereview.appspot.com/8366043/diff/11001/cmd/juju/constraints.go#newcode66
cmd/juju/constraints.go:66: var results
params.GetServiceConstraintsResults
Is the explicit declaration required?

https://codereview.appspot.com/8366043/diff/11001/state/statecmd/getconstraints.go
File state/statecmd/getconstraints.go (right):

https://codereview.appspot.com/8366043/diff/11001/state/statecmd/getconstraints.go#newcode1
state/statecmd/getconstraints.go:1: // Code shared by the CLI and API
for the SetConstraints function.
GetConstraints

https://codereview.appspot.com/8366043/diff/11001/state/statecmd/getconstraints.go#newcode11
state/statecmd/getconstraints.go:11: // GetServiceContstraints returns
the constraints for a given service
typo: GetServiceContstraints

https://codereview.appspot.com/8366043/

Revision history for this message
Brad Crittenden (bac) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmd/juju/constraints.go'
2--- cmd/juju/constraints.go 2013-03-20 16:44:16 +0000
3+++ cmd/juju/constraints.go 2013-04-04 15:56:21 +0000
4@@ -59,11 +59,12 @@
5 if c.ServiceName == "" {
6 cons, err = conn.State.EnvironConstraints()
7 } else {
8- var svc *state.Service
9- if svc, err = conn.State.Service(c.ServiceName); err != nil {
10- return err
11+ args := params.GetServiceConstraints{
12+ ServiceName: c.ServiceName,
13 }
14- cons, err = svc.Constraints()
15+
16+ results, err = statecmd.GetServiceConstraints(conn.State, args)
17+ cons = results.Constraints
18 }
19 if err != nil {
20 return err
21
22=== modified file 'state/api/apiclient.go'
23--- state/api/apiclient.go 2013-04-01 15:47:49 +0000
24+++ state/api/apiclient.go 2013-04-04 15:56:21 +0000
25@@ -168,6 +168,13 @@
26 return clientError(c.st.client.Call("Client", "", "ServiceDestroy", params, nil))
27 }
28
29+// GetServiceConstraints returns the constraints for the given service.
30+func (c *Client) GetServiceConstraints(service string) (constraints.Value, error) {
31+ results := new(params.GetServiceConstraintsResults)
32+ err := c.st.client.Call("Client", "", "GetServiceConstraints", params.GetServiceConstraints{service}, results)
33+ return results.Constraints, clientError(err)
34+}
35+
36 // SetServiceConstraints specifies the constraints for the given service.
37 func (c *Client) SetServiceConstraints(service string, constraints constraints.Value) error {
38 params := params.SetServiceConstraints{
39
40=== modified file 'state/api/params/params.go'
41--- state/api/params/params.go 2013-04-03 09:39:05 +0000
42+++ state/api/params/params.go 2013-04-04 15:56:21 +0000
43@@ -162,6 +162,16 @@
44 Pairs map[string]string
45 }
46
47+// GetServiceConstraints stores parameters for making the GetServiceConstraints call.
48+type GetServiceConstraints struct {
49+ ServiceName string
50+}
51+
52+// GetServiceConstraintsResults holds results of the GetServiceConstraints call.
53+type GetServiceConstraintsResults struct {
54+ Constraints constraints.Value
55+}
56+
57 // SetServiceConstraints stores parameters for making the SetServiceConstraints call.
58 type SetServiceConstraints struct {
59 ServiceName string
60
61=== modified file 'state/apiserver/api_test.go'
62--- state/apiserver/api_test.go 2013-04-01 19:54:06 +0000
63+++ state/apiserver/api_test.go 2013-04-04 15:56:21 +0000
64@@ -136,6 +136,10 @@
65 op: opClientServiceDestroy,
66 allow: []string{"user-admin", "user-other"},
67 }, {
68+ about: "Client.GetServiceConstraints",
69+ op: opClientGetServiceConstraints,
70+ allow: []string{"user-admin", "user-other"},
71+}, {
72 about: "Client.SetServiceConstraints",
73 op: opClientSetServiceConstraints,
74 allow: []string{"user-admin", "user-other"},
75@@ -446,6 +450,13 @@
76 return func() {}, err
77 }
78
79+func opClientGetServiceConstraints(c *C, st *api.State, mst *state.State) (func(), error) {
80+ // This test only checks that the call is made without error, ensuring the
81+ // signatures match.
82+ _, err := st.Client().GetServiceConstraints("wordpress")
83+ return func() {}, err
84+}
85+
86 func opClientSetServiceConstraints(c *C, st *api.State, mst *state.State) (func(), error) {
87 // This test only checks that the call is made without error, ensuring the
88 // signatures match.
89
90=== modified file 'state/apiserver/apiserver.go'
91--- state/apiserver/apiserver.go 2013-04-02 20:24:00 +0000
92+++ state/apiserver/apiserver.go 2013-04-04 15:56:21 +0000
93@@ -371,6 +371,11 @@
94 return statecmd.ServiceDestroy(c.root.srv.state, args)
95 }
96
97+// GetServiceConstraints returns the constraints for a given service.
98+func (c *srvClient) GetServiceConstraints(args params.GetServiceConstraints) (params.GetServiceConstraintsResults, error) {
99+ return statecmd.GetServiceConstraints(c.root.srv.state, args)
100+}
101+
102 // SetServiceConstraints sets the constraints for a given service.
103 func (c *srvClient) SetServiceConstraints(args params.SetServiceConstraints) error {
104 return statecmd.SetServiceConstraints(c.root.srv.state, args)
105
106=== added file 'state/statecmd/getconstraints.go'
107--- state/statecmd/getconstraints.go 1970-01-01 00:00:00 +0000
108+++ state/statecmd/getconstraints.go 2013-04-04 15:56:21 +0000
109@@ -0,0 +1,19 @@
110+// Code shared by the CLI and API for the GetConstraints function.
111+
112+package statecmd
113+
114+import (
115+ "launchpad.net/juju-core/constraints"
116+ "launchpad.net/juju-core/state"
117+ "launchpad.net/juju-core/state/api/params"
118+)
119+
120+// GetServiceConstraints returns the constraints for a given service
121+func GetServiceConstraints(st *state.State, args params.GetServiceConstraints) (params.GetServiceConstraintsResults, error) {
122+ svc, err := st.Service(args.ServiceName)
123+ if err != nil {
124+ return params.GetServiceConstraintsResults{constraints.Value{}}, err
125+ }
126+ constraints, err := svc.Constraints()
127+ return params.GetServiceConstraintsResults{constraints}, err
128+}

Subscribers

People subscribed via source and target branches