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

Optionally require a valid content type for all rest requests with content #22691

Merged
merged 43 commits into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e4b2d08
Require a valid content type for all rest requests with content
jaymode Jan 12, 2017
c53e296
start addressing review feedback
jaymode Jan 20, 2017
9448729
review updates for index templates
jaymode Jan 20, 2017
7a267ff
use Objects.requireNonNull for pipeline requests
jaymode Jan 20, 2017
3e78549
deprecate loadFromSource without xcontenttype
jaymode Jan 20, 2017
63ab38a
more deprecations :)
jaymode Jan 20, 2017
99f551f
cleanup deprecated usages and remove source methods without xcontenttype
jaymode Jan 23, 2017
76c9f5e
Merge branch 'master' into content_type
jaymode Jan 23, 2017
d4f0e13
more updates and add a sendErrorResponse method
jaymode Jan 23, 2017
b5d9e6f
fix line length
jaymode Jan 23, 2017
221f797
fix percolatequerybuilder serialization
jaymode Jan 23, 2017
f43bf3b
add a BWC compatibility layer that defaults to auto detection fallback
jaymode Jan 24, 2017
323e634
Merge branch 'master' into content_type
jaymode Jan 24, 2017
c6be540
serialization tests and updates
jaymode Jan 24, 2017
8072a05
Merge branch 'master' into content_type
jaymode Jan 26, 2017
0be9af3
review round 2 updates
jaymode Jan 26, 2017
84db4dd
change onOrAfter to after for now
jaymode Jan 26, 2017
2391d2d
rollback change to bwc test version
jaymode Jan 26, 2017
19cdb27
put mapping request can take bytes so we can pass from rest layer
jaymode Jan 26, 2017
0264168
fix reindex parsing of content-type
jaymode Jan 26, 2017
b18cae7
docs updates
jaymode Jan 26, 2017
7e94108
fix index request serialization for reindex
jaymode Jan 26, 2017
65bfe9e
make reindex work with the removal of the default value in IndexRequest
jaymode Jan 26, 2017
1d1d47e
add content type message to test
jaymode Jan 26, 2017
7357e4e
fix testing broken mapping to use valid json
jaymode Jan 26, 2017
88a1a56
ensure we consume the source_content_type parameter before checking i…
jaymode Jan 26, 2017
842806a
handle backwards compatibility in rest test client
jaymode Jan 27, 2017
26c6df8
modify rest test framework to ignore deprecated missing source_conten…
jaymode Jan 27, 2017
a441458
address more feedback
jaymode Jan 27, 2017
4d37b1b
Merge branch 'master' into content_type
jaymode Jan 27, 2017
e208082
address non-reindex comments
jaymode Jan 30, 2017
7b89522
more feedback changes
jaymode Jan 30, 2017
d2a3c6f
Merge branch 'master' into content_type
jaymode Jan 30, 2017
5270a44
add comment
jaymode Jan 30, 2017
e4f46d3
use writeOptionalWriteable the right way
jaymode Jan 30, 2017
4bd706a
use xcontent type to avoid deprecated method
jaymode Jan 30, 2017
dd19f71
add missing setting registration
jaymode Feb 1, 2017
9f862a6
Merge branch 'master' into content_type
jaymode Feb 1, 2017
4699539
Merge branch 'master' into content_type
jaymode Feb 1, 2017
fd62a34
use 5.3.0-snapshot for rolling upgrade
jaymode Feb 1, 2017
9bbdd71
Merge branch 'master' into content_type
jaymode Feb 2, 2017
ed3ee08
Merge branch 'master' into content_type
jaymode Feb 2, 2017
159b450
add status
jaymode Feb 2, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.plugin.noop.NoopPlugin;
import org.elasticsearch.plugin.noop.action.bulk.NoopBulkAction;
Expand Down Expand Up @@ -80,7 +81,7 @@ public TransportBulkRequestExecutor(TransportClient client, String indexName, St
public boolean bulkIndex(List<String> bulkData) {
NoopBulkRequestBuilder builder = NoopBulkAction.INSTANCE.newRequestBuilder(client);
for (String bulkItem : bulkData) {
builder.add(new IndexRequest(indexName, typeName).source(bulkItem.getBytes(StandardCharsets.UTF_8)));
builder.add(new IndexRequest(indexName, typeName).source(bulkItem.getBytes(StandardCharsets.UTF_8), XContentType.JSON));
}
BulkResponse bulkResponse;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentType;

public class NoopBulkRequestBuilder extends ActionRequestBuilder<BulkRequest, BulkResponse, NoopBulkRequestBuilder>
implements WriteRequestBuilder<NoopBulkRequestBuilder> {
Expand Down Expand Up @@ -95,17 +96,17 @@ public NoopBulkRequestBuilder add(UpdateRequestBuilder request) {
/**
* Adds a framed data in binary format
*/
public NoopBulkRequestBuilder add(byte[] data, int from, int length) throws Exception {
request.add(data, from, length, null, null);
public NoopBulkRequestBuilder add(byte[] data, int from, int length, XContentType xContentType) throws Exception {
request.add(data, from, length, null, null, xContentType);
return this;
}

/**
* Adds a framed data in binary format
*/
public NoopBulkRequestBuilder add(byte[] data, int from, int length, @Nullable String defaultIndex, @Nullable String defaultType)
throws Exception {
request.add(data, from, length, defaultIndex, defaultType);
public NoopBulkRequestBuilder add(byte[] data, int from, int length, @Nullable String defaultIndex, @Nullable String defaultType,
XContentType xContentType) throws Exception {
request.add(data, from, length, defaultIndex, defaultType, xContentType);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
}
bulkRequest.timeout(request.paramAsTime("timeout", BulkShardRequest.DEFAULT_TIMEOUT));
bulkRequest.setRefreshPolicy(request.param("refresh"));
bulkRequest.add(request.content(), defaultIndex, defaultType, defaultRouting, defaultFields, null, defaultPipeline, null, true);
bulkRequest.add(request.content(), defaultIndex, defaultType, defaultRouting, defaultFields, null, defaultPipeline, null, true,
request.getXContentType());

// short circuit the call to the transport layer
return channel -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,28 @@ public PutRepositoryRequest settings(Settings.Builder settings) {
/**
* Sets the repository settings.
*
* @param source repository settings in json, yaml or properties format
* @param source repository settings in json or yaml format
* @return this request
* @deprecated use {@link #settings(String, XContentType)} to avoid content type auto-detection
*/
@Deprecated
public PutRepositoryRequest settings(String source) {
this.settings = Settings.builder().loadFromSource(source).build();
return this;
}

/**
* Sets the repository settings.
*
* @param source repository settings in json or yaml format
* @param xContentType the content type of the source
* @return this request
*/
public PutRepositoryRequest settings(String source, XContentType xContentType) {
this.settings = Settings.builder().loadFromSource(source, xContentType).build();
return this;
}

/**
* Sets the repository settings.
*
Expand All @@ -160,7 +174,7 @@ public PutRepositoryRequest settings(Map<String, Object> source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
settings(builder.string());
settings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;

import java.util.Map;

Expand Down Expand Up @@ -89,16 +90,30 @@ public PutRepositoryRequestBuilder setSettings(Settings.Builder settings) {
}

/**
* Sets the repository settings in Json, Yaml or properties format
* Sets the repository settings in Json or Yaml format
*
* @param source repository settings
* @return this builder
* @deprecated use {@link #setSettings(String, XContentType)} instead to avoid content type auto detection
*/
@Deprecated
public PutRepositoryRequestBuilder setSettings(String source) {
request.settings(source);
return this;
}

/**
* Sets the repository settings in Json or Yaml format
*
* @param source repository settings
* @param xContentType the contenty type of the source
* @return this builder
*/
public PutRepositoryRequestBuilder setSettings(String source, XContentType xContentType) {
request.settings(source, xContentType);
return this;
}

/**
* Sets the repository settings
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,22 @@ public ClusterUpdateSettingsRequest transientSettings(Settings.Builder settings)

/**
* Sets the source containing the transient settings to be updated. They will not survive a full cluster restart
* @deprecated use {@link #transientSettings(String, XContentType)} to avoid content type detection
*/
@Deprecated
public ClusterUpdateSettingsRequest transientSettings(String source) {
this.transientSettings = Settings.builder().loadFromSource(source).build();
return this;
}

/**
* Sets the source containing the transient settings to be updated. They will not survive a full cluster restart
*/
public ClusterUpdateSettingsRequest transientSettings(String source, XContentType xContentType) {
this.transientSettings = Settings.builder().loadFromSource(source, xContentType).build();
return this;
}

/**
* Sets the transient settings to be updated. They will not survive a full cluster restart
*/
Expand All @@ -97,7 +107,7 @@ public ClusterUpdateSettingsRequest transientSettings(Map source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
transientSettings(builder.string());
transientSettings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
Expand All @@ -122,12 +132,22 @@ public ClusterUpdateSettingsRequest persistentSettings(Settings.Builder settings

/**
* Sets the source containing the persistent settings to be updated. They will get applied cross restarts
* @deprecated use {@link #persistentSettings(String, XContentType)} to avoid content type detection
*/
@Deprecated
public ClusterUpdateSettingsRequest persistentSettings(String source) {
this.persistentSettings = Settings.builder().loadFromSource(source).build();
return this;
}

/**
* Sets the source containing the persistent settings to be updated. They will get applied cross restarts
*/
public ClusterUpdateSettingsRequest persistentSettings(String source, XContentType xContentType) {
this.persistentSettings = Settings.builder().loadFromSource(source, xContentType).build();
return this;
}

/**
* Sets the persistent settings to be updated. They will get applied cross restarts
*/
Expand All @@ -136,7 +156,7 @@ public ClusterUpdateSettingsRequest persistentSettings(Map source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
persistentSettings(builder.string());
persistentSettings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;

import java.util.Map;

Expand Down Expand Up @@ -52,12 +53,22 @@ public ClusterUpdateSettingsRequestBuilder setTransientSettings(Settings.Builder

/**
* Sets the source containing the transient settings to be updated. They will not survive a full cluster restart
* @deprecated use {@link #setTransientSettings(String, XContentType)} to avoid content type detection
*/
@Deprecated
public ClusterUpdateSettingsRequestBuilder setTransientSettings(String settings) {
request.transientSettings(settings);
return this;
}

/**
* Sets the source containing the transient settings to be updated. They will not survive a full cluster restart
*/
public ClusterUpdateSettingsRequestBuilder setTransientSettings(String settings, XContentType xContentType) {
request.transientSettings(settings, xContentType);
return this;
}

/**
* Sets the transient settings to be updated. They will not survive a full cluster restart
*/
Expand All @@ -84,12 +95,22 @@ public ClusterUpdateSettingsRequestBuilder setPersistentSettings(Settings.Builde

/**
* Sets the source containing the persistent settings to be updated. They will get applied cross restarts
* @deprecated use {@link #setPersistentSettings(String, XContentType)} to avoid content type detection
*/
@Deprecated
public ClusterUpdateSettingsRequestBuilder setPersistentSettings(String settings) {
request.persistentSettings(settings);
return this;
}

/**
* Sets the source containing the persistent settings to be updated. They will get applied cross restarts
*/
public ClusterUpdateSettingsRequestBuilder setPersistentSettings(String settings, XContentType xContentType) {
request.persistentSettings(settings, xContentType);
return this;
}

/**
* Sets the persistent settings to be updated. They will get applied cross restarts
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,34 @@ public CreateSnapshotRequest settings(Settings.Builder settings) {
}

/**
* Sets repository-specific snapshot settings in JSON, YAML or properties format
* Sets repository-specific snapshot settings in JSON or YAML format
Copy link
Member

Choose a reason for hiding this comment

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

thanks for cleaning these comments up!

* <p>
* See repository documentation for more information.
*
* @param source repository-specific snapshot settings
* @return this request
* @deprecated use {@link #settings(String, XContentType)} to avoid content type detection
*/
@Deprecated
public CreateSnapshotRequest settings(String source) {
this.settings = Settings.builder().loadFromSource(source).build();
return this;
}

/**
* Sets repository-specific snapshot settings in JSON or YAML format
* <p>
* See repository documentation for more information.
*
* @param source repository-specific snapshot settings
* @param xContentType the content type of the source
* @return this request
*/
public CreateSnapshotRequest settings(String source, XContentType xContentType) {
this.settings = Settings.builder().loadFromSource(source, xContentType).build();
return this;
}

/**
* Sets repository-specific snapshot settings.
* <p>
Expand All @@ -312,7 +328,7 @@ public CreateSnapshotRequest settings(Map<String, Object> source) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
builder.map(source);
settings(builder.string());
settings(builder.string(), builder.contentType());
} catch (IOException e) {
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;

import java.util.Map;

Expand Down Expand Up @@ -147,12 +148,28 @@ public CreateSnapshotRequestBuilder setSettings(Settings.Builder settings) {
*
* @param source repository-specific snapshot settings
* @return this builder
* @deprecated use {@link #setSettings(String, XContentType)} to avoid content type detection
*/
@Deprecated
public CreateSnapshotRequestBuilder setSettings(String source) {
request.settings(source);
return this;
}

/**
* Sets repository-specific snapshot settings in YAML or JSON format
* <p>
* See repository documentation for more information.
*
* @param source repository-specific snapshot settings
* @param xContentType the content type of the source
* @return this builder
*/
public CreateSnapshotRequestBuilder setSettings(String source, XContentType xContentType) {
request.settings(source, xContentType);
return this;
}

/**
* Sets repository-specific snapshot settings.
* <p>
Expand Down
Loading