Search in sources :

Example 1 with GetRepositoriesResponse

use of org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse 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 GetRepositoriesResponse

use of org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse in project elasticsearch by elastic.

the class RepositoryBlocksIT method testGetRepositoryWithBlocks.

public void testGetRepositoryWithBlocks() {
    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);
        GetRepositoriesResponse response = client().admin().cluster().prepareGetRepositories("test-repo-blocks").execute().actionGet();
        assertThat(response.repositories(), hasSize(1));
    } finally {
        setClusterReadOnly(false);
    }
}
Also used : GetRepositoriesResponse(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse)

Example 3 with GetRepositoriesResponse

use of org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse in project elasticsearch by elastic.

the class RestGetRepositoriesAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] repositories = request.paramAsStringArray("repository", Strings.EMPTY_ARRAY);
    GetRepositoriesRequest getRepositoriesRequest = getRepositoryRequest(repositories);
    getRepositoriesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getRepositoriesRequest.masterNodeTimeout()));
    getRepositoriesRequest.local(request.paramAsBoolean("local", getRepositoriesRequest.local()));
    settingsFilter.addFilterSettingParams(request);
    return channel -> client.admin().cluster().getRepositories(getRepositoriesRequest, new RestBuilderListener<GetRepositoriesResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetRepositoriesResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            for (RepositoryMetaData repositoryMetaData : response.repositories()) {
                RepositoriesMetaData.toXContent(repositoryMetaData, builder, request);
            }
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) SettingsFilter(org.elasticsearch.common.settings.SettingsFilter) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) Set(java.util.Set) Requests.getRepositoryRequest(org.elasticsearch.client.Requests.getRepositoryRequest) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) GetRepositoriesResponse(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse) Strings(org.elasticsearch.common.Strings) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) GetRepositoriesRequest(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) GetRepositoriesRequest(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) GetRepositoriesResponse(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IOException(java.io.IOException)

Example 4 with GetRepositoriesResponse

use of org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse in project elasticsearch by elastic.

the class RestRepositoriesAction method doCatRequest.

@Override
protected RestChannelConsumer doCatRequest(RestRequest request, NodeClient client) {
    GetRepositoriesRequest getRepositoriesRequest = new GetRepositoriesRequest();
    getRepositoriesRequest.local(request.paramAsBoolean("local", getRepositoriesRequest.local()));
    getRepositoriesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getRepositoriesRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().getRepositories(getRepositoriesRequest, new RestResponseListener<GetRepositoriesResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetRepositoriesResponse getRepositoriesResponse) throws Exception {
            return RestTable.buildResponse(buildTable(request, getRepositoriesResponse), channel);
        }
    });
}
Also used : RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) Settings(org.elasticsearch.common.settings.Settings) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) GetRepositoriesRequest(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) GetRepositoriesResponse(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) RestResponse(org.elasticsearch.rest.RestResponse) GetRepositoriesRequest(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest) GetRepositoriesResponse(org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse)

Aggregations

GetRepositoriesResponse (org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesResponse)4 RepositoryMetaData (org.elasticsearch.cluster.metadata.RepositoryMetaData)3 GetRepositoriesRequest (org.elasticsearch.action.admin.cluster.repositories.get.GetRepositoriesRequest)2 NodeClient (org.elasticsearch.client.node.NodeClient)2 RepositoriesMetaData (org.elasticsearch.cluster.metadata.RepositoriesMetaData)2 Settings (org.elasticsearch.common.settings.Settings)2 RestController (org.elasticsearch.rest.RestController)2 RestRequest (org.elasticsearch.rest.RestRequest)2 GET (org.elasticsearch.rest.RestRequest.Method.GET)2 RestResponse (org.elasticsearch.rest.RestResponse)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Set (java.util.Set)1 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)1 VerifyRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse)1 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)1 Client (org.elasticsearch.client.Client)1 Requests.getRepositoryRequest (org.elasticsearch.client.Requests.getRepositoryRequest)1 MetaData (org.elasticsearch.cluster.metadata.MetaData)1 Strings (org.elasticsearch.common.Strings)1