Facade registration cleanup #7133

Merged
merged 9 commits into from Mar 24, 2017

Conversation

Projects
None yet
3 participants
Contributor

mjs commented Mar 22, 2017

Description of change

This change makes a number of improvements to the way API facades are registered. Highlights:

  • The global API facade registry has been removed. This avoids all the awkwardness and danger around globals and allows for more flexibility for upcoming projects.
  • The handling of feature flags has been removed from the facade registry type. This is no longer necessary and simplifies the registry implementation.
  • Fixed error handling in the facade registration infrastructure.

New facades now just require a call be added to apiserver.AllFacades.

A follow-up PR will tidy up the groupings of facades in AllFacades.

QA steps

Unit tests pass.

Sanity check:

$ juju bootstrap dev 
...
$ juju status
Model    Controller  Cloud/Region  Version
default  dev         dev           2.2-beta1.1

App  Version  Status  Scale  Charm  Store  Rev  OS  Notes

Unit  Workload  Agent  Machine  Public address  Ports  Message

Machine  State  DNS  Inst id  Series  AZ  Message

$ juju deploy cs:~cmars/mattermost                        
Located charm "cs:~cmars/mattermost-16".
Deploying charm "cs:~cmars/mattermost-16".
Deployment under prior agreement to terms: isrg-lets-encrypt
menno@maiwa ~/go/src/github.com/juju/juju ± apiserver-facade-cleanup 
$ watch --color juju status --color
# Deploys fine...
$ juju list-resources mattermost
[Service]
Resource  Supplied by  Revision
bdist     charmstore   3

Documentation changes

N.A.

Bug reference

N.A.

@mjs mjs changed the title from Apiserver facade cleanup to Facade registration cleanup Mar 22, 2017

Very very cool.
Some minor nits.

apiserver/allfacades.go
)
+
+// AllFacades returns a registry containing all known API facades.
+func AllFacades() *facade.Registry {
@wallyworld

wallyworld Mar 22, 2017

Owner

Thinking out loud - convention in tests at least would be to name this function MustAllFacades()
(as it panics instead of returning an error)

@mjs

mjs Mar 22, 2017

Contributor

I'd prefer the name as is, given that there's no alternative. As a compromise, how about I mention the possibility of a panic in the docstring?

@mjs

mjs Mar 22, 2017

Contributor

Done

+ reg := func(name string, version int, newFunc interface{}) {
+ err := registry.RegisterStandard(name, version, newFunc)
+ if err != nil {
+ panic(err)
@wallyworld

wallyworld Mar 22, 2017

Owner

can you add a comment that there's a test to ensure we don't panic in production

@mjs

mjs Mar 22, 2017

Contributor

Covered by docstring above I think

apiserver/application/application.go
@@ -71,7 +58,7 @@ func DeployApplication(backend Backend, args jjj.DeployApplicationParams) error
return err
}
-func newAPI(ctx facade.Context) (*API, error) {
+func NewFacade(ctx facade.Context) (*API, error) {
@wallyworld

wallyworld Mar 22, 2017

Owner

I know, i know, but we should comment these newly exported functions.

@mjs

mjs Mar 22, 2017

Contributor

Done (there were a lot!)

apiserver/applicationscaler/shim.go
-// newFacade wraps the supplied *state.State for the use of the Facade.
-func newFacade(st *state.State, res facade.Resources, auth facade.Authorizer) (*Facade, error) {
+// NewFacade wraps the supplied *state.State for the use of the Facade.
+func NewAPI(st *state.State, res facade.Resources, auth facade.Authorizer) (*Facade, error) {
@wallyworld

wallyworld Mar 22, 2017

Owner

mismatch in name

apiserver/facade/registry.go
@@ -148,3 +149,118 @@ func (f *Registry) Discard(name string, version int) {
}
}
}
+
+type niceFactory func(Context) (interface{}, error)
@wallyworld

wallyworld Mar 22, 2017

Owner

either rename these or comment :-)

@mjs

mjs Mar 22, 2017

Contributor

These aren't from me but I'll add some comments.

apiserver/hostkeyreporter/shim.go
@@ -11,7 +11,7 @@ import (
)
// newFacade wraps New to express the supplied *state.State as a Backend.
-func newFacade(st *state.State, res facade.Resources, auth facade.Authorizer) (*Facade, error) {
+func NewFacade(st *state.State, res facade.Resources, auth facade.Authorizer) (*Facade, error) {
@wallyworld

wallyworld Mar 22, 2017

Owner

name mismatch

@mjs

mjs Mar 22, 2017

Contributor

Fixed

Contributor

mjs commented Mar 22, 2017

$$merge$$

Contributor

jujubot commented Mar 22, 2017

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

Contributor

jujubot commented Mar 22, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10520

mjs added some commits Mar 3, 2017

apiserver: Unexport common.Facades
This is the first step in streamlining facade registration and begins to
clean up a lot of the badness that results from having a global facade
registry.

Helper functionality for registering standard facades as been moved from
apiserver/common to apiserver/facade.
apiserver/facade: Fix RegisterStandard panics
Return errors instead of panicking.
apiserver: Rearrange facade registration
Instead of each facade package registering facades in a global
registry, facade registrations are dynamically done in
apiserver.AllFacades().

This avoids the "magic" imports that used to exist in allfacades.go
and avoids the problems associated with globals.
apiserver: Don't pass featureflags when registering facades
The plan is to remove support for feature flags from the
registery. Facade registration based on feature flags can just be done
using conditionals in AllFacades().
apiserver: Remove feature flag support from registry
The facade registry no longer supports feature flags. This simplifies
the registry's concerns (especially useful for upcoming
changes). Conditional handling of facade registration is now handled
inside AllFacades().
apiserver: Extract hook context registration
It's tidier if this code lives elsewhere. Also handle registration
errors instead of ignoring them.
apiserver: Doc string fixes
Fixed missing and incorrect docstrings.
apiserver: Register new CMR facades in the new way
These were changed after the facade registration changes were
proposed.
Contributor

mjs commented Mar 23, 2017

$$merge$$

Contributor

jujubot commented Mar 23, 2017

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

Contributor

jujubot commented Mar 23, 2017

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/10550

Contributor

mjs commented Mar 24, 2017

$$merge$$

Contributor

jujubot commented Mar 24, 2017

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

@jujubot jujubot merged commit 2ceb076 into juju:develop Mar 24, 2017

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