From 32d506914aa01a6051e8316ccfe04376844fdd8a Mon Sep 17 00:00:00 2001 From: Yu Date: Sun, 17 Mar 2019 07:48:42 +0000 Subject: [PATCH 1/5] Make recovery API support only `detailed` params --- .../recovery/RecoveryRequestBuilder.java | 2 +- .../org/elasticsearch/common/Strings.java | 12 ++++- .../indices/recovery/RecoveryState.java | 6 +-- .../indices/recovery/RecoveryStateTests.java | 53 +++++++++++++++++++ .../ml/integration/JobResultsProviderIT.java | 1 + 5 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStateTests.java diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryRequestBuilder.java index 42b6dae859d7b..f89b783c35f35 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryRequestBuilder.java @@ -43,4 +43,4 @@ public RecoveryRequestBuilder setActiveOnly(boolean activeOnly) { request.activeOnly(activeOnly); return this; } -} \ No newline at end of file +} diff --git a/server/src/main/java/org/elasticsearch/common/Strings.java b/server/src/main/java/org/elasticsearch/common/Strings.java index da27bf0187bd2..70353b4d608ec 100644 --- a/server/src/main/java/org/elasticsearch/common/Strings.java +++ b/server/src/main/java/org/elasticsearch/common/Strings.java @@ -770,12 +770,22 @@ public static String toString(XContentBuilder xContentBuilder) { * */ public static String toString(ToXContent toXContent, boolean pretty, boolean human) { + return toString(toXContent, pretty, human, ToXContent.EMPTY_PARAMS); + } + + /** + * Return a {@link String} that is the json representation of the provided {@link ToXContent}. + * Wraps the output into an anonymous object if needed. Allows to control whether the outputted + * json needs to be pretty printed, human readable, and set params while parsing XContent. + * + */ + public static String toString(ToXContent toXContent, boolean pretty, boolean human, ToXContent.Params params) { try { XContentBuilder builder = createBuilder(pretty, human); if (toXContent.isFragment()) { builder.startObject(); } - toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS); + toXContent.toXContent(builder, params); if (toXContent.isFragment()) { builder.endObject(); } diff --git a/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java b/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java index 4d27362af22b5..cf81bdfc25f79 100644 --- a/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java +++ b/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java @@ -343,7 +343,7 @@ static final class Fields { static final String REUSED = "reused"; static final String REUSED_IN_BYTES = "reused_in_bytes"; static final String PERCENT = "percent"; - static final String DETAILS = "details"; + static final String DETAILED = "detailed"; static final String SIZE = "size"; static final String SOURCE_THROTTLE_TIME = "source_throttle_time"; static final String SOURCE_THROTTLE_TIME_IN_MILLIS = "source_throttle_time_in_millis"; @@ -929,8 +929,8 @@ public synchronized XContentBuilder toXContent(XContentBuilder builder, Params p builder.field(Fields.REUSED, reusedFileCount()); builder.field(Fields.RECOVERED, recoveredFileCount()); builder.field(Fields.PERCENT, String.format(Locale.ROOT, "%1.1f%%", recoveredFilesPercent())); - if (params.paramAsBoolean("details", false)) { - builder.startArray(Fields.DETAILS); + if (params.paramAsBoolean("detailed", false)) { + builder.startArray(Fields.DETAILED); for (File file : fileDetails.values()) { file.toXContent(builder, params); } diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStateTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStateTests.java new file mode 100644 index 0000000000000..7ef644233533c --- /dev/null +++ b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStateTests.java @@ -0,0 +1,53 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.indices.recovery; + +import org.elasticsearch.Version; +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.routing.RecoverySource; +import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.cluster.routing.ShardRoutingState; +import org.elasticsearch.cluster.routing.TestShardRouting; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.test.ESTestCase; + +import java.util.Collections; + +import static java.util.Collections.emptyMap; +import static java.util.Collections.emptySet; + +public class RecoveryStateTests extends ESTestCase { + + public void testRecoveryStateIndexToXContent() { + String expected = "{\"size\":{\"total_in_bytes\":0,\"reused_in_bytes\":0,\"recovered_in_bytes\":0,\"percent\":\"0.0%\"}," + + "\"files\":{\"total\":0,\"reused\":0,\"recovered\":0,\"percent\":\"0.0%\",\"detailed\":[]}," + + "\"total_time_in_millis\":0,\"source_throttle_time_in_millis\":0,\"target_throttle_time_in_millis\":0}"; + final DiscoveryNode discoveryNode = new DiscoveryNode("1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); + ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId("bla", "_na_", 0), discoveryNode.getId(), + randomBoolean(), ShardRoutingState.INITIALIZING); + RecoveryState recoveryState = new RecoveryState(shardRouting, discoveryNode, + shardRouting.recoverySource().getType() == RecoverySource.Type.PEER ? discoveryNode : null); + ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(RecoveryState.Fields.DETAILED, "true")); + String indexRecoveryState = Strings.toString(recoveryState.getIndex(), false, false, params); + assertEquals(indexRecoveryState, expected); + } +} diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java index cc1a857b5d8af..3c62db210f763 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java @@ -87,6 +87,7 @@ public void createComponents() throws Exception { waitForMlTemplates(); } + @AwaitsFix(bugUrl ="https://github.com/elastic/elasticsearch/issues/40134") public void testMultipleSimultaneousJobCreations() { int numJobs = randomIntBetween(4, 7); From a5b72c4d10f5a943fb4c834a243cb891a7325dd8 Mon Sep 17 00:00:00 2001 From: Yu Date: Sat, 6 Apr 2019 17:37:11 +0800 Subject: [PATCH 2/5] update and add rest layer test --- .../test/indices.recovery/10_basic.yml | 22 ++++++++ .../recovery/RecoveryRequestBuilder.java | 2 +- .../indices/recovery/RecoveryState.java | 4 +- .../indices/recovery/RecoveryStateTests.java | 53 ------------------- 4 files changed, 25 insertions(+), 56 deletions(-) delete mode 100644 server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStateTests.java diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.recovery/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.recovery/10_basic.yml index 08273ffcacef8..6d7562f61b9c5 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.recovery/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.recovery/10_basic.yml @@ -130,3 +130,25 @@ index: [v*] - match: { $body: {} } +--- +"Indices recovery test with detailed parameter": + + - do: + indices.create: + index: test_3 + body: + settings: + index: + number_of_replicas: 0 + + - do: + cluster.health: + wait_for_status: green + + - do: + indices.recovery: + index: [test_3] + human: true + detailed: true + + - match: { test_3.shards.0.index.files.details: [] } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryRequestBuilder.java index f89b783c35f35..42b6dae859d7b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/recovery/RecoveryRequestBuilder.java @@ -43,4 +43,4 @@ public RecoveryRequestBuilder setActiveOnly(boolean activeOnly) { request.activeOnly(activeOnly); return this; } -} +} \ No newline at end of file diff --git a/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java b/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java index cf81bdfc25f79..8dfd63a407f24 100644 --- a/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java +++ b/server/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java @@ -343,7 +343,7 @@ static final class Fields { static final String REUSED = "reused"; static final String REUSED_IN_BYTES = "reused_in_bytes"; static final String PERCENT = "percent"; - static final String DETAILED = "detailed"; + static final String DETAILS = "details"; static final String SIZE = "size"; static final String SOURCE_THROTTLE_TIME = "source_throttle_time"; static final String SOURCE_THROTTLE_TIME_IN_MILLIS = "source_throttle_time_in_millis"; @@ -930,7 +930,7 @@ public synchronized XContentBuilder toXContent(XContentBuilder builder, Params p builder.field(Fields.RECOVERED, recoveredFileCount()); builder.field(Fields.PERCENT, String.format(Locale.ROOT, "%1.1f%%", recoveredFilesPercent())); if (params.paramAsBoolean("detailed", false)) { - builder.startArray(Fields.DETAILED); + builder.startArray(Fields.DETAILS); for (File file : fileDetails.values()) { file.toXContent(builder, params); } diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStateTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStateTests.java deleted file mode 100644 index 7ef644233533c..0000000000000 --- a/server/src/test/java/org/elasticsearch/indices/recovery/RecoveryStateTests.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.indices.recovery; - -import org.elasticsearch.Version; -import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.routing.RecoverySource; -import org.elasticsearch.cluster.routing.ShardRouting; -import org.elasticsearch.cluster.routing.ShardRoutingState; -import org.elasticsearch.cluster.routing.TestShardRouting; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.test.ESTestCase; - -import java.util.Collections; - -import static java.util.Collections.emptyMap; -import static java.util.Collections.emptySet; - -public class RecoveryStateTests extends ESTestCase { - - public void testRecoveryStateIndexToXContent() { - String expected = "{\"size\":{\"total_in_bytes\":0,\"reused_in_bytes\":0,\"recovered_in_bytes\":0,\"percent\":\"0.0%\"}," + - "\"files\":{\"total\":0,\"reused\":0,\"recovered\":0,\"percent\":\"0.0%\",\"detailed\":[]}," + - "\"total_time_in_millis\":0,\"source_throttle_time_in_millis\":0,\"target_throttle_time_in_millis\":0}"; - final DiscoveryNode discoveryNode = new DiscoveryNode("1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); - ShardRouting shardRouting = TestShardRouting.newShardRouting(new ShardId("bla", "_na_", 0), discoveryNode.getId(), - randomBoolean(), ShardRoutingState.INITIALIZING); - RecoveryState recoveryState = new RecoveryState(shardRouting, discoveryNode, - shardRouting.recoverySource().getType() == RecoverySource.Type.PEER ? discoveryNode : null); - ToXContent.MapParams params = new ToXContent.MapParams(Collections.singletonMap(RecoveryState.Fields.DETAILED, "true")); - String indexRecoveryState = Strings.toString(recoveryState.getIndex(), false, false, params); - assertEquals(indexRecoveryState, expected); - } -} From e50cc7b61123a589ca74e58d116e38a52160c3d1 Mon Sep 17 00:00:00 2001 From: Yu Date: Sat, 6 Apr 2019 17:43:49 +0800 Subject: [PATCH 3/5] restore changes for Strings.java --- .../main/java/org/elasticsearch/common/Strings.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/common/Strings.java b/server/src/main/java/org/elasticsearch/common/Strings.java index 70353b4d608ec..da27bf0187bd2 100644 --- a/server/src/main/java/org/elasticsearch/common/Strings.java +++ b/server/src/main/java/org/elasticsearch/common/Strings.java @@ -770,22 +770,12 @@ public static String toString(XContentBuilder xContentBuilder) { * */ public static String toString(ToXContent toXContent, boolean pretty, boolean human) { - return toString(toXContent, pretty, human, ToXContent.EMPTY_PARAMS); - } - - /** - * Return a {@link String} that is the json representation of the provided {@link ToXContent}. - * Wraps the output into an anonymous object if needed. Allows to control whether the outputted - * json needs to be pretty printed, human readable, and set params while parsing XContent. - * - */ - public static String toString(ToXContent toXContent, boolean pretty, boolean human, ToXContent.Params params) { try { XContentBuilder builder = createBuilder(pretty, human); if (toXContent.isFragment()) { builder.startObject(); } - toXContent.toXContent(builder, params); + toXContent.toXContent(builder, ToXContent.EMPTY_PARAMS); if (toXContent.isFragment()) { builder.endObject(); } From 8707e885e0c5d0b5941758543e16d92fa0fab13c Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Thu, 20 Jun 2019 16:11:21 +0200 Subject: [PATCH 4/5] Fix docs recovery test --- docs/reference/indices/recovery.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/indices/recovery.asciidoc b/docs/reference/indices/recovery.asciidoc index 0929b36e7742d..6e03ddd16b71b 100644 --- a/docs/reference/indices/recovery.asciidoc +++ b/docs/reference/indices/recovery.asciidoc @@ -249,7 +249,7 @@ Response: } -------------------------------------------------- // TESTRESPONSE[s/"source" : \{[^}]*\}/"source" : $body.$_path/] -// TESTRESPONSE[s/"details" : \[[^\]]*\]//] +// TESTRESPONSE[s/"details" : \[[^\]]*\]/"details" : $body.$_path/] // TESTRESPONSE[s/: (\-)?[0-9]+/: $body.$_path/] // TESTRESPONSE[s/: "[^"]*"/: $body.$_path/] //// From 1ba84cfcace1ba20c4b5df5733ad312ad95e5878 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Thu, 20 Jun 2019 16:20:36 +0200 Subject: [PATCH 5/5] Add BWC conditon for newly added test --- .../resources/rest-api-spec/test/indices.recovery/10_basic.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.recovery/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.recovery/10_basic.yml index 9e17a548ab459..18206c89b0c90 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.recovery/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.recovery/10_basic.yml @@ -132,6 +132,9 @@ - match: { $body: {} } --- "Indices recovery test with detailed parameter": + - skip: + version: " - 7.9.99" + reason: bug with detailed parameter fixed in 8.0 - do: indices.create: