REST hl client: cluster health to default to cluster level (#31268)

With #29331 we added support for the cluster health API to the
high-level REST client. The transport client does not support the level
parameter, and it always returns all the info needed for shards level
rendering. We have maintained that behaviour when adding support for
cluster health to the high-level REST client, to ease migration, but the
correct thing to do is to default the high-level REST client to
`cluster` level, which is the same default as when going through the
Elasticsearch REST layer.
This commit is contained in:
Luca Cavanna 2018-06-13 15:06:13 +02:00 committed by GitHub
parent 66f7dd2c4d
commit 24163d10b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 8 deletions

View File

@ -129,7 +129,6 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
createIndex("index2", Settings.EMPTY); createIndex("index2", Settings.EMPTY);
ClusterHealthRequest request = new ClusterHealthRequest(); ClusterHealthRequest request = new ClusterHealthRequest();
request.timeout("5s"); request.timeout("5s");
request.level(ClusterHealthRequest.Level.CLUSTER);
ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync); ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync);
assertYellowShards(response); assertYellowShards(response);
@ -170,6 +169,7 @@ public class ClusterClientIT extends ESRestHighLevelClientTestCase {
createIndex("index", Settings.EMPTY); createIndex("index", Settings.EMPTY);
createIndex("index2", Settings.EMPTY); createIndex("index2", Settings.EMPTY);
ClusterHealthRequest request = new ClusterHealthRequest("index"); ClusterHealthRequest request = new ClusterHealthRequest("index");
request.level(ClusterHealthRequest.Level.SHARDS);
request.timeout("5s"); request.timeout("5s");
ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync); ClusterHealthResponse response = execute(request, highLevelClient().cluster()::health, highLevelClient().cluster()::healthAsync);

View File

@ -1568,7 +1568,7 @@ public class RequestConvertersTests extends ESTestCase {
healthRequest.level(level); healthRequest.level(level);
expectedParams.put("level", level.name().toLowerCase(Locale.ROOT)); expectedParams.put("level", level.name().toLowerCase(Locale.ROOT));
} else { } else {
expectedParams.put("level", "shards"); expectedParams.put("level", "cluster");
} }
if (randomBoolean()) { if (randomBoolean()) {
Priority priority = randomFrom(Priority.values()); Priority priority = randomFrom(Priority.values());

View File

@ -67,6 +67,7 @@ include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-wai
include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-level] include-tagged::{doc-tests}/ClusterClientDocumentationIT.java[health-request-level]
-------------------------------------------------- --------------------------------------------------
<1> The level of detail of the returned health information. Accepts a `ClusterHealthRequest.Level` value. <1> The level of detail of the returned health information. Accepts a `ClusterHealthRequest.Level` value.
Default value is `cluster`.
["source","java",subs="attributes,callouts,macros"] ["source","java",subs="attributes,callouts,macros"]
-------------------------------------------------- --------------------------------------------------

View File

@ -11,3 +11,10 @@ header, e.g. `client.index(indexRequest)` becomes
In case you are specifying headers In case you are specifying headers
e.g. `client.index(indexRequest, new Header("name" "value"))` becomes e.g. `client.index(indexRequest, new Header("name" "value"))` becomes
`client.index(indexRequest, RequestOptions.DEFAULT.toBuilder().addHeader("name", "value").build());` `client.index(indexRequest, RequestOptions.DEFAULT.toBuilder().addHeader("name", "value").build());`
==== Cluster Health API default to `cluster` level
The Cluster Health API used to default to `shards` level to ease migration
from transport client that doesn't support the `level` parameter and always
returns information including indices and shards details. The level default
value has been aligned with the Elasticsearch default level: `cluster`.

View File

@ -48,9 +48,9 @@ public class ClusterHealthRequest extends MasterNodeReadRequest<ClusterHealthReq
private Priority waitForEvents = null; private Priority waitForEvents = null;
/** /**
* Only used by the high-level REST Client. Controls the details level of the health information returned. * Only used by the high-level REST Client. Controls the details level of the health information returned.
* The default value is 'shards' so it is backward compatible with the transport client behaviour. * The default value is 'cluster'.
*/ */
private Level level = Level.SHARDS; private Level level = Level.CLUSTER;
public ClusterHealthRequest() { public ClusterHealthRequest() {
} }
@ -250,8 +250,7 @@ public class ClusterHealthRequest extends MasterNodeReadRequest<ClusterHealthReq
/** /**
* Set the level of detail for the health information to be returned. * Set the level of detail for the health information to be returned.
* Only used by the high-level REST Client * Only used by the high-level REST Client.
* The default value is 'shards' so it is backward compatible with the transport client behaviour.
*/ */
public void level(Level level) { public void level(Level level) {
this.level = Objects.requireNonNull(level, "level must not be null"); this.level = Objects.requireNonNull(level, "level must not be null");
@ -260,7 +259,6 @@ public class ClusterHealthRequest extends MasterNodeReadRequest<ClusterHealthReq
/** /**
* Get the level of detail for the health information to be returned. * Get the level of detail for the health information to be returned.
* Only used by the high-level REST Client. * Only used by the high-level REST Client.
* The default value is 'shards' so it is backward compatible with the transport client behaviour.
*/ */
public Level level() { public Level level() {
return level; return level;