Skip to content

Commit 14debdf

Browse files
Fix MultiVersionRepository BwC Tests
The HLRC doesn't like what its getting back from some older 6.x versions for the restore status so I moved that request to the low level client. Closes elastic#50819
1 parent 9ee2e11 commit 14debdf

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

qa/repository-multi-version/src/test/java/org/elasticsearch/upgrades/MultiVersionRepositoryAccessIT.java

+24-21
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
2424
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest;
2525
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
26-
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest;
2726
import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStatus;
2827
import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest;
2928
import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse;
@@ -38,7 +37,6 @@
3837
import org.elasticsearch.common.xcontent.DeprecationHandler;
3938
import org.elasticsearch.common.xcontent.XContentParser;
4039
import org.elasticsearch.common.xcontent.json.JsonXContent;
41-
import org.elasticsearch.snapshots.RestoreInfo;
4240
import org.elasticsearch.snapshots.SnapshotsService;
4341
import org.elasticsearch.test.rest.ESRestTestCase;
4442

@@ -50,7 +48,6 @@
5048
import java.util.Map;
5149
import java.util.stream.Collectors;
5250

53-
import static org.hamcrest.Matchers.equalTo;
5451
import static org.hamcrest.Matchers.hasItem;
5552
import static org.hamcrest.Matchers.hasSize;
5653
import static org.hamcrest.Matchers.is;
@@ -146,10 +143,10 @@ public void testCreateAndRestoreSnapshot() throws IOException {
146143
break;
147144
}
148145
if (TEST_STEP == TestStep.STEP3_OLD_CLUSTER) {
149-
ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards);
146+
ensureSnapshotRestoreWorks(repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards);
150147
} else if (TEST_STEP == TestStep.STEP4_NEW_CLUSTER) {
151148
for (TestStep value : TestStep.values()) {
152-
ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + value, shards);
149+
ensureSnapshotRestoreWorks(repoName, "snapshot-" + value, shards);
153150
}
154151
}
155152
} finally {
@@ -185,10 +182,10 @@ public void testReadOnlyRepo() throws IOException {
185182
"snapshot-" + TestStep.STEP1_OLD_CLUSTER, "snapshot-" + TestStep.STEP2_NEW_CLUSTER);
186183
}
187184
if (TEST_STEP == TestStep.STEP3_OLD_CLUSTER) {
188-
ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards);
185+
ensureSnapshotRestoreWorks(repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards);
189186
} else if (TEST_STEP == TestStep.STEP4_NEW_CLUSTER) {
190-
ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards);
191-
ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP2_NEW_CLUSTER, shards);
187+
ensureSnapshotRestoreWorks(repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards);
188+
ensureSnapshotRestoreWorks(repoName, "snapshot-" + TestStep.STEP2_NEW_CLUSTER, shards);
192189
}
193190
}
194191
}
@@ -208,15 +205,15 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
208205
assertSnapshotStatusSuccessful(client, repoName,
209206
snapshots.stream().map(sn -> (String) sn.get("snapshot")).toArray(String[]::new));
210207
if (TEST_STEP == TestStep.STEP1_OLD_CLUSTER) {
211-
ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards);
208+
ensureSnapshotRestoreWorks(repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards);
212209
} else {
213210
deleteSnapshot(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER);
214-
ensureSnapshotRestoreWorks(client, repoName, "snapshot-" + TestStep.STEP2_NEW_CLUSTER, shards);
211+
ensureSnapshotRestoreWorks(repoName, "snapshot-" + TestStep.STEP2_NEW_CLUSTER, shards);
215212
createSnapshot(client, repoName, "snapshot-1");
216-
ensureSnapshotRestoreWorks(client, repoName, "snapshot-1", shards);
213+
ensureSnapshotRestoreWorks(repoName, "snapshot-1", shards);
217214
deleteSnapshot(client, repoName, "snapshot-" + TestStep.STEP2_NEW_CLUSTER);
218215
createSnapshot(client, repoName, "snapshot-2");
219-
ensureSnapshotRestoreWorks(client, repoName, "snapshot-2", shards);
216+
ensureSnapshotRestoreWorks(repoName, "snapshot-2", shards);
220217
}
221218
} else {
222219
if (minimumNodeVersion().before(SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION)) {
@@ -230,8 +227,8 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
230227
} else {
231228
assertThat(listSnapshots(repoName), hasSize(2));
232229
if (TEST_STEP == TestStep.STEP4_NEW_CLUSTER) {
233-
ensureSnapshotRestoreWorks(client, repoName, "snapshot-1", shards);
234-
ensureSnapshotRestoreWorks(client, repoName, "snapshot-2", shards);
230+
ensureSnapshotRestoreWorks(repoName, "snapshot-1", shards);
231+
ensureSnapshotRestoreWorks(repoName, "snapshot-2", shards);
235232
}
236233
}
237234
}
@@ -269,14 +266,20 @@ private List<Map<String, Object>> listSnapshots(String repoName) throws IOExcept
269266
}
270267
}
271268

272-
private static void ensureSnapshotRestoreWorks(RestHighLevelClient client, String repoName, String name,
273-
int shards) throws IOException {
269+
@SuppressWarnings("unchecked")
270+
private void ensureSnapshotRestoreWorks(String repoName, String name, int shards) throws IOException {
274271
wipeAllIndices();
275-
final RestoreInfo restoreInfo =
276-
client.snapshot().restore(new RestoreSnapshotRequest().repository(repoName).snapshot(name).waitForCompletion(true),
277-
RequestOptions.DEFAULT).getRestoreInfo();
278-
assertThat(restoreInfo.failedShards(), is(0));
279-
assertThat(restoreInfo.successfulShards(), equalTo(shards));
272+
try (InputStream entity = client().performRequest(
273+
new Request("POST", "/_snapshot/" + repoName + "/" + name + "/_restore?wait_for_completion=true")).getEntity().getContent();
274+
XContentParser parser = JsonXContent.jsonXContent.createParser(
275+
xContentRegistry(), DeprecationHandler.THROW_UNSUPPORTED_OPERATION, entity)) {
276+
final Map<String, Object> raw = parser.map();
277+
logger.error(raw);
278+
final Map<String, Object> snapshot = (Map<String, Object>) raw.get("snapshot");
279+
final Map<String, Object> shardStats = (Map<String, Object>) snapshot.get("shards");
280+
assertThat(shardStats.get("successful"), is(shards));
281+
assertThat(shardStats.get("failed"), is(0));
282+
}
280283
}
281284

282285
private static void createRepository(RestHighLevelClient client, String repoName, boolean readOnly) throws IOException {

0 commit comments

Comments
 (0)