Merge lp:~jameinel/juju-core/api-named-resources-datadir into lp:~go-bot/juju-core/trunk

Proposed by John A Meinel
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: 2754
Proposed branch: lp:~jameinel/juju-core/api-named-resources-datadir
Merge into: lp:~go-bot/juju-core/trunk
Prerequisite: lp:~jameinel/juju-core/api-named-resources
Diff against target: 120 lines (+35/-6)
5 files modified
state/apiserver/client/client.go (+1/-3)
state/apiserver/client/run.go (+11/-2)
state/apiserver/common/resource.go (+12/-0)
state/apiserver/common/resource_test.go (+9/-0)
state/apiserver/root.go (+2/-1)
To merge this branch: bzr merge lp:~jameinel/juju-core/api-named-resources-datadir
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+220215@code.launchpad.net

Commit message

state/apiserver/common: StringResource

This adds a new resource type: common.StringResource. It just lets us
register "dataDir" as a Resource, instead of having to give Client
secret insight into attributes of the srvRoot object. That brings us
closer to having all of the Facades all part of a simple Registry
instead of having special cases.

https://codereview.appspot.com/99410043/

Description of the change

state/apiserver/common: StringResource

This adds a new resource type: common.StringResource. It just lets us
register "dataDir" as a Resource, instead of having to give Client
secret insight into attributes of the srvRoot object. That brings us
closer to having all of the Facades all part of a simple Registry
instead of having special cases.

https://codereview.appspot.com/99410043/

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :
Download full text (5.4 KiB)

Reviewers: mp+220215_code.launchpad.net,

Message:
Please take a look.

Description:
state/apiserver/common: StringResource

This adds a new resource type: common.StringResource. It just lets us
register "dataDir" as a Resource, instead of having to give Client
secret insight into attributes of the srvRoot object. That brings us
closer to having all of the Facades all part of a simple Registry
instead of having special cases.

https://code.launchpad.net/~jameinel/juju-core/api-named-resources-datadir/+merge/220215

Requires:
https://code.launchpad.net/~jameinel/juju-core/api-named-resources/+merge/220208

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/99410043/

Affected files (+37, -6 lines):
   A [revision details]
   M state/apiserver/client/client.go
   M state/apiserver/client/run.go
   M state/apiserver/common/resource.go
   M state/apiserver/common/resource_test.go
   M state/apiserver/root.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: state/apiserver/root.go
=== modified file 'state/apiserver/root.go'
--- state/apiserver/root.go 2014-05-20 08:17:21 +0000
+++ state/apiserver/root.go 2014-05-20 09:42:11 +0000
@@ -73,7 +73,8 @@
    resources: common.NewResources(),
    entity: entity,
   }
- r.clientAPI.API = client.NewAPI(r.srv.state, r.resources, r,
r.srv.dataDir)
+ r.resources.RegisterNamed("dataDir", common.StringResource(r.srv.dataDir))
+ r.clientAPI.API = client.NewAPI(r.srv.state, r.resources, r)
   return r
  }

Index: state/apiserver/client/client.go
=== modified file 'state/apiserver/client/client.go'
--- state/apiserver/client/client.go 2014-05-13 04:50:10 +0000
+++ state/apiserver/client/client.go 2014-05-20 09:42:11 +0000
@@ -36,7 +36,6 @@
   auth common.Authorizer
   resources *common.Resources
   client *Client
- dataDir string
   // statusSetter provides common methods for updating an entity's
provisioning status.
   statusSetter *common.StatusSetter
  }
@@ -47,12 +46,11 @@
  }

  // NewAPI creates a new instance of the Client API.
