Skip to content

Commit

Permalink
Re-enable deprecated _xpack/sql routes via REST compatibility (#75949)
Browse files Browse the repository at this point in the history
  • Loading branch information
joegallo committed Jan 14, 2022
1 parent 37a2562 commit a2dac35
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
25 changes: 15 additions & 10 deletions x-pack/qa/xpack-prefix-rest-compat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -170,6 +161,20 @@ tasks.named("yamlRestTestV7CompatTransform").configure{ task ->
task.replaceKeyInDo("ml.validate_detector", "xpack-ml.validate_detector")
task.addAllowedWarningRegex(".*_xpack/ml.* 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("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")
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit a2dac35

Please sign in to comment.