Search in sources :

Example 26 with RestoreSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testMoveShardWhileSnapshotting.

public void testMoveShardWhileSnapshotting() throws Exception {
    Client client = client();
    Path repositoryLocation = randomRepoPath();
    logger.info("-->  creating repository");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("mock").setSettings(Settings.builder().put("location", repositoryLocation).put("random", randomAsciiOfLength(10)).put("wait_after_unblock", 200)));
    // Create index on 2 nodes and make sure each node has a primary by setting no replicas
    assertAcked(prepareCreate("test-idx", 2, Settings.builder().put("number_of_replicas", 0)));
    logger.info("--> indexing some data");
    for (int i = 0; i < 100; i++) {
        index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
    }
    refresh();
    assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    // Pick one node and block it
    String blockedNode = blockNodeWithIndex("test-repo", "test-idx");
    logger.info("--> snapshot");
    client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(false).setIndices("test-idx").get();
    logger.info("--> waiting for block to kick in");
    waitForBlock(blockedNode, "test-repo", TimeValue.timeValueSeconds(60));
    logger.info("--> execution was blocked on node [{}], moving shards away from this node", blockedNode);
    Settings.Builder excludeSettings = Settings.builder().put("index.routing.allocation.exclude._name", blockedNode);
    client().admin().indices().prepareUpdateSettings("test-idx").setSettings(excludeSettings).get();
    logger.info("--> unblocking blocked node");
    unblockNode("test-repo", blockedNode);
    logger.info("--> waiting for completion");
    SnapshotInfo snapshotInfo = waitForCompletion("test-repo", "test-snap", TimeValue.timeValueSeconds(600));
    logger.info("Number of failed shards [{}]", snapshotInfo.shardFailures().size());
    logger.info("--> done");
    List<SnapshotInfo> snapshotInfos = client().admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots();
    assertThat(snapshotInfos.size(), equalTo(1));
    assertThat(snapshotInfos.get(0).state(), equalTo(SnapshotState.SUCCESS));
    assertThat(snapshotInfos.get(0).shardFailures().size(), equalTo(0));
    logger.info("--> delete index");
    cluster().wipeIndices("test-idx");
    logger.info("--> replace mock repository with real one at the same location");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", repositoryLocation)));
    logger.info("--> restore index");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
}
Also used : Path(java.nio.file.Path) Matchers.containsString(org.hamcrest.Matchers.containsString) Client(org.elasticsearch.client.Client) Settings(org.elasticsearch.common.settings.Settings) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 27 with RestoreSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testDeleteSnapshot.

public void testDeleteSnapshot() throws Exception {
    final int numberOfSnapshots = between(5, 15);
    Client client = client();
    Path repo = randomRepoPath();
    logger.info("-->  creating repository at {}", repo.toAbsolutePath());
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", repo).put("compress", false).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
    createIndex("test-idx");
    ensureGreen();
    int[] numberOfFiles = new int[numberOfSnapshots];
    logger.info("--> creating {} snapshots ", numberOfSnapshots);
    for (int i = 0; i < numberOfSnapshots; i++) {
        for (int j = 0; j < 10; j++) {
            index("test-idx", "doc", Integer.toString(i * 10 + j), "foo", "bar" + i * 10 + j);
        }
        refresh();
        logger.info("--> snapshot {}", i);
        CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-" + i).setWaitForCompletion(true).setIndices("test-idx").get();
        assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
        assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
        // Store number of files after each snapshot
        numberOfFiles[i] = numberOfFiles(repo);
    }
    assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(10L * numberOfSnapshots));
    int numberOfFilesBeforeDeletion = numberOfFiles(repo);
    logger.info("--> delete all snapshots except the first one and last one");
    for (int i = 1; i < numberOfSnapshots - 1; i++) {
        client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-" + i).get();
    }
    int numberOfFilesAfterDeletion = numberOfFiles(repo);
    assertThat(numberOfFilesAfterDeletion, lessThan(numberOfFilesBeforeDeletion));
    logger.info("--> delete index");
    cluster().wipeIndices("test-idx");
    logger.info("--> restore index");
    String lastSnapshot = "test-snap-" + (numberOfSnapshots - 1);
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", lastSnapshot).setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits(), equalTo(10L * numberOfSnapshots));
    logger.info("--> delete the last snapshot");
    client.admin().cluster().prepareDeleteSnapshot("test-repo", lastSnapshot).get();
    logger.info("--> make sure that number of files is back to what it was when the first snapshot was made, " + "plus one because one backup index-N file should remain");
    assertThat(numberOfFiles(repo), equalTo(numberOfFiles[0] + 1));
}
Also used : Path(java.nio.file.Path) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Client(org.elasticsearch.client.Client) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 28 with RestoreSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testBasicWorkFlow.

public void testBasicWorkFlow() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", randomRepoPath()).put("compress", randomBoolean()).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
    createIndex("test-idx-1", "test-idx-2", "test-idx-3");
    ensureGreen();
    logger.info("--> indexing some data");
    for (int i = 0; i < 100; i++) {
        index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i);
        index("test-idx-2", "doc", Integer.toString(i), "foo", "baz" + i);
        index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i);
    }
    refresh();
    assertHitCount(client.prepareSearch("test-idx-1").setSize(0).get(), 100L);
    assertHitCount(client.prepareSearch("test-idx-2").setSize(0).get(), 100L);
    assertHitCount(client.prepareSearch("test-idx-3").setSize(0).get(), 100L);
    ListenableActionFuture<FlushResponse> flushResponseFuture = null;
    if (randomBoolean()) {
        ArrayList<String> indicesToFlush = new ArrayList<>();
        for (int i = 1; i < 4; i++) {
            if (randomBoolean()) {
                indicesToFlush.add("test-idx-" + i);
            }
        }
        if (!indicesToFlush.isEmpty()) {
            String[] indices = indicesToFlush.toArray(new String[indicesToFlush.size()]);
            logger.info("--> starting asynchronous flush for indices {}", Arrays.toString(indices));
            flushResponseFuture = client.admin().indices().prepareFlush(indices).execute();
        }
    }
    logger.info("--> snapshot");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-*", "-test-idx-3").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    List<SnapshotInfo> snapshotInfos = client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots(randomFrom("test-snap", "_all", "*", "*-snap", "test*")).get().getSnapshots();
    assertThat(snapshotInfos.size(), equalTo(1));
    SnapshotInfo snapshotInfo = snapshotInfos.get(0);
    assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
    assertThat(snapshotInfo.version(), equalTo(Version.CURRENT));
    logger.info("--> delete some data");
    for (int i = 0; i < 50; i++) {
        client.prepareDelete("test-idx-1", "doc", Integer.toString(i)).get();
    }
    for (int i = 50; i < 100; i++) {
        client.prepareDelete("test-idx-2", "doc", Integer.toString(i)).get();
    }
    for (int i = 0; i < 100; i += 2) {
        client.prepareDelete("test-idx-3", "doc", Integer.toString(i)).get();
    }
    assertAllSuccessful(refresh());
    assertHitCount(client.prepareSearch("test-idx-1").setSize(0).get(), 50L);
    assertHitCount(client.prepareSearch("test-idx-2").setSize(0).get(), 50L);
    assertHitCount(client.prepareSearch("test-idx-3").setSize(0).get(), 50L);
    logger.info("--> close indices");
    client.admin().indices().prepareClose("test-idx-1", "test-idx-2").get();
    logger.info("--> restore all indices from the snapshot");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    ensureGreen();
    for (int i = 0; i < 5; i++) {
        assertHitCount(client.prepareSearch("test-idx-1").setSize(0).get(), 100L);
        assertHitCount(client.prepareSearch("test-idx-2").setSize(0).get(), 100L);
        assertHitCount(client.prepareSearch("test-idx-3").setSize(0).get(), 50L);
    }
    // Test restore after index deletion
    logger.info("--> delete indices");
    cluster().wipeIndices("test-idx-1", "test-idx-2");
    logger.info("--> restore one index after deletion");
    restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-*", "-test-idx-2").execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    ensureGreen();
    for (int i = 0; i < 5; i++) {
        assertHitCount(client.prepareSearch("test-idx-1").setSize(0).get(), 100L);
    }
    ClusterState clusterState = client.admin().cluster().prepareState().get().getState();
    assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true));
    assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(false));
    if (flushResponseFuture != null) {
        // Finish flush
        flushResponseFuture.actionGet();
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) FlushResponse(org.elasticsearch.action.admin.indices.flush.FlushResponse) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) Client(org.elasticsearch.client.Client)

Example 29 with RestoreSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testChangeSettingsOnRestore.

