From a698f4dce22f95ff234ff67ca04a3905fd9906a5 Mon Sep 17 00:00:00 2001 From: Jaime Pan <33685703+NEUpanning@users.noreply.github.com> Date: Thu, 28 Sep 2023 16:54:55 +0800 Subject: [PATCH] Extract NodeInfoMetrics to top-level class (#99990) --- .../cluster/node/info/NodesInfoMetrics.java | 75 +++++++++++++++++++ .../cluster/node/info/NodesInfoRequest.java | 66 +++++----------- .../node/info/NodesInfoRequestBuilder.java | 22 +++--- .../node/info/TransportNodesInfoAction.java | 24 +++--- .../remote/RemoteClusterNodesAction.java | 3 +- .../ingest/PutPipelineTransportAction.java | 3 +- .../admin/cluster/RestNodesInfoAction.java | 3 +- .../rest/action/cat/RestNodeAttrsAction.java | 3 +- .../rest/action/cat/RestNodesAction.java | 9 ++- .../rest/action/cat/RestPluginsAction.java | 3 +- .../rest/action/cat/RestThreadPoolAction.java | 3 +- .../node/info/NodesInfoRequestTests.java | 12 +-- .../remote/RemoteClusterNodesActionTests.java | 3 +- .../nodeinfo/AutoscalingNodeInfoService.java | 3 +- .../TransportNodeEnrollmentAction.java | 3 +- .../InternalEnrollmentTokenGenerator.java | 5 +- 16 files changed, 147 insertions(+), 93 deletions(-) create mode 100644 server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoMetrics.java diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoMetrics.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoMetrics.java new file mode 100644 index 0000000000000..3e632f9bdd212 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoMetrics.java @@ -0,0 +1,75 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.action.admin.cluster.node.info; + +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.Writeable; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * This class is a container that encapsulates the necessary information needed to indicate which node information is requested. + */ +public class NodesInfoMetrics implements Writeable { + private Set requestedMetrics = Metric.allMetrics(); + + public NodesInfoMetrics() {} + + public NodesInfoMetrics(StreamInput in) throws IOException { + requestedMetrics.clear(); + requestedMetrics.addAll(Arrays.asList(in.readStringArray())); + } + + public Set requestedMetrics() { + return requestedMetrics; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeStringArray(requestedMetrics.toArray(new String[0])); + } + + /** + * An enumeration of the "core" sections of metrics that may be requested + * from the nodes information endpoint. Eventually this list will be + * pluggable. + */ + public enum Metric { + SETTINGS("settings"), + OS("os"), + PROCESS("process"), + JVM("jvm"), + THREAD_POOL("thread_pool"), + TRANSPORT("transport"), + HTTP("http"), + REMOTE_CLUSTER_SERVER("remote_cluster_server"), + PLUGINS("plugins"), + INGEST("ingest"), + AGGREGATIONS("aggregations"), + INDICES("indices"); + + private final String metricName; + + Metric(String name) { + this.metricName = name; + } + + public String metricName() { + return this.metricName; + } + + public static Set allMetrics() { + return Arrays.stream(values()).map(Metric::metricName).collect(Collectors.toSet()); + } + } +} diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java index 4e52116020be2..04b2a7d980678 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequest.java @@ -13,18 +13,16 @@ import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; -import java.util.Arrays; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; -import java.util.stream.Collectors; /** * A request to get node (cluster) level information. */ public class NodesInfoRequest extends BaseNodesRequest { - private Set requestedMetrics = Metric.allMetrics(); + private NodesInfoMetrics nodesInfoMetrics; /** * Create a new NodeInfoRequest from a {@link StreamInput} object. @@ -34,8 +32,7 @@ public class NodesInfoRequest extends BaseNodesRequest { */ public NodesInfoRequest(StreamInput in) throws IOException { super(in); - requestedMetrics.clear(); - requestedMetrics.addAll(Arrays.asList(in.readStringArray())); + nodesInfoMetrics = new NodesInfoMetrics(in); } /** @@ -45,6 +42,7 @@ public NodesInfoRequest(StreamInput in) throws IOException { @SuppressWarnings("this-escape") public NodesInfoRequest(String... nodesIds) { super(nodesIds); + nodesInfoMetrics = new NodesInfoMetrics(); all(); } @@ -52,7 +50,7 @@ public NodesInfoRequest(String... nodesIds) { * Clears all info flags. */ public NodesInfoRequest clear() { - requestedMetrics.clear(); + nodesInfoMetrics.requestedMetrics().clear(); return this; } @@ -60,7 +58,7 @@ public NodesInfoRequest clear() { * Sets to return all the data. */ public NodesInfoRequest all() { - requestedMetrics.addAll(Metric.allMetrics()); + nodesInfoMetrics.requestedMetrics().addAll(NodesInfoMetrics.Metric.allMetrics()); return this; } @@ -68,17 +66,17 @@ public NodesInfoRequest all() { * Get the names of requested metrics */ public Set requestedMetrics() { - return Set.copyOf(requestedMetrics); + return Set.copyOf(nodesInfoMetrics.requestedMetrics()); } /** * Add metric */ public NodesInfoRequest addMetric(String metric) { - if (Metric.allMetrics().contains(metric) == false) { + if (NodesInfoMetrics.Metric.allMetrics().contains(metric) == false) { throw new IllegalStateException("Used an illegal metric: " + metric); } - requestedMetrics.add(metric); + nodesInfoMetrics.requestedMetrics().add(metric); return this; } @@ -87,12 +85,12 @@ public NodesInfoRequest addMetric(String metric) { */ public NodesInfoRequest addMetrics(String... metrics) { SortedSet metricsSet = new TreeSet<>(Set.of(metrics)); - if (Metric.allMetrics().containsAll(metricsSet) == false) { - metricsSet.removeAll(Metric.allMetrics()); + if (NodesInfoMetrics.Metric.allMetrics().containsAll(metricsSet) == false) { + metricsSet.removeAll(NodesInfoMetrics.Metric.allMetrics()); String plural = metricsSet.size() == 1 ? "" : "s"; throw new IllegalStateException("Used illegal metric" + plural + ": " + metricsSet); } - requestedMetrics.addAll(metricsSet); + nodesInfoMetrics.requestedMetrics().addAll(metricsSet); return this; } @@ -100,17 +98,17 @@ public NodesInfoRequest addMetrics(String... metrics) { * Remove metric */ public NodesInfoRequest removeMetric(String metric) { - if (Metric.allMetrics().contains(metric) == false) { + if (NodesInfoMetrics.Metric.allMetrics().contains(metric) == false) { throw new IllegalStateException("Used an illegal metric: " + metric); } - requestedMetrics.remove(metric); + nodesInfoMetrics.requestedMetrics().remove(metric); return this; } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeStringCollection(requestedMetrics); + nodesInfoMetrics.writeTo(out); } /** @@ -118,7 +116,7 @@ public void writeTo(StreamOutput out) throws IOException { * @param metrics the metrics to include in the request * @return */ - public static NodesInfoRequest requestWithMetrics(Metric... metrics) { + public static NodesInfoRequest requestWithMetrics(NodesInfoMetrics.Metric... metrics) { NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(); nodesInfoRequest.clear(); for (var metric : metrics) { @@ -127,37 +125,7 @@ public static NodesInfoRequest requestWithMetrics(Metric... metrics) { return nodesInfoRequest; } - /** - * An enumeration of the "core" sections of metrics that may be requested - * from the nodes information endpoint. Eventually this list list will be - * pluggable. - */ - public enum Metric { - SETTINGS("settings"), - OS("os"), - PROCESS("process"), - JVM("jvm"), - THREAD_POOL("thread_pool"), - TRANSPORT("transport"), - HTTP("http"), - REMOTE_CLUSTER_SERVER("remote_cluster_server"), - PLUGINS("plugins"), - INGEST("ingest"), - AGGREGATIONS("aggregations"), - INDICES("indices"); - - private final String metricName; - - Metric(String name) { - this.metricName = name; - } - - public String metricName() { - return this.metricName; - } - - public static Set allMetrics() { - return Arrays.stream(values()).map(Metric::metricName).collect(Collectors.toSet()); - } + public NodesInfoMetrics getNodesInfoMetrics() { + return nodesInfoMetrics; } } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestBuilder.java index e839553021c3e..543804869eaa0 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestBuilder.java @@ -38,7 +38,7 @@ public NodesInfoRequestBuilder all() { * Should the node settings be returned. */ public NodesInfoRequestBuilder setSettings(boolean settings) { - addOrRemoveMetric(settings, NodesInfoRequest.Metric.SETTINGS); + addOrRemoveMetric(settings, NodesInfoMetrics.Metric.SETTINGS); return this; } @@ -46,7 +46,7 @@ public NodesInfoRequestBuilder setSettings(boolean settings) { * Should the node OS info be returned. */ public NodesInfoRequestBuilder setOs(boolean os) { - addOrRemoveMetric(os, NodesInfoRequest.Metric.OS); + addOrRemoveMetric(os, NodesInfoMetrics.Metric.OS); return this; } @@ -54,7 +54,7 @@ public NodesInfoRequestBuilder setOs(boolean os) { * Should the node OS process be returned. */ public NodesInfoRequestBuilder setProcess(boolean process) { - addOrRemoveMetric(process, NodesInfoRequest.Metric.PROCESS); + addOrRemoveMetric(process, NodesInfoMetrics.Metric.PROCESS); return this; } @@ -62,7 +62,7 @@ public NodesInfoRequestBuilder setProcess(boolean process) { * Should the node JVM info be returned. */ public NodesInfoRequestBuilder setJvm(boolean jvm) { - addOrRemoveMetric(jvm, NodesInfoRequest.Metric.JVM); + addOrRemoveMetric(jvm, NodesInfoMetrics.Metric.JVM); return this; } @@ -70,7 +70,7 @@ public NodesInfoRequestBuilder setJvm(boolean jvm) { * Should the node thread pool info be returned. */ public NodesInfoRequestBuilder setThreadPool(boolean threadPool) { - addOrRemoveMetric(threadPool, NodesInfoRequest.Metric.THREAD_POOL); + addOrRemoveMetric(threadPool, NodesInfoMetrics.Metric.THREAD_POOL); return this; } @@ -78,7 +78,7 @@ public NodesInfoRequestBuilder setThreadPool(boolean threadPool) { * Should the node Transport info be returned. */ public NodesInfoRequestBuilder setTransport(boolean transport) { - addOrRemoveMetric(transport, NodesInfoRequest.Metric.TRANSPORT); + addOrRemoveMetric(transport, NodesInfoMetrics.Metric.TRANSPORT); return this; } @@ -86,7 +86,7 @@ public NodesInfoRequestBuilder setTransport(boolean transport) { * Should the node HTTP info be returned. */ public NodesInfoRequestBuilder setHttp(boolean http) { - addOrRemoveMetric(http, NodesInfoRequest.Metric.HTTP); + addOrRemoveMetric(http, NodesInfoMetrics.Metric.HTTP); return this; } @@ -94,7 +94,7 @@ public NodesInfoRequestBuilder setHttp(boolean http) { * Should the node plugins info be returned. */ public NodesInfoRequestBuilder setPlugins(boolean plugins) { - addOrRemoveMetric(plugins, NodesInfoRequest.Metric.PLUGINS); + addOrRemoveMetric(plugins, NodesInfoMetrics.Metric.PLUGINS); return this; } @@ -102,7 +102,7 @@ public NodesInfoRequestBuilder setPlugins(boolean plugins) { * Should the node ingest info be returned. */ public NodesInfoRequestBuilder setIngest(boolean ingest) { - addOrRemoveMetric(ingest, NodesInfoRequest.Metric.INGEST); + addOrRemoveMetric(ingest, NodesInfoMetrics.Metric.INGEST); return this; } @@ -110,11 +110,11 @@ public NodesInfoRequestBuilder setIngest(boolean ingest) { * Should the node indices info be returned. */ public NodesInfoRequestBuilder setIndices(boolean indices) { - addOrRemoveMetric(indices, NodesInfoRequest.Metric.INDICES); + addOrRemoveMetric(indices, NodesInfoMetrics.Metric.INDICES); return this; } - private void addOrRemoveMetric(boolean includeMetric, NodesInfoRequest.Metric metric) { + private void addOrRemoveMetric(boolean includeMetric, NodesInfoMetrics.Metric metric) { if (includeMetric) { request.addMetric(metric.metricName()); } else { diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java index ccd6ccde2dabd..14dffce86daa5 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/node/info/TransportNodesInfoAction.java @@ -79,18 +79,18 @@ protected NodeInfo nodeOperation(NodeInfoRequest nodeRequest, Task task) { NodesInfoRequest request = nodeRequest.request; Set metrics = request.requestedMetrics(); return nodeService.info( - metrics.contains(NodesInfoRequest.Metric.SETTINGS.metricName()), - metrics.contains(NodesInfoRequest.Metric.OS.metricName()), - metrics.contains(NodesInfoRequest.Metric.PROCESS.metricName()), - metrics.contains(NodesInfoRequest.Metric.JVM.metricName()), - metrics.contains(NodesInfoRequest.Metric.THREAD_POOL.metricName()), - metrics.contains(NodesInfoRequest.Metric.TRANSPORT.metricName()), - metrics.contains(NodesInfoRequest.Metric.HTTP.metricName()), - metrics.contains(NodesInfoRequest.Metric.REMOTE_CLUSTER_SERVER.metricName()), - metrics.contains(NodesInfoRequest.Metric.PLUGINS.metricName()), - metrics.contains(NodesInfoRequest.Metric.INGEST.metricName()), - metrics.contains(NodesInfoRequest.Metric.AGGREGATIONS.metricName()), - metrics.contains(NodesInfoRequest.Metric.INDICES.metricName()) + metrics.contains(NodesInfoMetrics.Metric.SETTINGS.metricName()), + metrics.contains(NodesInfoMetrics.Metric.OS.metricName()), + metrics.contains(NodesInfoMetrics.Metric.PROCESS.metricName()), + metrics.contains(NodesInfoMetrics.Metric.JVM.metricName()), + metrics.contains(NodesInfoMetrics.Metric.THREAD_POOL.metricName()), + metrics.contains(NodesInfoMetrics.Metric.TRANSPORT.metricName()), + metrics.contains(NodesInfoMetrics.Metric.HTTP.metricName()), + metrics.contains(NodesInfoMetrics.Metric.REMOTE_CLUSTER_SERVER.metricName()), + metrics.contains(NodesInfoMetrics.Metric.PLUGINS.metricName()), + metrics.contains(NodesInfoMetrics.Metric.INGEST.metricName()), + metrics.contains(NodesInfoMetrics.Metric.AGGREGATIONS.metricName()), + metrics.contains(NodesInfoMetrics.Metric.INDICES.metricName()) ); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/cluster/remote/RemoteClusterNodesAction.java b/server/src/main/java/org/elasticsearch/action/admin/cluster/remote/RemoteClusterNodesAction.java index 5898f258865d7..49d1dde59477b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/cluster/remote/RemoteClusterNodesAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/cluster/remote/RemoteClusterNodesAction.java @@ -15,6 +15,7 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionType; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoMetrics; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.action.support.ActionFilters; @@ -108,7 +109,7 @@ protected void doExecute(Task task, Request request, ActionListener li threadContext.markAsSystemContext(); if (request.remoteClusterServer) { final NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().clear() - .addMetrics(NodesInfoRequest.Metric.REMOTE_CLUSTER_SERVER.metricName()); + .addMetrics(NodesInfoMetrics.Metric.REMOTE_CLUSTER_SERVER.metricName()); transportService.sendRequest( transportService.getLocalNode(), NodesInfoAction.NAME, diff --git a/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineTransportAction.java b/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineTransportAction.java index 65d5ad5807ecb..b1e2533d1038d 100644 --- a/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineTransportAction.java +++ b/server/src/main/java/org/elasticsearch/action/ingest/PutPipelineTransportAction.java @@ -9,6 +9,7 @@ package org.elasticsearch.action.ingest; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoMetrics; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.AcknowledgedResponse; @@ -66,7 +67,7 @@ protected void masterOperation(Task task, PutPipelineRequest request, ClusterSta ingestService.putPipeline(request, listener, (nodeListener) -> { NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(); nodesInfoRequest.clear(); - nodesInfoRequest.addMetric(NodesInfoRequest.Metric.INGEST.metricName()); + nodesInfoRequest.addMetric(NodesInfoMetrics.Metric.INGEST.metricName()); client.admin().cluster().nodesInfo(nodesInfoRequest, nodeListener); }); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesInfoAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesInfoAction.java index ad591c07ffec0..fc04374411536 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesInfoAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesInfoAction.java @@ -8,6 +8,7 @@ package org.elasticsearch.rest.action.admin.cluster; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoMetrics; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.client.internal.node.NodeClient; import org.elasticsearch.common.Strings; @@ -28,7 +29,7 @@ @ServerlessScope(Scope.INTERNAL) public class RestNodesInfoAction extends BaseRestHandler { - static final Set ALLOWED_METRICS = NodesInfoRequest.Metric.allMetrics(); + static final Set ALLOWED_METRICS = NodesInfoMetrics.Metric.allMetrics(); private final SettingsFilter settingsFilter; diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java index a9a1a09a4f01c..9a032ce064cf6 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java @@ -9,6 +9,7 @@ package org.elasticsearch.rest.action.cat; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoMetrics; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; @@ -60,7 +61,7 @@ public RestChannelConsumer doCatRequest(final RestRequest request, final NodeCli @Override public void processResponse(final ClusterStateResponse clusterStateResponse) { NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(); - nodesInfoRequest.clear().addMetric(NodesInfoRequest.Metric.PROCESS.metricName()); + nodesInfoRequest.clear().addMetric(NodesInfoMetrics.Metric.PROCESS.metricName()); client.admin().cluster().nodesInfo(nodesInfoRequest, new RestResponseListener(channel) { @Override public RestResponse buildResponse(NodesInfoResponse nodesInfoResponse) throws Exception { diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java index 296daeeedb7d1..1c4d5f7d8fdbd 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java @@ -9,6 +9,7 @@ package org.elasticsearch.rest.action.cat; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoMetrics; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; @@ -90,10 +91,10 @@ public void processResponse(final ClusterStateResponse clusterStateResponse) { NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(); nodesInfoRequest.clear() .addMetrics( - NodesInfoRequest.Metric.JVM.metricName(), - NodesInfoRequest.Metric.OS.metricName(), - NodesInfoRequest.Metric.PROCESS.metricName(), - NodesInfoRequest.Metric.HTTP.metricName() + NodesInfoMetrics.Metric.JVM.metricName(), + NodesInfoMetrics.Metric.OS.metricName(), + NodesInfoMetrics.Metric.PROCESS.metricName(), + NodesInfoMetrics.Metric.HTTP.metricName() ); client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener(channel) { @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestPluginsAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestPluginsAction.java index 16ad6b4c289e4..7aba2c8e38a6d 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestPluginsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestPluginsAction.java @@ -9,6 +9,7 @@ package org.elasticsearch.rest.action.cat; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoMetrics; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules; @@ -61,7 +62,7 @@ public RestChannelConsumer doCatRequest(final RestRequest request, final NodeCli @Override public void processResponse(final ClusterStateResponse clusterStateResponse) throws Exception { NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(); - nodesInfoRequest.clear().addMetric(NodesInfoRequest.Metric.PLUGINS.metricName()); + nodesInfoRequest.clear().addMetric(NodesInfoMetrics.Metric.PLUGINS.metricName()); client.admin().cluster().nodesInfo(nodesInfoRequest, new RestResponseListener(channel) { @Override public RestResponse buildResponse(final NodesInfoResponse nodesInfoResponse) throws Exception { diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java index 727bd361e5def..c94f40b83856e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java @@ -9,6 +9,7 @@ package org.elasticsearch.rest.action.cat; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoMetrics; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; @@ -77,7 +78,7 @@ public RestChannelConsumer doCatRequest(final RestRequest request, final NodeCli public void processResponse(final ClusterStateResponse clusterStateResponse) { NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(); nodesInfoRequest.clear() - .addMetrics(NodesInfoRequest.Metric.PROCESS.metricName(), NodesInfoRequest.Metric.THREAD_POOL.metricName()); + .addMetrics(NodesInfoMetrics.Metric.PROCESS.metricName(), NodesInfoMetrics.Metric.THREAD_POOL.metricName()); client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener(channel) { @Override public void processResponse(final NodesInfoResponse nodesInfoResponse) { diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestTests.java index a572625fb9f9c..16c0ed251aa3d 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoRequestTests.java @@ -32,7 +32,7 @@ public class NodesInfoRequestTests extends ESTestCase { */ public void testAddMetricsSet() throws Exception { NodesInfoRequest request = new NodesInfoRequest(randomAlphaOfLength(8)); - randomSubsetOf(NodesInfoRequest.Metric.allMetrics()).forEach(request::addMetric); + randomSubsetOf(NodesInfoMetrics.Metric.allMetrics()).forEach(request::addMetric); NodesInfoRequest deserializedRequest = roundTripRequest(request); assertThat(request.requestedMetrics(), equalTo(deserializedRequest.requestedMetrics())); } @@ -42,7 +42,7 @@ public void testAddMetricsSet() throws Exception { */ public void testAddSingleMetric() throws Exception { NodesInfoRequest request = new NodesInfoRequest(randomAlphaOfLength(8)); - request.addMetric(randomFrom(NodesInfoRequest.Metric.allMetrics())); + request.addMetric(randomFrom(NodesInfoMetrics.Metric.allMetrics())); NodesInfoRequest deserializedRequest = roundTripRequest(request); assertThat(request.requestedMetrics(), equalTo(deserializedRequest.requestedMetrics())); } @@ -53,7 +53,7 @@ public void testAddSingleMetric() throws Exception { public void testRemoveSingleMetric() throws Exception { NodesInfoRequest request = new NodesInfoRequest(randomAlphaOfLength(8)); request.all(); - String metric = randomFrom(NodesInfoRequest.Metric.allMetrics()); + String metric = randomFrom(NodesInfoMetrics.Metric.allMetrics()); request.removeMetric(metric); NodesInfoRequest deserializedRequest = roundTripRequest(request); @@ -63,7 +63,7 @@ public void testRemoveSingleMetric() throws Exception { /** * Test that a newly constructed NodesInfoRequestObject requests all of the - * possible metrics defined in {@link NodesInfoRequest.Metric}. + * possible metrics defined in {@link NodesInfoMetrics.Metric}. */ public void testNodesInfoRequestDefaults() { NodesInfoRequest defaultNodesInfoRequest = new NodesInfoRequest(randomAlphaOfLength(8)); @@ -80,7 +80,7 @@ public void testNodesInfoRequestAll() throws Exception { NodesInfoRequest request = new NodesInfoRequest("node"); request.all(); - assertThat(request.requestedMetrics(), equalTo(NodesInfoRequest.Metric.allMetrics())); + assertThat(request.requestedMetrics(), equalTo(NodesInfoMetrics.Metric.allMetrics())); } /** @@ -101,7 +101,7 @@ public void testUnknownMetricsRejected() { String unknownMetric2 = "unknown_metric2"; Set unknownMetrics = new HashSet<>(); unknownMetrics.add(unknownMetric1); - unknownMetrics.addAll(randomSubsetOf(NodesInfoRequest.Metric.allMetrics())); + unknownMetrics.addAll(randomSubsetOf(NodesInfoMetrics.Metric.allMetrics())); NodesInfoRequest request = new NodesInfoRequest(); diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/remote/RemoteClusterNodesActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/remote/RemoteClusterNodesActionTests.java index 7c6c1ffdcf98b..18c586a4a51ae 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/remote/RemoteClusterNodesActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/remote/RemoteClusterNodesActionTests.java @@ -13,6 +13,7 @@ import org.elasticsearch.action.ActionListenerResponseHandler; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoMetrics; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; import org.elasticsearch.action.support.ActionFilters; @@ -108,7 +109,7 @@ public void testDoExecuteForRemoteServerNodes() { doAnswer(invocation -> { final NodesInfoRequest nodesInfoRequest = invocation.getArgument(2); - assertThat(nodesInfoRequest.requestedMetrics(), containsInAnyOrder(NodesInfoRequest.Metric.REMOTE_CLUSTER_SERVER.metricName())); + assertThat(nodesInfoRequest.requestedMetrics(), containsInAnyOrder(NodesInfoMetrics.Metric.REMOTE_CLUSTER_SERVER.metricName())); final ActionListenerResponseHandler handler = invocation.getArgument(3); handler.handleResponse(nodesInfoResponse); return null; diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/nodeinfo/AutoscalingNodeInfoService.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/nodeinfo/AutoscalingNodeInfoService.java index 118cd19d01b79..578689828de6b 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/nodeinfo/AutoscalingNodeInfoService.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/capacity/nodeinfo/AutoscalingNodeInfoService.java @@ -11,6 +11,7 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.FailedNodeException; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoMetrics; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest; import org.elasticsearch.action.support.nodes.BaseNodeResponse; @@ -138,7 +139,7 @@ private void sendToMissingNodes(Function nodeLookup, Set< .map(BaseNodeResponse::getNode) .map(DiscoveryNode::getId) .toArray(String[]::new) - ).clear().addMetric(NodesInfoRequest.Metric.OS.metricName()).timeout(fetchTimeout), + ).clear().addMetric(NodesInfoMetrics.Metric.OS.metricName()).timeout(fetchTimeout), ActionListener.wrap(nodesInfoResponse -> { final Map builderBuilder = Maps.newHashMapWithExpectedSize( nodesStatsResponse.getNodes().size() diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/enrollment/TransportNodeEnrollmentAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/enrollment/TransportNodeEnrollmentAction.java index 65747c94590b5..152c6aeaf14e7 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/enrollment/TransportNodeEnrollmentAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/enrollment/TransportNodeEnrollmentAction.java @@ -11,6 +11,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoMetrics; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.HandledTransportAction; @@ -142,7 +143,7 @@ protected void doExecute(Task task, NodeEnrollmentRequest request, ActionListene } final List nodeList = new ArrayList<>(); - final NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().addMetric(NodesInfoRequest.Metric.TRANSPORT.metricName()); + final NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().addMetric(NodesInfoMetrics.Metric.TRANSPORT.metricName()); executeAsyncWithOrigin(client, SECURITY_ORIGIN, NodesInfoAction.INSTANCE, nodesInfoRequest, ActionListener.wrap(response -> { for (NodeInfo nodeInfo : response.getNodes()) { nodeList.add(nodeInfo.getInfo(TransportInfo.class).getAddress().publishAddress().toString()); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/enrollment/InternalEnrollmentTokenGenerator.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/enrollment/InternalEnrollmentTokenGenerator.java index 1e874dead9956..d0acc61570853 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/enrollment/InternalEnrollmentTokenGenerator.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/enrollment/InternalEnrollmentTokenGenerator.java @@ -13,6 +13,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoAction; +import org.elasticsearch.action.admin.cluster.node.info.NodesInfoMetrics; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest; import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.client.internal.Client; @@ -65,7 +66,7 @@ public InternalEnrollmentTokenGenerator(Environment environment, SSLService sslS public void maybeCreateNodeEnrollmentToken(Consumer consumer, Iterator backoff) { // the enrollment token can only be used against the node that generated it final NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().nodesIds("_local") - .addMetrics(NodesInfoRequest.Metric.HTTP.metricName(), NodesInfoRequest.Metric.TRANSPORT.metricName()); + .addMetrics(NodesInfoMetrics.Metric.HTTP.metricName(), NodesInfoMetrics.Metric.TRANSPORT.metricName()); client.execute(NodesInfoAction.INSTANCE, nodesInfoRequest, ActionListener.wrap(response -> { assert response.getNodes().size() == 1; @@ -133,7 +134,7 @@ public void maybeCreateNodeEnrollmentToken(Consumer consumer, Iterator consumer, Iterator backoff) { // the enrollment token can only be used against the node that generated it final NodesInfoRequest nodesInfoRequest = new NodesInfoRequest().nodesIds("_local") - .addMetric(NodesInfoRequest.Metric.HTTP.metricName()); + .addMetric(NodesInfoMetrics.Metric.HTTP.metricName()); client.execute(NodesInfoAction.INSTANCE, nodesInfoRequest, ActionListener.wrap(response -> { assert response.getNodes().size() == 1; NodeInfo nodeInfo = response.getNodes().get(0);