-func NewAPI(st *state.State, resources *common.Resources, authorizer
common.Authorizer, datadir string) *API {
+func NewAPI(st *state.State, resources *common.Resources, authorizer
common.Authorizer) *API {
   r := &API{
    state: st,
    auth: authorizer,
    resources: resources,
- dataDir: datadir,
    statusSetter: common.NewStatusSetter(st, common.AuthAlways(true)),
   }
   r.client = &Client{

Index: state/apiserver/client/run.go
=== modified file 'state/apiserver/client/run.go'
--- state/apiserver/client/run.go 2014-04-23 08:50:28 +0000
+++ state/apiserver/client/run.go 2014-05-20 09:42:11 +0000
@@ -14,6 +14,7 @@
   "launchpad.net/juju-core/instance"
   "launchpad.net/juju-core/state"
   "launchpad.net/juju-core/state/api/params"
+ "launchpad.net/juju-core/state/apiserver/common"
   "launchpad.net/juju-cor...

Read more...

Revision history for this message
Dimiter Naydenov (dimitern) wrote :
Revision history for this message
Roger Peppe (rogpeppe) wrote :
Download full text (7.1 KiB)

FWIW this seems like an odd twisting of the Resources type to me.

The Resources type is there specifically for a connection
to hold resources on behalf of a client so that they can
be cleaned up when the connection goes away. These
changes seem to be turning it into a general registry of arbitrary
stuff that the api server uses to remember things for itself.

I'm sure I'm lacking insight into the eventual destination here,
but it seems to me that having dataDir registered in this
way is more obscure than "giving Client secret insight into attributes of
the srvRoot object" (it's actually registered by newSrvRoot, and
could be made public if required).

Basically, I prefer to see this stuff statically typed when possible.

On 20 May 2014 10:45, John A Meinel <email address hidden> wrote:
> Reviewers: mp+220215_code.launchpad.net,
>
> Message:
> Please take a look.
>
> Description:
> state/apiserver/common: StringResource
>
> This adds a new resource type: common.StringResource. It just lets us
> register "dataDir" as a Resource, instead of having to give Client
> secret insight into attributes of the srvRoot object. That brings us
> closer to having all of the Facades all part of a simple Registry
> instead of having special cases.
>
> https://code.launchpad.net/~jameinel/juju-core/api-named-resources-datadir/+merge/220215
>
> Requires:
> https://code.launchpad.net/~jameinel/juju-core/api-named-resources/+merge/220208
>
> (do not edit description out of merge proposal)
>
>
> Please review this at https://codereview.appspot.com/99410043/
>
> Affected files (+37, -6 lines):
> A [revision details]
> M state/apiserver/client/client.go
> M state/apiserver/client/run.go
> M state/apiserver/common/resource.go
> M state/apiserver/common/resource_test.go
> M state/apiserver/root.go
>
>
> Index: [revision details]
> === added file '[revision details]'
> --- [revision details] 2012-01-01 00:00:00 +0000
> +++ [revision details] 2012-01-01 00:00:00 +0000
> @@ -0,0 +1,2 @@
> +Old revision: <email address hidden>
> +New revision: <email address hidden>
>
> Index: state/apiserver/root.go
> === modified file 'state/apiserver/root.go'
> --- state/apiserver/root.go 2014-05-20 08:17:21 +0000
> +++ state/apiserver/root.go 2014-05-20 09:42:11 +0000
> @@ -73,7 +73,8 @@
> resources: common.NewResources(),
> entity: entity,
> }
> - r.clientAPI.API = client.NewAPI(r.srv.state, r.resources, r,
> r.srv.dataDir)
> + r.resources.RegisterNamed("dataDir", common.StringResource(r.srv.dataDir))
> + r.clientAPI.API = client.NewAPI(r.srv.state, r.resources, r)
> return r
> }
>
>
>
> Index: state/apiserver/client/client.go
> === modified file 'state/apiserver/client/client.go'
> --- state/apiserver/client/client.go 2014-05-13 04:50:10 +0000
> +++ state/apiserver/client/client.go 2014-05-20 09:42:11 +0000
> @@ -36,7 +36,6 @@
> auth common.Authorizer
> resources *common.Resources
> client *Client
> - dataDir string
> // statusSetter provides common methods for updat...

