Skip to content

Commit dba91db

Browse files
committed
Fix IT
Signed-off-by: Lakshya Taragi <[email protected]>
1 parent 6f9c522 commit dba91db

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

client/rest-high-level/src/test/java/org/opensearch/client/SnapshotRequestConvertersTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,15 @@ public void testSnapshotsStatus() {
230230
Map<String, String> expectedParams = new HashMap<>();
231231
String repository = RequestConvertersTests.randomIndicesNames(1, 1)[0];
232232
String[] snapshots = RequestConvertersTests.randomIndicesNames(1, 5);
233+
String[] indices = RequestConvertersTests.randomIndicesNames(1, 5);
233234
StringBuilder snapshotNames = new StringBuilder(snapshots[0]);
234235
for (int idx = 1; idx < snapshots.length; idx++) {
235236
snapshotNames.append(",").append(snapshots[idx]);
236237
}
237238
boolean ignoreUnavailable = randomBoolean();
238239
String endpoint = "/_snapshot/" + repository + "/" + snapshotNames.toString() + "/_status";
239240

240-
SnapshotsStatusRequest snapshotsStatusRequest = new SnapshotsStatusRequest(repository, snapshots);
241+
SnapshotsStatusRequest snapshotsStatusRequest = new SnapshotsStatusRequest(repository, snapshots, indices);
241242
RequestConvertersTests.setRandomClusterManagerTimeout(snapshotsStatusRequest, expectedParams);
242243
snapshotsStatusRequest.ignoreUnavailable(ignoreUnavailable);
243244
expectedParams.put("ignore_unavailable", Boolean.toString(ignoreUnavailable));

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
package org.opensearch.upgrades;
3434

35+
import com.sun.jna.StringArray;
3536
import org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
3637
import org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
3738
import org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus;
@@ -44,6 +45,7 @@
4445
import org.opensearch.client.RestClient;
4546
import org.opensearch.client.RestHighLevelClient;
4647
import org.opensearch.common.settings.Settings;
48+
import org.opensearch.core.common.Strings;
4749
import org.opensearch.core.xcontent.DeprecationHandler;
4850
import org.opensearch.core.xcontent.XContentParser;
4951
import org.opensearch.common.xcontent.json.JsonXContent;
@@ -141,14 +143,14 @@ public void testCreateAndRestoreSnapshot() throws IOException {
141143
case STEP2_NEW_CLUSTER:
142144
case STEP4_NEW_CLUSTER:
143145
assertSnapshotStatusSuccessful(client, repoName,
144-
snapshots.stream().map(sn -> (String) sn.get("snapshot")).toArray(String[]::new));
146+
snapshots.stream().map(sn -> (String) sn.get("snapshot")).toArray(String[]::new), Strings.EMPTY_ARRAY);
145147
break;
146148
case STEP1_OLD_CLUSTER:
147-
assertSnapshotStatusSuccessful(client, repoName, "snapshot-" + TEST_STEP);
149+
assertSnapshotStatusSuccessful(client, repoName, new String[] {"snapshot-" + TEST_STEP}, Strings.EMPTY_ARRAY);
148150
break;
149151
case STEP3_OLD_CLUSTER:
150152
assertSnapshotStatusSuccessful(
151-
client, repoName, "snapshot-" + TEST_STEP, "snapshot-" + TestStep.STEP3_OLD_CLUSTER);
153+
client, repoName, new String[] {"snapshot-" + TEST_STEP, "snapshot -" + TestStep.STEP3_OLD_CLUSTER}, Strings.EMPTY_ARRAY);
152154
break;
153155
}
154156
if (TEST_STEP == TestStep.STEP3_OLD_CLUSTER) {
@@ -186,10 +188,10 @@ public void testReadOnlyRepo() throws IOException {
186188
break;
187189
}
188190
if (TEST_STEP == TestStep.STEP1_OLD_CLUSTER || TEST_STEP == TestStep.STEP3_OLD_CLUSTER) {
189-
assertSnapshotStatusSuccessful(client, repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER);
191+
assertSnapshotStatusSuccessful(client, repoName, new String[] {"snapshot-" + TestStep.STEP1_OLD_CLUSTER}, Strings.EMPTY_ARRAY);
190192
} else {
191193
assertSnapshotStatusSuccessful(client, repoName,
192-
"snapshot-" + TestStep.STEP1_OLD_CLUSTER, "snapshot-" + TestStep.STEP2_NEW_CLUSTER);
194+
new String[] {"snapshot-" + TestStep.STEP1_OLD_CLUSTER, "snapshot-" + TestStep.STEP2_NEW_CLUSTER}, Strings.EMPTY_ARRAY);
193195
}
194196
if (TEST_STEP == TestStep.STEP3_OLD_CLUSTER) {
195197
ensureSnapshotRestoreWorks(repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards);
@@ -214,7 +216,7 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
214216
// Every step creates one snapshot
215217
assertThat(snapshots, hasSize(TEST_STEP.ordinal() + 1));
216218
assertSnapshotStatusSuccessful(client, repoName,
217-
snapshots.stream().map(sn -> (String) sn.get("snapshot")).toArray(String[]::new));
219+
snapshots.stream().map(sn -> (String) sn.get("snapshot")).toArray(String[]::new), Strings.EMPTY_ARRAY);
218220
if (TEST_STEP == TestStep.STEP1_OLD_CLUSTER) {
219221
ensureSnapshotRestoreWorks(repoName, "snapshot-" + TestStep.STEP1_OLD_CLUSTER, shards);
220222
} else {
@@ -239,9 +241,9 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
239241
}
240242

