Search in sources :

Example 21 with RestoreSnapshotResponse

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

the class AzureSnapshotRestoreTests method testMultipleSnapshots.

/**
     * For issue #51: https://github.com/elastic/elasticsearch-cloud-azure/issues/51
     */
public void testMultipleSnapshots() throws URISyntaxException, StorageException {
    final String indexName = "test-idx-1";
    final String typeName = "doc";
    final String repositoryName = "test-repo";
    final String snapshot1Name = "test-snap-1";
    final String snapshot2Name = "test-snap-2";
    Client client = client();
    logger.info("creating index [{}]", indexName);
    createIndex(indexName);
    ensureGreen();
    logger.info("indexing first document");
    index(indexName, typeName, Integer.toString(1), "foo", "bar " + Integer.toString(1));
    refresh();
    assertThat(client.prepareSearch(indexName).setSize(0).get().getHits().getTotalHits(), equalTo(1L));
    logger.info("creating Azure repository with path [{}]", getRepositoryPath());
    PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository(repositoryName).setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), getContainerName()).put(Repository.BASE_PATH_SETTING.getKey(), getRepositoryPath()).put(Repository.BASE_PATH_SETTING.getKey(), randomIntBetween(1000, 10000), ByteSizeUnit.BYTES)).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    logger.info("creating snapshot [{}]", snapshot1Name);
    CreateSnapshotResponse createSnapshotResponse1 = client.admin().cluster().prepareCreateSnapshot(repositoryName, snapshot1Name).setWaitForCompletion(true).setIndices(indexName).get();
    assertThat(createSnapshotResponse1.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse1.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse1.getSnapshotInfo().totalShards()));
    assertThat(client.admin().cluster().prepareGetSnapshots(repositoryName).setSnapshots(snapshot1Name).get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
    logger.info("indexing second document");
    index(indexName, typeName, Integer.toString(2), "foo", "bar " + Integer.toString(2));
    refresh();
    assertThat(client.prepareSearch(indexName).setSize(0).get().getHits().getTotalHits(), equalTo(2L));
    logger.info("creating snapshot [{}]", snapshot2Name);
    CreateSnapshotResponse createSnapshotResponse2 = client.admin().cluster().prepareCreateSnapshot(repositoryName, snapshot2Name).setWaitForCompletion(true).setIndices(indexName).get();
    assertThat(createSnapshotResponse2.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse2.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse2.getSnapshotInfo().totalShards()));
    assertThat(client.admin().cluster().prepareGetSnapshots(repositoryName).setSnapshots(snapshot2Name).get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
    logger.info("closing index [{}]", indexName);
    client.admin().indices().prepareClose(indexName).get();
    logger.info("attempting restore from snapshot [{}]", snapshot1Name);
    RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot(repositoryName, snapshot1Name).setWaitForCompletion(true).get();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    ensureGreen();
    assertThat(client.prepareSearch(indexName).setSize(0).get().getHits().getTotalHits(), equalTo(1L));
}
Also used : CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) Client(org.elasticsearch.client.Client) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 22 with RestoreSnapshotResponse

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

the class IndexWithShadowReplicasIT method testRestoreToShadow.

/**
     * Tests the case where we create an index without shadow replicas, snapshot it and then restore into
     * an index with shadow replicas enabled.
     */
public void testRestoreToShadow() throws ExecutionException, InterruptedException {
    final Path dataPath = createTempDir();
    Settings nodeSettings = nodeSettings(dataPath);
    internalCluster().startNodes(3, nodeSettings);
    Settings idxSettings = Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build();
    assertAcked(prepareCreate("foo").setSettings(idxSettings));
    ensureGreen();
    final int numDocs = randomIntBetween(10, 100);
    for (int i = 0; i < numDocs; i++) {
        client().prepareIndex("foo", "doc", "" + i).setSource("foo", "bar").get();
    }
    assertNoFailures(client().admin().indices().prepareFlush().setForce(true).execute().actionGet());
    assertAcked(client().admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())));
    CreateSnapshotResponse createSnapshotResponse = client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("foo").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    assertThat(client().admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
    Settings shadowSettings = Settings.builder().put(IndexMetaData.SETTING_DATA_PATH, dataPath.toAbsolutePath().toString()).put(IndexMetaData.SETTING_SHADOW_REPLICAS, true).put(IndexMetaData.SETTING_SHARED_FILESYSTEM, true).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 2).build();
    logger.info("--> restore the index into shadow replica index");
    RestoreSnapshotResponse restoreSnapshotResponse = client().admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setIndexSettings(shadowSettings).setWaitForCompletion(true).setRenamePattern("(.+)").setRenameReplacement("$1-copy").execute().actionGet();
    assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
    ensureGreen();
    refresh();
    Index index = resolveIndex("foo-copy");
    for (IndicesService service : internalCluster().getDataNodeInstances(IndicesService.class)) {
        if (service.hasIndex(index)) {
            IndexShard shard = service.indexServiceSafe(index).getShardOrNull(0);
            if (shard.routingEntry().primary()) {
                assertFalse(shard instanceof ShadowIndexShard);
            } else {
                assertTrue(shard instanceof ShadowIndexShard);
            }
        }
    }
    logger.info("--> performing query");
    SearchResponse resp = client().prepareSearch("foo-copy").setQuery(matchAllQuery()).get();
    assertHitCount(resp, numDocs);
}
Also used : Path(java.nio.file.Path) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) ShadowIndexShard(org.elasticsearch.index.shard.ShadowIndexShard) IndexShard(org.elasticsearch.index.shard.IndexShard) IndicesService(org.elasticsearch.indices.IndicesService) ShadowIndexShard(org.elasticsearch.index.shard.ShadowIndexShard) Settings(org.elasticsearch.common.settings.Settings) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 23 with RestoreSnapshotResponse

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

the class ESBlobStoreRepositoryIntegTestCase method assertSuccessfulRestore.

public static RestoreSnapshotResponse assertSuccessfulRestore(RestoreSnapshotRequestBuilder requestBuilder) {
    RestoreSnapshotResponse response = requestBuilder.get();
    assertSuccessfulRestore(response);
    return response;
}
Also used : RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 24 with RestoreSnapshotResponse

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

the class HdfsTests method testSimpleWorkflow.

public void testSimpleWorkflow() {
    Client client = client();
    PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo").setType("hdfs").setSettings(Settings.builder().put("uri", "hdfs:///").put("conf.fs.AbstractFileSystem.hdfs.impl", TestingFs.class.getName()).put("path", "foo").put("chunk_size", randomIntBetween(100, 1000) + "k").put("compress", randomBoolean())).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    createIndex("test-idx-1");
    createIndex("test-idx-2");
    createIndex("test-idx-3");
    ensureGreen();
    logger.info("--> indexing some data");
    for (int i = 0; i < 100; i++) {
        client().prepareIndex("test-idx-1", "doc", Integer.toString(i)).setSource("foo", "bar" + i).get();
        client().prepareIndex("test-idx-2", "doc", Integer.toString(i)).setSource("foo", "bar" + i).get();
        client().prepareIndex("test-idx-3", "doc", Integer.toString(i)).setSource("foo", "bar" + i).get();
    }
    client().admin().indices().prepareRefresh().get();
    assertThat(count(client, "test-idx-1"), equalTo(100L));
    assertThat(count(client, "test-idx-2"), equalTo(100L));
    assertThat(count(client, "test-idx-3"), equalTo(100L));
    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()));
    assertThat(client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
    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();
    }
    client().admin().indices().prepareRefresh().get();
    assertThat(count(client, "test-idx-1"), equalTo(50L));
    assertThat(count(client, "test-idx-2"), equalTo(50L));
    assertThat(count(client, "test-idx-3"), equalTo(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();
    assertThat(count(client, "test-idx-1"), equalTo(100L));
    assertThat(count(client, "test-idx-2"), equalTo(100L));
    assertThat(count(client, "test-idx-3"), equalTo(50L));
    // Test restore after index deletion
    logger.info("--> delete indices");
    client().admin().indices().prepareDelete("test-idx-1", "test-idx-2").get();
    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();
    assertThat(count(client, "test-idx-1"), equalTo(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));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) Client(org.elasticsearch.client.Client) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 25 with RestoreSnapshotResponse

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

the class AbstractS3SnapshotRestoreTest method testEncryption.

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch-cloud-aws/issues/211")
public void testEncryption() {
    Client client = client();
    logger.info("-->  creating s3 repository with bucket[{}] and path [{}]", internalCluster().getInstance(Settings.class).get("repositories.s3.bucket"), basePath);
    Settings repositorySettings = Settings.builder().put(S3Repository.Repository.BASE_PATH_SETTING.getKey(), basePath).put(S3Repository.Repository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(1000, 10000)).put(S3Repository.Repository.SERVER_SIDE_ENCRYPTION_SETTING.getKey(), true).build();
    PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo").setType("s3").setSettings(repositorySettings).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    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();
    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));
    assertThat(client.prepareSearch("test-idx-3").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-*", "-test-idx-3").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse.getSnapshotInfo().totalShards()));
    assertThat(client.admin().cluster().prepareGetSnapshots("test-repo").setSnapshots("test-snap").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
    Settings settings = internalCluster().getInstance(Settings.class);
    Settings bucket = settings.getByPrefix("repositories.s3.");
    AmazonS3 s3Client = internalCluster().getInstance(AwsS3Service.class).client(repositorySettings, null, randomBoolean(), null);
    String bucketName = bucket.get("bucket");
    logger.info("--> verify encryption for bucket [{}], prefix [{}]", bucketName, basePath);
    List<S3ObjectSummary> summaries = s3Client.listObjects(bucketName, basePath).getObjectSummaries();
    for (S3ObjectSummary summary : summaries) {
        assertThat(s3Client.getObjectMetadata(bucketName, summary.getKey()).getSSEAlgorithm(), equalTo("AES256"));
    }
    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();
    }
    refresh();
    assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().getTotalHits(), equalTo(50L));
    assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().getTotalHits(), equalTo(50L));
    assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().getTotalHits(), equalTo(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();
    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));
    assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().getTotalHits(), equalTo(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();
    assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().getTotalHits(), equalTo(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));
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) ClusterState(org.elasticsearch.cluster.ClusterState) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) AwsS3Service(org.elasticsearch.cloud.aws.AwsS3Service) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) Client(org.elasticsearch.client.Client) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) Settings(org.elasticsearch.common.settings.Settings) 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