Search in sources :

Example 1 with SnapshotsStatusRequest

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

the class SnapshotRequestConverters method snapshotsStatus.

static Request snapshotsStatus(SnapshotsStatusRequest snapshotsStatusRequest) {
    String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot").addPathPart(snapshotsStatusRequest.repository()).addCommaSeparatedPathParts(snapshotsStatusRequest.snapshots()).addPathPartAsIs("_status").build();
    Request request = new Request(HttpGet.METHOD_NAME, endpoint);
    RequestConverters.Params parameters = new RequestConverters.Params();
    parameters.withMasterTimeout(snapshotsStatusRequest.masterNodeTimeout());
    parameters.withIgnoreUnavailable(snapshotsStatusRequest.ignoreUnavailable());
    request.addParameters(parameters.asMap());
    return request;
}
Also used : CleanupRepositoryRequest(org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest) DeleteRepositoryRequest(org.opensearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest) VerifyRepositoryRequest(org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest) CloneSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.clone.CloneSnapshotRequest) DeleteSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest) GetRepositoriesRequest(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) RestoreSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest) PutRepositoryRequest(org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest) CreateSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) SnapshotsStatusRequest(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest)

Example 2 with SnapshotsStatusRequest

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

the class SnapshotRequestConvertersTests method testSnapshotsStatus.

public void testSnapshotsStatus() {
    Map<String, String> expectedParams = new HashMap<>();
    String repository = RequestConvertersTests.randomIndicesNames(1, 1)[0];
    String[] snapshots = RequestConvertersTests.randomIndicesNames(1, 5);
    StringBuilder snapshotNames = new StringBuilder(snapshots[0]);
    for (int idx = 1; idx < snapshots.length; idx++) {
        snapshotNames.append(",").append(snapshots[idx]);
    }
    boolean ignoreUnavailable = randomBoolean();
    String endpoint = "/_snapshot/" + repository + "/" + snapshotNames.toString() + "/_status";
    SnapshotsStatusRequest snapshotsStatusRequest = new SnapshotsStatusRequest(repository, snapshots);
    RequestConvertersTests.setRandomMasterTimeout(snapshotsStatusRequest, expectedParams);
    snapshotsStatusRequest.ignoreUnavailable(ignoreUnavailable);
    expectedParams.put("ignore_unavailable", Boolean.toString(ignoreUnavailable));
    Request request = SnapshotRequestConverters.snapshotsStatus(snapshotsStatusRequest);
    assertThat(request.getEndpoint(), equalTo(endpoint));
    assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
    assertThat(request.getParameters(), equalTo(expectedParams));
    assertThat(request.getEntity(), is(nullValue()));
}
Also used : HashMap(java.util.HashMap) SnapshotsStatusRequest(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest) VerifyRepositoryRequest(org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest) RestoreSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest) SnapshotsStatusRequest(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest) DeleteRepositoryRequest(org.opensearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest) AcknowledgedRequest(org.opensearch.action.support.master.AcknowledgedRequest) DeleteSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest) GetRepositoriesRequest(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) PutRepositoryRequest(org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest) CreateSnapshotRequest(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest)

Example 3 with SnapshotsStatusRequest

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

the class SnapshotStatusApisIT method testStatusApiConsistency.

public void testStatusApiConsistency() {
    createRepository("test-repo", "fs");
    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();
    createFullSnapshot("test-repo", "test-snap");
    List<SnapshotInfo> snapshotInfos = clusterAdmin().prepareGetSnapshots("test-repo").get().getSnapshots();
    assertThat(snapshotInfos.size(), equalTo(1));
    SnapshotInfo snapshotInfo = snapshotInfos.get(0);
    assertThat(snapshotInfo.state(), equalTo(SnapshotState.SUCCESS));
    assertThat(snapshotInfo.version(), equalTo(Version.CURRENT));
    final List<SnapshotStatus> snapshotStatus = clusterAdmin().snapshotsStatus(new SnapshotsStatusRequest("test-repo", new String[] { "test-snap" })).actionGet().getSnapshots();
    assertThat(snapshotStatus.size(), equalTo(1));
    final SnapshotStatus snStatus = snapshotStatus.get(0);
    assertEquals(snStatus.getStats().getStartTime(), snapshotInfo.startTime());
    assertEquals(snStatus.getStats().getTime(), snapshotInfo.endTime() - snapshotInfo.startTime());
}
Also used : SnapshotStatus(org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus) SnapshotsStatusRequest(org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest)

Example 4 with SnapshotsStatusRequest

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

Example 5 with SnapshotsStatusRequest

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

SnapshotsStatusRequest (org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest)6 CreateSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest)3 DeleteRepositoryRequest (org.opensearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest)2 GetRepositoriesRequest (org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest)2 PutRepositoryRequest (org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest)2 VerifyRepositoryRequest (org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest)2 DeleteSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest)2 GetSnapshotsRequest (org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest)2 RestoreSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest)2 SnapshotStatus (org.opensearch.action.admin.cluster.snapshots.status.SnapshotStatus)2 SnapshotsStatusResponse (org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse)2 IOException (java.io.IOException)1 Arrays.asList (java.util.Arrays.asList)1 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CleanupRepositoryRequest (org.opensearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest)1 CloneSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.clone.CloneSnapshotRequest)1 CreateSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)1 SnapshotStats (org.opensearch.action.admin.cluster.snapshots.status.SnapshotStats)1