Search in sources :

Example 1 with VerifyRepositoryResponse

use of org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse in project elasticsearch by elastic.

the class RepositoriesIT method testRepositoryCreation.

public void testRepositoryCreation() throws Exception {
    Client client = client();
    Path location = randomRepoPath();
    logger.info("-->  creating repository");
    PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo-1").setType("fs").setSettings(Settings.builder().put("location", location)).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    logger.info("--> verify the repository");
    int numberOfFiles = FileSystemUtils.files(location).length;
    VerifyRepositoryResponse verifyRepositoryResponse = client.admin().cluster().prepareVerifyRepository("test-repo-1").get();
    assertThat(verifyRepositoryResponse.getNodes().length, 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");
    putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo-2").setType("fs").setSettings(Settings.builder().put("location", randomRepoPath())).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    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("--> 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.elasticsearch.cluster.metadata.RepositoriesMetaData) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) MetaData(org.elasticsearch.cluster.metadata.MetaData) RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) VerifyRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) Client(org.elasticsearch.client.Client) GetRepositoriesResponse(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse)

Example 2 with VerifyRepositoryResponse

use of org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse in project elasticsearch by elastic.

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().length, equalTo(cluster().numDataAndMasterNodes()));
    } finally {
        setClusterReadOnly(false);
    }
}
Also used : VerifyRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse)

Example 3 with VerifyRepositoryResponse

use of org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse in project elasticsearch by elastic.

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, "type").setSource("test", "init").execute().actionGet();
    }
    docs = between(10, 100);
    for (int i = 0; i < docs; i++) {
        client().prepareIndex(OTHER_INDEX_NAME, "type").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().length, 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.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) VerifyRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse) Before(org.junit.Before)

Aggregations

VerifyRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse)3 Path (java.nio.file.Path)1 GetRepositoriesResponse (org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse)1 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)1 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)1 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)1 Client (org.elasticsearch.client.Client)1 MetaData (org.elasticsearch.cluster.metadata.MetaData)1 RepositoriesMetaData (org.elasticsearch.cluster.metadata.RepositoriesMetaData)1 RepositoryMetaData (org.elasticsearch.cluster.metadata.RepositoryMetaData)1 Before (org.junit.Before)1