241243
private static void assertSnapshotStatusSuccessful(RestHighLevelClient client, String repoName,
242-
String... snapshots) throws IOException {
244+
String[] snapshots, String[] indices) throws IOException {
243245
final SnapshotsStatusResponse statusResponse = client.snapshot()
244-
.status(new SnapshotsStatusRequest(repoName, snapshots), RequestOptions.DEFAULT);
246+
.status(new SnapshotsStatusRequest(repoName, snapshots, indices), RequestOptions.DEFAULT);
245247
for (SnapshotStatus status : statusResponse.getSnapshots()) {
246248
assertThat(status.getShardsStats().getFailedShards(), is(0));
247249
}

server/src/internalClusterTest/java/org/opensearch/snapshots/RemoteIndexSnapshotStatusApiIT.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.opensearch.cluster.SnapshotsInProgress;
4242
import org.opensearch.common.action.ActionFuture;
4343
import org.opensearch.common.settings.Settings;
44+
import org.opensearch.repositories.blobstore.BlobStoreRepository;
4445
import org.opensearch.test.OpenSearchIntegTestCase;
4546
import org.opensearch.threadpool.ThreadPool;
4647
import org.junit.Before;
@@ -50,7 +51,6 @@
5051
import java.util.concurrent.TimeUnit;
5152

5253
import static org.opensearch.remotestore.RemoteStoreBaseIntegTestCase.remoteStoreClusterSettings;
53-
import static org.opensearch.repositories.blobstore.BlobStoreRepository.SNAPSHOT_V2;
5454
import static org.opensearch.snapshots.SnapshotsService.MAX_SHARDS_ALLOWED_IN_STATUS_API;
5555
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
5656
import static org.hamcrest.Matchers.equalTo;
@@ -206,7 +206,10 @@ public void testStatusAPICallForShallowV2Snapshot() throws Exception {
206206

207207
logger.info("Create repository for shallow V2 snapshots");
208208
final String snapshotRepoName = "snapshot-repo-name";
209-
Settings.Builder snapshotV2RepoSettings = snapshotRepoSettingsForShallowCopy().put(SNAPSHOT_V2.getKey(), Boolean.TRUE);
209+
Settings.Builder snapshotV2RepoSettings = snapshotRepoSettingsForShallowCopy().put(
210+
BlobStoreRepository.SHALLOW_SNAPSHOT_V2.getKey(),
211+
Boolean.TRUE
212+
);
210213
createRepository(snapshotRepoName, "fs", snapshotV2RepoSettings);
211214

212215
final String index1 = "remote-index-1";

server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotStatusApisIT.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ public void testSnapshotStatusFailuresWithIndexFilter() throws Exception {
697697

698698
assertBusy(() -> {
699699
// failure due to passing index filter for multiple snapshots
700-
ActionRequestValidationException ex1 = expectThrows(
700+
ActionRequestValidationException ex = expectThrows(
701701
ActionRequestValidationException.class,
702702
() -> client().admin()
703703
.cluster()
@@ -708,10 +708,12 @@ public void testSnapshotStatusFailuresWithIndexFilter() throws Exception {
708708
.actionGet()
709709
);
710710
String cause = "index list filter is supported only for a single snapshot";
711-
assertTrue(ex1.getMessage().contains(cause));
711+
assertTrue(ex.getMessage().contains(cause));
712+
}, 1, TimeUnit.MINUTES);
712713

714+
assertBusy(() -> {
713715
// failure due to index not found in snapshot
714-
SnapshotException ex2 = expectThrows(
716+
SnapshotException ex = expectThrows(
715717
SnapshotException.class,
716718
() -> client().admin()
717719
.cluster()
@@ -721,16 +723,20 @@ public void testSnapshotStatusFailuresWithIndexFilter() throws Exception {
721723
.execute()
722724
.actionGet()
723725
);
724-
assertEquals(ex2.status(), RestStatus.NOT_FOUND);
725-
cause = String.format(
726+
assertEquals(ex.status(), RestStatus.NOT_FOUND);
727+
String cause = String.format(
728+
Locale.ROOT,
726729
"[%s:%s] indices [%s] missing in snapshot [%s]",
727730
repositoryName,
728731
snapshot2,
729732
String.join(", ", List.of(index2, index3)),
730733
snapshot2
731734
);
732-
assertEquals(cause, ex2.getMessage());
735+
assertEquals(cause, ex.getMessage());
736+
737+
}, 1, TimeUnit.MINUTES);
733738

739+
assertBusy(() -> {
734740
// failure due to too many shards requested
735741
logger.info("Set MAX_SHARDS_ALLOWED_IN_STATUS_API to a low value");
736742
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
@@ -753,8 +759,7 @@ public void testSnapshotStatusFailuresWithIndexFilter() throws Exception {
753759
logger.info("Reset MAX_SHARDS_ALLOWED_IN_STATUS_API to default value");
754760
updateSettingsRequest.persistentSettings(Settings.builder().putNull(MAX_SHARDS_ALLOWED_IN_STATUS_API.getKey()));
755761
assertAcked(internalCluster().client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
756-
757-
}, 1, TimeUnit.MINUTES);
762+
}, 2, TimeUnit.MINUTES);
758763
}
759764

760765
private static SnapshotIndexShardStatus stateFirstShard(SnapshotStatus snapshotStatus, String indexName) {

server/src/main/java/org/opensearch/snapshots/SnapshotsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ public void createSnapshotV2(final CreateSnapshotRequest request, final ActionLi
509509
Collections.emptyList(),
510510
request.includeGlobalState(),
511511
userMeta,
512-
remoteStoreIndexShallowCopy,
512+
true,
513513
pinnedTimestamp
514514
);
515515
if (!clusterService.state().nodes().isLocalNodeElectedClusterManager()) {

0 commit comments

Comments
 (0)