use of org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest in project OpenSearch by opensearch-project.
the class SnapshotRequestConverters method getRepositories.
static Request getRepositories(GetRepositoriesRequest getRepositoriesRequest) {
String[] repositories = getRepositoriesRequest.repositories() == null ? Strings.EMPTY_ARRAY : getRepositoriesRequest.repositories();
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_snapshot").addCommaSeparatedPathParts(repositories).build();
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
RequestConverters.Params parameters = new RequestConverters.Params();
parameters.withMasterTimeout(getRepositoriesRequest.masterNodeTimeout());
parameters.withLocal(getRepositoriesRequest.local());
request.addParameters(parameters.asMap());
return request;
}
use of org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest in project OpenSearch by opensearch-project.
the class SnapshotRequestConvertersTests method testGetRepositories.
public void testGetRepositories() {
Map<String, String> expectedParams = new HashMap<>();
StringBuilder endpoint = new StringBuilder("/_snapshot");
GetRepositoriesRequest getRepositoriesRequest = new GetRepositoriesRequest();
RequestConvertersTests.setRandomMasterTimeout(getRepositoriesRequest, expectedParams);
RequestConvertersTests.setRandomLocal(getRepositoriesRequest::local, expectedParams);
if (randomBoolean()) {
String[] entries = new String[] { "a", "b", "c" };
getRepositoriesRequest.repositories(entries);
endpoint.append("/" + String.join(",", entries));
}
Request request = SnapshotRequestConverters.getRepositories(getRepositoriesRequest);
assertThat(request.getEndpoint(), equalTo(endpoint.toString()));
assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
assertThat(expectedParams, equalTo(request.getParameters()));
}
use of org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest in project OpenSearch by opensearch-project.
the class SnapshotIT method testSnapshotGetDefaultRepositories.
public void testSnapshotGetDefaultRepositories() throws IOException {
assertTrue(createTestRepository("other", FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged());
assertTrue(createTestRepository("test", FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged());
GetRepositoriesResponse response = execute(new GetRepositoriesRequest(), highLevelClient().snapshot()::getRepository, highLevelClient().snapshot()::getRepositoryAsync);
assertThat(2, equalTo(response.repositories().size()));
}
use of org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest in project OpenSearch by opensearch-project.
the class SnapshotIT method testSnapshotGetRepositoriesUsingParams.
public void testSnapshotGetRepositoriesUsingParams() throws IOException {
String testRepository = "test";
assertTrue(createTestRepository(testRepository, FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged());
assertTrue(createTestRepository("other", FsRepository.TYPE, "{\"location\": \".\"}").isAcknowledged());
GetRepositoriesRequest request = new GetRepositoriesRequest();
request.repositories(new String[] { testRepository });
GetRepositoriesResponse response = execute(request, highLevelClient().snapshot()::getRepository, highLevelClient().snapshot()::getRepositoryAsync);
assertThat(1, equalTo(response.repositories().size()));
}
use of org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest in project OpenSearch by opensearch-project.
the class SnapshotClientDocumentationIT method testSnapshotGetRepository.
public void testSnapshotGetRepository() throws IOException {
RestHighLevelClient client = highLevelClient();
createTestRepositories();
// tag::get-repository-request
GetRepositoriesRequest request = new GetRepositoriesRequest();
// end::get-repository-request
// tag::get-repository-request-repositories
String[] repositories = new String[] { repositoryName };
// <1>
request.repositories(repositories);
// end::get-repository-request-repositories
// tag::get-repository-request-local
// <1>
request.local(true);
// end::get-repository-request-local
// tag::get-repository-request-masterTimeout
// <1>
request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
// <2>
request.masterNodeTimeout("1m");
// end::get-repository-request-masterTimeout
// tag::get-repository-execute
GetRepositoriesResponse response = client.snapshot().getRepository(request, RequestOptions.DEFAULT);
// end::get-repository-execute
// tag::get-repository-response
List<RepositoryMetadata> repositoryMetadataResponse = response.repositories();
// end::get-repository-response
assertThat(1, equalTo(repositoryMetadataResponse.size()));
assertThat(repositoryName, equalTo(repositoryMetadataResponse.get(0).name()));
}
Aggregations