From e8c22f13bf08f00dc3ce26728cc38dd2a1bf3260 Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Mon, 2 Aug 2021 08:30:46 -0400 Subject: [PATCH 1/3] Resurrect _xpack/sql routes --- .../org/elasticsearch/xpack/sql/proto/Protocol.java | 4 ++++ .../xpack/sql/plugin/RestSqlClearCursorAction.java | 7 ++++++- .../xpack/sql/plugin/RestSqlQueryAction.java | 10 +++++++++- .../xpack/sql/plugin/RestSqlStatsAction.java | 7 ++++++- .../xpack/sql/plugin/RestSqlTranslateAction.java | 10 +++++++++- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/Protocol.java b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/Protocol.java index 682bf343a621b..2d44256892a73 100644 --- a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/Protocol.java +++ b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/Protocol.java @@ -95,9 +95,13 @@ public final class Protocol { * 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/"; diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java index d1e23bef499f6..d7c9d093c7acb 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java +++ b/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.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 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 diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java index 2303304acf7e7..1017092bc4f9e 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java +++ b/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.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 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 validAcceptMediaTypes() { diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlStatsAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlStatsAction.java index 915a29921eca4..8c671edf82762 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlStatsAction.java +++ b/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.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 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 diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java index 56fe46708fcaa..d99a3c5c39792 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java +++ b/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.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 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 From b40b6c5a9c6507089913afc939996891b3f8f973 Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Thu, 13 Jan 2022 22:13:18 -0500 Subject: [PATCH 2/3] Keep things sorted --- .../qa/xpack-prefix-rest-compat/build.gradle | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/x-pack/qa/xpack-prefix-rest-compat/build.gradle b/x-pack/qa/xpack-prefix-rest-compat/build.gradle index c9f3ca4b3d018..c124eff099f5b 100644 --- a/x-pack/qa/xpack-prefix-rest-compat/build.gradle +++ b/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", "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,15 @@ 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("ssl.certificates", "xpack-ssl.certificates", "Test get SSL certificates") task.addAllowedWarningRegexForTest(".*_xpack/ssl.* is deprecated.*", "Test get SSL certificates") } From ffb934f46902c956f15e54fe06af258d3cedd61a Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Thu, 13 Jan 2022 23:08:22 -0500 Subject: [PATCH 3/3] Add transform tests for the _xpack/sql routes --- .../qa/xpack-prefix-rest-compat/build.gradle | 7 +++- .../api/xpack-sql.clear_cursor.json | 28 +++++++++++++++ .../rest-api-spec/api/xpack-sql.query.json | 35 +++++++++++++++++++ .../api/xpack-sql.translate.json | 30 ++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 x-pack/qa/xpack-prefix-rest-compat/src/yamlRestTestV7Compat/resources/rest-api-spec/api/xpack-sql.clear_cursor.json create mode 100644 x-pack/qa/xpack-prefix-rest-compat/src/yamlRestTestV7Compat/resources/rest-api-spec/api/xpack-sql.query.json create mode 100644 x-pack/qa/xpack-prefix-rest-compat/src/yamlRestTestV7Compat/resources/rest-api-spec/api/xpack-sql.translate.json diff --git a/x-pack/qa/xpack-prefix-rest-compat/build.gradle b/x-pack/qa/xpack-prefix-rest-compat/build.gradle index c124eff099f5b..ebeab608dd23a 100644 --- a/x-pack/qa/xpack-prefix-rest-compat/build.gradle +++ b/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("license", "migration", "ml", "rollup", "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( @@ -171,6 +171,11 @@ tasks.named("yamlRestTestV7CompatTransform").configure{ task -> 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") } diff --git a/x-pack/qa/xpack-prefix-rest-compat/src/yamlRestTestV7Compat/resources/rest-api-spec/api/xpack-sql.clear_cursor.json b/x-pack/qa/xpack-prefix-rest-compat/src/yamlRestTestV7Compat/resources/rest-api-spec/api/xpack-sql.clear_cursor.json new file mode 100644 index 0000000000000..ee706fc0736cd --- /dev/null +++ b/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 + } + } +} diff --git a/x-pack/qa/xpack-prefix-rest-compat/src/yamlRestTestV7Compat/resources/rest-api-spec/api/xpack-sql.query.json b/x-pack/qa/xpack-prefix-rest-compat/src/yamlRestTestV7Compat/resources/rest-api-spec/api/xpack-sql.query.json new file mode 100644 index 0000000000000..d153e0f3484c3 --- /dev/null +++ b/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 + } + } +} diff --git a/x-pack/qa/xpack-prefix-rest-compat/src/yamlRestTestV7Compat/resources/rest-api-spec/api/xpack-sql.translate.json b/x-pack/qa/xpack-prefix-rest-compat/src/yamlRestTestV7Compat/resources/rest-api-spec/api/xpack-sql.translate.json new file mode 100644 index 0000000000000..1fad4a643dbb9 --- /dev/null +++ b/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 + } + } +}