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

Simplify Plugin API for constructing modules #12952

Merged
merged 6 commits into from Aug 18, 2015

Conversation

rjernst
Copy link
Member

@rjernst rjernst commented Aug 18, 2015

The Plugin interface currently contains 6 different methods for
adding modules. Elasticsearch has 3 different levels of injectors,
and for each of those, there are two methods. The first takes no
arguments and returns a collection of class objects to construct. The
second takes a Settings object and returns a collection of module
objects already constructed. The settings argument is unecessary because
the plugin can already get the settings from its constructor. Removing
that, the only difference between the two versions is returning an
already constructed Module, or a module Class, and there is no reason
the plugin can't construct all their modules themselves.

This change reduces the plugin api down to just 3 methods for adding
modules. Each returns a Collection. It also removes the
processModule method, which was unnecessary since onModule
implementations fullfill the same requirement. And finally, it renames
the modules() method to nodeModules() so it is clear these are created
once for each node.

@rjernst rjernst added >breaking :Core/Infra/Plugins Plugin API and infrastructure v2.0.0 labels Aug 18, 2015
The Plugin interface currently contains 6 different methods for
adding modules. Elasticsearch has 3 different levels of injectors,
and for each of those, there are two methods. The first takes no
arguments and returns a collection of class objects to construct. The
second takes a Settings object and returns a collection of module
objects already constructed. The settings argument is unecessary because
the plugin can already get the settings from its constructor. Removing
that, the only difference between the two versions is returning an
already constructed Module, or a module Class, and there is no reason
the plugin can't construct all their modules themselves.

This change reduces the plugin api down to just 3 methods for adding
modules. Each returns a Collection<Module>. It also removes the
processModule method, which was unnecessary since onModule
implementations fullfill the same requirement. And finally, it renames
the modules() method to nodeModules() so it is clear these are created
once for each node.
@dadoonet
Copy link
Member

I really like the change. Something I'm just wondering.
Does this PR change anything in the way some components are loaded?

I mean that before the change plugin components were loaded only when used. For example, AwsEc2Service is loaded only if the user set discovery to ec2. Is it still the case with this PR? Components are loaded only on demand?

@rjernst
Copy link
Member Author

rjernst commented Aug 18, 2015

@dadoonet This does not change anything about component loading. Components are still returned as classes and constructed with the injector. This is simply about modules, whose sole purpose is to bind classes the injector will use when necessary.

@dadoonet
Copy link
Member

@rjernst Thanks for confirming!
The change looks good to me but I think another reviewer would be great.

@kimchy
Copy link
Member

kimchy commented Aug 18, 2015

I really like this change!. Two notes:

  • If we are already changing the Plugin interface, I would just merge AbstractPlugin into Plugin and remove the interface aspect.
  • Why did you remove passing Settings to the different modules constructions? Those modules might need the Settings to properly construct? How will they do it now?

@rjernst
Copy link
Member Author

rjernst commented Aug 18, 2015

@kimchy Plugins have the option of a ctor that takes Settings. They can store this, and pass to any of their modules that need settings.

@rjernst
Copy link
Member Author

rjernst commented Aug 18, 2015

Ok, settings are needed for the shard/index modules, since those settings are the index settings, not the node settings. I'll add that parameter back.

@kimchy
Copy link
Member

kimchy commented Aug 18, 2015

Yea, it is the shard/index level Settings that are important... . I would still think how to clean up the duplication of which Settings to use, thinking that maybe cleanest is to pass the right Settings to all callbacks (modules/service) and not rely on black magic constructor based Settings injection, which one needs to remember are node based settings. But that is a different change.

@rjernst
Copy link
Member Author

rjernst commented Aug 18, 2015

@kimchy I merged AbstractPlugin and Plugin, and added back Settings for the index/shard modules methods.

public Settings additionalSettings() {
return Settings.Builder.EMPTY_SETTINGS;
}
public abstract class AbstractPlugin extends Plugin {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we really need this class?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ooops, meant to remove that.

@s1monw
Copy link
Contributor

s1monw commented Aug 18, 2015

added one comment other than that LGTM

rjernst added a commit that referenced this pull request Aug 18, 2015
Simplify Plugin API for constructing modules
@rjernst rjernst merged commit 32a0973 into elastic:master Aug 18, 2015
@rjernst rjernst removed the review label Aug 18, 2015
@rjernst rjernst deleted the construct_it_yourself branch August 18, 2015 21:28
@rjernst
Copy link
Member Author

rjernst commented Aug 18, 2015

I will backport to the 2.0 branch once the beta is out.

rjernst added a commit that referenced this pull request Aug 19, 2015
The Plugin interface currently contains 6 different methods for
adding modules. Elasticsearch has 3 different levels of injectors,
and for each of those, there are two methods. The first takes no
arguments and returns a collection of class objects to construct. The
second takes a Settings object and returns a collection of module
objects already constructed. The settings argument is unecessary because
the plugin can already get the settings from its constructor. Removing
that, the only difference between the two versions is returning an
already constructed Module, or a module Class, and there is no reason
the plugin can't construct all their modules themselves.

This change reduces the plugin api down to just 3 methods for adding
modules. Each returns a Collection<Module>. It also removes the
processModule method, which was unnecessary since onModule
implementations fullfill the same requirement. And finally, it renames
the modules() method to nodeModules() so it is clear these are created
once for each node.

Backport of #12952
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants