Search in sources :

Example 1 with NodesInfoRequest

use of org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest 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 2 with NodesInfoRequest

use of org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest in project elasticsearch by elastic.

the class RestNodesInfoAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String[] nodeIds;
    Set<String> metrics;
    // this means one must differentiate between allowed metrics and arbitrary node ids in the same place
    if (request.hasParam("nodeId") && !request.hasParam("metrics")) {
        Set<String> metricsOrNodeIds = Strings.splitStringByCommaToSet(request.param("nodeId", "_all"));
        boolean isMetricsOnly = ALLOWED_METRICS.containsAll(metricsOrNodeIds);
        if (isMetricsOnly) {
            nodeIds = new String[] { "_all" };
            metrics = metricsOrNodeIds;
        } else {
            nodeIds = metricsOrNodeIds.toArray(new String[] {});
            metrics = Sets.newHashSet("_all");
        }
    } else {
        nodeIds = Strings.splitStringByCommaToArray(request.param("nodeId", "_all"));
        metrics = Strings.splitStringByCommaToSet(request.param("metrics", "_all"));
    }
    final NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(nodeIds);
    nodesInfoRequest.timeout(request.param("timeout"));
    // shortcut, don't do checks if only all is specified
    if (metrics.size() == 1 && metrics.contains("_all")) {
        nodesInfoRequest.all();
    } else {
        nodesInfoRequest.clear();
        nodesInfoRequest.settings(metrics.contains("settings"));
        nodesInfoRequest.os(metrics.contains("os"));
        nodesInfoRequest.process(metrics.contains("process"));
        nodesInfoRequest.jvm(metrics.contains("jvm"));
        nodesInfoRequest.threadPool(metrics.contains("thread_pool"));
        nodesInfoRequest.transport(metrics.contains("transport"));
        nodesInfoRequest.http(metrics.contains("http"));
        nodesInfoRequest.plugins(metrics.contains("plugins"));
        nodesInfoRequest.ingest(metrics.contains("ingest"));
        nodesInfoRequest.indices(metrics.contains("indices"));
    }
    settingsFilter.addFilterSettingParams(request);
    return channel -> client.admin().cluster().nodesInfo(nodesInfoRequest, new NodesResponseRestListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) SettingsFilter(org.elasticsearch.common.settings.SettingsFilter) GET(org.elasticsearch.rest.RestRequest.Method.GET) Set(java.util.Set) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Sets(org.elasticsearch.common.util.set.Sets) Strings(org.elasticsearch.common.Strings) NodesResponseRestListener(org.elasticsearch.rest.action.RestActions.NodesResponseRestListener) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)

Example 3 with NodesInfoRequest

use of org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest 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 4 with NodesInfoRequest

use of org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest in project elasticsearch by elastic.

the class PutPipelineTransportAction method masterOperation.

@Override
protected void masterOperation(PutPipelineRequest request, ClusterState state, ActionListener<WritePipelineResponse> listener) throws Exception {
    NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
    nodesInfoRequest.clear();
    nodesInfoRequest.ingest(true);
    nodesInfoAction.execute(nodesInfoRequest, new ActionListener<NodesInfoResponse>() {

        @Override
        public void onResponse(NodesInfoResponse nodeInfos) {
            try {
                Map<DiscoveryNode, IngestInfo> ingestInfos = new HashMap<>();
                for (NodeInfo nodeInfo : nodeInfos.getNodes()) {
                    ingestInfos.put(nodeInfo.getNode(), nodeInfo.getIngest());
                }
                pipelineStore.put(clusterService, ingestInfos, request, listener);
            } catch (Exception e) {
                onFailure(e);
            }
        }

        @Override
        public void onFailure(Exception e) {
            listener.onFailure(e);
        }
    });
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest) HashMap(java.util.HashMap) Map(java.util.Map) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException)

Example 5 with NodesInfoRequest

use of org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest in project graylog2-server by Graylog2.

the class Cluster method getAllNodes.

public Map<String, NodeInfo> getAllNodes() {
    final ClusterAdminClient clusterAdminClient = c.admin().cluster();
    final NodesInfoRequest request = clusterAdminClient.prepareNodesInfo().all().request();
    final ImmutableMap.Builder<String, NodeInfo> builder = ImmutableMap.builder();
    for (NodeInfo nodeInfo : clusterAdminClient.nodesInfo(request).actionGet().getNodes()) {
        builder.put(nodeInfo.getNode().id(), nodeInfo);
    }
    return builder.build();
}
Also used : ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

NodesInfoRequest (org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)10 NodeInfo (org.elasticsearch.action.admin.cluster.node.info.NodeInfo)7 NodesInfoResponse (org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse)7 NodeClient (org.elasticsearch.client.node.NodeClient)5 Settings (org.elasticsearch.common.settings.Settings)5 RestController (org.elasticsearch.rest.RestController)5 RestRequest (org.elasticsearch.rest.RestRequest)5 GET (org.elasticsearch.rest.RestRequest.Method.GET)5 ClusterStateRequest (org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)4 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)4 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)4 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)4 Table (org.elasticsearch.common.Table)4 RestResponse (org.elasticsearch.rest.RestResponse)4 RestActionListener (org.elasticsearch.rest.action.RestActionListener)4 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)4 Map (java.util.Map)3 Strings (org.elasticsearch.common.Strings)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2