Search in sources :

Example 11 with SnapshotsStatusResponse

use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse in project OpenSearch by opensearch-project.

the class SharedClusterSnapshotRestoreIT method testRestoreSnapshotWithCorruptedGlobalState.

/**
 * Tests that a snapshot with a corrupted global state file can still be restored
 */
public void testRestoreSnapshotWithCorruptedGlobalState() throws Exception {
    final Path repo = randomRepoPath();
    final String repoName = "test-repo";
    createRepository(repoName, "fs", repo);
    createIndex("test-idx-1", "test-idx-2");
    indexRandom(true, client().prepareIndex("test-idx-1").setSource("foo", "bar"), client().prepareIndex("test-idx-2").setSource("foo", "bar"), client().prepareIndex("test-idx-2").setSource("foo", "bar"));
    flushAndRefresh("test-idx-1", "test-idx-2");
    final String snapshotName = "test-snap";
    final SnapshotInfo snapshotInfo = createFullSnapshot(repoName, snapshotName);
    final Path globalStatePath = repo.resolve("meta-" + snapshotInfo.snapshotId().getUUID() + ".dat");
    try (SeekableByteChannel outChan = Files.newByteChannel(globalStatePath, StandardOpenOption.WRITE)) {
        outChan.truncate(randomInt(10));
    }
    List<SnapshotInfo> snapshotInfos = clusterAdmin().prepareGetSnapshots(repoName).get().getSnapshots();
    assertThat(snapshotInfos.size(), equalTo(1));
    assertThat(snapshotInfos.get(0).state(), equalTo(SnapshotState.SUCCESS));
    assertThat(snapshotInfos.get(0).snapshotId().getName(), equalTo(snapshotName));
    SnapshotsStatusResponse snapshotStatusResponse = clusterAdmin().prepareSnapshotStatus(repoName).setSnapshots(snapshotName).get();
    assertThat(snapshotStatusResponse.getSnapshots(), hasSize(1));
    assertThat(snapshotStatusResponse.getSnapshots().get(0).getSnapshot().getSnapshotId().getName(), equalTo(snapshotName));
    assertAcked(client().admin().indices().prepareDelete("test-idx-1", "test-idx-2"));
    SnapshotException ex = expectThrows(SnapshotException.class, () -> clusterAdmin().prepareRestoreSnapshot(repoName, snapshotName).setRestoreGlobalState(true).setWaitForCompletion(true).get());
    assertThat(ex.getRepositoryName(), equalTo(repoName));
    assertThat(ex.getSnapshotName(), equalTo(snapshotName));
    assertThat(ex.getMessage(), containsString("failed to read global metadata"));
    RestoreSnapshotResponse restoreSnapshotResponse = clusterAdmin().prepareRestoreSnapshot(repoName, snapshotName).setWaitForCompletion(true).get();
    assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(0));
    assertThat(restoreSnapshotResponse.getRestoreInfo().successfulShards(), equalTo(snapshotInfo.successfulShards()));
    ensureGreen("test-idx-1", "test-idx-2");
    assertHitCount(client().prepareSearch("test-idx-*").setSize(0).get(), 3);
}
Also used : Path(java.nio.file.Path) SeekableByteChannel(java.nio.channels.SeekableByteChannel) SnapshotsStatusResponse(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)

Example 12 with SnapshotsStatusResponse

use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse in project OpenSearch by opensearch-project.

the class ConcurrentSnapshotsIT method assertSnapshotStatusCountOnRepo.

private static void assertSnapshotStatusCountOnRepo(String otherBlockedRepoName, int count) {
    final SnapshotsStatusResponse snapshotsStatusResponse = client().admin().cluster().prepareSnapshotStatus(otherBlockedRepoName).get();
    final List<SnapshotStatus> snapshotStatuses = snapshotsStatusResponse.getSnapshots();
    assertThat(snapshotStatuses, hasSize(count));
}
Also used : SnapshotsStatusResponse(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse) SnapshotStatus(org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus)

Example 13 with SnapshotsStatusResponse

use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse in project OpenSearch by opensearch-project.

the class CorruptedBlobStoreRepositoryIT method testDeleteSnapshotWithCorruptedGlobalState.

