use of org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse 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.GetRepositoriesResponse 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.GetRepositoriesResponse 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()));
}
use of org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse in project OpenSearch by opensearch-project.
the class RepositoriesServiceIT method testUpdateRepository.
public void testUpdateRepository() {
final InternalTestCluster cluster = internalCluster();
final String repositoryName = "test-repo";
final Client client = client();
final RepositoriesService repositoriesService = cluster.getDataOrMasterNodeInstances(RepositoriesService.class).iterator().next();
final Settings.Builder repoSettings = Settings.builder().put("location", randomRepoPath());
assertAcked(client.admin().cluster().preparePutRepository(repositoryName).setType(FsRepository.TYPE).setSettings(repoSettings).get());
final GetRepositoriesResponse originalGetRepositoriesResponse = client.admin().cluster().prepareGetRepositories(repositoryName).get();
assertThat(originalGetRepositoriesResponse.repositories(), hasSize(1));
RepositoryMetadata originalRepositoryMetadata = originalGetRepositoriesResponse.repositories().get(0);
assertThat(originalRepositoryMetadata.type(), equalTo(FsRepository.TYPE));
final Repository originalRepository = repositoriesService.repository(repositoryName);
assertThat(originalRepository, instanceOf(FsRepository.class));
final boolean updated = randomBoolean();
final String updatedRepositoryType = updated ? "mock" : FsRepository.TYPE;
assertAcked(client.admin().cluster().preparePutRepository(repositoryName).setType(updatedRepositoryType).setSettings(repoSettings).get());
final GetRepositoriesResponse updatedGetRepositoriesResponse = client.admin().cluster().prepareGetRepositories(repositoryName).get();
assertThat(updatedGetRepositoriesResponse.repositories(), hasSize(1));
final RepositoryMetadata updatedRepositoryMetadata = updatedGetRepositoriesResponse.repositories().get(0);
assertThat(updatedRepositoryMetadata.type(), equalTo(updatedRepositoryType));
final Repository updatedRepository = repositoriesService.repository(repositoryName);
assertThat(updatedRepository, updated ? not(sameInstance(originalRepository)) : sameInstance(originalRepository));
}
use of org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse in project OpenSearch by opensearch-project.
the class RepositoriesIT method testRepositoryCreation.
public void testRepositoryCreation() throws Exception {
Client client = client();
Path location = randomRepoPath();
createRepository("test-repo-1", "fs", location);
logger.info("--> verify the repository");
int numberOfFiles = FileSystemUtils.files(location).length;
VerifyRepositoryResponse verifyRepositoryResponse = client.admin().cluster().prepareVerifyRepository("test-repo-1").get();
assertThat(verifyRepositoryResponse.getNodes().size(), equalTo(cluster().numDataAndMasterNodes()));
logger.info("--> verify that we didn't leave any files as a result of verification");
assertThat(FileSystemUtils.files(location).length, equalTo(numberOfFiles));
logger.info("--> check that repository is really there");
ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().clear().setMetadata(true).get();
Metadata metadata = clusterStateResponse.getState().getMetadata();
RepositoriesMetadata repositoriesMetadata = metadata.custom(RepositoriesMetadata.TYPE);
assertThat(repositoriesMetadata, notNullValue());
assertThat(repositoriesMetadata.repository("test-repo-1"), notNullValue());
assertThat(repositoriesMetadata.repository("test-repo-1").type(), equalTo("fs"));
logger.info("--> creating another repository");
createRepository("test-repo-2", "fs");
logger.info("--> check that both repositories are in cluster state");
clusterStateResponse = client.admin().cluster().prepareState().clear().setMetadata(true).get();
metadata = clusterStateResponse.getState().getMetadata();
repositoriesMetadata = metadata.custom(RepositoriesMetadata.TYPE);
assertThat(repositoriesMetadata, notNullValue());
assertThat(repositoriesMetadata.repositories().size(), equalTo(2));
assertThat(repositoriesMetadata.repository("test-repo-1"), notNullValue());
assertThat(repositoriesMetadata.repository("test-repo-1").type(), equalTo("fs"));
assertThat(repositoriesMetadata.repository("test-repo-2"), notNullValue());
assertThat(repositoriesMetadata.repository("test-repo-2").type(), equalTo("fs"));
logger.info("--> check that both repositories can be retrieved by getRepositories query");
GetRepositoriesResponse repositoriesResponse = client.admin().cluster().prepareGetRepositories(randomFrom("_all", "*", "test-repo-*")).get();
assertThat(repositoriesResponse.repositories().size(), equalTo(2));
assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-1"), notNullValue());
assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-2"), notNullValue());
logger.info("--> check that trying to create a repository with the same settings repeatedly does not update cluster state");
String beforeStateUuid = clusterStateResponse.getState().stateUUID();
assertThat(client.admin().cluster().preparePutRepository("test-repo-1").setType("fs").setSettings(Settings.builder().put("location", location)).get().isAcknowledged(), equalTo(true));
assertEquals(beforeStateUuid, client.admin().cluster().prepareState().clear().get().getState().stateUUID());
logger.info("--> delete repository test-repo-1");
client.admin().cluster().prepareDeleteRepository("test-repo-1").get();
repositoriesResponse = client.admin().cluster().prepareGetRepositories().get();
assertThat(repositoriesResponse.repositories().size(), equalTo(1));
assertThat(findRepository(repositoriesResponse.repositories(), "test-repo-2"), notNullValue());
logger.info("--> delete repository test-repo-2");
client.admin().cluster().prepareDeleteRepository("test-repo-2").get();
repositoriesResponse = client.admin().cluster().prepareGetRepositories().get();
assertThat(repositoriesResponse.repositories().size(), equalTo(0));
}
Aggregations