Search in sources :

Example 11 with SnapshotStatus

use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus 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 12 with SnapshotStatus

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

the class CloneSnapshotIT method testClonePreventsSnapshotDelete.

public void testClonePreventsSnapshotDelete() throws Exception {
    final String clusterManagerName = internalCluster().startClusterManagerOnlyNode();
    internalCluster().startDataOnlyNode();
    final String repoName = "repo-name";
    createRepository(repoName, "mock");
    final String indexName = "index-1";
    createIndexWithRandomDocs(indexName, randomIntBetween(5, 10));
    final String sourceSnapshot = "source-snapshot";
    createFullSnapshot(repoName, sourceSnapshot);
    indexRandomDocs(indexName, randomIntBetween(20, 100));
    final String targetSnapshot = "target-snapshot";
    blockNodeOnAnyFiles(repoName, clusterManagerName);
    final ActionFuture<AcknowledgedResponse> cloneFuture = startClone(repoName, sourceSnapshot, targetSnapshot, indexName);
    waitForBlock(clusterManagerName, repoName, TimeValue.timeValueSeconds(30L));
    assertFalse(cloneFuture.isDone());
    ConcurrentSnapshotExecutionException ex = expectThrows(ConcurrentSnapshotExecutionException.class, () -> startDeleteSnapshot(repoName, sourceSnapshot).actionGet());
    assertThat(ex.getMessage(), containsString("cannot delete snapshot while it is being cloned"));
    unblockNode(repoName, clusterManagerName);
    assertAcked(cloneFuture.get());
    final List<SnapshotStatus> status = clusterAdmin().prepareSnapshotStatus(repoName).setSnapshots(sourceSnapshot, targetSnapshot).get().getSnapshots();
    assertThat(status, hasSize(2));
    final SnapshotIndexStatus status1 = status.get(0).getIndices().get(indexName);
    final SnapshotIndexStatus status2 = status.get(1).getIndices().get(indexName);
    assertEquals(status1.getStats().getTotalFileCount(), status2.getStats().getTotalFileCount());
    assertEquals(status1.getStats().getTotalSize(), status2.getStats().getTotalSize());
}
Also used : SnapshotStatus(org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) SnapshotIndexStatus(org.opensearch.action.admin.cluster.snapshots.status.SnapshotIndexStatus) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 13 with SnapshotStatus

use of org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus 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)

Aggregations

SnapshotStatus (org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus)13 SnapshotsStatusResponse (org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse)8 Matchers.containsString (org.hamcrest.Matchers.containsString)5 CreateSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)4 SnapshotIndexShardStatus (org.opensearch.action.admin.cluster.snapshots.status.SnapshotIndexShardStatus)4 SnapshotIndexStatus (org.opensearch.action.admin.cluster.snapshots.status.SnapshotIndexStatus)4 SnapshotStats (org.opensearch.action.admin.cluster.snapshots.status.SnapshotStats)3 ArrayList (java.util.ArrayList)2 RestoreSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)2 SnapshotsStatusRequest (org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest)2 Client (org.opensearch.client.Client)2 Path (java.nio.file.Path)1 List (java.util.List)1 GetSnapshotsResponse (org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)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 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)1