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

Add a Painless Context REST API #39382

Merged
merged 36 commits into from
Mar 14, 2019
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7b3aacb
Add skeleton for context action.
jdconrad Jan 17, 2019
759eb4e
Store PainlessScriptEngine.t
jdconrad Jan 17, 2019
1c1edba
Merge branch 'master' into docapi
jdconrad Jan 23, 2019
cf6b680
Add methods to access lookups for doc api.
jdconrad Jan 30, 2019
613cfe6
Merge branch 'master' into docapi
jdconrad Jan 31, 2019
0c48a73
Merge branch 'master' into docapi
jdconrad Feb 4, 2019
1ae7533
Convert to use HandledRestAction
jdconrad Feb 4, 2019
28b7cde
Progress on API for returning methods
jdconrad Feb 4, 2019
eafa7b9
Revent prettyprint
jdconrad Feb 4, 2019
fed13ea
Merge branch 'master' into docapi
jdconrad Feb 25, 2019
eab2c38
Add a Painless Context REST API
jdconrad Feb 25, 2019
13b3133
Fix style
jdconrad Feb 25, 2019
f519aba
Merge branch 'master' into docapi
jdconrad Feb 26, 2019
f1f4e5d
Merge branch 'master' into docapi
jdconrad Feb 28, 2019
9afc790
Move to action package.
jdconrad Feb 28, 2019
1f81c2c
Merge branch 'master' into docapi
jdconrad Mar 1, 2019
e4644d4
Merge branch 'master' into docapi
jdconrad Mar 4, 2019
2e40711
Add POJOs to handle serialization and response XContent.
jdconrad Mar 5, 2019
8ad179f
Update serialization.
jdconrad Mar 5, 2019
46f7504
Merge branch 'master' into docapi
jdconrad Mar 5, 2019
c480335
Merge branch 'master' into docapi
jdconrad Mar 5, 2019
c586417
Merge branch 'master' into docapi
jdconrad Mar 6, 2019
c54fe76
Merge branch 'master' into docapi
jdconrad Mar 7, 2019
a74a4dd
Add serialization tests.
jdconrad Mar 7, 2019
c0effbe
Fix generics.
jdconrad Mar 7, 2019
dd43131
Merge branch 'master' into docapi
jdconrad Mar 7, 2019
7f3d4a1
Merge branch 'master' into docapi
jdconrad Mar 11, 2019
7f218eb
Add yaml tests.
jdconrad Mar 11, 2019
a651b4b
Add rest spec
jdconrad Mar 11, 2019
f9ac3b1
Fix naming convention test.
jdconrad Mar 11, 2019
3b06a61
Merge branch 'master' into docapi
jdconrad Mar 12, 2019
79b1221
Add imported info to class, add matches to yaml tests, and update
jdconrad Mar 12, 2019
2b22fb3
Fix ignored imports in ANTLR files.
jdconrad Mar 12, 2019
17a3efc
Merge branch 'master' into docapi
jdconrad Mar 12, 2019
3a88b15
Merge branch 'master' into docapi
jdconrad Mar 13, 2019
5e97670
Response to PR comments.
jdconrad Mar 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add serialization tests.
  • Loading branch information
jdconrad committed Mar 7, 2019
commit a74a4ddd487eea421cdffe07040d5c137bf6967c
Original file line number Diff line number Diff line change
@@ -23,14 +23,17 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.painless.lookup.PainlessClassBinding;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class PainlessContextClassBindingInfo implements Writeable, ToXContentObject {
@@ -41,6 +44,27 @@ public class PainlessContextClassBindingInfo implements Writeable, ToXContentObj
public static final ParseField READ_ONLY = new ParseField("read_only");
public static final ParseField PARAMETERS = new ParseField("parameters");

@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<PainlessContextClassBindingInfo, Void> PARSER = new ConstructingObjectParser<>(
PainlessContextClassBindingInfo.class.getCanonicalName(),
(v) ->
new PainlessContextClassBindingInfo(
(String)v[0],
(String)v[1],
(String)v[2],
(int)v[3],
(List<String>)v[4]
)
);

static {
PARSER.declareString(ConstructingObjectParser.constructorArg(), DECLARING);
PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME);
PARSER.declareString(ConstructingObjectParser.constructorArg(), RTN);
PARSER.declareInt(ConstructingObjectParser.constructorArg(), READ_ONLY);
PARSER.declareStringArray(ConstructingObjectParser.constructorArg(), PARAMETERS);
}