public void testChangeSettingsOnRestore() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", randomRepoPath()).put("compress", randomBoolean()).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
    logger.info("--> create test index with synonyms search analyzer");
    Settings.Builder indexSettings = Settings.builder().put(indexSettings()).put(SETTING_NUMBER_OF_REPLICAS, between(0, 1)).put(INDEX_REFRESH_INTERVAL_SETTING.getKey(), "10s").put("index.analysis.analyzer.my_analyzer.type", "custom").put("index.analysis.analyzer.my_analyzer.tokenizer", "standard").putArray("index.analysis.analyzer.my_analyzer.filter", "lowercase", "my_synonym").put("index.analysis.filter.my_synonym.type", "synonym").put("index.analysis.filter.my_synonym.synonyms", "foo => bar");
    assertAcked(prepareCreate("test-idx", 2, indexSettings));
    int numberOfShards = getNumShards("test-idx").numPrimaries;
    assertAcked(client().admin().indices().preparePutMapping("test-idx").setType("type1").setSource("field1", "type=text,analyzer=standard,search_analyzer=my_analyzer"));
    final int numdocs = randomIntBetween(10, 100);
    IndexRequestBuilder[] builders = new IndexRequestBuilder[numdocs];
    for (int i = 0; i < builders.length; i++) {
        builders[i] = client().prepareIndex("test-idx", "type1", Integer.toString(i)).setSource("field1", "bar " + i);
    }
    indexRandom(true, builders);
    flushAndRefresh();
    assertHitCount(client.prepareSearch("test-idx").setSize(0).setQuery(matchQuery("field1", "foo")).get(), numdocs);
    assertHitCount(client.prepareSearch("test-idx").setSize(0).setQuery(matchQuery("field1", "bar")).get(), numdocs);
    logger.info("--> snapshot it");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    logger.info("--> delete the index and recreate it while changing refresh interval and analyzer");
    cluster().wipeIndices("test-idx");
    Settings newIndexSettings = Settings.builder().put("refresh_interval", "5s").put("index.analysis.analyzer.my_analyzer.type", "standard").build();
    Settings newIncorrectIndexSettings = Settings.builder().put(newIndexSettings).put(SETTING_NUMBER_OF_SHARDS, numberOfShards + 100).build();
    logger.info("--> try restoring while changing the number of shards - should fail");
    assertThrows(client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setIgnoreIndexSettings("index.analysis.*").setIndexSettings(newIncorrectIndexSettings).setWaitForCompletion(true), SnapshotRestoreException.class);
    logger.info("--> try restoring while changing the number of replicas to a negative number - should fail");
    Settings newIncorrectReplicasIndexSettings = Settings.builder().put(newIndexSettings).put(SETTING_NUMBER_OF_REPLICAS.substring(IndexMetaData.INDEX_SETTING_PREFIX.length()), randomIntBetween(-10, -1)).build();
    assertThrows(client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setIgnoreIndexSettings("index.analysis.*").setIndexSettings(newIncorrectReplicasIndexSettings).setWaitForCompletion(true), IllegalArgumentException.class);
    logger.info("--> restore index with correct settings from the snapshot");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setIgnoreIndexSettings("index.analysis.*").setIndexSettings(newIndexSettings).setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    logger.info("--> assert that correct settings are restored");
    GetSettingsResponse getSettingsResponse = client.admin().indices().prepareGetSettings("test-idx").execute().actionGet();
    assertThat(getSettingsResponse.getSetting("test-idx", INDEX_REFRESH_INTERVAL_SETTING.getKey()), equalTo("5s"));
    // Make sure that number of shards didn't change
    assertThat(getSettingsResponse.getSetting("test-idx", SETTING_NUMBER_OF_SHARDS), equalTo("" + numberOfShards));
    assertThat(getSettingsResponse.getSetting("test-idx", "index.analysis.analyzer.my_analyzer.type"), equalTo("standard"));
    assertThat(getSettingsResponse.getSetting("test-idx", "index.analysis.filter.my_synonym.type"), nullValue());
    assertHitCount(client.prepareSearch("test-idx").setSize(0).setQuery(matchQuery("field1", "foo")).get(), 0);
    assertHitCount(client.prepareSearch("test-idx").setSize(0).setQuery(matchQuery("field1", "bar")).get(), numdocs);
    logger.info("--> delete the index and recreate it while deleting all index settings");
    cluster().wipeIndices("test-idx");
    logger.info("--> restore index with correct settings from the snapshot");
    restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setIgnoreIndexSettings(// delete everything we can delete
    "*").setIndexSettings(newIndexSettings).setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    logger.info("--> assert that correct settings are restored and index is still functional");
    getSettingsResponse = client.admin().indices().prepareGetSettings("test-idx").execute().actionGet();
    assertThat(getSettingsResponse.getSetting("test-idx", INDEX_REFRESH_INTERVAL_SETTING.getKey()), equalTo("5s"));
    // Make sure that number of shards didn't change
    assertThat(getSettingsResponse.getSetting("test-idx", SETTING_NUMBER_OF_SHARDS), equalTo("" + numberOfShards));
    assertHitCount(client.prepareSearch("test-idx").setSize(0).setQuery(matchQuery("field1", "foo")).get(), 0);
    assertHitCount(client.prepareSearch("test-idx").setSize(0).setQuery(matchQuery("field1", "bar")).get(), numdocs);
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) Client(org.elasticsearch.client.Client) Settings(org.elasticsearch.common.settings.Settings) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 30 with RestoreSnapshotResponse

use of org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testRenameOnRestore.

public void testRenameOnRestore() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())));
    createIndex("test-idx-1", "test-idx-2", "test-idx-3");
    ensureGreen();
    assertAcked(client.admin().indices().prepareAliases().addAlias("test-idx-1", "alias-1").addAlias("test-idx-2", "alias-2").addAlias("test-idx-3", "alias-3"));
    logger.info("--> indexing some data");
    for (int i = 0; i < 100; i++) {
        index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i);
        index("test-idx-2", "doc", Integer.toString(i), "foo", "bar" + i);
    }
    refresh();
    assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    logger.info("--> snapshot");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-1", "test-idx-2").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    logger.info("--> restore indices with different names");
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setRenamePattern("(.+)").setRenameReplacement("$1-copy").setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    assertThat(client.prepareSearch("test-idx-1-copy").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    assertThat(client.prepareSearch("test-idx-2-copy").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    logger.info("--> close just restored indices");
    client.admin().indices().prepareClose("test-idx-1-copy", "test-idx-2-copy").get();
    logger.info("--> and try to restore these indices again");
    restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setRenamePattern("(.+)").setRenameReplacement("$1-copy").setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    assertThat(client.prepareSearch("test-idx-1-copy").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    assertThat(client.prepareSearch("test-idx-2-copy").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    logger.info("--> close indices");
    assertAcked(client.admin().indices().prepareClose("test-idx-1", "test-idx-2-copy"));
    logger.info("--> restore indices with different names");
    restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setRenamePattern("(.+-2)").setRenameReplacement("$1-copy").setWaitForCompletion(true).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    logger.info("--> delete indices");
    cluster().wipeIndices("test-idx-1", "test-idx-1-copy", "test-idx-2", "test-idx-2-copy");
    logger.info("--> try renaming indices using the same name");
    try {
        client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setRenamePattern("(.+)").setRenameReplacement("same-name").setWaitForCompletion(true).execute().actionGet();
        fail("Shouldn't be here");
    } catch (SnapshotRestoreException ex) {
    // Expected
    }
    logger.info("--> try renaming indices using the same name");
    try {
        client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setRenamePattern("test-idx-2").setRenameReplacement("test-idx-1").setWaitForCompletion(true).execute().actionGet();
        fail("Shouldn't be here");
    } catch (SnapshotRestoreException ex) {
    // Expected
    }
    logger.info("--> try renaming indices using invalid index name");
    try {
        client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setIndices("test-idx-1").setRenamePattern(".+").setRenameReplacement("__WRONG__").setWaitForCompletion(true).execute().actionGet();
        fail("Shouldn't be here");
    } catch (InvalidIndexNameException ex) {
    // Expected
    }
    logger.info("--> try renaming indices into existing alias name");
    try {
        client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setIndices("test-idx-1").setRenamePattern(".+").setRenameReplacement("alias-3").setWaitForCompletion(true).execute().actionGet();
        fail("Shouldn't be here");
    } catch (InvalidIndexNameException ex) {
    // Expected
    }
    logger.info("--> try renaming indices into existing alias of itself");
    try {
        client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setIndices("test-idx-1").setRenamePattern("test-idx").setRenameReplacement("alias").setWaitForCompletion(true).execute().actionGet();
        fail("Shouldn't be here");
    } catch (SnapshotRestoreException ex) {
    // Expected
    }
    logger.info("--> try renaming indices into existing alias of another restored index");
    try {
        client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setIndices("test-idx-1", "test-idx-2").setRenamePattern("test-idx-1").setRenameReplacement("alias-2").setWaitForCompletion(true).execute().actionGet();
        fail("Shouldn't be here");
    } catch (SnapshotRestoreException ex) {
    // Expected
    }
    logger.info("--> try renaming indices into existing alias of itself, but don't restore aliases ");
    restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setIndices("test-idx-1").setRenamePattern("test-idx").setRenameReplacement("alias").setWaitForCompletion(true).setIncludeAliases(false).execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
}
Also used : CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) InvalidIndexNameException(org.elasticsearch.indices.InvalidIndexNameException) Client(org.elasticsearch.client.Client) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Aggregations

RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)36 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)27 Client (org.elasticsearch.client.Client)27 Path (java.nio.file.Path)12 Matchers.containsString (org.hamcrest.Matchers.containsString)10 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)8 ClusterState (org.elasticsearch.cluster.ClusterState)7 Settings (org.elasticsearch.common.settings.Settings)6 ClusterAdminClient (org.elasticsearch.client.ClusterAdminClient)5 ArrayList (java.util.ArrayList)4 GetSnapshotsResponse (org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)4 SearchResponse (org.elasticsearch.action.search.SearchResponse)4 List (java.util.List)3 GetSettingsResponse (org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse)2 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)2 InvalidIndexNameException (org.elasticsearch.indices.InvalidIndexNameException)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)1 ImmutableList (com.google.common.collect.ImmutableList)1 FutureActionListener (io.crate.action.FutureActionListener)1