Search in sources :

Example 1 with VerifyRepositoryResponse

use of org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse in project OpenSearch by opensearch-project.

the class SnapshotIT method testVerifyRepository.

public void testVerifyRepository() throws IOException {
    AcknowledgedResponse putRepositoryResponse = createTestRepository("test", FsRepository.TYPE, "{\"location\": \".\"}");
    assertTrue(putRepositoryResponse.isAcknowledged());
    VerifyRepositoryRequest request = new VerifyRepositoryRequest("test");
    VerifyRepositoryResponse response = execute(request, highLevelClient().snapshot()::verifyRepository, highLevelClient().snapshot()::verifyRepositoryAsync);
    assertThat(response.getNodes().size(), equalTo(1));
}
Also used : AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) VerifyRepositoryResponse(org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse) VerifyRepositoryRequest(org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest)

Example 2 with VerifyRepositoryResponse

use of org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse in project OpenSearch by opensearch-project.

the class RepositoryBlocksIT method testVerifyRepositoryWithBlocks.

public void testVerifyRepositoryWithBlocks() {
    assertAcked(client().admin().cluster().preparePutRepository("test-repo-blocks").setType("fs").setVerify(false).setSettings(Settings.builder().put("location", randomRepoPath())));
    // This test checks that the Get Repository operation is never blocked, even if the cluster is read only.
    try {
        setClusterReadOnly(true);
        VerifyRepositoryResponse response = client().admin().cluster().prepareVerifyRepository("test-repo-blocks").execute().actionGet();
        assertThat(response.getNodes().size(), equalTo(cluster().numDataAndMasterNodes()));
    } finally {
        setClusterReadOnly(false);
    }
}
Also used : VerifyRepositoryResponse(org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse)

Example 3 with VerifyRepositoryResponse

use of org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse 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)

Example 4 with VerifyRepositoryResponse

use of org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse in project OpenSearch by opensearch-project.

the class SnapshotClientDocumentationIT method testSnapshotVerifyRepository.

public void testSnapshotVerifyRepository() throws IOException {
    RestHighLevelClient client = highLevelClient();
    createTestRepositories();
    // tag::verify-repository-request
    VerifyRepositoryRequest request = new VerifyRepositoryRequest(repositoryName);
    // end::verify-repository-request
    // tag::verify-repository-request-masterTimeout
    // <1>
    request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
    // <2>
    request.masterNodeTimeout("1m");
    // end::verify-repository-request-masterTimeout
    // tag::verify-repository-request-timeout
    // <1>
    request.timeout(TimeValue.timeValueMinutes(1));
    // <2>
    request.timeout("1m");
    // end::verify-repository-request-timeout
    // tag::verify-repository-execute
    VerifyRepositoryResponse response = client.snapshot().verifyRepository(request, RequestOptions.DEFAULT);
    // end::verify-repository-execute
    // tag::verify-repository-response
    List<VerifyRepositoryResponse.NodeView> repositoryMetadataResponse = response.getNodes();
    // end::verify-repository-response
    assertThat(1, equalTo(repositoryMetadataResponse.size()));
    final boolean async = Booleans.parseBoolean(System.getProperty("tests.rest.async", "false"));
    if (async) {
        assertThat("asyncIntegTest-0", equalTo(repositoryMetadataResponse.get(0).getName()));
    } else {
        assertThat("integTest-0", equalTo(repositoryMetadataResponse.get(0).getName()));
    }
}
Also used : VerifyRepositoryResponse(org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) VerifyRepositoryRequest(org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest)

Example 5 with VerifyRepositoryResponse

use of org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse in project OpenSearch by opensearch-project.

the class SnapshotBlocksIT method setUpRepository.

@Before
protected void setUpRepository() throws Exception {
    createIndex(INDEX_NAME, OTHER_INDEX_NAME);
    int docs = between(10, 100);
    for (int i = 0; i < docs; i++) {
        client().prepareIndex(INDEX_NAME).setSource("test", "init").execute().actionGet();
    }
    docs = between(10, 100);
    for (int i = 0; i < docs; i++) {
        client().prepareIndex(OTHER_INDEX_NAME).setSource("test", "init").execute().actionGet();
    }
    logger.info("--> register a repository");
    assertAcked(client().admin().cluster().preparePutRepository(REPOSITORY_NAME).setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())));
    logger.info("--> verify the repository");
    VerifyRepositoryResponse verifyResponse = client().admin().cluster().prepareVerifyRepository(REPOSITORY_NAME).get();
    assertThat(verifyResponse.getNodes().size(), equalTo(cluster().numDataAndMasterNodes()));
    logger.info("--> create a snapshot");
    CreateSnapshotResponse snapshotResponse = client().admin().cluster().prepareCreateSnapshot(REPOSITORY_NAME, SNAPSHOT_NAME).setIncludeGlobalState(true).setWaitForCompletion(true).execute().actionGet();
    assertThat(snapshotResponse.status(), equalTo(RestStatus.OK));
    ensureSearchable();
}
Also used : CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) VerifyRepositoryResponse(org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse) Before(org.junit.Before)

Aggregations

VerifyRepositoryResponse (org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse)5 VerifyRepositoryRequest (org.opensearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest)2 Path (java.nio.file.Path)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Before (org.junit.Before)1 GetRepositoriesResponse (org.opensearch.action.admin.cluster.repositories.get.GetRepositoriesResponse)1 CreateSnapshotResponse (org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)1 ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)1 AcknowledgedResponse (org.opensearch.action.support.master.AcknowledgedResponse)1 Client (org.opensearch.client.Client)1 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)1 Metadata (org.opensearch.cluster.metadata.Metadata)1 RepositoriesMetadata (org.opensearch.cluster.metadata.RepositoriesMetadata)1 RepositoryMetadata (org.opensearch.cluster.metadata.RepositoryMetadata)1