Search in sources :

Example 26 with ClusterStateResponse

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

the class TransportClientRetryIT method testRetry.

public void testRetry() throws IOException, ExecutionException, InterruptedException {
    Iterable<TransportService> instances = internalCluster().getInstances(TransportService.class);
    TransportAddress[] addresses = new TransportAddress[internalCluster().size()];
    int i = 0;
    for (TransportService instance : instances) {
        addresses[i++] = instance.boundAddress().publishAddress();
    }
    Settings.Builder builder = Settings.builder().put("client.transport.nodes_sampler_interval", "1s").put("node.name", "transport_client_retry_test").put(ClusterName.CLUSTER_NAME_SETTING.getKey(), internalCluster().getClusterName()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir());
    try (TransportClient client = new MockTransportClient(builder.build())) {
        client.addTransportAddresses(addresses);
        assertEquals(client.connectedNodes().size(), internalCluster().size());
        int size = cluster().size();
        //kill all nodes one by one, leaving a single master/data node at the end of the loop
        for (int j = 1; j < size; j++) {
            internalCluster().stopRandomNode(input -> true);
            ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest().local(true);
            ClusterState clusterState;
            //use both variants of execute method: with and without listener
            if (randomBoolean()) {
                clusterState = client.admin().cluster().state(clusterStateRequest).get().getState();
            } else {
                PlainListenableActionFuture<ClusterStateResponse> future = new PlainListenableActionFuture<>(client.threadPool());
                client.admin().cluster().state(clusterStateRequest, future);
                clusterState = future.get().getState();
            }
            assertThat(clusterState.nodes().getSize(), greaterThanOrEqualTo(size - j));
            assertThat(client.connectedNodes().size(), greaterThanOrEqualTo(size - j));
        }
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MockTransportClient(org.elasticsearch.transport.MockTransportClient) TransportAddress(org.elasticsearch.common.transport.TransportAddress) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) MockTransportClient(org.elasticsearch.transport.MockTransportClient) TransportService(org.elasticsearch.transport.TransportService) PlainListenableActionFuture(org.elasticsearch.action.support.PlainListenableActionFuture) Settings(org.elasticsearch.common.settings.Settings)

Example 27 with ClusterStateResponse

use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project graylog2-server by Graylog2.

the class Indices method areReopened.

public Map<String, Boolean> areReopened(Collection<String> indices) {
    final ClusterStateResponse clusterState = c.admin().cluster().prepareState().all().get();
    final ImmutableOpenMap<String, IndexMetaData> indicesMetaData = clusterState.getState().getMetaData().getIndices();
    return indices.stream().collect(Collectors.toMap(index -> index, index -> checkForReopened(indicesMetaData.get(index))));
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) GetAliasesResponse(org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse) SortBuilders(org.elasticsearch.search.sort.SortBuilders) DateTimeZone(org.joda.time.DateTimeZone) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) LoggerFactory(org.slf4j.LoggerFactory) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) IndexClosedException(org.elasticsearch.indices.IndexClosedException) QueryBuilders(org.elasticsearch.index.query.QueryBuilders) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) ClusterState(org.elasticsearch.cluster.ClusterState) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest) Settings(org.elasticsearch.common.settings.Settings) WriteConsistencyLevel(org.elasticsearch.action.WriteConsistencyLevel) PutIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) IndexRangeStats(org.graylog2.indexer.searches.IndexRangeStats) IndexSet(org.graylog2.indexer.IndexSet) IndexMapping(org.graylog2.indexer.IndexMapping) Max(org.elasticsearch.search.aggregations.metrics.max.Max) Collectors.toSet(java.util.stream.Collectors.toSet) SearchHit(org.elasticsearch.search.SearchHit) SearchType(org.elasticsearch.action.search.SearchType) ImmutableSet(com.google.common.collect.ImmutableSet) Min(org.elasticsearch.search.aggregations.metrics.min.Min) ImmutableMap(com.google.common.collect.ImmutableMap) Terms(org.elasticsearch.search.aggregations.bucket.terms.Terms) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) Collection(java.util.Collection) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) Set(java.util.Set) FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) List(java.util.List) AuditActor(org.graylog2.audit.AuditActor) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) Optional(java.util.Optional) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) HashMap(java.util.HashMap) SearchRequest(org.elasticsearch.action.search.SearchRequest) Singleton(javax.inject.Singleton) ActionFuture(org.elasticsearch.action.ActionFuture) OpenIndexRequest(org.elasticsearch.action.admin.indices.open.OpenIndexRequest) UpdateSettingsRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) ForceMergeRequest(org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest) XContentHelper(org.elasticsearch.common.xcontent.XContentHelper) Inject(javax.inject.Inject) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) GetIndexRequestBuilder(org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder) ImmutableList(com.google.common.collect.ImmutableList) NodeId(org.graylog2.plugin.system.NodeId) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) TimeValue(org.elasticsearch.common.unit.TimeValue) ES_INDEX_CREATE(org.graylog2.audit.AuditEventTypes.ES_INDEX_CREATE) GetIndexResponse(org.elasticsearch.action.admin.indices.get.GetIndexResponse) Duration(com.github.joschi.jadconfig.util.Duration) Messages(org.graylog2.indexer.messages.Messages) AuditEventSender(org.graylog2.audit.AuditEventSender) Nullable(javax.annotation.Nullable) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) Logger(org.slf4j.Logger) QueryBuilders.matchAllQuery(org.elasticsearch.index.query.QueryBuilders.matchAllQuery) GetIndexRequest(org.elasticsearch.action.admin.indices.get.GetIndexRequest) IndexNotFoundException(org.graylog2.indexer.IndexNotFoundException) Client(org.elasticsearch.client.Client) DateTime(org.joda.time.DateTime) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) AggregationBuilders(org.elasticsearch.search.aggregations.AggregationBuilders) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) TimeUnit(java.util.concurrent.TimeUnit) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) FlushRequest(org.elasticsearch.action.admin.indices.flush.FlushRequest) DocsStats(org.elasticsearch.index.shard.DocsStats) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SortParseElement(org.elasticsearch.search.sort.SortParseElement) UnmodifiableIterator(com.google.common.collect.UnmodifiableIterator) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) Collections(java.util.Collections) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 28 with ClusterStateResponse

use of org.elasticsearch.action.admin.cluster.state.ClusterStateResponse in project graylog2-server by Graylog2.

the class IndicesTest method testClose.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testClose() throws Exception {
    final ClusterStateRequest beforeRequest = client.admin().cluster().prepareState().setIndices(INDEX_NAME).request();
    final ClusterStateResponse beforeResponse = client.admin().cluster().state(beforeRequest).actionGet(ES_TIMEOUT);
    assertThat(beforeResponse.getState().getMetaData().getConcreteAllOpenIndices()).containsExactly(INDEX_NAME);
    indices.close(INDEX_NAME);
    final ClusterStateRequest request = client.admin().cluster().prepareState().setIndices(INDEX_NAME).request();
    final ClusterStateResponse response = client.admin().cluster().state(request).actionGet(ES_TIMEOUT);
    assertThat(response.getState().getMetaData().getConcreteAllClosedIndices()).containsExactly(INDEX_NAME);
}
Also used : ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 29 with ClusterStateResponse

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

the class SQLTransportIntegrationTest method getIndexSettings.

/**
     * Get the IndexSettings as JSON String
     *
     * @param index the name of the index
     * @return the IndexSettings as JSON String
     * @throws IOException
     */
protected String getIndexSettings(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();
    for (IndexMetaData indexMetaData : metaData) {
        builder.startObject(indexMetaData.getIndex(), XContentBuilder.FieldCaseConversion.NONE);
        builder.startObject("settings");
        Settings settings = indexMetaData.getSettings();
        for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
            builder.field(entry.getKey(), entry.getValue());
        }
        builder.endObject();
        builder.endObject();
    }
    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) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 30 with ClusterStateResponse

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

the class SnapshotRestoreIntegrationTest method waitForCompletion.

private SnapshotInfo waitForCompletion(String repository, String snapshot, TimeValue timeout) throws InterruptedException {
    long start = System.currentTimeMillis();
    SnapshotId snapshotId = new SnapshotId(repository, snapshot);
    while (System.currentTimeMillis() - start < timeout.millis()) {
        List<SnapshotInfo> snapshotInfos = client().admin().cluster().prepareGetSnapshots(repository).setSnapshots(snapshot).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().getMetaData().custom(SnapshotsInProgress.TYPE);
            if (snapshotsInProgress == null || snapshotsInProgress.snapshot(snapshotId) == null) {
                return snapshotInfos.get(0);
            }
        }
        Thread.sleep(100);
    }
    fail("Timeout waiting for snapshot completion!");
    return null;
}
Also used : SnapshotId(org.elasticsearch.cluster.metadata.SnapshotId) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) SnapshotsInProgress(org.elasticsearch.cluster.SnapshotsInProgress)

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