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

Allow plugins to define custom operations that they use scripts for #10419

Closed

Conversation

javanna
Copy link
Member

@javanna javanna commented Apr 3, 2015

Plugins can now define multiple operations/contexts that they use scripts for. Fine-grained settings can then be used to enable/disable scripts based on each single registered context.

Also added a new generic category called plugins, which will be used as a default when the context is not specified. This allows us to restore backwards compatibility for plugins on ScriptService by restoring the old methods that don't require the script context and making them internally use the plugins context, as they can only be called from plugins.

Closes #10347

…ripts for

Plugins can now define multiple operations/contexts that they use scripts for. Fine-grained settings can then be used to enable/disable scripts based on each single registered context.

Also added a new generic category called `plugins`, which will be used as a default when the context is not specified. This allows us to restore backwards compatibility for plugins on `ScriptService` by restoring the old methods that don't require the script context and making them internally use the `plugins` context, as they can only be called from plugins.

Closes elastic#10347
@javanna javanna changed the title Scripting: allow plugins to define custom operations that they use scrip... Scripting: allow plugins to define custom operations that they use scripts for Apr 3, 2015
@javanna javanna added >enhancement :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache v1.6.0 v2.0.0-beta1 review labels Apr 3, 2015
@javanna
Copy link
Member Author

javanna commented Apr 3, 2015

@uboness assigning this to you for review

@uboness
Copy link
Contributor

uboness commented Apr 6, 2015

@javanna (don't kill me) thinking out load.. going back to the previous enum... would it be better to change that enum to an interface, such that the contract ScriptService's methods will be clearer/"safer".. yet the context will still be based on an opaque string. Something like:

public interface ScriptContext {

    enum Std implements ScriptContext {
        MAPPING() {
            public String key() {
                return "mapping";
            }
        },
        SEARCH() {
            public String key() {
                return "search";
            }
        },
        UPDATE() {
            public String key() {
                return "update";
            }
        },
        AGGS() {
            public String key() {
                return "aggs";
            }
        };
    }

    String key();

    class Plugin implements ScriptContext {

        private String key;

        public Plugin(String pluginName, String context) {
            this.key = pluginName + "_" + context;
        }

        public String key() {
            return key;
        }
    }
}

the Plugin class is there just to promote plugins to implement the context in a consistent manner. (also, not sure if it will, but we open up the option for the context to hold more info in the future, without breaking the contract of the service methods)

@javanna
Copy link
Member Author

javanna commented Apr 7, 2015

@uboness makes sense to me, just pushed a new commit.

* @deprecated create a new {@link org.elasticsearch.script.ScriptContext.Plugin} instance instead
*/
@Deprecated
Plugin GENERIC_PLUGIN = new Plugin("plugin");
Copy link
Contributor

Choose a reason for hiding this comment

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

why not put this under Standard and deprecate it as an option?

Copy link
Member Author

Choose a reason for hiding this comment

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

will do

@uboness
Copy link
Contributor

uboness commented Apr 7, 2015

left a couple of comments

@javanna
Copy link
Member Author

javanna commented Apr 7, 2015

Pushed another commit. Wondering: shall we restrict ScriptModule#registerScriptContext(ScriptContext) to ScriptModule#registerScriptContext(ScriptContext.Plugin) and make ScriptContext.Plugin final? That would allow us to actually enforce conventions on context keys etc. rather than only semi-enforcing them. Would that be too restrictive? Can you think of cases where implementing ScriptContext directly would be useful over using Plugin?

@uboness
Copy link
Contributor

uboness commented Apr 7, 2015

I like it... hmm... I can't think of any scenario where you'd want to register custom contexts outside of a plugin. outside of a plugin is only within the core codebase and for that we can always extend the std enum. It's easier to start restrictive and open it up if we find the need to.. rather than open it up now and later try to restrict it. So I'd say go for it...

@javanna
Copy link
Member Author

javanna commented Apr 7, 2015

pushed another commit, restricted the custom script context to ScriptContext.Plugin instances only. We still rely on plugins providing the right info, there can still be interaction between different plugins (think of a plugin registering context plugin1_test and plugin2 using it), but I think this as far as we can take it (at least there's a single way to plug in custom contexts providing plugin name and operation).

Are we happy about using the _ operator between plugin name and operation. That will need to be used as part of fine-grained settings e.g. script.engine.groovy.inline.plugin1_feature1: on . I think we could potentially replace _ with . too, shouldn't hurt but maybe more confusing? Thoughts @clintongormley ?

@uboness
Copy link
Contributor

uboness commented Apr 7, 2015

pushed another commit, restricted the custom script context to ScriptContext.Plugin instances only. We still rely on plugins providing the right info, there can still be interaction between different plugins (think of a plugin registering context plugin1_test and plugin2 using it), but I think this as far as we can take it (at least there's a single way to plug in custom contexts providing plugin name and operation).

agreed

Are we happy about using the _ operator

yea... I chose this one as I wasn't sure how it'd effect 1) the parsing of the settings, 2) would confuse when reading the settings as . is used to separate other elements there.

@javanna
Copy link
Member Author

javanna commented Apr 7, 2015

cool @uboness can you go over it one last time please? should be ready

executed from sandboxed languages as part of `aggregations` and `search`
operations though, as the above defaults still get applied.
executed from sandboxed languages as part of `aggregations`, `search`
and `plugin` operations though, as the above defaults still get applied.

Copy link
Contributor

Choose a reason for hiding this comment

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

shall we add a NOTE: here about custom plugin contexts?

Copy link
Member Author

Choose a reason for hiding this comment

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

Plugins are briefly mentioned a few lines above:

Plugins can also define custom operations that they use scripts for instead of using the generic plugin category. Those operations can be referred to in the following form: $pluginName_$operation.

That said I haven't explained how plugins can do it, but we don't really have reference for plugins so maybe this is enough?

@clintongormley
Copy link

Are we happy about using the _ operator
yea... I chose this one as I wasn't sure how it'd effect 1) the parsing of the settings, 2) would confuse when reading the settings as . is used to separate other elements there.

Agreed. I'm happy with _

@uboness
Copy link
Contributor

uboness commented Apr 7, 2015

left a small comment on docs (not sure if we want to mention plugin as we don't really mention plugins anywhere else AFAIK)... other than that LGTM

javanna added a commit that referenced this pull request Apr 8, 2015
…ripts for

Plugins can now define multiple operations/contexts that they use scripts for. Fine-grained settings can then be used to enable/disable scripts based on each single registered context.

Also added a new generic category called `plugin`, which will be used as a default when the context is not specified. This allows us to restore backwards compatibility for plugins on `ScriptService` by restoring the old methods that don't require the script context and making them internally use the `plugin` context, as they can only be called from plugins.

Closes #10347
Closes #10419
@javanna javanna closed this in 7bd7ea8 Apr 8, 2015
@javanna javanna removed the review label Apr 8, 2015
@javanna
Copy link
Member Author

javanna commented Apr 8, 2015

ping @dadoonet you might want to update plugins to use the plugin category, or even define their own script context.

dadoonet added a commit to elastic/elasticsearch-river-rabbitmq that referenced this pull request Apr 25, 2015
From elastic/elasticsearch#10419

We need to adapt river code from es-1.x (1.6.0)

Closes #99.
dadoonet added a commit to elastic/elasticsearch-river-couchdb that referenced this pull request Apr 25, 2015
From elastic/elasticsearch#10419

We need to adapt river code from es-1.x (1.6.0)

Closes #98.
dadoonet added a commit to elastic/elasticsearch-river-couchdb that referenced this pull request Apr 25, 2015
From elastic/elasticsearch#10419

We need to adapt river code from es-1.x (1.6.0)

Closes #98.

(cherry picked from commit e0bb184)
@clintongormley clintongormley changed the title Scripting: allow plugins to define custom operations that they use scripts for Allow plugins to define custom operations that they use scripts for Jun 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >enhancement v1.6.0 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants