Search in sources :

Example 1 with ClusterStateRequest

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

the class RestClusterGetSettingsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest().routingTable(false).nodes(false);
    final boolean renderDefaults = request.paramAsBoolean("include_defaults", false);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestBuilderListener<ClusterStateResponse>(channel) {

        @Override
        public RestResponse buildResponse(ClusterStateResponse response, XContentBuilder builder) throws Exception {
            return new BytesRestResponse(RestStatus.OK, renderResponse(response.getState(), renderDefaults, builder, request));
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) SettingsFilter(org.elasticsearch.common.settings.SettingsFilter) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) ToXContent(org.elasticsearch.common.xcontent.ToXContent) Set(java.util.Set) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) Settings(org.elasticsearch.common.settings.Settings) RestStatus(org.elasticsearch.rest.RestStatus) RestRequest(org.elasticsearch.rest.RestRequest) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Requests(org.elasticsearch.client.Requests) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IOException(java.io.IOException)

Example 2 with ClusterStateRequest

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

the class RestClusterStateAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest();
    clusterStateRequest.indicesOptions(IndicesOptions.fromRequest(request, clusterStateRequest.indicesOptions()));
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    final String[] indices = Strings.splitStringByCommaToArray(request.param("indices", "_all"));
    boolean isAllIndicesOnly = indices.length == 1 && "_all".equals(indices[0]);
    if (!isAllIndicesOnly) {
        clusterStateRequest.indices(indices);
    }
    if (request.hasParam("metric")) {
        EnumSet<ClusterState.Metric> metrics = ClusterState.Metric.parseString(request.param("metric"), true);
        // do not ask for what we do not need.
        clusterStateRequest.nodes(metrics.contains(ClusterState.Metric.NODES) || metrics.contains(ClusterState.Metric.MASTER_NODE));
        /*
             * there is no distinction in Java api between routing_table and routing_nodes, it's the same info set over the wire, one single
             * flag to ask for it
             */
        clusterStateRequest.routingTable(metrics.contains(ClusterState.Metric.ROUTING_TABLE) || metrics.contains(ClusterState.Metric.ROUTING_NODES));
        clusterStateRequest.metaData(metrics.contains(ClusterState.Metric.METADATA));
        clusterStateRequest.blocks(metrics.contains(ClusterState.Metric.BLOCKS));
        clusterStateRequest.customs(metrics.contains(ClusterState.Metric.CUSTOMS));
    }
    settingsFilter.addFilterSettingParams(request);
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestBuilderListener<ClusterStateResponse>(channel) {

        @Override
        public RestResponse buildResponse(ClusterStateResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            builder.field(Fields.CLUSTER_NAME, response.getClusterName().value());
            builder.byteSizeField(Fields.CLUSTER_STATE_SIZE_IN_BYTES, Fields.CLUSTER_STATE_SIZE, response.getTotalCompressedSize());
            response.getState().toXContent(builder, request);
            builder.endObject();
            return new BytesRestResponse(RestStatus.OK, builder);
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) SettingsFilter(org.elasticsearch.common.settings.SettingsFilter) RestResponse(org.elasticsearch.rest.RestResponse) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) Set(java.util.Set) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) HashSet(java.util.HashSet) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) RestStatus(org.elasticsearch.rest.RestStatus) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Requests(org.elasticsearch.client.Requests) Collections(java.util.Collections) EnumSet(java.util.EnumSet) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) IOException(java.io.IOException) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 3 with ClusterStateRequest

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

the class RestIndicesAction 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.clear().indices(indices).metaData(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    final IndicesOptions strictExpandIndicesOptions = IndicesOptions.strictExpand();
    clusterStateRequest.indicesOptions(strictExpandIndicesOptions);
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            final ClusterState state = clusterStateResponse.getState();
            final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, strictExpandIndicesOptions, indices);
            assert concreteIndices.length == state.metaData().getIndices().size();
            ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(indices);
            clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local()));
            client.admin().cluster().health(clusterHealthRequest, new RestActionListener<ClusterHealthResponse>(channel) {

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

                        @Override
                        public RestResponse buildResponse(IndicesStatsResponse indicesStatsResponse) throws Exception {
                            Table tab = buildTable(request, concreteIndices, clusterHealthResponse, indicesStatsResponse, state.metaData());
                            return RestTable.buildResponse(tab, channel);
                        }
                    });
                }
            });
        }
    });
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) GET(org.elasticsearch.rest.RestRequest.Method.GET) Table(org.elasticsearch.common.Table) IndexStats(org.elasticsearch.action.admin.indices.stats.IndexStats) Index(org.elasticsearch.index.Index) ClusterIndexHealth(org.elasticsearch.cluster.health.ClusterIndexHealth) Strings(org.elasticsearch.common.Strings) HashSet(java.util.HashSet) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) ClusterState(org.elasticsearch.cluster.ClusterState) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest) Settings(org.elasticsearch.common.settings.Settings) Locale(java.util.Locale) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Requests(org.elasticsearch.client.Requests) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) RestResponse(org.elasticsearch.rest.RestResponse) DateTime(org.joda.time.DateTime) Set(java.util.Set) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) RestController(org.elasticsearch.rest.RestController) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Collections(java.util.Collections) RestActionListener(org.elasticsearch.rest.action.RestActionListener) ClusterState(org.elasticsearch.cluster.ClusterState) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) Table(org.elasticsearch.common.Table) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) 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) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) IndicesStatsRequest(org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest)

Example 4 with ClusterStateRequest

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

the class RestNodeAttrsAction 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().jvm(false).os(false).process(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestResponseListener<NodesInfoResponse>(channel) {

                @Override
                public RestResponse buildResponse(NodesInfoResponse nodesInfoResponse) throws Exception {
                    return RestTable.buildResponse(buildTable(request, clusterStateResponse, nodesInfoResponse), channel);
                }
            });
        }
    });
}
Also used : DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) RestRequest(org.elasticsearch.rest.RestRequest) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) NodeClient(org.elasticsearch.client.node.NodeClient) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) RestActionListener(org.elasticsearch.rest.action.RestActionListener) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)

Example 5 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)

Aggregations

ClusterStateRequest (org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)25 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)20 Settings (org.elasticsearch.common.settings.Settings)15 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)9 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 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)6 Set (java.util.Set)5 Map (java.util.Map)4 NodeInfo (org.elasticsearch.action.admin.cluster.node.info.NodeInfo)4