From 0bf9dcf027280bdc19e3962c4a124d6534fe6192 Mon Sep 17 00:00:00 2001 From: Sohaib Iftikhar Date: Tue, 1 May 2018 23:02:06 +0200 Subject: [PATCH] Fixes after merging with master MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — fixed document:integTest --- .../elasticsearch/client/IndicesClient.java | 4 +-- .../client/RequestConverters.java | 8 ++--- .../client/RequestConvertersTests.java | 2 +- .../IndicesClientDocumentationIT.java | 3 +- .../high-level/indices/flush_synced.asciidoc | 3 +- docs/reference/indices/recovery.asciidoc | 1 + .../indices/flush/SyncedFlushResponse.java | 31 ++++++++++--------- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java index 1ef12f3a4031b..444a27e744cf5 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java @@ -273,7 +273,7 @@ public void flushAsync(FlushRequest flushRequest, ActionListener * Synced flush API on elastic.co */ public SyncedFlushResponse flushSynced(SyncedFlushRequest syncedFlushRequest, Header... headers) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(syncedFlushRequest, Request::syncedFlush, + return restHighLevelClient.performRequestAndParseEntity(syncedFlushRequest, RequestConverters::syncedFlush, SyncedFlushResponse::fromXContent, emptySet(), headers); } @@ -284,7 +284,7 @@ public SyncedFlushResponse flushSynced(SyncedFlushRequest syncedFlushRequest, He * Synced flush API on elastic.co */ public void flushSyncedAsync(SyncedFlushRequest syncedFlushRequest, ActionListener listener, Header... headers) { - restHighLevelClient.performRequestAsyncAndParseEntity(syncedFlushRequest, Request::syncedFlush, + restHighLevelClient.performRequestAsyncAndParseEntity(syncedFlushRequest, RequestConverters::syncedFlush, SyncedFlushResponse::fromXContent, listener, emptySet(), headers); } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index 4d02f7c4a3106..2f54d1d158b78 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -209,10 +209,10 @@ static Request flush(FlushRequest flushRequest) { static Request syncedFlush(SyncedFlushRequest syncedFlushRequest) { String[] indices = syncedFlushRequest.indices() == null ? Strings.EMPTY_ARRAY : syncedFlushRequest.indices(); - String endpoint = endpoint(indices, "_flush/synced"); - Params syncedFlushparameters = Params.builder(); - syncedFlushparameters.withIndicesOptions(syncedFlushRequest.indicesOptions()); - return new Request(HttpPost.METHOD_NAME, endpoint, syncedFlushparameters.getParams(), null); + Request request = new Request(HttpPost.METHOD_NAME, endpoint(indices, "_flush/synced")); + Params parameters = new Params(request); + parameters.withIndicesOptions(syncedFlushRequest.indicesOptions()); + return request; } static Request forceMerge(ForceMergeRequest forceMergeRequest) { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java index 769bef3184a1d..b58e289d3eb80 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java @@ -599,7 +599,7 @@ public void testSyncedFlush() { } Map expectedParams = new HashMap<>(); setRandomIndicesOptions(syncedFlushRequest::indicesOptions, syncedFlushRequest::indicesOptions, expectedParams); - Request request = Request.syncedFlush(syncedFlushRequest); + Request request = RequestConverters.syncedFlush(syncedFlushRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); if (indices != null && indices.length > 0) { endpoint.add(String.join(",", indices)); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java index 3fdf83f816dd8..ef59ebe4024c1 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java @@ -75,6 +75,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -821,7 +822,7 @@ public void testSyncedFlushIndex() throws Exception { int successfulCopies = failureEntry.getValue().getSuccessfulCopies(); // <10> int failedCopies = failureEntry.getValue().getFailedCopies(); // <11> String failureReason = failureEntry.getValue().getFailureReason(); // <12> - ShardRouting routing = failureEntry.getValue().getShardRouting(); // <13> + Optional routing = failureEntry.getValue().getShardRouting(); // <13> } } } diff --git a/docs/java-rest/high-level/indices/flush_synced.asciidoc b/docs/java-rest/high-level/indices/flush_synced.asciidoc index 15cb0165502e5..41d4ae05d3558 100644 --- a/docs/java-rest/high-level/indices/flush_synced.asciidoc +++ b/docs/java-rest/high-level/indices/flush_synced.asciidoc @@ -82,7 +82,8 @@ include-tagged::{doc-tests}/IndicesClientDocumentationIT.java[flush-synced-respo <10> Successful copies of the shard mentioned in 8. <11> Failed copies of the shard mentioned in 8. <12> Reason for failure of copies of the shard mentioned in 8. -<13> Routing information (like id, state, version etc.) for the failed shard copies. +<13> Optional. Routing information (like id, state, version etc.) for the failed shard copies. +If the entire shard failed then this returns Optional.empty. By default, if the indices were not found, an `ElasticsearchException` will be thrown: diff --git a/docs/reference/indices/recovery.asciidoc b/docs/reference/indices/recovery.asciidoc index 49f58e645bcda..ef1cac48dd5bc 100644 --- a/docs/reference/indices/recovery.asciidoc +++ b/docs/reference/indices/recovery.asciidoc @@ -88,6 +88,7 @@ Response: "total_time_in_millis" : 175576, "source" : { "repository" : "my_repository", + "snapshot_uuid" : "faOyRKQOQwy8ze5yhwlAcQ", "snapshot" : "my_snapshot", "index" : "index1", "version" : "{version}" diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/flush/SyncedFlushResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/flush/SyncedFlushResponse.java index ef2fcfcc0fbec..3ef0bff91dee5 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/flush/SyncedFlushResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/flush/SyncedFlushResponse.java @@ -22,7 +22,6 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.common.ParsingException; -import org.elasticsearch.common.inject.internal.Nullable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; @@ -38,11 +37,12 @@ import org.elasticsearch.rest.RestStatus; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; +import java.util.ArrayList; +import java.util.Map; import java.util.HashMap; import java.util.List; -import java.util.Map; +import java.util.Optional; import static java.util.Collections.unmodifiableMap; import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; @@ -138,7 +138,7 @@ private Map buildResponsePerIndex() { shardResults.failureReason(), shardResults.totalShards(), shardResults.successfulShards(), - null) + Optional.empty()) ); continue; } @@ -151,7 +151,8 @@ private Map buildResponsePerIndex() { shardResults.failureReason(), shardResults.totalShards(), shardResults.successfulShards(), - shardEntry.getKey()) + Optional.of(shardEntry.getKey()) + ) ); } } @@ -269,11 +270,11 @@ private static SyncedFlushResponse innerFromXContent(XContentParser parser) thro for (Map.Entry> entry: failures.entrySet()) { Map shardResponses = new HashMap<>(); for (ShardFailure container: entry.getValue()) { - if (container.shardRouting != null) { - shardResponses.put(container.shardRouting, + container.maybeShardRouting.ifPresent(shardRouting -> + shardResponses.put(shardRouting, new SyncedFlushService.ShardSyncedFlushResponse(container.failureReason) - ); - } + ) + ); } // Size of entry.getValue() will at least be one ShardFailure container = entry.getValue().get(0); @@ -339,16 +340,16 @@ static ShardCounts calculateShardCounts(Iterable result public static final class ShardFailure { ShardId shardId; String failureReason; - ShardRouting shardRouting; + Optional maybeShardRouting; int totalCopies; int successfulCopies; int failedCopies; ShardFailure(ShardId shardId, String failureReason, int totalCopies, int successfulCopies, - @Nullable ShardRouting shardRouting) { + Optional maybeShardRouting) { this.shardId = shardId; this.failureReason = failureReason; - this.shardRouting = shardRouting; + this.maybeShardRouting = maybeShardRouting; this.totalCopies = totalCopies; this.successfulCopies = successfulCopies; this.failedCopies = this.totalCopies - this.successfulCopies; @@ -362,8 +363,8 @@ public String getFailureReason() { return failureReason; } - public ShardRouting getShardRouting() { - return shardRouting; + public Optional getShardRouting() { + return maybeShardRouting; } public int getTotalCopies() { @@ -424,7 +425,7 @@ public static ShardFailure fromXContent(XContentParser parser, String indexName) shardId != null && totalCopies != null && successfulCopies != null) { - return new ShardFailure(shardId, failureReason, totalCopies, successfulCopies, routing); + return new ShardFailure(shardId, failureReason, totalCopies, successfulCopies, Optional.ofNullable(routing)); } else { throw new ParsingException(startLocation, "Unable to construct ShardsSyncedFlushResult"); }