Merge lp:~allenap/gwacl/list-deployments into lp:gwacl

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: 140
Merged at revision: 136
Proposed branch: lp:~allenap/gwacl/list-deployments
Merge into: lp:gwacl
Diff against target: 111 lines (+96/-0)
2 files modified
management.go (+27/-0)
management_test.go (+69/-0)
To merge this branch: bzr merge lp:~allenap/gwacl/list-deployments
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+171532@code.launchpad.net

Commit message

Convenience function to list deployments.

The list can be narrowed by passing an optional list of deployment names.

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) wrote :

Looks good!

[0]

We should probably optimize ListDeployments for the case where len(DeploymentNames) == 1 and use GetDeployment in this case. This is just an optimization but I suspect the Azure provider will do that so would you mind adding a TODO?

[1]

Again, something that can be done later but it would be nice to add a call to ListDeployments() in example/management/run.go.

review: Approve
Revision history for this message
Gavin Panella (allenap) wrote :

> [0]
>
> We should probably optimize ListDeployments for the case where
> len(DeploymentNames) == 1 and use GetDeployment in this case. This is just an
> optimization but I suspect the Azure provider will do that so would you mind
> adding a TODO?

This seems like an unnecessary optimisation. If it proves to be much
slower to filter the response from GetHostedServiceProperties instead
of calling GetDeployment then we have reason to do this. Until then
this is just more code and more testing, and more places for bugs to
hide.

>
> [1]
>
> Again, something that can be done later but it would be nice to add a call to
> ListDeployments() in example/management/run.go.

Okay, I'll do that in a second branch now, so that this unblocks you.

Thanks for the review!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'management.go'
2--- management.go 2013-06-24 16:01:59 +0000
3+++ management.go 2013-06-26 12:35:35 +0000
4@@ -20,3 +20,30 @@
5 }
6 return instances, nil
7 }
8+
9+type ListDeploymentsRequest struct {
10+ ServiceName string
11+ DeploymentNames []string
12+}
13+
14+func (api *ManagementAPI) ListDeployments(request *ListDeploymentsRequest) ([]Deployment, error) {
15+ properties, err := api.GetHostedServiceProperties(request.ServiceName, true)
16+ if err != nil {
17+ return nil, err
18+ }
19+ // Return all deployments if no deployment names were specified.
20+ if len(request.DeploymentNames) == 0 {
21+ return properties.Deployments, nil
22+ }
23+ // Filter the deployment list according to the given names.
24+ deployments := []Deployment{}
25+ for _, deployment := range properties.Deployments {
26+ for _, name := range request.DeploymentNames {
27+ if deployment.Name == name {
28+ deployments = append(deployments, deployment)
29+ break
30+ }
31+ }
32+ }
33+ return deployments, nil
34+}
35
36=== modified file 'management_test.go'
37--- management_test.go 2013-06-24 14:37:31 +0000
38+++ management_test.go 2013-06-26 12:35:35 +0000
39@@ -81,3 +81,72 @@
40 c.Assert(err, NotNil)
41 c.Assert(err.Error(), Equals, "GET request failed (404: Not Found)")
42 }
43+
44+// TestListDeployments goes through the happy path for ListDeployments.
45+func (suite *managementAPISuite) TestListDeployments(c *C) {
46+ // The list of properties for "S1".
47+ propertiesS1 := HostedService{
48+ ServiceName: "S1",
49+ Deployments: []Deployment{
50+ {Name: "one"}, {Name: "two"},
51+ },
52+ }
53+ propertiesS1XML, err := propertiesS1.Serialize()
54+ c.Assert(err, IsNil)
55+ propertiesS1Response := DispatcherResponse{
56+ response: &x509Response{
57+ Body: []byte(propertiesS1XML),
58+ StatusCode: http.StatusOK,
59+ },
60+ }
61+ // Rig the prepared response in.
62+ record := []*x509Request{}
63+ rigRecordingPreparedResponseDispatcher(
64+ &record, []DispatcherResponse{propertiesS1Response},
65+ )
66+ // Finally, exercise ListDeployments.
67+ api := makeAPI(c)
68+ request := &ListDeploymentsRequest{ServiceName: propertiesS1.ServiceName}
69+ deployments, err := api.ListDeployments(request)
70+ c.Assert(err, IsNil)
71+ c.Check(deployments, DeepEquals, propertiesS1.Deployments)
72+ // Only one request to the API is made.
73+ c.Assert(len(record), Equals, 1)
74+}
75+
76+// TestListDeploymentsWithNames demonstrates that only the named deployments
77+// are returned.
78+func (suite *managementAPISuite) TestListDeploymentsWithNames(c *C) {
79+ // The list of properties for "S1".
80+ propertiesS1 := HostedService{
81+ ServiceName: "S1",
82+ Deployments: []Deployment{
83+ {Name: "Arthur"}, {Name: "Bobby"},
84+ },
85+ }
86+ propertiesS1XML, err := propertiesS1.Serialize()
87+ c.Assert(err, IsNil)
88+ propertiesS1Response := DispatcherResponse{
89+ response: &x509Response{
90+ Body: []byte(propertiesS1XML),
91+ StatusCode: http.StatusOK,
92+ },
93+ }
94+ // Rig the prepared response in.
95+ record := []*x509Request{}
96+ rigRecordingPreparedResponseDispatcher(
97+ &record, []DispatcherResponse{propertiesS1Response},
98+ )
99+ // Finally, exercise ListDeployments.
100+ api := makeAPI(c)
101+ request := &ListDeploymentsRequest{
102+ ServiceName: propertiesS1.ServiceName,
103+ DeploymentNames: []string{"Arthur"},
104+ }
105+ deployments, err := api.ListDeployments(request)
106+ c.Assert(err, IsNil)
107+ // Only the first deployment - named "Arthur" - is returned.
108+ c.Check(deployments, DeepEquals, []Deployment{propertiesS1.Deployments[0]})
109+ // Only one request to the API is made.
110+ c.Assert(len(record), Equals, 1)
111+}

Subscribers

People subscribed via source and target branches

to all changes: