Search in sources :

Example 6 with GetSnapshotsRequest

use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project OpenSearch by opensearch-project.

the class SnapshotClientDocumentationIT method testSnapshotGetSnapshots.

@SuppressWarnings("unused")
public void testSnapshotGetSnapshots() throws IOException {
    RestHighLevelClient client = highLevelClient();
    createTestRepositories();
    createTestIndex();
    createTestSnapshots();
    // tag::get-snapshots-request
    GetSnapshotsRequest request = new GetSnapshotsRequest();
    // end::get-snapshots-request
    // tag::get-snapshots-request-repositoryName
    // <1>
    request.repository(repositoryName);
    // end::get-snapshots-request-repositoryName
    // tag::get-snapshots-request-snapshots
    String[] snapshots = { snapshotName };
    // <1>
    request.snapshots(snapshots);
    // end::get-snapshots-request-snapshots
    // tag::get-snapshots-request-masterTimeout
    // <1>
    request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
    // <2>
    request.masterNodeTimeout("1m");
    // end::get-snapshots-request-masterTimeout
    // tag::get-snapshots-request-verbose
    // <1>
    request.verbose(true);
    // end::get-snapshots-request-verbose
    // tag::get-snapshots-request-ignore-unavailable
    // <1>
    request.ignoreUnavailable(false);
    // end::get-snapshots-request-ignore-unavailable
    // tag::get-snapshots-execute
    GetSnapshotsResponse response = client.snapshot().get(request, RequestOptions.DEFAULT);
    // end::get-snapshots-execute
    // tag::get-snapshots-response
    List<SnapshotInfo> snapshotsInfos = response.getSnapshots();
    SnapshotInfo snapshotInfo = snapshotsInfos.get(0);
    // <1>
    RestStatus restStatus = snapshotInfo.status();
    // <2>
    SnapshotId snapshotId = snapshotInfo.snapshotId();
    // <3>
    SnapshotState snapshotState = snapshotInfo.state();
    // <4>
    List<SnapshotShardFailure> snapshotShardFailures = snapshotInfo.shardFailures();
    // <5>
    long startTime = snapshotInfo.startTime();
    // <6>
    long endTime = snapshotInfo.endTime();
    // end::get-snapshots-response
    assertEquals(1, snapshotsInfos.size());
}
Also used : SnapshotShardFailure(org.opensearch.snapshots.SnapshotShardFailure) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) SnapshotId(org.opensearch.snapshots.SnapshotId) GetSnapshotsResponse(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse) SnapshotInfo(org.opensearch.snapshots.SnapshotInfo) SnapshotState(org.opensearch.snapshots.SnapshotState) RestStatus(org.opensearch.rest.RestStatus)

Example 7 with GetSnapshotsRequest

use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project OpenSearch by opensearch-project.

the class SnapshotRequestConvertersTests method testGetAllSnapshots.

public void testGetAllSnapshots() {
    Map<String, String> expectedParams = new HashMap<>();
    String repository = RequestConvertersTests.randomIndicesNames(1, 1)[0];
    String endpoint = String.format(Locale.ROOT, "/_snapshot/%s/_all", repository);
    GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest(repository);
    RequestConvertersTests.setRandomMasterTimeout(getSnapshotsRequest, expectedParams);
    boolean ignoreUnavailable = randomBoolean();
    getSnapshotsRequest.ignoreUnavailable(ignoreUnavailable);
    expectedParams.put("ignore_unavailable", Boolean.toString(ignoreUnavailable));
    boolean verbose = randomBoolean();
    getSnapshotsRequest.verbose(verbose);
    expectedParams.put("verbose", Boolean.toString(verbose));
    Request request = SnapshotRequestConverters.getSnapshots(getSnapshotsRequest);
    assertThat(request.getEndpoint(), equalTo(endpoint));
    assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
    assertThat(request.getParameters(), equalTo(expectedParams));
    assertNull(request.getEntity());
}
Also used : GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) HashMap(java.util.HashMap) 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 8 with GetSnapshotsRequest

use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project OpenSearch by opensearch-project.

the class RestGetSnapshotsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String repository = request.param("repository");
    String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);
    GetSnapshotsRequest getSnapshotsRequest = getSnapshotsRequest(repository).snapshots(snapshots);
    getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));
    getSnapshotsRequest.verbose(request.paramAsBoolean("verbose", getSnapshotsRequest.verbose()));
    getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestToXContentListener<>(channel));
}
Also used : List(java.util.List) NodeClient(org.opensearch.client.node.NodeClient) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) IOException(java.io.IOException) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest) BaseRestHandler(org.opensearch.rest.BaseRestHandler) Requests.getSnapshotsRequest(org.opensearch.client.Requests.getSnapshotsRequest) Strings(org.opensearch.common.Strings) Collections.singletonList(java.util.Collections.singletonList) GetSnapshotsRequest(org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest)

Aggregations

GetSnapshotsRequest (org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest)8 CreateSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest)4 HashMap (java.util.HashMap)3 DeleteRepositoryRequest (org.opensearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest)3 GetRepositoriesRequest (org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest)3 PutRepositoryRequest (org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest)3 VerifyRepositoryRequest (org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest)3 DeleteSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest)3 GetSnapshotsResponse (org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse)3 RestoreSnapshotRequest (org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest)3 SnapshotsStatusRequest (org.opensearch.action.admin.cluster.snapshots.status.SnapshotsStatusRequest)3 SnapshotInfo (org.opensearch.snapshots.SnapshotInfo)3 List (java.util.List)2 AcknowledgedRequest (org.opensearch.action.support.master.AcknowledgedRequest)2 NodeClient (org.opensearch.client.node.NodeClient)2 RestRequest (org.opensearch.rest.RestRequest)2 GET (org.opensearch.rest.RestRequest.Method.GET)2 SnapshotState (org.opensearch.snapshots.SnapshotState)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1