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());
}
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());
}
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));
}
Aggregations