diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/nodes.hot_threads/10_basic_compat.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/nodes.hot_threads/10_basic_compat.yml new file mode 100644 index 0000000000000..a78130342519b --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/nodes.hot_threads/10_basic_compat.yml @@ -0,0 +1,21 @@ +--- +setup: + - skip: + version: "9.0.0 - " + reason: "compatible from 8.x to 7.x" + features: + - "headers" + - "allowed_warnings_regex" + +--- +"Get hot threads": + + - do: + headers: + Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" + Accept: "application/vnd.elasticsearch+json;compatible-with=7" + nodes.hot_threads: {} + allowed_warnings_regex: + - ".*hot_?threads.* is a deprecated endpoint.*" + - match: + $body: /:::/ diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java index 6f2376e52e901..f27b7e2f23e44 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java @@ -13,6 +13,7 @@ import org.elasticsearch.action.admin.cluster.node.hotthreads.NodesHotThreadsResponse; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; +import org.elasticsearch.core.RestApiVersion; import org.elasticsearch.core.TimeValue; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; @@ -23,16 +24,59 @@ import java.io.IOException; import java.util.List; +import java.util.Locale; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestNodesHotThreadsAction extends BaseRestHandler { + private static final String formatDeprecatedMessageWithoutNodeID = "[%s] is a deprecated endpoint. " + + "Please use [/_nodes/hot_threads] instead."; + private static final String formatDeprecatedMessageWithNodeID = "[%s] is a deprecated endpoint. " + + "Please use [/_nodes/{nodeId}/hot_threads] instead."; + private static final String DEPRECATED_MESSAGE_CLUSTER_NODES_HOT_THREADS = String.format(Locale.ROOT, + formatDeprecatedMessageWithoutNodeID, + "/_cluster/nodes/hot_threads" + ); + private static final String DEPRECATED_MESSAGE_CLUSTER_NODES_NODEID_HOT_THREADS = String.format(Locale.ROOT, + formatDeprecatedMessageWithNodeID, + "/_cluster/nodes/{nodeId}/hot_threads" + ); + private static final String DEPRECATED_MESSAGE_CLUSTER_NODES_HOTTHREADS = String.format(Locale.ROOT, + formatDeprecatedMessageWithoutNodeID, + "/_cluster/nodes/hotthreads" + ); + private static final String DEPRECATED_MESSAGE_CLUSTER_NODES_NODEID_HOTTHREADS = String.format(Locale.ROOT, + formatDeprecatedMessageWithNodeID, + "/_cluster/nodes/{nodeId}/hotthreads" + ); + private static final String DEPRECATED_MESSAGE_NODES_HOTTHREADS = String.format(Locale.ROOT, + formatDeprecatedMessageWithoutNodeID, + "/_nodes/hotthreads" + ); + private static final String DEPRECATED_MESSAGE_NODES_NODEID_HOTTHREADS = String.format(Locale.ROOT, + formatDeprecatedMessageWithNodeID, + "/_nodes/{nodeId}/hotthreads" + ); + @Override public List routes() { return List.of( new Route(GET, "/_nodes/hot_threads"), - new Route(GET, "/_nodes/{nodeId}/hot_threads") + new Route(GET, "/_nodes/{nodeId}/hot_threads"), + + Route.builder(GET, "/_cluster/nodes/hot_threads") + .deprecated(DEPRECATED_MESSAGE_CLUSTER_NODES_HOT_THREADS, RestApiVersion.V_7).build(), + Route.builder(GET, "/_cluster/nodes/{nodeId}/hot_threads") + .deprecated(DEPRECATED_MESSAGE_CLUSTER_NODES_NODEID_HOT_THREADS, RestApiVersion.V_7).build(), + Route.builder(GET, "/_cluster/nodes/hotthreads") + .deprecated(DEPRECATED_MESSAGE_CLUSTER_NODES_HOTTHREADS, RestApiVersion.V_7).build(), + Route.builder(GET, "/_cluster/nodes/{nodeId}/hotthreads") + .deprecated(DEPRECATED_MESSAGE_CLUSTER_NODES_NODEID_HOTTHREADS, RestApiVersion.V_7).build(), + Route.builder(GET, "/_nodes/hotthreads") + .deprecated(DEPRECATED_MESSAGE_NODES_HOTTHREADS, RestApiVersion.V_7).build(), + Route.builder(GET, "/_nodes/{nodeId}/hotthreads") + .deprecated(DEPRECATED_MESSAGE_NODES_NODEID_HOTTHREADS, RestApiVersion.V_7).build() ); }