Read more...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'state/apiserver/client/client.go'
2--- state/apiserver/client/client.go 2014-05-13 04:50:10 +0000
3+++ state/apiserver/client/client.go 2014-05-20 09:49:27 +0000
4@@ -36,7 +36,6 @@
5 auth common.Authorizer
6 resources *common.Resources
7 client *Client
8- dataDir string
9 // statusSetter provides common methods for updating an entity's provisioning status.
10 statusSetter *common.StatusSetter
11 }
12@@ -47,12 +46,11 @@
13 }
14
15 // NewAPI creates a new instance of the Client API.
16-func NewAPI(st *state.State, resources *common.Resources, authorizer common.Authorizer, datadir string) *API {
17+func NewAPI(st *state.State, resources *common.Resources, authorizer common.Authorizer) *API {
18 r := &API{
19 state: st,
20 auth: authorizer,
21 resources: resources,
22- dataDir: datadir,
23 statusSetter: common.NewStatusSetter(st, common.AuthAlways(true)),
24 }
25 r.client = &Client{
26
27=== modified file 'state/apiserver/client/run.go'
28--- state/apiserver/client/run.go 2014-04-23 08:50:28 +0000
29+++ state/apiserver/client/run.go 2014-05-20 09:49:27 +0000
30@@ -14,6 +14,7 @@
31 "launchpad.net/juju-core/instance"
32 "launchpad.net/juju-core/state"
33 "launchpad.net/juju-core/state/api/params"
34+ "launchpad.net/juju-core/state/apiserver/common"
35 "launchpad.net/juju-core/utils"
36 "launchpad.net/juju-core/utils/set"
37 "launchpad.net/juju-core/utils/ssh"
38@@ -75,6 +76,14 @@
39 return result, nil
40 }
41
42+func (c *Client) getDataDir() string {
43+ dataResource, ok := c.api.resources.Get("dataDir").(common.StringResource)
44+ if !ok {
45+ return ""
46+ }
47+ return dataResource.String()
48+}
49+
50 // Run the commands specified on the machines identified through the
51 // list of machines, units and services.
52 func (c *Client) Run(run params.RunParams) (results params.RunResults, err error) {
53@@ -110,7 +119,7 @@
54 execParam := remoteParamsForMachine(machine, command, run.Timeout)
55 params = append(params, execParam)
56 }
57- return ParallelExecute(c.api.dataDir, params), nil
58+ return ParallelExecute(c.getDataDir(), params), nil
59 }
60
61 // RunOnAllMachines attempts to run the specified command on all the machines.
62@@ -125,7 +134,7 @@
63 for _, machine := range machines {
64 params = append(params, remoteParamsForMachine(machine, command, run.Timeout))
65 }
66- return ParallelExecute(c.api.dataDir, params), nil
67+ return ParallelExecute(c.getDataDir(), params), nil
68 }
69
70 // RemoteExec extends the standard ssh.ExecParams by providing the machine and
71
72=== modified file 'state/apiserver/common/resource.go'
73--- state/apiserver/common/resource.go 2014-05-20 09:49:27 +0000
74+++ state/apiserver/common/resource.go 2014-05-20 09:49:27 +0000
75@@ -111,3 +111,15 @@
76 defer rs.mu.Unlock()
77 return len(rs.resources)
78 }
79+
80+// StringResource is just a regular 'string' that matches the Resource
81+// interface.
82+type StringResource string
83+
84+func (StringResource) Stop() error {
85+ return nil
86+}
87+
88+func (s StringResource) String() string {
89+ return string(s)
90+}
91
92=== modified file 'state/apiserver/common/resource_test.go'
93--- state/apiserver/common/resource_test.go 2014-05-20 09:49:27 +0000
94+++ state/apiserver/common/resource_test.go 2014-05-20 09:49:27 +0000
95@@ -147,3 +147,12 @@
96
97 c.Assert(rs.Count(), gc.Equals, 0)
98 }
99+
100+func (resourceSuite) TestStringResource(c *gc.C) {
101+ rs := common.NewResources()
102+ r1 := common.StringResource("foobar")
103+ id := rs.Register(r1)
104+ c.Check(rs.Get(id), gc.Equals, r1)
105+ asStr := rs.Get(id).(common.StringResource).String()
106+ c.Check(asStr, gc.Equals, "foobar")
107+}
108
109=== modified file 'state/apiserver/root.go'
110--- state/apiserver/root.go 2014-05-20 09:49:27 +0000
111+++ state/apiserver/root.go 2014-05-20 09:49:27 +0000
112@@ -73,7 +73,8 @@
113 resources: common.NewResources(),
114 entity: entity,
115 }
116- r.clientAPI.API = client.NewAPI(r.srv.state, r.resources, r, r.srv.dataDir)
117+ r.resources.RegisterNamed("dataDir", common.StringResource(r.srv.dataDir))
118+ r.clientAPI.API = client.NewAPI(r.srv.state, r.resources, r)
119 return r
120 }
121

Subscribers

People subscribed via source and target branches

to status/vote changes: