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

Cleanup ScriptType #21179

Merged
merged 7 commits into from
Oct 31, 2016
Merged

Cleanup ScriptType #21179

merged 7 commits into from
Oct 31, 2016

Conversation

jdconrad
Copy link
Contributor

Refactored ScriptType to clean up some of the variable and method names. Added more documentation. Deprecated the 'in' ParseField in favor of 'stored' to match the indexed scripts being replaced by stored scripts.

Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

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

left 2 minor suggestions LGTM otherwise

public static void writeTo(ScriptType scriptType, StreamOutput out) throws IOException{
if (scriptType != null) {
out.writeVInt(scriptType.val);
if (FILE.id == id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe so switch(id) {? looks cleaner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a bit awkward because the id is not considered a compile-time constant since it's set through the enum constructor. One option would be to add compile time constants for each id and use that instead, but I think the if statement is probably simpler.

* - loaded from file
* ScriptType represents the way a script is stored and retrieved from the {@link ScriptService}.
* It's also used to by {@link ScriptSettings} and {@link ScriptModes} to determine whether or not
* a {@link Script} is allowed to be executed based on both default and user-defined settings.
*/
public enum ScriptType {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we can implement Writeable here then we don't need the static writeTo method anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing this now. Will re-test and commit once the tests are good.

/**
* INLINE scripts are specified in numerous queries and compiled on-the-fly.
* They will be cached based on the lang and code of the script.
* They are turned off by default for security purposes.
Copy link
Member

Choose a reason for hiding this comment

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

They are turned off for groovy by default because it is insecure but they are on by default for painless and mustache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

/**
* STORED scripts are saved as part of the {@link org.elasticsearch.cluster.ClusterState}
* based on user requests. They will be cached when they are first used in a query.
* They are turned off by default for security purposes.
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added here too.

} else {
out.writeVInt(INLINE.val); //Default to inline
throw new IllegalStateException("Error reading ScriptType id [" + id + "] from stream, expected one of [" +
Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:)

this.scriptType = scriptType;
this.defaultScriptEnabled = defaultScriptEnabled;
/**
* Writes an int to the output stream based on the id of the {@link ScriptType}.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need to explain that wire format for the enum is an int.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed. Should inherit the base class JavaDoc.

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

Left a few minor things as well, mostly around the docs.

*/
ScriptType(int id, String name, ParseField parseField, boolean defaultEnabled) {
this.id = id;
this.name = name;
Copy link
Member

Choose a reason for hiding this comment

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

The name is always the name in the ParseField so maybe we should just get it from there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Forces the name of the ParseField to be the same as the name of the enum.

@jdconrad jdconrad merged commit 185dff7 into elastic:master Oct 31, 2016
@jdconrad
Copy link
Contributor Author

@nik9000 and @s1monw Thanks for the reviews!

jdconrad added a commit that referenced this pull request Nov 1, 2016
@jdconrad jdconrad deleted the splittypes branch November 18, 2016 21:07
@clintongormley clintongormley added :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache and removed :Indexed Scripts/Templates labels Feb 13, 2018
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 >non-issue v5.1.1 v6.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants