Search in sources :

Example 31 with PutRepositoryResponse

use of org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse in project elasticsearch by elastic.

the class AzureSnapshotRestoreListSnapshotsTests method testList.

public void testList() throws Exception {
    Client client = client();
    logger.info("-->  creating azure primary repository");
    PutRepositoryResponse putRepositoryResponsePrimary = client.admin().cluster().preparePutRepository("primary").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), containerName)).get();
    assertThat(putRepositoryResponsePrimary.isAcknowledged(), equalTo(true));
    logger.info("--> start get snapshots on primary");
    long startWait = System.currentTimeMillis();
    client.admin().cluster().prepareGetSnapshots("primary").get();
    long endWait = System.currentTimeMillis();
    // definitely should be done in 30s, and if its not working as expected, it takes over 1m
    assertThat(endWait - startWait, lessThanOrEqualTo(30000L));
    logger.info("-->  creating azure secondary repository");
    PutRepositoryResponse putRepositoryResponseSecondary = client.admin().cluster().preparePutRepository("secondary").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), containerName).put(Repository.LOCATION_MODE_SETTING.getKey(), "secondary_only")).get();
    assertThat(putRepositoryResponseSecondary.isAcknowledged(), equalTo(true));
    logger.info("--> start get snapshots on secondary");
    startWait = System.currentTimeMillis();
    client.admin().cluster().prepareGetSnapshots("secondary").get();
    endWait = System.currentTimeMillis();
    logger.info("--> end of get snapshots on secondary. Took {} ms", endWait - startWait);
    assertThat(endWait - startWait, lessThanOrEqualTo(30000L));
}
Also used : PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) Client(org.elasticsearch.client.Client)

Example 32 with PutRepositoryResponse

use of org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse in project elasticsearch by elastic.

the class AzureSnapshotRestoreTests method testNonExistingRepo_23.

/**
     * Test case for issue #23: https://github.com/elastic/elasticsearch-cloud-azure/issues/23
     */
public void testNonExistingRepo_23() {
    Client client = client();
    logger.info("-->  creating azure repository with path [{}]", getRepositoryPath());
    PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), getContainerName()).put(Repository.BASE_PATH_SETTING.getKey(), getRepositoryPath()).put(Repository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(1000, 10000), ByteSizeUnit.BYTES)).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    logger.info("--> restore non existing snapshot");
    try {
        client.admin().cluster().prepareRestoreSnapshot("test-repo", "no-existing-snapshot").setWaitForCompletion(true).get();
        fail("Shouldn't be here");
    } catch (SnapshotMissingException ex) {
    // Expected
    }
}
Also used : SnapshotMissingException(org.elasticsearch.snapshots.SnapshotMissingException) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) Client(org.elasticsearch.client.Client) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient)

Example 33 with PutRepositoryResponse

use of org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse in project elasticsearch by elastic.

the class AzureSnapshotRestoreTests method testMultipleRepositories.

