|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * |
| 4 | + * The OpenSearch Contributors require contributions made to |
| 5 | + * this file be licensed under the Apache-2.0 license or a |
| 6 | + * compatible open source license. |
| 7 | + */ |
| 8 | + |
| 9 | +package org.opensearch.remotestore; |
| 10 | + |
| 11 | +import org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest; |
| 12 | +import org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse; |
| 13 | +import org.opensearch.client.Client; |
| 14 | +import org.opensearch.cluster.metadata.IndexMetadata; |
| 15 | +import org.opensearch.cluster.metadata.RepositoryMetadata; |
| 16 | +import org.opensearch.common.settings.Settings; |
| 17 | +import org.opensearch.index.IndexSettings; |
| 18 | +import org.opensearch.indices.RemoteStoreSettings; |
| 19 | +import org.opensearch.repositories.fs.ReloadableFsRepository; |
| 20 | +import org.opensearch.snapshots.AbstractSnapshotIntegTestCase; |
| 21 | +import org.junit.After; |
| 22 | +import org.junit.Before; |
| 23 | + |
| 24 | +import java.nio.file.Path; |
| 25 | +import java.util.concurrent.ExecutionException; |
| 26 | + |
| 27 | +import static org.opensearch.repositories.fs.ReloadableFsRepository.REPOSITORIES_FAILRATE_SETTING; |
| 28 | + |
| 29 | +public abstract class RemoteSnapshotIT extends AbstractSnapshotIntegTestCase { |
| 30 | + protected static final String BASE_REMOTE_REPO = "test-rs-repo" + TEST_REMOTE_STORE_REPO_SUFFIX; |
| 31 | + protected Path remoteRepoPath; |
| 32 | + |
| 33 | + @Before |
| 34 | + public void setup() { |
| 35 | + remoteRepoPath = randomRepoPath().toAbsolutePath(); |
| 36 | + } |
| 37 | + |
| 38 | + @After |
| 39 | + public void teardown() { |
| 40 | + clusterAdmin().prepareCleanupRepository(BASE_REMOTE_REPO).get(); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + protected Settings nodeSettings(int nodeOrdinal) { |
| 45 | + return Settings.builder() |
| 46 | + .put(super.nodeSettings(nodeOrdinal)) |
| 47 | + .put(remoteStoreClusterSettings(BASE_REMOTE_REPO, remoteRepoPath)) |
| 48 | + .build(); |
| 49 | + } |
| 50 | + |
| 51 | + protected Settings pinnedTimestampSettings() { |
| 52 | + Settings settings = Settings.builder() |
| 53 | + .put(RemoteStoreSettings.CLUSTER_REMOTE_STORE_PINNED_TIMESTAMP_ENABLED.getKey(), true) |
| 54 | + .build(); |
| 55 | + return settings; |
| 56 | + } |
| 57 | + |
| 58 | + protected Settings.Builder getIndexSettings(int numOfShards, int numOfReplicas) { |
| 59 | + Settings.Builder settingsBuilder = Settings.builder() |
| 60 | + .put(super.indexSettings()) |
| 61 | + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numOfShards) |
| 62 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, numOfReplicas) |
| 63 | + .put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), "300s"); |
| 64 | + return settingsBuilder; |
| 65 | + } |
| 66 | + |
| 67 | + protected void indexDocuments(Client client, String indexName, int numOfDocs) { |
| 68 | + indexDocuments(client, indexName, 0, numOfDocs); |
| 69 | + } |
| 70 | + |
| 71 | + void indexDocuments(Client client, String indexName, int fromId, int toId) { |
| 72 | + for (int i = fromId; i < toId; i++) { |
| 73 | + String id = Integer.toString(i); |
| 74 | + client.prepareIndex(indexName).setId(id).setSource("text", "sometext").get(); |
| 75 | + } |
| 76 | + client.admin().indices().prepareFlush(indexName).get(); |
| 77 | + } |
| 78 | + |
| 79 | + protected void setFailRate(String repoName, int value) throws ExecutionException, InterruptedException { |
| 80 | + GetRepositoriesRequest gr = new GetRepositoriesRequest(new String[] { repoName }); |
| 81 | + GetRepositoriesResponse res = client().admin().cluster().getRepositories(gr).get(); |
| 82 | + RepositoryMetadata rmd = res.repositories().get(0); |
| 83 | + Settings.Builder settings = Settings.builder() |
| 84 | + .put("location", rmd.settings().get("location")) |
| 85 | + .put(REPOSITORIES_FAILRATE_SETTING.getKey(), value); |
| 86 | + createRepository(repoName, ReloadableFsRepository.TYPE, settings); |
| 87 | + } |
| 88 | + |
| 89 | +} |
0 commit comments