Search in sources :

Example 6 with GetSnapshotsResponse

use of org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse in project elasticsearch by elastic.

the class RestoreBackwardsCompatIT method testOldSnapshot.

private void testOldSnapshot(String version, String repo, String snapshot) throws IOException {
    logger.info("--> get snapshot and check its version");
    GetSnapshotsResponse getSnapshotsResponse = client().admin().cluster().prepareGetSnapshots(repo).setSnapshots(snapshot).get();
    assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(1));
    SnapshotInfo snapshotInfo = getSnapshotsResponse.getSnapshots().get(0);
    assertThat(snapshotInfo.version().toString(), equalTo(version));
    logger.info("--> restoring snapshot");
    RestoreSnapshotResponse response = client().admin().cluster().prepareRestoreSnapshot(repo, snapshot).setRestoreGlobalState(true).setWaitForCompletion(true).get();
    assertThat(response.status(), equalTo(RestStatus.OK));
    RestoreInfo restoreInfo = response.getRestoreInfo();
    assertThat(restoreInfo.successfulShards(), greaterThan(0));
    assertThat(restoreInfo.successfulShards(), equalTo(restoreInfo.totalShards()));
    assertThat(restoreInfo.failedShards(), equalTo(0));
    String index = restoreInfo.indices().get(0);
    logger.info("--> check search");
    SearchResponse searchResponse = client().prepareSearch(index).get();
    assertThat(searchResponse.getHits().getTotalHits(), greaterThan(1L));
    logger.info("--> check settings");
    ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
    assertThat(clusterState.metaData().persistentSettings().get(FilterAllocationDecider.CLUSTER_ROUTING_EXCLUDE_GROUP_SETTING.getKey() + "version_attr"), equalTo(version));
    logger.info("--> check templates");
    IndexTemplateMetaData template = clusterState.getMetaData().templates().get("template_" + version.toLowerCase(Locale.ROOT));
    assertThat(template, notNullValue());
    assertThat(template.patterns(), equalTo(Collections.singletonList("te*")));
    assertThat(template.settings().getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, -1), equalTo(1));
    assertThat(template.mappings().size(), equalTo(1));
    assertThat(template.mappings().get("type1").string(), anyOf(equalTo("{\"type1\":{\"_source\":{\"enabled\":false}}}"), equalTo("{\"type1\":{\"_source\":{\"enabled\":\"false\"}}}"), equalTo("{\"type1\":{\"_source\":{\"enabled\":\"0\"}}}"), equalTo("{\"type1\":{\"_source\":{\"enabled\":0}}}"), equalTo("{\"type1\":{\"_source\":{\"enabled\":\"off\"}}}"), equalTo("{\"type1\":{\"_source\":{\"enabled\":\"no\"}}}")));
    assertThat(template.aliases().size(), equalTo(3));
    assertThat(template.aliases().get("alias1"), notNullValue());
    assertThat(template.aliases().get("alias2").filter().string(), containsString(version));
    assertThat(template.aliases().get("alias2").indexRouting(), equalTo("kimchy"));
    assertThat(template.aliases().get("{index}-alias"), notNullValue());
    logger.info("--> cleanup");
    cluster().wipeIndices(restoreInfo.indices().toArray(new String[restoreInfo.indices().size()]));
    cluster().wipeTemplates();
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) RestoreInfo(org.elasticsearch.snapshots.RestoreInfo) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) Matchers.containsString(org.hamcrest.Matchers.containsString) RestoreSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 7 with GetSnapshotsResponse

use of org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse in project crate by crate.

the class SnapshotRestoreDDLDispatcherTest method testResolveMultiTablesIndexNamesFromSnapshot.