/**
 * Tests that a snapshot with a corrupted global state file can still be deleted
 */
public void testDeleteSnapshotWithCorruptedGlobalState() throws Exception {
    final Path repo = randomRepoPath();
    createRepository("test-repo", "fs", Settings.builder().put("location", repo).put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES));
    createIndex("test-idx-1", "test-idx-2");
    indexRandom(true, client().prepareIndex("test-idx-1").setSource("foo", "bar"), client().prepareIndex("test-idx-2").setSource("foo", "bar"), client().prepareIndex("test-idx-2").setSource("foo", "bar"));
    flushAndRefresh("test-idx-1", "test-idx-2");
    SnapshotInfo snapshotInfo = createFullSnapshot("test-repo", "test-snap");
    final Path globalStatePath = repo.resolve("meta-" + snapshotInfo.snapshotId().getUUID() + ".dat");
    if (randomBoolean()) {
        // Delete the global state metadata file
        IOUtils.deleteFilesIgnoringExceptions(globalStatePath);
    } else {
        // Truncate the global state metadata file
        try (SeekableByteChannel outChan = Files.newByteChannel(globalStatePath, StandardOpenOption.WRITE)) {
            outChan.truncate(randomInt(10));
        }
    }
    List<SnapshotInfo> snapshotInfos = clusterAdmin().prepareGetSnapshots("test-repo").get().getSnapshots();
    assertThat(snapshotInfos.size(), equalTo(1));
    assertThat(snapshotInfos.get(0).state(), equalTo(SnapshotState.SUCCESS));
    assertThat(snapshotInfos.get(0).snapshotId().getName(), equalTo("test-snap"));
    SnapshotsStatusResponse snapshotStatusResponse = clusterAdmin().prepareSnapshotStatus("test-repo").setSnapshots("test-snap").get();
    assertThat(snapshotStatusResponse.getSnapshots(), hasSize(1));
    assertThat(snapshotStatusResponse.getSnapshots().get(0).getSnapshot().getSnapshotId().getName(), equalTo("test-snap"));
    assertAcked(startDeleteSnapshot("test-repo", "test-snap").get());
    expectThrows(SnapshotMissingException.class, () -> clusterAdmin().prepareGetSnapshots("test-repo").addSnapshots("test-snap").get());
    assertRequestBuilderThrows(clusterAdmin().prepareSnapshotStatus("test-repo").addSnapshots("test-snap"), SnapshotMissingException.class);
    createFullSnapshot("test-repo", "test-snap");
}
Also used : Path(java.nio.file.Path) SeekableByteChannel(java.nio.channels.SeekableByteChannel) SnapshotsStatusResponse(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse)

Example 14 with SnapshotsStatusResponse

use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse in project OpenSearch by opensearch-project.

the class SnapshotClientDocumentationIT method testSnapshotSnapshotsStatus.

public void testSnapshotSnapshotsStatus() throws IOException {
    RestHighLevelClient client = highLevelClient();
    createTestRepositories();
    createTestIndex();
    createTestSnapshots();
    // tag::snapshots-status-request
    SnapshotsStatusRequest request = new SnapshotsStatusRequest();
    // end::snapshots-status-request
    // tag::snapshots-status-request-repository
    // <1>
    request.repository(repositoryName);
    // end::snapshots-status-request-repository
    // tag::snapshots-status-request-snapshots
    String[] snapshots = new String[] { snapshotName };
    // <1>
    request.snapshots(snapshots);
    // end::snapshots-status-request-snapshots
    // tag::snapshots-status-request-ignoreUnavailable
    // <1>
    request.ignoreUnavailable(true);
    // end::snapshots-status-request-ignoreUnavailable
    // tag::snapshots-status-request-masterTimeout
    // <1>
    request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
    // <2>
    request.masterNodeTimeout("1m");
    // end::snapshots-status-request-masterTimeout
    // tag::snapshots-status-execute
    SnapshotsStatusResponse response = client.snapshot().status(request, RequestOptions.DEFAULT);
    // end::snapshots-status-execute
    // tag::snapshots-status-response
    List<SnapshotStatus> snapshotStatusesResponse = response.getSnapshots();
    // <1>
    SnapshotStatus snapshotStatus = snapshotStatusesResponse.get(0);
    // <2>
    SnapshotsInProgress.State snapshotState = snapshotStatus.getState();
    // <3>
    SnapshotStats shardStats = snapshotStatus.getIndices().get(indexName).getShards().get(0).getStats();
    // end::snapshots-status-response
    assertThat(snapshotStatusesResponse.size(), equalTo(1));
    assertThat(snapshotStatusesResponse.get(0).getSnapshot().getRepository(), equalTo(SnapshotClientDocumentationIT.repositoryName));
    assertThat(snapshotStatusesResponse.get(0).getSnapshot().getSnapshotId().getName(), equalTo(snapshotName));
    assertThat(snapshotState.completed(), equalTo(true));
}
Also used : SnapshotsStatusResponse(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse) SnapshotStatus(org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus) SnapshotStats(org.opensearch.action.admin.cluster.snapshots.status.SnapshotStats) SnapshotsStatusRequest(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest) SnapshotsInProgress(org.opensearch.cluster.SnapshotsInProgress) RestHighLevelClient(org.opensearch.client.RestHighLevelClient)

