Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

state: pass in mgo.Session when opening State #8056

Merged
merged 5 commits into from Nov 14, 2017

Conversation

axw
Copy link
Contributor

@axw axw commented Nov 13, 2017

Description of change

  • update state openers (Open, OpenController, Initialize) to accept an mgo.Session, rather than dialling from those methods. The session is copied, so the caller retains ownership of the session it passes in.
  • remove the State.MongoConnectionInfo and State.CACert methods, as they were relying on recording mongo connection info on the State object

QA steps

Smoke test: bootstrap, destroy.

Documentation changes

None.

Bug reference

None.

@axw
Copy link
Contributor Author

axw commented Nov 13, 2017

@@ -15,7 +17,7 @@ import (
// controller addresses and the CA public certificate.
type AddressAndCertGetter interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface name is now a bit inaccurate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed it, although the types in this file aren't very well scoped anyway. CA certs have bugger all to do with addresses, and what's the ModelUUID doing in there? Anyway.

@@ -492,8 +493,8 @@ func (m *mockState) APIHostPorts() ([][]network.HostPort, error) {
}, nil
}

func (m *mockState) CACert() string {
return testing.CACert
func (m *mockState) ControllerConfig() (controller.Config, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was used for the backend of the APIAddresser. I've updated the PR with a commit to remove CACert from that interface.

}
caCert, ok := controllerConfig.CACert()
if !ok {
return nil, errors.New("CA certificate missing from controller config")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's define NoCACertErr or something instead of the same string in several places.
Perhaps CACert() method itself on controllerConfig should return an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally it would return neither a bool nor an error, since it's not possible to have controller config without a CA certificate past bootstrap. I'm ignoring the bool now, will add a card to change the controller.Config method.

@@ -79,6 +79,7 @@ func newAPIHandler(srv *Server, st *state.State, rpcConn *rpc.Conn, modelUUID st
modelUUID: modelUUID,
serverHost: serverHost,
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need what? whitespace? accidentally snuck in as I added a resource, then removed it again - reverted

MongoInfo *mongo.MongoInfo
// MongoSession is the mgo.Session to use for storing and
// accessing state data. The caller remains responsible
// for closing the session.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for closing this session ??

(to distinguish from the copy that is made)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

state/open.go Outdated
MongoDialOpts mongo.DialOpts
// MongoSession is the mgo.Session to use for storing and
// accessing state data. The caller remains responsible
// for closing the session; Open will copy it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/the/the passed in session?

Not sure if that clarification is needed? Makes sense to make the change to me anyway. YMMV

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/the/this/ like in the other case

} `bson:"authenticatedUsers"`
} `bson:"authInfo"`
}
if err := st.session.DB(jujuDB).Run(bson.D{{"connectionStatus", 1}}, &connectionStatus); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment here? I don't quite grok this at first read.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup - sorry, done

We shouldn't need to know about how to connect
to MongoDB given a State object, we just need
a connection.
This is a property of controller config, so
use that where necessary, rather than relying
on the CACert value in the mongo info.
No longer needed, so stop storing it.
Next step is to stop passing it into
State altogether, and instead just
pass in a mgo.Session.
Functions in the State package that create
State objects now accept an mgo.Session,
rather than the mongo connection info and
dial options. For now at least, they copy
the session.
@axw axw force-pushed the open-state-mongo-session branch 2 times, most recently from 469bbed to d90d7f7 Compare November 14, 2017 07:57
@axw
Copy link
Contributor Author

axw commented Nov 14, 2017

$$merge$$

@jujubot
Copy link
Collaborator

jujubot commented Nov 14, 2017

Status: merge request accepted. Url: http://ci.jujucharms.com/job/github-merge-juju

@jujubot
Copy link
Collaborator

jujubot commented Nov 14, 2017

Build failed: Tests failed
build url: http://ci.jujucharms.com/job/github-merge-juju/505

Remove CACert from the APIAddresser type, which
is embedded and exposed by various facades. Add
CACert as a method directly to those facades
that require it. Also remove CACert method from
client-side APIAddresser type, and move to clients
that require it.
@axw
Copy link
Contributor Author

axw commented Nov 14, 2017

$$merge$$

@jujubot
Copy link
Collaborator

jujubot commented Nov 14, 2017

Status: merge request accepted. Url: http://ci.jujucharms.com/job/github-merge-juju

@jujubot
Copy link
Collaborator

jujubot commented Nov 14, 2017

Build failed: Tests failed
build url: http://ci.jujucharms.com/job/github-merge-juju/508

@axw
Copy link
Contributor Author

axw commented Nov 14, 2017

$$merge$$

@jujubot
Copy link
Collaborator

jujubot commented Nov 14, 2017

Status: merge request accepted. Url: http://ci.jujucharms.com/job/github-merge-juju

@axw
Copy link
Contributor Author

axw commented Nov 14, 2017

Build failed: it's a mystery

@axw
Copy link
Contributor Author

axw commented Nov 14, 2017

$$merge$$

@jujubot
Copy link
Collaborator

jujubot commented Nov 14, 2017

Status: merge request accepted. Url: http://ci.jujucharms.com/job/github-merge-juju

@nskaggs
Copy link
Contributor

nskaggs commented Nov 14, 2017

$$merge$$

@jujubot jujubot merged commit eff693a into juju:state-controller-refactor Nov 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants