Search in sources :

Example 21 with ClusterStateResponse

use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.

the class AbstractSnapshotIntegTestCase method waitForCompletion.

public SnapshotInfo waitForCompletion(String repository, String snapshotName, TimeValue timeout) throws InterruptedException {
    long start = System.currentTimeMillis();
    while (System.currentTimeMillis() - start < timeout.millis()) {
        List<SnapshotInfo> snapshotInfos = client().admin().cluster().prepareGetSnapshots(repository).setSnapshots(snapshotName).get().getSnapshots();
        assertThat(snapshotInfos.size(), equalTo(1));
        if (snapshotInfos.get(0).state().completed()) {
            // Make sure that snapshot clean up operations are finished
            ClusterStateResponse stateResponse = client().admin().cluster().prepareState().get();
            SnapshotsInProgress snapshotsInProgress = stateResponse.getState().custom(SnapshotsInProgress.TYPE);
            if (snapshotsInProgress == null) {
                return snapshotInfos.get(0);
            } else {
                boolean found = false;
                for (SnapshotsInProgress.Entry entry : snapshotsInProgress.entries()) {
                    final Snapshot curr = entry.snapshot();
                    if (curr.getRepository().equals(repository) && curr.getSnapshotId().getName().equals(snapshotName)) {
                        found = true;
                        break;
                    }
                }
                if (found == false) {
                    return snapshotInfos.get(0);
                }
            }
        }
        Thread.sleep(100);
    }
    fail("Timeout!!!");
    return null;
}
Also used : ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) SnapshotsInProgress(org.elasticsearch.cluster.SnapshotsInProgress)

Example 22 with ClusterStateResponse

use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse 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 23 with ClusterStateResponse

use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.

the class GatewayIndexStateIT method testTwoNodesSingleDoc.

public void testTwoNodesSingleDoc() throws Exception {
    logger.info("--> cleaning nodes");
    logger.info("--> starting 2 nodes");
    internalCluster().startNodes(2);
    logger.info("--> indexing a simple document");
    client().prepareIndex("test", "type1", "1").setSource("field1", "value1").setRefreshPolicy(IMMEDIATE).get();
    logger.info("--> waiting for green status");
    ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));
    logger.info("--> verify 1 doc in the index");
    for (int i = 0; i < 10; i++) {
        assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
    }
    logger.info("--> closing test index...");
    client().admin().indices().prepareClose("test").execute().actionGet();
    ClusterStateResponse stateResponse = client().admin().cluster().prepareState().execute().actionGet();
    assertThat(stateResponse.getState().metaData().index("test").getState(), equalTo(IndexMetaData.State.CLOSE));
    assertThat(stateResponse.getState().routingTable().index("test"), nullValue());
    logger.info("--> opening the index...");
    client().admin().indices().prepareOpen("test").execute().actionGet();
    logger.info("--> waiting for green status");
    health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));
    logger.info("--> verify 1 doc in the index");
    assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
    for (int i = 0; i < 10; i++) {
        assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
    }
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)

Example 24 with ClusterStateResponse

use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project elasticsearch by elastic.

the class GatewayIndexStateIT method testJustMasterNode.

public void testJustMasterNode() throws Exception {
    logger.info("--> cleaning nodes");
    logger.info("--> starting 1 master node non data");
    internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build());
    logger.info("--> create an index");
    client().admin().indices().prepareCreate("test").setWaitForActiveShards(ActiveShardCount.NONE).execute().actionGet();
    logger.info("--> closing master node");
    internalCluster().closeNonSharedNodes(false);
    logger.info("--> starting 1 master node non data again");
    internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build());
    logger.info("--> waiting for test index to be created");
    ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setIndices("test").execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));
    logger.info("--> verify we have an index");
    ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().setIndices("test").execute().actionGet();
    assertThat(clusterStateResponse.getState().metaData().hasIndex("test"), equalTo(true));
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)

Example 25 with ClusterStateResponse

use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project crate by crate.

the class SQLTransportIntegrationTest method getIndexMapping.

/**
     * Get all mappings from an index as JSON String
     *
     * @param index the name of the index
     * @return the index mapping as String
     * @throws IOException
     */
protected String getIndexMapping(String index) throws IOException {
    ClusterStateRequest request = Requests.clusterStateRequest().routingTable(false).nodes(false).metaData(true).indices(index);
    ClusterStateResponse response = client().admin().cluster().state(request).actionGet();
    MetaData metaData = response.getState().metaData();
    XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
    IndexMetaData indexMetaData = metaData.iterator().next();
    for (ObjectCursor<MappingMetaData> cursor : indexMetaData.getMappings().values()) {
        builder.field(cursor.value.type());
        builder.map(cursor.value.sourceAsMap());
    }
    builder.endObject();
    return builder.string();
}
Also used : ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) MetaData(org.elasticsearch.cluster.metadata.MetaData) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)52 Settings (org.elasticsearch.common.settings.Settings)20 ClusterStateRequest (org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)18 NodeClient (org.elasticsearch.client.node.NodeClient)12 RestController (org.elasticsearch.rest.RestController)12 RestRequest (org.elasticsearch.rest.RestRequest)12 RestResponse (org.elasticsearch.rest.RestResponse)12 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)10 Table (org.elasticsearch.common.Table)10 GET (org.elasticsearch.rest.RestRequest.Method.GET)10 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)10 ClusterState (org.elasticsearch.cluster.ClusterState)9 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)9 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)8 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)8 RestActionListener (org.elasticsearch.rest.action.RestActionListener)8 Strings (org.elasticsearch.common.Strings)7 MetaData (org.elasticsearch.cluster.metadata.MetaData)6 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)6 IOException (java.io.IOException)5