Move the GetBundleChanges call in a new Bundle facade. #6354

Merged
merged 3 commits into from Oct 3, 2016

Conversation

Projects
None yet
5 participants
Member

frankban commented Sep 29, 2016

Also make the new facade available on both controller and model connections.

This is done so that GUI users can render the bundle uncommitted state even without a model connection.
Note that, even if this is a backward incompatible API change, I think we can be quite sure that the GUI is the only client of this API.

Move the GetBundleChanges call in a new Bundle facade.
Also make the new facade available on both controller and model connections.

This is done so that GUI users can render the bundle uncommitted state even without a model connection.
Note that, even if this is a backward incompatible API change, I think we can be quite sure that the GUI is the only client of this API.

LGTM after a couple small changes.

apiserver/bundle/bundle_test.go
// Licensed under the AGPLv3, see LICENCE file for details.
-package client_test
+package bundle_test
@natefinch

natefinch Sep 29, 2016

Contributor

please don't use export_test... if the only thing that it is needed is to access an newFacade, just put this test in package bundle, and use the unexported function directly.

@frankban

frankban Sep 30, 2016

Member

Ok, I ended up exposing NewFacade, which feels right for other reasons as well.

apiserver/bundle/bundle_test.go
-func (s *serverSuite) TestGetBundleChangesBundleContentError(c *gc.C) {
- args := params.GetBundleChangesParams{
+type bundleSuite struct {
+ jujutesting.JujuConnSuite
@natefinch

natefinch Sep 29, 2016

Contributor

This doesn't appear to actually need to be a jujuConnSuite... newFacade doesn't actually use s.State, for example. We try to avoid making new suites that depend on JujuConnSuite because it's so slow.

@howbazaar

howbazaar Sep 29, 2016

Owner

The StateSuite from state/testing is sufficient if you need a *state.State. See apiserver/pinger_test.go for an example.

apiserver/bundle/bundle.go
-// GetBundleChanges returns the list of changes required to deploy the given
-// bundle data. The changes are sorted by requirements, so that they can be
-// applied in order.
-func (c *Client) GetBundleChanges(args params.GetBundleChangesParams) (params.GetBundleChangesResults, error) {
@howbazaar

howbazaar Sep 29, 2016

Owner

You can't just delete this from the client facade now. We have committed to backwards compatibility with RC1.

This means that this method needs to stay, but can forward to the new facade for implementation.

apiserver/bundle/bundle.go
- return params.GetBundleChangesResults{}, err
+// init registers the Bundle facade.
+func init() {
+ common.RegisterStandardFacade("Bundle", 0, newFacade)
@howbazaar

howbazaar Sep 29, 2016

Owner

All new facades start from version 1, not zero.

@frankban

frankban Sep 30, 2016

Member

Good to know, done.

apiserver/bundle/bundle_test.go
// Licensed under the AGPLv3, see LICENCE file for details.
-package client_test
@howbazaar

howbazaar Sep 29, 2016

Owner

You will need to keep a test in the client to show that client calls still work.

apiserver/bundle/bundle_test.go
-func (s *serverSuite) TestGetBundleChangesBundleContentError(c *gc.C) {
- args := params.GetBundleChangesParams{
+type bundleSuite struct {
+ jujutesting.JujuConnSuite
@natefinch

natefinch Sep 29, 2016

Contributor

This doesn't appear to actually need to be a jujuConnSuite... newFacade doesn't actually use s.State, for example. We try to avoid making new suites that depend on JujuConnSuite because it's so slow.

@howbazaar

howbazaar Sep 29, 2016

Owner

The StateSuite from state/testing is sufficient if you need a *state.State. See apiserver/pinger_test.go for an example.

apiserver/params/params.go
-// GetBundleChangesParams holds parameters for making GetBundleChanges calls.
-type GetBundleChangesParams struct {
+// BundleGetChangesParams holds parameters for making Bundle.GetChanges calls.
+type BundleGetChangesParams struct {
@howbazaar

howbazaar Sep 29, 2016

Owner

Why keep the "Get" in the name? If you are changing the name anyway, probably better to remove the "Get" altogether.

BundelChangesParam, and BundleChangesResults.

While you are at it, BundleChangesChange -> BundleChange ?

apiserver/restrict_controller.go
@@ -32,5 +37,5 @@ func controllerFacadesOnly(facadeName, _ string) error {
func isControllerFacade(facadeName string) bool {
// Note: the Pinger facade can be used in both model and controller
@howbazaar

howbazaar Sep 29, 2016

Owner

You should update the Note to match the behaviour.

apiserver/bundle/bundle.go
+}
+
+// NewFacade creates and returns a new Bundle API facade.
+func NewFacade(_ *state.State, _ facade.Resources, auth facade.Authorizer) (Bundle, error) {
@axw

axw Oct 3, 2016

Member

(Sorry for the somewhat conflicting advice. This is a newish thing.)

Please have the RegisterStandardFacade call an unexported function which has this signature, and have that call NewFacade. NewFacade should not mention state.State. In other facades we are creating a "Backend" interface which contains the subset of State that that facade needs. In this case you don't even need State, so you can just not include it in the NewFacade signature.

i.e. something like:

common.RegisterStandardFacade("Bundle", 1, newFacade)
...
func newFacade(_ *state.State, _ facade.Resources, auth facade.Authorizer) (Bundle, error) {
    return NewFacade(auth)
}
...
func NewFacade(auth facade.Authorizer) (Bundle, error) {
...

axw approved these changes Oct 3, 2016

LGTM with suggested simplifications

apiserver/bundle/bundle_test.go
+)
+
+type bundleSuite struct {
+ statetesting.StateSuite
@axw

axw Oct 3, 2016

Member

this will be unnecessary if you drop State from the external interface

apiserver/bundle/bundle_test.go
+ model, err := s.State.ControllerModel()
+ c.Assert(err, jc.ErrorIsNil)
+ auth := apiservertesting.FakeAuthorizer{
+ Tag: model.Owner(),
@axw

axw Oct 3, 2016

Member

Just set it to some fake user tag. We don't care about the relationship to the model (clearly, since you're not using State), just that it's a client making the request.

@frankban

frankban Oct 3, 2016

Member

Right, done.

Member

frankban commented Oct 3, 2016

Thank you for the reviews!
$$merge$$

Contributor

jujubot commented Oct 3, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit ec33a8d into juju:master Oct 3, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment