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

Remove @Inject from rest handlers #15687

Closed
wants to merge 12 commits into from
Closed

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Dec 28, 2015

Do this by adding a single @Inject to NetworkModule. This gives us
a string to pull on: move parameters from injected to constructor.

This is an incremental step to cleaning up our reliance on guice and should
be minimally invasive.

Closes #15685

@nik9000 nik9000 added review :Core/Infra/REST API REST infrastructure and utilities v5.0.0-alpha1 labels Dec 28, 2015
@nik9000
Copy link
Member Author

nik9000 commented Dec 29, 2015

I'm still running tests now. On a slow machine today....

@rjernst
Copy link
Member

rjernst commented Dec 29, 2015

We just got rid of RestModule! Why can't the rest actions be created in NetworkModule?

@nik9000
Copy link
Member Author

nik9000 commented Dec 29, 2015

Why can't the rest actions be created in NetworkModule?

I guess it could. I pulled them out initially because I wanted to work on rest stuff in isolation from the transport stuff. I can smoosh it back together but I kind of like rest stuff registered in a RestModule and transport stuff NetworkModule. NetworkModule just looks so much more cohesive now.

@rjernst
Copy link
Member

rjernst commented Dec 29, 2015

I kind of like rest stuff registered in a RestModule and transport stuff NetworkModule

The entire point of the refactoring that removed RestModule was Rest is really network. Transport and rest requests aren't really any different, they all have to do with communicating with ES over the network (and while the transport actions are not yet registered in NetworkModule, I mentioned in the PR that it was my intention to do that in a follow up).

@s1monw
Copy link
Contributor

s1monw commented Dec 29, 2015

The entire point of the refactoring that removed RestModule was Rest is really network. Transport and rest requests aren't really any different, they all have to do with communicating with ES over the network (and while the transport actions are not yet registered in NetworkModule, I mentioned in the PR that it was my intention to do that in a follow up).

while I agree I think we can do this in a followup? This is already awesome and worth a push as it is? :)

@s1monw
Copy link
Contributor

s1monw commented Dec 29, 2015

oh nevermind, now I see it's adding RestModule back, yeah I think we should never ever again add modules back, can you just fold it into networkModule?

public <T extends BaseRestHandler> void add(Class<T> type, Function<RestGlobalContext, T> builder) {
requireNonNull(type, "Must define the handler type being registered");
requireNonNull(builder, "Must define the builder to register");
Object old = actions.put(type, builder);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: use putIfAbsent then you don't modify even if it's there?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@nik9000
Copy link
Member Author

nik9000 commented Dec 29, 2015

oh nevermind, now I see it's adding RestModule back, yeah I think we should never ever again add modules back, can you just fold it into networkModule?

I'll do it but I don't get it. NetworkModule without the rest stuff it just sets up the transport implementations and leaves the ticklish bits to something else. But its a separate thing. I'll put it back.

@nik9000
Copy link
Member Author

nik9000 commented Jan 4, 2016

I believe I've addressed all the comments, @s1monw.

@nik9000
Copy link
Member Author

nik9000 commented Jan 4, 2016

Rebased. Sorry for the trouble.

@nik9000
Copy link
Member Author

nik9000 commented Jan 12, 2016

I'm going to rebase again. Any interest in another review?

Do this by creating RestModule which has a single @Inject. This gives us
a string to pull on: move parameters from injected to constructor.

This is an incremental step to cleaning up our reliance on guice and should
be minimally invasive.

Closes elastic#15685
Moves registration from the REST handlers into NetworkModule. The handlers
now declare where they'd like to be registered and NetworkModule picks it
up and registers them.

This also fixes a bug I found in ordering of startup: if a plugin depended
on some guice injected resource to build the rest handler then it wouldn't
have the resource ready. So I push the creation of the rest handlers to
after all guice injection is complete.
Removed BaseSingleMethodRestHandler and renamed BaseMultiMethodRestHandler
to BaseStandardRegistrationsRestHandler. You can now extend just the one
class and get either behavior depending on the flavor of constructor used.

Reverted the name change to the registerTransportHandler method.

Add SettingsFilter to NetworkModule's constructor.
Removes more getters in favor of pushing the HeadersAndContextCopyClient
into the global context. BaseRestHandler is now very very simple.
@nik9000
Copy link
Member Author

nik9000 commented Jan 12, 2016

Rebased!

@nik9000
Copy link
Member Author

nik9000 commented Mar 8, 2016

This is super out of date now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/REST API REST infrastructure and utilities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants