use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project OpenSearch by opensearch-project.
the class SnapshotRequestConverters method getSnapshots.
static Request getSnapshots(GetSnapshotsRequest getSnapshotsRequest) {
RequestConverters.EndpointBuilder endpointBuilder = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot").addPathPart(getSnapshotsRequest.repository());
String endpoint;
if (getSnapshotsRequest.snapshots().length == 0) {
endpoint = endpointBuilder.addPathPart("_all").build();
} else {
endpoint = endpointBuilder.addCommaSeparatedPathParts(getSnapshotsRequest.snapshots()).build();
}
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withMasterTimeout(getSnapshotsRequest.masterNodeTimeout());
parameters.putParam("ignore_unavailable", Boolean.toString(getSnapshotsRequest.ignoreUnavailable()));
parameters.putParam("verbose", Boolean.toString(getSnapshotsRequest.verbose()));
request.addParameters(parameters.asMap());
return request;
}
use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project OpenSearch by opensearch-project.
the class SnapshotRequestConvertersTests method testGetSnapshots.
public void testGetSnapshots() {
Map<String, String> expectedParams = new HashMap<>();
String repository = RequestConvertersTests.randomIndicesNames(1, 1)[0];
String snapshot1 = "snapshot1-" + randomAlphaOfLengthBetween(2, 5).toLowerCase(Locale.ROOT);
String snapshot2 = "snapshot2-" + randomAlphaOfLengthBetween(2, 5).toLowerCase(Locale.ROOT);
String endpoint = String.format(Locale.ROOT, "/_snapshot/%s/%s,%s", repository, snapshot1, snapshot2);
GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest();
getSnapshotsRequest.repository(repository);
getSnapshotsRequest.snapshots(Arrays.asList(snapshot1, snapshot2).toArray(new String[0]));
RequestConvertersTests.setRandomMasterTimeout(getSnapshotsRequest, expectedParams);
if (randomBoolean()) {
boolean ignoreUnavailable = randomBoolean();
getSnapshotsRequest.ignoreUnavailable(ignoreUnavailable);
expectedParams.put("ignore_unavailable", Boolean.toString(ignoreUnavailable));
} else {
expectedParams.put("ignore_unavailable", Boolean.FALSE.toString());
}
if (randomBoolean()) {
boolean verbose = randomBoolean();
getSnapshotsRequest.verbose(verbose);
expectedParams.put("verbose", Boolean.toString(verbose));
} else {
expectedParams.put("verbose", Boolean.TRUE.toString());
}
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 SnapshotStatusApisIT method testExceptionOnMissingSnapBlob.
public void testExceptionOnMissingSnapBlob() throws IOException {
disableRepoConsistencyCheck("This test intentionally corrupts the repository");
final Path repoPath = randomRepoPath();
createRepository("test-repo", "fs", repoPath);
final SnapshotInfo snapshotInfo = createFullSnapshot("test-repo", "test-snap");
logger.info("--> delete snap-${uuid}.dat file for this snapshot to simulate concurrent delete");
IOUtils.rm(repoPath.resolve(BlobStoreRepository.SNAPSHOT_PREFIX + snapshotInfo.snapshotId().getUUID() + ".dat"));
expectThrows(SnapshotMissingException.class, () -> client().admin().cluster().getSnapshots(new GetSnapshotsRequest("test-repo", new String[] { "test-snap" })).actionGet());
}
use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project OpenSearch by opensearch-project.
the class RestSnapshotAction method doCatRequest.
@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, NodeClient client) {
GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest().repository(request.param("repository")).snapshots(new String[] { GetSnapshotsRequest.ALL_SNAPSHOTS });
getSnapshotsRequest.ignoreUnavailable(request.paramAsBoolean("ignore_unavailable", getSnapshotsRequest.ignoreUnavailable()));
getSnapshotsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getSnapshotsRequest.masterNodeTimeout()));
return channel -> client.admin().cluster().getSnapshots(getSnapshotsRequest, new RestResponseListener<GetSnapshotsResponse>(channel) {
@Override
public RestResponse buildResponse(GetSnapshotsResponse getSnapshotsResponse) throws Exception {
return RestTable.buildResponse(buildTable(request, getSnapshotsResponse), channel);
}
});
}
use of org.opensearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest in project OpenSearch by opensearch-project.
the class SnapshotIT method testGetSnapshots.
public void testGetSnapshots() throws IOException {
String repository = "test_repository";
String snapshot1 = "test_snapshot1";
String snapshot2 = "test_snapshot2";
AcknowledgedResponse putRepositoryResponse = createTestRepository(repository, FsRepository.TYPE, "{\"location\": \".\"}");
assertTrue(putRepositoryResponse.isAcknowledged());
CreateSnapshotRequest createSnapshotRequest1 = new CreateSnapshotRequest(repository, snapshot1);
createSnapshotRequest1.waitForCompletion(true);
CreateSnapshotResponse putSnapshotResponse1 = createTestSnapshot(createSnapshotRequest1);
CreateSnapshotRequest createSnapshotRequest2 = new CreateSnapshotRequest(repository, snapshot2);
createSnapshotRequest2.waitForCompletion(true);
Map<String, Object> originalMetadata = randomUserMetadata();
createSnapshotRequest2.userMetadata(originalMetadata);
CreateSnapshotResponse putSnapshotResponse2 = createTestSnapshot(createSnapshotRequest2);
// check that the request went ok without parsing JSON here. When using the high level client, check acknowledgement instead.
assertEquals(RestStatus.OK, putSnapshotResponse1.status());
assertEquals(RestStatus.OK, putSnapshotResponse2.status());
GetSnapshotsRequest request;
if (randomBoolean()) {
request = new GetSnapshotsRequest(repository);
} else if (randomBoolean()) {
request = new GetSnapshotsRequest(repository, new String[] { "_all" });
} else {
request = new GetSnapshotsRequest(repository, new String[] { snapshot1, snapshot2 });
}
GetSnapshotsResponse response = execute(request, highLevelClient().snapshot()::get, highLevelClient().snapshot()::getAsync);
assertEquals(2, response.getSnapshots().size());
assertThat(response.getSnapshots().stream().map((s) -> s.snapshotId().getName()).collect(Collectors.toList()), contains("test_snapshot1", "test_snapshot2"));
Optional<Map<String, Object>> returnedMetadata = response.getSnapshots().stream().filter(s -> s.snapshotId().getName().equals("test_snapshot2")).findFirst().map(SnapshotInfo::userMetadata);
if (returnedMetadata.isPresent()) {
assertEquals(originalMetadata, returnedMetadata.get());
} else {
assertNull("retrieved metadata is null, expected non-null metadata", originalMetadata);
}
}
Aggregations