private final String declaring;
private final String name;
private final String rtn;
@@ -82,6 +106,10 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeStringCollection(parameters);
}

public static PainlessContextClassBindingInfo fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject();
@@ -94,4 +122,21 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par

return builder;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PainlessContextClassBindingInfo that = (PainlessContextClassBindingInfo) o;
return readOnly == that.readOnly &&
Objects.equals(declaring, that.declaring) &&
Objects.equals(name, that.name) &&
Objects.equals(rtn, that.rtn) &&
Objects.equals(parameters, that.parameters);
}

@Override
public int hashCode() {
return Objects.hash(declaring, name, rtn, readOnly, parameters);
}
}
Original file line number Diff line number Diff line change
@@ -23,23 +23,54 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.painless.lookup.PainlessClass;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class PainlessContextClassInfo implements Writeable, ToXContentObject {

public static final ParseField NAME = new ParseField("name");
public static final ParseField CONSTRUCTOR = new ParseField("constructor");
public static final ParseField STATIC_METHOD = new ParseField("static_method");
public static final ParseField METHOD = new ParseField("method");
public static final ParseField STATIC_FIELD = new ParseField("static_field");
public static final ParseField FIELD = new ParseField("field");
public static final ParseField CONSTRUCTORS = new ParseField("constructors");
public static final ParseField STATIC_METHODS = new ParseField("static_methods");
public static final ParseField METHODS = new ParseField("methods");
public static final ParseField STATIC_FIELDS = new ParseField("static_fields");
public static final ParseField FIELDS = new ParseField("fields");

@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<PainlessContextClassInfo, Void> PARSER = new ConstructingObjectParser<>(
PainlessContextClassInfo.class.getCanonicalName(),
(v) ->
new PainlessContextClassInfo(
(String)v[0],
(List<PainlessContextConstructorInfo>)v[1],
(List<PainlessContextMethodInfo>)v[2],
(List<PainlessContextMethodInfo>)v[3],
(List<PainlessContextFieldInfo>)v[4],
(List<PainlessContextFieldInfo>)v[5]
)
);

static {
PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME);
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(),
(p, c) -> PainlessContextConstructorInfo.fromXContent(p), CONSTRUCTORS);
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(),
(p, c) -> PainlessContextMethodInfo.fromXContent(p), STATIC_METHODS);
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(),
(p, c) -> PainlessContextMethodInfo.fromXContent(p), METHODS);
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(),
(p, c) -> PainlessContextFieldInfo.fromXContent(p), STATIC_FIELDS);
PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(),
(p, c) -> PainlessContextFieldInfo.fromXContent(p), FIELDS);
}

private final String name;
private final List<PainlessContextConstructorInfo> constructors;
@@ -90,33 +121,39 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeList(fields);
}

public static PainlessContextClassInfo fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(NAME.getPreferredName(), name);

for (PainlessContextConstructorInfo constructor : constructors) {
builder.field(CONSTRUCTOR.getPreferredName(), constructor);
}

for (PainlessContextMethodInfo staticMethod : staticMethods) {
builder.field(STATIC_METHOD.getPreferredName(), staticMethod);
}

for (PainlessContextMethodInfo method : methods) {
builder.field(METHOD.getPreferredName(), method);
}

for (PainlessContextFieldInfo staticField : staticFields) {
builder.field(STATIC_FIELD.getPreferredName(), staticField);
}

