Просмотр исходного кода

Re-enable deprecated _xpack/sql routes via REST compatibility (#75949)

Joe Gallo 3 лет назад
Родитель
Сommit
d7d3485546

+ 4 - 0
x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/CoreProtocol.java

@@ -95,9 +95,13 @@ public class CoreProtocol {
      * SQL-related endpoints
      */
     public static final String CLEAR_CURSOR_REST_ENDPOINT = "/_sql/close";
+    public static final String CLEAR_CURSOR_DEPRECATED_REST_ENDPOINT = "/_xpack/sql/close";
     public static final String SQL_QUERY_REST_ENDPOINT = "/_sql";
+    public static final String SQL_QUERY_DEPRECATED_REST_ENDPOINT = "/_xpack/sql";
     public static final String SQL_TRANSLATE_REST_ENDPOINT = "/_sql/translate";
+    public static final String SQL_TRANSLATE_DEPRECATED_REST_ENDPOINT = "/_xpack/sql/translate";
     public static final String SQL_STATS_REST_ENDPOINT = "/_sql/stats";
+    public static final String SQL_STATS_DEPRECATED_REST_ENDPOINT = "/_xpack/sql/stats";
     // async
     public static final String SQL_ASYNC_REST_ENDPOINT = "/_sql/async/";
     public static final String SQL_ASYNC_STATUS_REST_ENDPOINT = SQL_ASYNC_REST_ENDPOINT + "status/";

+ 6 - 1
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java

@@ -8,6 +8,7 @@
 package org.elasticsearch.xpack.sql.plugin;
 
 import org.elasticsearch.client.internal.node.NodeClient;
+import org.elasticsearch.core.RestApiVersion;
 import org.elasticsearch.rest.BaseRestHandler;
 import org.elasticsearch.rest.RestRequest;
 import org.elasticsearch.rest.action.RestToXContentListener;
@@ -25,7 +26,11 @@ public class RestSqlClearCursorAction extends BaseRestHandler {
 
     @Override
     public List<Route> routes() {
-        return List.of(new Route(POST, Protocol.CLEAR_CURSOR_REST_ENDPOINT));
+        return List.of(
+            Route.builder(POST, Protocol.CLEAR_CURSOR_REST_ENDPOINT)
+                .replaces(POST, Protocol.CLEAR_CURSOR_DEPRECATED_REST_ENDPOINT, RestApiVersion.V_7)
+                .build()
+        );
     }
 
     @Override

+ 9 - 1
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java

@@ -8,6 +8,7 @@
 package org.elasticsearch.xpack.sql.plugin;
 
 import org.elasticsearch.client.internal.node.NodeClient;
+import org.elasticsearch.core.RestApiVersion;
 import org.elasticsearch.rest.BaseRestHandler;
 import org.elasticsearch.rest.RestRequest;
 import org.elasticsearch.rest.action.RestCancellableNodeClient;
@@ -31,7 +32,14 @@ public class RestSqlQueryAction extends BaseRestHandler {
 
     @Override
     public List<Route> routes() {
-        return List.of(new Route(GET, Protocol.SQL_QUERY_REST_ENDPOINT), new Route(POST, Protocol.SQL_QUERY_REST_ENDPOINT));
+        return List.of(
+            Route.builder(GET, Protocol.SQL_QUERY_REST_ENDPOINT)
+                .replaces(GET, Protocol.SQL_QUERY_DEPRECATED_REST_ENDPOINT, RestApiVersion.V_7)
+                .build(),
+            Route.builder(POST, Protocol.SQL_QUERY_REST_ENDPOINT)
+                .replaces(POST, Protocol.SQL_QUERY_DEPRECATED_REST_ENDPOINT, RestApiVersion.V_7)
+                .build()
+        );
     }
 
     public MediaTypeRegistry<? extends MediaType> validAcceptMediaTypes() {

+ 6 - 1
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlStatsAction.java

@@ -8,6 +8,7 @@
 package org.elasticsearch.xpack.sql.plugin;
 
 import org.elasticsearch.client.internal.node.NodeClient;
+import org.elasticsearch.core.RestApiVersion;
 import org.elasticsearch.rest.BaseRestHandler;
 import org.elasticsearch.rest.RestRequest;
 import org.elasticsearch.rest.action.RestActions;
@@ -21,7 +22,11 @@ public class RestSqlStatsAction extends BaseRestHandler {
 
     @Override
     public List<Route> routes() {
-        return List.of(new Route(GET, Protocol.SQL_STATS_REST_ENDPOINT));
+        return List.of(
+            Route.builder(GET, Protocol.SQL_STATS_REST_ENDPOINT)
+                .replaces(GET, Protocol.SQL_STATS_DEPRECATED_REST_ENDPOINT, RestApiVersion.V_7)
+                .build()
+        );
     }
 
     @Override

+ 9 - 1
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java

@@ -7,6 +7,7 @@
 package org.elasticsearch.xpack.sql.plugin;
 
 import org.elasticsearch.client.internal.node.NodeClient;
+import org.elasticsearch.core.RestApiVersion;
 import org.elasticsearch.rest.BaseRestHandler;
 import org.elasticsearch.rest.RestRequest;
 import org.elasticsearch.rest.action.RestToXContentListener;
@@ -28,7 +29,14 @@ public class RestSqlTranslateAction extends BaseRestHandler {
 
     @Override
     public List<Route> routes() {
-        return List.of(new Route(GET, Protocol.SQL_TRANSLATE_REST_ENDPOINT), new Route(POST, Protocol.SQL_TRANSLATE_REST_ENDPOINT));
+        return List.of(
+            Route.builder(GET, Protocol.SQL_TRANSLATE_REST_ENDPOINT)
+                .replaces(GET, Protocol.SQL_TRANSLATE_DEPRECATED_REST_ENDPOINT, RestApiVersion.V_7)
+                .build(),
+            Route.builder(POST, Protocol.SQL_TRANSLATE_REST_ENDPOINT)
+                .replaces(POST, Protocol.SQL_TRANSLATE_DEPRECATED_REST_ENDPOINT, RestApiVersion.V_7)
+                .build()
+        );
     }
 
     @Override

+ 15 - 10
x-pack/qa/xpack-prefix-rest-compat/build.gradle

@@ -34,7 +34,7 @@ dependencies {
 tasks.named("copyRestCompatTestTask").configure { task ->
     task.dependsOn(configurations.compatXpackTests);
     task.setXpackConfig(configurations.compatXpackTests);
-    task.getIncludeXpack().set(List.of("ml", "rollup", "license", "migration", "ssl"));
+    task.getIncludeXpack().set(List.of("license", "migration", "ml", "rollup", "sql", "ssl"));
     task.getOutputResourceDir().set(project.getLayout().getBuildDirectory().dir("restResources/v${compatVersion}/yamlTests/original"));
     task.setXpackConfigToFileTree(
       config -> project.fileTree(
@@ -114,15 +114,6 @@ tasks.named("yamlRestTestV7CompatTransform").configure{ task ->
   task.replaceKeyInDo("migration.deprecations", "xpack-migration.deprecations")
   task.addAllowedWarningRegex(".*_xpack/migration.* is deprecated.*")
 
-  task.replaceKeyInDo("rollup.delete_job", "xpack-rollup.delete_job")
-  task.replaceKeyInDo("rollup.get_jobs", "xpack-rollup.get_jobs")
-  task.replaceKeyInDo("rollup.get_rollup_caps", "xpack-rollup.get_rollup_caps")
-  task.replaceKeyInDo("rollup.get_rollup_index_caps", "xpack-rollup.get_rollup_index_caps")
-  task.replaceKeyInDo("rollup.put_job", "xpack-rollup.put_job")
-  task.replaceKeyInDo("rollup.start_job", "xpack-rollup.start_job")
-  task.replaceKeyInDo("rollup.stop_job", "xpack-rollup.stop_job")
-  task.addAllowedWarningRegex(".*_xpack/rollup.* is deprecated.*")
-
   task.replaceKeyInDo("ml.close_job", "xpack-ml.close_job")
   task.replaceKeyInDo("ml.delete_calendar", "xpack-ml.delete_calendar")
   task.replaceKeyInDo("ml.delete_calendar_event", "xpack-ml.delete_calendar_event")
@@ -171,6 +162,20 @@ tasks.named("yamlRestTestV7CompatTransform").configure{ task ->
   task.addAllowedWarningRegex(".*_xpack/ml.* is deprecated.*")
   task.addAllowedWarningRegex("bucket_span .* is not an integral .* of the number of sconds in 1d.* This is now deprecated.*")
 
+  task.replaceKeyInDo("rollup.delete_job", "xpack-rollup.delete_job")
+  task.replaceKeyInDo("rollup.get_jobs", "xpack-rollup.get_jobs")
+  task.replaceKeyInDo("rollup.get_rollup_caps", "xpack-rollup.get_rollup_caps")
+  task.replaceKeyInDo("rollup.get_rollup_index_caps", "xpack-rollup.get_rollup_index_caps")
+  task.replaceKeyInDo("rollup.put_job", "xpack-rollup.put_job")
+  task.replaceKeyInDo("rollup.start_job", "xpack-rollup.start_job")
+  task.replaceKeyInDo("rollup.stop_job", "xpack-rollup.stop_job")
+  task.addAllowedWarningRegex(".*_xpack/rollup.* is deprecated.*")
+
+  task.replaceKeyInDo("sql.clear_cursor", "xpack-sql.clear_cursor")
+  task.replaceKeyInDo("sql.query", "xpack-sql.query")
+  task.replaceKeyInDo("sql.translate", "xpack-sql.translate")
+  task.addAllowedWarningRegex(".*_xpack/sql.* is deprecated.*")
+
   task.replaceKeyInDo("ssl.certificates", "xpack-ssl.certificates", "Test get SSL certificates")
   task.addAllowedWarningRegexForTest(".*_xpack/ssl.* is deprecated.*", "Test get SSL certificates")
 }

+ 28 - 0
x-pack/qa/xpack-prefix-rest-compat/src/yamlRestTestV7Compat/resources/rest-api-spec/api/xpack-sql.clear_cursor.json

@@ -0,0 +1,28 @@
+{
+  "xpack-sql.clear_cursor":{
+    "documentation":{
+      "url":"https://www.elastic.co/guide/en/elasticsearch/reference/current/clear-sql-cursor-api.html",
+      "description":"Clears the SQL cursor"
+    },
+    "stability":"stable",
+    "visibility":"public",
+    "headers":{
+      "accept": [ "application/vnd.elasticsearch+json;compatible-with=7"],
+      "content_type": ["application/vnd.elasticsearch+json;compatible-with=7"]
+    },
+    "url":{
+      "paths":[
+        {
+          "path":"/_xpack/sql/close",
+          "methods":[
+            "POST"
+          ]
+        }
+      ]
+    },
+    "body":{
+      "description":"Specify the cursor value in the `cursor` element to clean the cursor.",
+      "required":true
+    }
+  }
+}

+ 35 - 0
x-pack/qa/xpack-prefix-rest-compat/src/yamlRestTestV7Compat/resources/rest-api-spec/api/xpack-sql.query.json

@@ -0,0 +1,35 @@
+{
+  "xpack-sql.query":{
+    "documentation":{
+      "url":"https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-search-api.html",
+      "description":"Executes a SQL request"
+    },
+    "stability":"stable",
+    "visibility":"public",
+    "headers":{
+      "accept": [ "application/vnd.elasticsearch+json;compatible-with=7"],
+      "content_type": ["application/vnd.elasticsearch+json;compatible-with=7"]
+    },
+    "url":{
+      "paths":[
+        {
+          "path":"/_xpack/sql",
+          "methods":[
+            "POST",
+            "GET"
+          ]
+        }
+      ]
+    },
+    "params":{
+      "format":{
+        "type":"string",
+        "description":"a short version of the Accept header, e.g. json, yaml"
+      }
+    },
+    "body":{
+      "description":"Use the `query` element to start a query. Use the `cursor` element to continue a query.",
+      "required":true
+    }
+  }
+}

+ 30 - 0
x-pack/qa/xpack-prefix-rest-compat/src/yamlRestTestV7Compat/resources/rest-api-spec/api/xpack-sql.translate.json

@@ -0,0 +1,30 @@
+{
+  "xpack-sql.translate":{
+    "documentation":{
+      "url":"https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-translate-api.html",
+      "description":"Translates SQL into Elasticsearch queries"
+    },
+    "stability":"stable",
+    "visibility":"public",
+    "headers":{
+      "accept": [ "application/vnd.elasticsearch+json;compatible-with=7"],
+      "content_type": ["application/vnd.elasticsearch+json;compatible-with=7"]
+    },
+    "url":{
+      "paths":[
+        {
+          "path":"/_xpack/sql/translate",
+          "methods":[
+            "POST",
+            "GET"
+          ]
+        }
+      ]
+    },
+    "params":{},
+    "body":{
+      "description":"Specify the query in the `query` element.",
+      "required":true
+    }
+  }
+}