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

Deguice rest handlers #22575

Merged
merged 5 commits into from Jan 20, 2017
Merged

Deguice rest handlers #22575

merged 5 commits into from Jan 20, 2017

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Jan 12, 2017

There are presently 7 ctor args used in any rest handlers:

  • Settings: Every handler uses it to initialize a logger and
    some other strange things.
  • RestController: Every handler registers itself with it.
  • ClusterSettings: Used by RestClusterGetSettingsAction to
    render the default values for cluster settings.
  • IndexScopedSettings: Used by RestGetSettingsAction to get
    the default values for index settings.
  • SettingsFilter: Used by a few handlers to filter returned
    settings so we don't expose stuff like passwords.
  • IndexNameExpressionResolver: Used by _cat/indices to
    filter the list of indices.
  • Supplier<DiscoveryNodes>: Used to fill enrich the response
    by handlers that list tasks.

We probably want to reduce these arguments over time but
switching construction away from guice gives us tighter
control over the list of available arguments.

These parameters are passed to plugins using
ActionPlugin#initRestHandlers which is expected to build and
return that handlers immediately. This felt simpler than
returning an reference to the ctors given all the different
possible args.

Breaks java plugins by moving rest handlers off of guice.

this.transportClient = transportClient;
this.settings = settings;
this.indexNameExpressionResolver = indexNameExpressionResolver;
this.indexScopedSettings = indexScopedSettings;
this.clusterSettings = clusterSettings;
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not really sure if it'd have been better to have the bits that are only needed to init the rest handlers on the rest handler method instead of the ctor but I went with the ctor because it felt like how we build these module now. I'm happy either way.

@@ -43,7 +51,11 @@
}