for (PainlessContextFieldInfo field : fields) {
builder.field(FIELD.getPreferredName(), field);
}

builder.field(CONSTRUCTORS.getPreferredName(), constructors);
builder.field(STATIC_METHODS.getPreferredName(), staticMethods);
builder.field(METHODS.getPreferredName(), methods);
builder.field(STATIC_FIELDS.getPreferredName(), staticFields);
builder.field(FIELDS.getPreferredName(), fields);
builder.endObject();

return builder;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PainlessContextClassInfo that = (PainlessContextClassInfo) o;
return Objects.equals(name, that.name) &&
Objects.equals(constructors, that.constructors) &&
Objects.equals(staticMethods, that.staticMethods) &&
Objects.equals(methods, that.methods) &&
Objects.equals(staticFields, that.staticFields) &&
Objects.equals(fields, that.fields);
}

@Override
public int hashCode() {
return Objects.hash(name, constructors, staticMethods, methods, staticFields, fields);
}
}
Original file line number Diff line number Diff line change
@@ -23,14 +23,17 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.painless.lookup.PainlessConstructor;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class PainlessContextConstructorInfo implements Writeable, ToXContentObject {
@@ -41,6 +44,21 @@ public class PainlessContextConstructorInfo implements Writeable, ToXContentObje
private final String declaring;
private final List<String> parameters;

@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<PainlessContextConstructorInfo, Void> PARSER = new ConstructingObjectParser<>(
PainlessContextConstructorInfo.class.getCanonicalName(),
(v) ->
new PainlessContextConstructorInfo(
(String)v[0],
(List<String>)v[1]
)
);

static {
PARSER.declareString(ConstructingObjectParser.constructorArg(), DECLARING);
PARSER.declareStringArray(ConstructingObjectParser.constructorArg(), PARAMETERS);
}

public PainlessContextConstructorInfo(PainlessConstructor painlessConstructor) {
this (
painlessConstructor.javaConstructor.getDeclaringClass().getName(),
@@ -64,6 +82,10 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeStringCollection(parameters);
}

public static PainlessContextConstructorInfo fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject();
@@ -73,4 +95,18 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par

return builder;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PainlessContextConstructorInfo that = (PainlessContextConstructorInfo) o;
return Objects.equals(declaring, that.declaring) &&
Objects.equals(parameters, that.parameters);
}

@Override
public int hashCode() {
return Objects.hash(declaring, parameters);
}
}
Original file line number Diff line number Diff line change
@@ -23,18 +23,37 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.painless.lookup.PainlessField;

import java.io.IOException;
import java.util.Objects;

public class PainlessContextFieldInfo implements Writeable, ToXContentObject {

public static final ParseField DECLARING = new ParseField("declaring");
public static final ParseField NAME = new ParseField("name");
public static final ParseField TYPE = new ParseField("type");

private static final ConstructingObjectParser<PainlessContextFieldInfo, Void> PARSER = new ConstructingObjectParser<>(
PainlessContextFieldInfo.class.getCanonicalName(),
(v) ->
new PainlessContextFieldInfo(
(String)v[0],
(String)v[1],
(String)v[2]
)
);

static {
PARSER.declareString(ConstructingObjectParser.constructorArg(), DECLARING);
PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME);
PARSER.declareString(ConstructingObjectParser.constructorArg(), TYPE);
}

private final String declaring;
private final String name;
private final String type;
@@ -66,6 +85,10 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(type);
}

public static PainlessContextFieldInfo fromXContent(XContentParser parser) {
return PARSER.apply(parser, null);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
@@ -76,4 +99,19 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

return builder;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PainlessContextFieldInfo that = (PainlessContextFieldInfo) o;
return Objects.equals(declaring, that.declaring) &&
Objects.equals(name, that.name) &&
Objects.equals(type, that.type);
}

@Override
public int hashCode() {
return Objects.hash(declaring, name, type);
}
}
Loading