Search in sources :

Example 1 with GetRepositoriesResponse

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()));
}
Also used : GetRepositoriesRequest(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) GetRepositoriesResponse(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse)

Example 2 with GetRepositoriesResponse

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()));
}
Also used : GetRepositoriesRequest(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) GetRepositoriesResponse(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse)

Example 3 with GetRepositoriesResponse

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()));
}
Also used : RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) GetRepositoriesRequest(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) GetRepositoriesResponse(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse)

Example 4 with GetRepositoriesResponse

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));
}
Also used : FsRepository(org.opensearch.repositories.fs.FsRepository) MockRepository(org.opensearch.snapshots.mockstore.MockRepository) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) InternalTestCluster(org.opensearch.test.InternalTestCluster) Client(org.opensearch.client.Client) GetRepositoriesResponse(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse) Settings(org.opensearch.common.settings.Settings) FsRepository(org.opensearch.repositories.fs.FsRepository)

Example 5 with GetRepositoriesResponse

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));
}
Also used : Path(java.nio.file.Path) RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) Metadata(org.opensearch.cluster.metadata.Metadata) RepositoriesMetadata(org.opensearch.cluster.metadata.RepositoriesMetadata) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) VerifyRepositoryResponse(org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Client(org.opensearch.client.Client) GetRepositoriesResponse(org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse)

Aggregations

GetRepositoriesResponse (org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse)8 GetRepositoriesRequest (org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesRequest)5 RepositoryMetadata (org.opensearch.cluster.metadata.RepositoryMetadata)4 Client (org.opensearch.client.Client)2 Path (java.nio.file.Path)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 DeleteRepositoryRequest (org.opensearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest)1 VerifyRepositoryResponse (org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse)1 ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)1 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)1 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)1 NodeClient (org.opensearch.client.node.NodeClient)1 Metadata (org.opensearch.cluster.metadata.Metadata)1 RepositoriesMetadata (org.opensearch.cluster.metadata.RepositoriesMetadata)1 Table (org.opensearch.common.Table)1 Settings (org.opensearch.common.settings.Settings)1 FsRepository (org.opensearch.repositories.fs.FsRepository)1 RestRequest (org.opensearch.rest.RestRequest)1