@Override
public List<Class<? extends RestHandler>> getRestHandlers() {
return Arrays.asList(RestNoopBulkAction.class, RestNoopSearchAction.class);
public List<RestHandler> initRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
Copy link
Member Author

Choose a reason for hiding this comment

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

See commit message for my I did this instead of some fancy ctor reference stuff.

@@ -47,7 +46,6 @@
import static org.elasticsearch.rest.RestStatus.OK;

public class RestNoopBulkAction extends BaseRestHandler {
@Inject
Copy link
Member Author

Choose a reason for hiding this comment

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

Most of the files I touched I did this.

@@ -19,6 +19,8 @@

package org.elasticsearch.common.path;

import joptsimple.internal.Strings;
Copy link
Member Author

Choose a reason for hiding this comment

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

Oops. I'll remove.

@@ -111,7 +113,10 @@ public synchronized void insert(String[] path, int index, T value) {
// in case the target(last) node already exist but without a value
// than the value should be updated.
if (index == (path.length - 1)) {
assert (node.value == null || node.value == value);
if (node.value != null) {
throw new IllegalArgumentException("Path [" + Strings.join(path, "/")+ "] already has a value ["
Copy link
Member Author

Choose a reason for hiding this comment

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

Since we lost the "no duplicate" behavior from ActionModule I figured we should duplicate it here, but with paths.

@@ -218,4 +220,8 @@ public IndexScopedSettings getIndexScopedSettings() {
public ClusterSettings getClusterSettings() {
return clusterSettings;
}

public SettingsFilter getSettingsFilter() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Exposed to ActionModule to build rest handlers. Still needs to be bound I think.

return Collections.emptyList();
}


Copy link
Member Author

Choose a reason for hiding this comment

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

Oops. No need for this one. Can remove.


import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.action.admin.cluster.RestListTasksAction.listTasksResponseListener;


public class RestCancelTasksAction extends BaseRestHandler {
private final ClusterService clusterService;
private final Supplier<DiscoveryNodes> nodesInCluster;
Copy link
Member Author

Choose a reason for hiding this comment

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

I switched this to the provider because I thought it'd be cleaner than exposing all of ClusterService.

@@ -99,32 +109,69 @@ public ActionResponse newResponse() {
}

public void testSetupRestHandlerContainsKnownBuiltin() {
assertThat(ActionModule.setupRestHandlers(emptyList()), hasItem(RestMainAction.class));
SettingsModule settings = new SettingsModule(Settings.EMPTY);
Copy link
Member Author

Choose a reason for hiding this comment

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

I switched these to assert based on paths instead of class which makes more sense in the new world.

for (ActionPlugin plugin : actionPlugins) {
for (Class<? extends RestHandler> handler : plugin.getRestHandlers()) {
registerRestHandler(handlers, handler);
for (RestHandler handler : plugin.initRestHandlers(settings, restController, clusterSettings, indexScopedSettings,
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if instead of exposing all of these to plugins we should remove a few. Some (indexScopedSettings, clusterSettings) are fairly single purpose.

@@ -63,7 +72,9 @@
/**
* Rest handlers added by this plugin.
*/
default List<Class<? extends RestHandler>> getRestHandlers() {
default List<RestHandler> initRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
Copy link
Member

Choose a reason for hiding this comment

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

I think we should still call this getRestHandlers

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.

@nik9000
Copy link
Member Author

nik9000 commented Jan 17, 2017

@rjernst, could you have another look?

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for this!

There are presently 7 ctor args used in any rest handlers:
* `Settings`: Every handler uses it to initialize a logger and
  some other strange things.
* `RestController`: Every handler registers itself with it.
* `ClusterSettings`: Used by `RestClusterGetSettingsAction` to
  render the default values for cluster settings.
* `IndexScopedSettings`: Used by `RestGetSettingsAction` to get
  the default values for index settings.
* `SettingsFilter`: Used by a few handlers to filter returned
  settings so we don't expose stuff like passwords.
* `IndexNameExpressionResolver`: Used by `_cat/indices` to
  filter the list of indices.
* `Supplier<DiscoveryNodes>`: Used to fill enrich the response
  by handlers that list tasks.

We probably want to reduce these arguments over time but
switching construction away from guice gives us tighter
control over the list of available arguments.

These parameters are passed to plugins using
`ActionPlugin#initRestHandlers` which is expected to build and
return that handlers immediately. This felt simpler than
returning an reference to the ctors given all the different
possible args.
@nik9000 nik9000 merged commit 6265ef1 into elastic:master Jan 20, 2017
@nik9000
Copy link
Member Author

nik9000 commented Jan 20, 2017

Thanks for reviewing @rjernst!

@nik9000
Copy link
Member Author

nik9000 commented Jan 20, 2017

master: 6265ef1
5.x: 6050f22

nik9000 added a commit that referenced this pull request Jan 20, 2017
There are presently 7 ctor args used in any rest handlers:
* `Settings`: Every handler uses it to initialize a logger and
  some other strange things.
* `RestController`: Every handler registers itself with it.
* `ClusterSettings`: Used by `RestClusterGetSettingsAction` to
  render the default values for cluster settings.
* `IndexScopedSettings`: Used by `RestGetSettingsAction` to get
  the default values for index settings.
* `SettingsFilter`: Used by a few handlers to filter returned
  settings so we don't expose stuff like passwords.
* `IndexNameExpressionResolver`: Used by `_cat/indices` to
  filter the list of indices.
* `Supplier<DiscoveryNodes>`: Used to fill enrich the response
  by handlers that list tasks.

We probably want to reduce these arguments over time but
switching construction away from guice gives us tighter
control over the list of available arguments.

These parameters are passed to plugins using
`ActionPlugin#initRestHandlers` which is expected to build and
return that handlers immediately. This felt simpler than
returning an reference to the ctors given all the different
possible args.

Breaks java plugins by moving rest handlers off of guice.
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Jan 23, 2017
* master: (33 commits)
  Docs fix - Added missing link to new Adjacency-matrix agg
  Pass `forceExecution` flag to transport interceptor (elastic#22739)
  Version: Add missing releases from 2.x in Version.java (elastic#22594)
  CONSOLE-ify filter aggregation docs
  CONSOLE-ify date_range aggregation docs
  Add single static instance of SpecialPermission (elastic#22726)
  Simplify InternalEngine#innerIndex (elastic#22721)
  Upgrade to Lucene 6.4.0 (elastic#22724)
  Fix broken TaskInfo.toString()
  Add CheckedSupplier and CheckedRunnable to core (elastic#22725)
  Revert "Make build Gradle 2.14 / 3.x compatible (elastic#22669)"
  Fixes retrieval of the latest snapshot index blob (elastic#22700)
  CONSOLE-ify date histogram docs
  CONSOLE-ify min and max aggregation docs
  CONSOLE-ify global-aggregation.asciidoc
  Fix script score function that combines _score and weight (elastic#22713)
  Corrected a plural verb to a singular one. (elastic#22681)
  Fix duplicates from search.query (elastic#22701)
  Readd unconverted snippets mark for doc
  Deguice rest handlers (elastic#22575)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants