Search in sources :

Example 6 with ClusterStateRequest

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

the class RestAllocationAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final String[] nodes = Strings.splitStringByCommaToArray(request.param("nodes", "data:true"));
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().routingTable(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse state) {
            NodesStatsRequest statsRequest = new NodesStatsRequest(nodes);
            statsRequest.clear().fs(true).indices(new CommonStatsFlags(CommonStatsFlags.Flag.Store));
            client.admin().cluster().nodesStats(statsRequest, new RestResponseListener<NodesStatsResponse>(channel) {

                @Override
                public RestResponse buildResponse(NodesStatsResponse stats) throws Exception {
                    Table tab = buildTable(request, state, stats);
                    return RestTable.buildResponse(tab, channel);
                }
            });
        }
    });
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) Strings(org.elasticsearch.common.Strings) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) RestRequest(org.elasticsearch.rest.RestRequest) ObjectIntScatterMap(com.carrotsearch.hppc.ObjectIntScatterMap) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) CommonStatsFlags(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags) NodeClient(org.elasticsearch.client.node.NodeClient) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) RestActionListener(org.elasticsearch.rest.action.RestActionListener) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) Table(org.elasticsearch.common.Table) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) CommonStatsFlags(org.elasticsearch.action.admin.indices.stats.CommonStatsFlags) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)

Example 7 with ClusterStateRequest

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

the class RestShardsAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    clusterStateRequest.clear().nodes(true).metaData(true).routingTable(true).indices(indices);
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
            indicesStatsRequest.all();
            indicesStatsRequest.indices(indices);
            client.admin().indices().stats(indicesStatsRequest, new RestResponseListener<IndicesStatsResponse>(channel) {

                @Override
                public RestResponse buildResponse(IndicesStatsResponse indicesStatsResponse) throws Exception {
                    return RestTable.buildResponse(buildTable(request, clusterStateResponse, indicesStatsResponse), channel);
                }
            });
        }
    });
}
Also used : ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) CommitStats(org.elasticsearch.index.engine.CommitStats) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) Table(org.elasticsearch.common.Table) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) Engine(org.elasticsearch.index.engine.Engine) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest) Settings(org.elasticsearch.common.settings.Settings) ShardStats(org.elasticsearch.action.admin.indices.stats.ShardStats) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Locale(java.util.Locale) TimeValue(org.elasticsearch.common.unit.TimeValue) RestRequest(org.elasticsearch.rest.RestRequest) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) NodeClient(org.elasticsearch.client.node.NodeClient) CommonStats(org.elasticsearch.action.admin.indices.stats.CommonStats) RestActionListener(org.elasticsearch.rest.action.RestActionListener) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest)

Example 8 with ClusterStateRequest

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

the class RestThreadPoolAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.clear().process(true).threadPool(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {

                @Override
                public void processResponse(final NodesInfoResponse nodesInfoResponse) {
                    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
                    nodesStatsRequest.clear().threadPool(true);
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {

                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
Also used : GET(org.elasticsearch.rest.RestRequest.Method.GET) Table(org.elasticsearch.common.Table) HashMap(java.util.HashMap) HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Regex(org.elasticsearch.common.regex.Regex) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ThreadPoolStats(org.elasticsearch.threadpool.ThreadPoolStats) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) RestResponse(org.elasticsearch.rest.RestResponse) Set(java.util.Set) RestController(org.elasticsearch.rest.RestController) NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest) TreeMap(java.util.TreeMap) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) Collections(java.util.Collections) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) RestActionListener(org.elasticsearch.rest.action.RestActionListener) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponse(org.elasticsearch.rest.RestResponse) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.elasticsearch.rest.action.RestActionListener) NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)

Example 9 with ClusterStateRequest

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

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

the class Indices method isReopened.

public boolean isReopened(String indexName) {
    final ClusterState clusterState = c.admin().cluster().state(new ClusterStateRequest()).actionGet().getState();
    final IndexMetaData metaData = clusterState.getMetaData().getIndices().get(indexName);
    return checkForReopened(metaData);
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

ClusterStateRequest (org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)21 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)17 Settings (org.elasticsearch.common.settings.Settings)14 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 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 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)8 RestActionListener (org.elasticsearch.rest.action.RestActionListener)8 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)7 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)7 Strings (org.elasticsearch.common.Strings)7 Set (java.util.Set)5 Map (java.util.Map)4 NodeInfo (org.elasticsearch.action.admin.cluster.node.info.NodeInfo)4 NodesInfoRequest (org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)4