Skip to content

Commit

Permalink
Put mapping and index template requests do not need content type dete…
Browse files Browse the repository at this point in the history
…ction for 5.3.0+ (#24835)

This change cleans up some missed TODOs for content type detection on the source of put mapping and
put index template requests. In 5.3.0 and newer versions, the source is always JSON so the content
type detection is not needed. The TODOs were missed after the change was backported to 5.3.

Relates #24798
  • Loading branch information
jaymode authored May 25, 2017
1 parent fab6b00 commit f60f79f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public void readFrom(StreamInput in) throws IOException {
indicesOptions = IndicesOptions.readIndicesOptions(in);
type = in.readOptionalString();
source = in.readString();
if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { // TODO change to V_5_3 once backported
if (in.getVersion().before(Version.V_5_3_0)) {
// we do not know the format from earlier versions so convert if necessary
source = XContentHelper.convertToJson(new BytesArray(source), false, false, XContentFactory.xContentType(source));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public void readFrom(StreamInput in) throws IOException {
for (int i = 0; i < size; i++) {
final String type = in.readString();
String mappingSource = in.readString();
if (in.getVersion().before(Version.V_6_0_0_alpha1_UNRELEASED)) { // TODO change to V_5_3_0 once backported
if (in.getVersion().before(Version.V_5_3_0)) {
// we do not know the incoming type so convert it if needed
mappingSource =
XContentHelper.convertToJson(new BytesArray(mappingSource), false, false, XContentFactory.xContentType(mappingSource));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,19 @@ public void testPutMappingRequestSerialization() throws IOException {
request.source(mapping, XContentType.YAML);
assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), request.source());

BytesStreamOutput bytesStreamOutput = new BytesStreamOutput();
request.writeTo(bytesStreamOutput);
StreamInput in = StreamInput.wrap(bytesStreamOutput.bytes().toBytesRef().bytes);
PutMappingRequest serialized = new PutMappingRequest();
serialized.readFrom(in);
final Version version = randomFrom(Version.CURRENT, Version.V_5_3_0, Version.V_5_3_1, Version.V_5_3_2, Version.V_5_4_0);
try (BytesStreamOutput bytesStreamOutput = new BytesStreamOutput()) {
bytesStreamOutput.setVersion(version);
request.writeTo(bytesStreamOutput);
try (StreamInput in = StreamInput.wrap(bytesStreamOutput.bytes().toBytesRef().bytes)) {
in.setVersion(version);
PutMappingRequest serialized = new PutMappingRequest();
serialized.readFrom(in);

String source = serialized.source();
assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), source);
String source = serialized.source();
assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), source);
}
}
}

public void testSerializationBwc() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,19 @@ public void testPutIndexTemplateRequestSerializationXContent() throws IOExceptio
assertNotEquals(mapping, request.mappings().get("bar"));
assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), request.mappings().get("bar"));

BytesStreamOutput out = new BytesStreamOutput();
request.writeTo(out);
final Version version = randomFrom(Version.CURRENT, Version.V_5_3_0, Version.V_5_3_1, Version.V_5_3_2, Version.V_5_4_0);
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(version);
request.writeTo(out);

StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes);
PutIndexTemplateRequest serialized = new PutIndexTemplateRequest();
serialized.readFrom(in);
assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML), serialized.mappings().get("bar"));
try (StreamInput in = StreamInput.wrap(out.bytes().toBytesRef().bytes)) {
in.setVersion(version);
PutIndexTemplateRequest serialized = new PutIndexTemplateRequest();
serialized.readFrom(in);
assertEquals(XContentHelper.convertToJson(new BytesArray(mapping), false, XContentType.YAML),
serialized.mappings().get("bar"));
}
}
}

public void testPutIndexTemplateRequestSerializationXContentBwc() throws IOException {
Expand Down

0 comments on commit f60f79f

Please sign in to comment.