@Test
public void testResolveMultiTablesIndexNamesFromSnapshot() throws Exception {
    List<RestoreSnapshotAnalyzedStatement.RestoreTableInfo> tables = Arrays.asList(new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(new TableIdent(null, "my_table"), null), new RestoreSnapshotAnalyzedStatement.RestoreTableInfo(new TableIdent(null, "my_partitioned_table"), null));
    List<SnapshotInfo> snapshots = Arrays.asList(new SnapshotInfo(new Snapshot("snapshot01", Collections.singletonList(".partitioned.my_partitioned_table.046jcchm6krj4e1g60o30c0"), 0)), new SnapshotInfo(new Snapshot("snapshot03", Collections.singletonList("my_table"), 0)));
    CompletableFuture<List<String>> future = new CompletableFuture<>();
    SnapshotRestoreDDLDispatcher.ResolveFromSnapshotActionListener actionListener = new SnapshotRestoreDDLDispatcher.ResolveFromSnapshotActionListener(future, tables, new HashSet<>());
    // need to mock here as constructor is not accessible
    GetSnapshotsResponse response = mock(GetSnapshotsResponse.class);
    when(response.getSnapshots()).thenReturn(snapshots);
    actionListener.onResponse(response);
    assertThat(future.get(), containsInAnyOrder("my_table", PartitionName.templateName(null, "my_partitioned_table") + "*"));
}
Also used : TableIdent(io.crate.metadata.TableIdent) RestoreSnapshotAnalyzedStatement(io.crate.analyze.RestoreSnapshotAnalyzedStatement) Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) CompletableFuture(java.util.concurrent.CompletableFuture) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) List(java.util.List) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with GetSnapshotsResponse

use of org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse in project elasticsearch by elastic.

the class RestSnapshotAction method doCatRequest.

@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, NodeClient client) {
    GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest().repository(request.param("repository")).snapshots(new String[] { GetSnapshotsRequest.ALL_SNAPSHOTS });
    getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));
    getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestResponseListener<GetSnapshotsResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetSnapshotsResponse getSnapshotsResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, getSnapshotsResponse), channel);
        }
    });
}
Also used : DateTimeFormat(org.joda.time.format.DateTimeFormat) GET(org.elasticsearch.rest.RestRequest.Method.GET) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) RestResponse(org.elasticsearch.rest.RestResponse) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) GetSnapshotsRequest(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) TimeUnit(java.util.concurrent.TimeUnit) Settings(org.elasticsearch.common.settings.Settings) TimeValue(org.elasticsearch.common.unit.TimeValue) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) SnapshotState(org.elasticsearch.snapshots.SnapshotState) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) GetSnapshotsRequest(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) RestResponse(org.elasticsearch.rest.RestResponse)

Example 9 with GetSnapshotsResponse

use of org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse in project elasticsearch by elastic.

the class SnapshotBlocksIT method testGetSnapshotWithBlocks.

public void testGetSnapshotWithBlocks() {
    // This test checks that the Get Snapshot operation is never blocked, even if the cluster is read only.
    try {
        setClusterReadOnly(true);
        GetSnapshotsResponse response = client().admin().cluster().prepareGetSnapshots(REPOSITORY_NAME).execute().actionGet();
        assertThat(response.getSnapshots(), hasSize(1));
        assertThat(response.getSnapshots().get(0).snapshotId().getName(), equalTo(SNAPSHOT_NAME));
    } finally {
        setClusterReadOnly(false);
    }
}
Also used : GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)

Example 10 with GetSnapshotsResponse

use of org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse in project elasticsearch by elastic.

the class SharedClusterSnapshotRestoreIT method testDataFileFailureDuringSnapshot.