Example 15 with SnapshotsStatusResponse

use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse in project OpenSearch by opensearch-project.

the class SnapshotIT method testSnapshotsStatus.

public void testSnapshotsStatus() throws IOException {
    String testRepository = "test";
    String testSnapshot = "snapshot";
    String testIndex = "test_index";
    AcknowledgedResponse putRepositoryResponse = createTestRepository(testRepository, FsRepository.TYPE, "{\"location\": \".\"}");
    assertTrue(putRepositoryResponse.isAcknowledged());
    createIndex(testIndex, Settings.EMPTY);
    CreateSnapshotRequest createSnapshotRequest = new CreateSnapshotRequest(testRepository, testSnapshot);
    createSnapshotRequest.indices(testIndex);
    createSnapshotRequest.waitForCompletion(true);
    CreateSnapshotResponse createSnapshotResponse = createTestSnapshot(createSnapshotRequest);
    // check that the request went ok without parsing JSON here. When using the high level client, check acknowledgement instead.
    assertEquals(RestStatus.OK, createSnapshotResponse.status());
    SnapshotsStatusRequest request = new SnapshotsStatusRequest();
    request.repository(testRepository);
    request.snapshots(new String[] { testSnapshot });
    SnapshotsStatusResponse response = execute(request, highLevelClient().snapshot()::status, highLevelClient().snapshot()::statusAsync);
    assertThat(response.getSnapshots().size(), equalTo(1));
    assertThat(response.getSnapshots().get(0).getSnapshot().getRepository(), equalTo(testRepository));
    assertThat(response.getSnapshots().get(0).getSnapshot().getSnapshotId().getName(), equalTo(testSnapshot));
    assertThat(response.getSnapshots().get(0).getIndices().containsKey(testIndex), is(true));
}
Also used : SnapshotsStatusResponse(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) CreateSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) SnapshotsStatusRequest(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse)

Aggregations

SnapshotsStatusResponse (org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse)15 SnapshotStatus (org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus)8 CreateSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 RestoreSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)4 Path (java.nio.file.Path)3 SeekableByteChannel (java.nio.channels.SeekableByteChannel)2 GetSnapshotsResponse (org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)2 SnapshotIndexShardStatus (org.opensearch.action.admin.cluster.snapshots.status.SnapshotIndexShardStatus)2 SnapshotIndexStatus (org.opensearch.action.admin.cluster.snapshots.status.SnapshotIndexStatus)2 SnapshotStats (org.opensearch.action.admin.cluster.snapshots.status.SnapshotStats)2 SnapshotsStatusRequest (org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest)2 ArrayList (java.util.ArrayList)1 CreateSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest)1 GetStoredScriptResponse (org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptResponse)1 GetIndexTemplatesResponse (org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse)1 DeletePipelineRequest (org.opensearch.action.ingest.DeletePipelineRequest)1 GetPipelineResponse (org.opensearch.action.ingest.GetPipelineResponse)1 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)1 Client (org.opensearch.client.Client)1