From 41f73e0acf7376c8a33e1747c31dd553bea27d5e Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Thu, 30 Nov 2017 11:33:01 +0100 Subject: [PATCH] Fix version for include_global_state in Snapshot Status API It also adds a Rest test. Related #26853 --- .../snapshots/status/SnapshotStatus.java | 4 +- .../elasticsearch/snapshots/SnapshotInfo.java | 2 +- .../test/snapshot.get/10_basic.yml | 62 ++++++++++++++++++- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStatus.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStatus.java index a4613af601a..7b41d96c0e3 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStatus.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStatus.java @@ -147,7 +147,7 @@ public class SnapshotStatus implements ToXContentObject, Streamable { builder.add(SnapshotIndexShardStatus.readShardSnapshotStatus(in)); } shards = Collections.unmodifiableList(builder); - if (in.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) { + if (in.getVersion().onOrAfter(Version.V_6_2_0)) { includeGlobalState = in.readOptionalBoolean(); } updateShardStats(); @@ -161,7 +161,7 @@ public class SnapshotStatus implements ToXContentObject, Streamable { for (SnapshotIndexShardStatus shard : shards) { shard.writeTo(out); } - if (out.getVersion().onOrAfter(Version.V_7_0_0_alpha1)) { + if (out.getVersion().onOrAfter(Version.V_6_2_0)) { out.writeOptionalBoolean(includeGlobalState); } } diff --git a/core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java b/core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java index ea2a9ac78dd..b75b840e8b2 100644 --- a/core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java +++ b/core/src/main/java/org/elasticsearch/snapshots/SnapshotInfo.java @@ -72,7 +72,7 @@ public final class SnapshotInfo implements Comparable, ToXContent, private static final String INCLUDE_GLOBAL_STATE = "include_global_state"; private static final Version VERSION_INCOMPATIBLE_INTRODUCED = Version.V_5_2_0; - private static final Version INCLUDE_GLOBAL_STATE_INTRODUCED = Version.V_7_0_0_alpha1; + private static final Version INCLUDE_GLOBAL_STATE_INTRODUCED = Version.V_6_2_0; public static final Version VERBOSE_INTRODUCED = Version.V_5_5_0; private static final Comparator COMPARATOR = diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.get/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.get/10_basic.yml index 70008415122..d17655daad2 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.get/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/snapshot.get/10_basic.yml @@ -49,7 +49,7 @@ setup: snapshot: test_nonexistent_snapshot --- -"Get missing snapshot info succeeds when ignoreUnavailable is true": +"Get missing snapshot info succeeds when ignore_unavailable is true": - do: snapshot.get: @@ -96,3 +96,63 @@ setup: snapshot.delete: repository: test_repo_get_1 snapshot: test_snapshot + +--- +"Get snapshot info contains include_global_state": + - skip: + version: " - 6.1.99" + reason: "include_global_state field has been added in the response in 6.2.0" + + - do: + indices.create: + index: test_index + body: + settings: + number_of_shards: 1 + number_of_replicas: 0 + + - do: + snapshot.create: + repository: test_repo_get_1 + snapshot: test_snapshot_with_include_global_state + wait_for_completion: true + body: | + { "include_global_state": true } + + - do: + snapshot.get: + repository: test_repo_get_1 + snapshot: test_snapshot_with_include_global_state + + - is_true: snapshots + - match: { snapshots.0.snapshot: test_snapshot_with_include_global_state } + - match: { snapshots.0.state: SUCCESS } + - match: { snapshots.0.include_global_state: true } + + - do: + snapshot.delete: + repository: test_repo_get_1 + snapshot: test_snapshot_with_include_global_state + + - do: + snapshot.create: + repository: test_repo_get_1 + snapshot: test_snapshot_without_include_global_state + wait_for_completion: true + body: | + { "include_global_state": false } + + - do: + snapshot.get: + repository: test_repo_get_1 + snapshot: test_snapshot_without_include_global_state + + - is_true: snapshots + - match: { snapshots.0.snapshot: test_snapshot_without_include_global_state } + - match: { snapshots.0.state: SUCCESS } + - match: { snapshots.0.include_global_state: false } + + - do: + snapshot.delete: + repository: test_repo_get_1 + snapshot: test_snapshot_without_include_global_state