|
9 | 9 |
|
10 | 10 | package org.elasticsearch.cluster;
|
11 | 11 |
|
| 12 | +import org.apache.logging.log4j.LogManager; |
| 13 | +import org.apache.logging.log4j.Logger; |
| 14 | +import org.elasticsearch.TransportVersions; |
12 | 15 | import org.elasticsearch.action.ActionListener;
|
| 16 | +import org.elasticsearch.action.admin.cluster.node.usage.NodeUsageStatsForThreadPoolsAction; |
| 17 | +import org.elasticsearch.action.admin.cluster.node.usage.TransportNodeUsageStatsForThreadPoolsAction; |
13 | 18 | import org.elasticsearch.client.internal.Client;
|
14 | 19 |
|
15 | 20 | import java.util.Map;
|
|
19 | 24 | * <p>
|
20 | 25 | * Results are returned as a map of node ID to node usage stats.
|
21 | 26 | */
|
22 |
| -public interface NodeUsageStatsForThreadPoolsCollector { |
| 27 | +public class NodeUsageStatsForThreadPoolsCollector { |
23 | 28 | /**
|
24 |
| - * This will be used when there is no NodeUsageLoadCollector available. |
| 29 | + * This will be used when there is no NodeUsageStatsForThreadPoolsCollector available. |
25 | 30 | */
|
26 |
| - NodeUsageStatsForThreadPoolsCollector EMPTY = (client, clusterState, listener) -> listener.onResponse(Map.of()); |
| 31 | + public static final NodeUsageStatsForThreadPoolsCollector EMPTY = new NodeUsageStatsForThreadPoolsCollector() { |
| 32 | + public void collectUsageStats( |
| 33 | + Client client, |
| 34 | + ClusterState clusterState, |
| 35 | + ActionListener<Map<String, NodeUsageStatsForThreadPools>> listener |
| 36 | + ) { |
| 37 | + listener.onResponse(Map.of()); |
| 38 | + } |
| 39 | + }; |
27 | 40 |
|
28 | 41 | /**
|
29 | 42 | * Collects the thread pool usage stats ({@link NodeUsageStatsForThreadPools}) for each node in the cluster.
|
30 | 43 | *
|
31 | 44 | * @param listener The listener to receive the usage results.
|
32 | 45 | */
|
33 |
| - void collectUsageStats(Client client, ClusterState clusterState, ActionListener<Map<String, NodeUsageStatsForThreadPools>> listener); |
| 46 | + public void collectUsageStats( |
| 47 | + Client client, |
| 48 | + ClusterState clusterState, |
| 49 | + ActionListener<Map<String, NodeUsageStatsForThreadPools>> listener |
| 50 | + ) { |
| 51 | + if (clusterState.getMinTransportVersion().onOrAfter(TransportVersions.TRANSPORT_NODE_USAGE_STATS_FOR_THREAD_POOLS_ACTION)) { |
| 52 | + client.execute( |
| 53 | + TransportNodeUsageStatsForThreadPoolsAction.TYPE, |
| 54 | + new NodeUsageStatsForThreadPoolsAction.Request(), |
| 55 | + listener.map(response -> response.getAllNodeUsageStatsForThreadPools()) |
| 56 | + ); |
| 57 | + } else { |
| 58 | + listener.onResponse(Map.of()); |
| 59 | + } |
| 60 | + } |
34 | 61 | }
|
0 commit comments