public void testDataFileFailureDuringSnapshot() throws Exception {
    Client client = client();
    logger.info("-->  creating repository");
    assertAcked(client.admin().cluster().preparePutRepository("test-repo").setType("mock").setSettings(Settings.builder().put("location", randomRepoPath()).put("random", randomAsciiOfLength(10)).put("random_data_file_io_exception_rate", 0.3)));
    createIndex("test-idx");
    ensureGreen();
    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));
    logger.info("--> snapshot");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
    if (createSnapshotResponse.getSnapshotInfo().totalShards() == createSnapshotResponse.getSnapshotInfo().successfulShards()) {
        logger.info("--> no failures");
        // If we are here, that means we didn't have any failures, let's check it
        assertThat(getFailureCount("test-repo"), equalTo(0L));
    } else {
        logger.info("--> some failures");
        assertThat(getFailureCount("test-repo"), greaterThan(0L));
        assertThat(createSnapshotResponse.getSnapshotInfo().shardFailures().size(), greaterThan(0));
        for (SnapshotShardFailure shardFailure : createSnapshotResponse.getSnapshotInfo().shardFailures()) {
            assertThat(shardFailure.nodeId(), notNullValue());
            assertThat(shardFailure.index(), equalTo("test-idx"));
        }
        GetSnapshotsResponse getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("test-repo").addSnapshots("test-snap").get();
        assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(1));
        SnapshotInfo snapshotInfo = getSnapshotsResponse.getSnapshots().get(0);
        assertThat(snapshotInfo.state(), equalTo(SnapshotState.PARTIAL));
        assertThat(snapshotInfo.shardFailures().size(), greaterThan(0));
        assertThat(snapshotInfo.totalShards(), greaterThan(snapshotInfo.successfulShards()));
        // Verify that snapshot status also contains the same failures
        SnapshotsStatusResponse snapshotsStatusResponse = client.admin().cluster().prepareSnapshotStatus("test-repo").addSnapshots("test-snap").get();
        assertThat(snapshotsStatusResponse.getSnapshots().size(), equalTo(1));
        SnapshotStatus snapshotStatus = snapshotsStatusResponse.getSnapshots().get(0);
        assertThat(snapshotStatus.getIndices().size(), equalTo(1));
        SnapshotIndexStatus indexStatus = snapshotStatus.getIndices().get("test-idx");
        assertThat(indexStatus, notNullValue());
        assertThat(indexStatus.getShardsStats().getFailedShards(), equalTo(snapshotInfo.failedShards()));
        assertThat(indexStatus.getShardsStats().getDoneShards(), equalTo(snapshotInfo.successfulShards()));
        assertThat(indexStatus.getShards().size(), equalTo(snapshotInfo.totalShards()));
        int numberOfFailures = 0;
        for (SnapshotIndexShardStatus shardStatus : indexStatus.getShards().values()) {
            if (shardStatus.getStage() == SnapshotIndexShardStage.FAILURE) {
                assertThat(shardStatus.getFailure(), notNullValue());
                numberOfFailures++;
            } else {
                assertThat(shardStatus.getFailure(), nullValue());
            }
        }
        assertThat(indexStatus.getShardsStats().getFailedShards(), equalTo(numberOfFailures));
    }
}
Also used : SnapshotsStatusResponse(org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse) GetSnapshotsResponse(org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) ShardSnapshotStatus(org.elasticsearch.cluster.SnapshotsInProgress.ShardSnapshotStatus) SnapshotStatus(org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStatus) CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) SnapshotIndexStatus(org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotIndexStatus) SnapshotIndexShardStatus(org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotIndexShardStatus) Client(org.elasticsearch.client.Client)

Aggregations

GetSnapshotsResponse (org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)13 Client (org.elasticsearch.client.Client)8 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)7 Path (java.nio.file.Path)5 RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)5 SnapshotStatus (org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStatus)4 SnapshotsStatusResponse (org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse)4 List (java.util.List)3 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)3 SnapshotIndexShardStatus (org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotIndexShardStatus)3 SnapshotIndexStatus (org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotIndexStatus)3 Settings (org.elasticsearch.common.settings.Settings)3 RepositoryException (org.elasticsearch.repositories.RepositoryException)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeUnit (java.util.concurrent.TimeUnit)2 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 ClusterState (org.elasticsearch.cluster.ClusterState)2