public void testMultipleRepositories() {
    Client client = client();
    logger.info("-->  creating azure repository with path [{}]", getRepositoryPath());
    PutRepositoryResponse putRepositoryResponse1 = client.admin().cluster().preparePutRepository("test-repo1").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), getContainerName().concat("-1")).put(Repository.BASE_PATH_SETTING.getKey(), getRepositoryPath()).put(Repository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(1000, 10000), ByteSizeUnit.BYTES)).get();
    assertThat(putRepositoryResponse1.isAcknowledged(), equalTo(true));
    PutRepositoryResponse putRepositoryResponse2 = client.admin().cluster().preparePutRepository("test-repo2").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), getContainerName().concat("-2")).put(Repository.BASE_PATH_SETTING.getKey(), getRepositoryPath()).put(Repository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(1000, 10000), ByteSizeUnit.BYTES)).get();
    assertThat(putRepositoryResponse2.isAcknowledged(), equalTo(true));
    createIndex("test-idx-1", "test-idx-2");
    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);
    }
    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 1");
    CreateSnapshotResponse createSnapshotResponse1 = client.admin().cluster().prepareCreateSnapshot("test-repo1", "test-snap").setWaitForCompletion(true).setIndices("test-idx-1").get();
    assertThat(createSnapshotResponse1.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse1.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse1.getSnapshotInfo().totalShards()));
    logger.info("--> snapshot 2");
    CreateSnapshotResponse createSnapshotResponse2 = client.admin().cluster().prepareCreateSnapshot("test-repo2", "test-snap").setWaitForCompletion(true).setIndices("test-idx-2").get();
    assertThat(createSnapshotResponse2.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertThat(createSnapshotResponse2.getSnapshotInfo().successfulShards(), equalTo(createSnapshotResponse2.getSnapshotInfo().totalShards()));
    assertThat(client.admin().cluster().prepareGetSnapshots("test-repo1").setSnapshots("test-snap").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
    assertThat(client.admin().cluster().prepareGetSnapshots("test-repo2").setSnapshots("test-snap").get().getSnapshots().get(0).state(), equalTo(SnapshotState.SUCCESS));
    // Test restore after index deletion
    logger.info("--> delete indices");
    cluster().wipeIndices("test-idx-1", "test-idx-2");
    logger.info("--> restore one index after deletion from snapshot 1");
    RestoreSnapshotResponse restoreSnapshotResponse1 = client.admin().cluster().prepareRestoreSnapshot("test-repo1", "test-snap").setWaitForCompletion(true).setIndices("test-idx-1").get();
    assertThat(restoreSnapshotResponse1.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));
    logger.info("--> restore other index after deletion from snapshot 2");
    RestoreSnapshotResponse restoreSnapshotResponse2 = client.admin().cluster().prepareRestoreSnapshot("test-repo2", "test-snap").setWaitForCompletion(true).setIndices("test-idx-2").get();
    assertThat(restoreSnapshotResponse2.getRestoreInfo().totalShards(), greaterThan(0));
    ensureGreen();
    assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().getTotalHits(), equalTo(100L));
    clusterState = client.admin().cluster().prepareState().get().getState();
    assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true));
    assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(true));
}
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) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 34 with PutRepositoryResponse

use of org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse in project crate by crate.

the class SysSnapshotsTest method createRepository.

private void createRepository(String name) {
    PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository(name).setType("fs").setSettings(Settings.settingsBuilder().put("location", new File(TEMP_FOLDER.getRoot(), "backup").getAbsolutePath()).put("chunk_size", "5k").put("compress", false)).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
}
Also used : PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) File(java.io.File)

Example 35 with PutRepositoryResponse

use of org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse in project crate by crate.

the class SysRepositoriesServiceTest method createRepository.

private void createRepository(String name) {
    PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository(name).setType("fs").setSettings(Settings.settingsBuilder().put("location", new File(TEMP_FOLDER.getRoot(), "backup").getAbsolutePath()).put("chunk_size", "5k").put("compress", false)).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    repositories.add(name);
}
Also used : PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) File(java.io.File)

Aggregations

PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)36 Client (org.elasticsearch.client.Client)23 ClusterAdminClient (org.elasticsearch.client.ClusterAdminClient)14 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)12 RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)8 Settings (org.elasticsearch.common.settings.Settings)8 Path (java.nio.file.Path)7 ClusterState (org.elasticsearch.cluster.ClusterState)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 NodeClient (org.elasticsearch.client.node.NodeClient)4 ArrayList (java.util.ArrayList)3 SnapshotMissingException (org.elasticsearch.snapshots.SnapshotMissingException)3 File (java.io.File)2 IOException (java.io.IOException)2 List (java.util.List)2 GetSnapshotsResponse (org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)2 SnapshotStatus (org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStatus)2 SnapshotsStatusResponse (org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse)2 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)2 MetaData (org.elasticsearch.cluster.metadata.MetaData)2