Deprecate X-Pack centric SQL endpoints (#35964)

This commit is part of our plan to deprecate and ultimately remove the
use of _xpack in the REST APIs.
This commit is contained in:
Jason Tedor 2018-11-27 22:16:21 -05:00 committed by GitHub
parent e50e0f997a
commit c42d9d91c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 76 additions and 39 deletions

View File

@ -9,7 +9,7 @@ and returns the results. For example:
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
POST /_xpack/sql?format=txt POST /_sql?format=txt
{ {
"query": "SELECT * FROM library ORDER BY page_count DESC LIMIT 5" "query": "SELECT * FROM library ORDER BY page_count DESC LIMIT 5"
} }
@ -48,7 +48,7 @@ specified then the response is returned in the same format as the request.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
POST /_xpack/sql?format=json POST /_sql?format=json
{ {
"query": "SELECT * FROM library ORDER BY page_count DESC", "query": "SELECT * FROM library ORDER BY page_count DESC",
"fetch_size": 5 "fetch_size": 5
@ -85,7 +85,7 @@ case of text format the cursor is returned as `Cursor` http header.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
POST /_xpack/sql?format=json POST /_sql?format=json
{ {
"cursor": "sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWYUpOYklQMHhRUEtld3RsNnFtYU1hQQ==:BAFmBGRhdGUBZgVsaWtlcwFzB21lc3NhZ2UBZgR1c2Vy9f///w8=" "cursor": "sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWYUpOYklQMHhRUEtld3RsNnFtYU1hQQ==:BAFmBGRhdGUBZgVsaWtlcwFzB21lc3NhZ2UBZgR1c2Vy9f///w8="
} }
@ -123,7 +123,7 @@ To clear the state earlier, you can use the clear cursor command:
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
POST /_xpack/sql/close POST /_sql/close
{ {
"cursor": "sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWYUpOYklQMHhRUEtld3RsNnFtYU1hQQ==:BAFmBGRhdGUBZgVsaWtlcwFzB21lc3NhZ2UBZgR1c2Vy9f///w8=" "cursor": "sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWYUpOYklQMHhRUEtld3RsNnFtYU1hQQ==:BAFmBGRhdGUBZgVsaWtlcwFzB21lc3NhZ2UBZgR1c2Vy9f///w8="
} }
@ -152,7 +152,7 @@ parameter.
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
POST /_xpack/sql?format=txt POST /_sql?format=txt
{ {
"query": "SELECT * FROM library ORDER BY page_count DESC", "query": "SELECT * FROM library ORDER BY page_count DESC",
"filter": { "filter": {

View File

@ -8,7 +8,7 @@ into native Elasticsearch queries. For example:
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
POST /_xpack/sql/translate POST /_sql/translate
{ {
"query": "SELECT * FROM library ORDER BY page_count DESC", "query": "SELECT * FROM library ORDER BY page_count DESC",
"fetch_size": 10 "fetch_size": 10

View File

@ -22,7 +22,7 @@ And now you can execute SQL using the <<sql-rest>> right away:
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
POST /_xpack/sql?format=txt POST /_sql?format=txt
{ {
"query": "SELECT * FROM library WHERE release_date < '2000-01-01'" "query": "SELECT * FROM library WHERE release_date < '2000-01-01'"
} }

View File

@ -61,7 +61,7 @@ public class XPackIT extends AbstractRollingTestCase {
bulk.addParameter("refresh", "true"); bulk.addParameter("refresh", "true");
client().performRequest(bulk); client().performRequest(bulk);
Request sql = new Request("POST", "/_xpack/sql"); Request sql = new Request("POST", "/_sql");
sql.setJsonEntity("{\"query\": \"SELECT * FROM sql_test WHERE f > 1 ORDER BY f ASC\"}"); sql.setJsonEntity("{\"query\": \"SELECT * FROM sql_test WHERE f > 1 ORDER BY f ASC\"}");
String response = EntityUtils.toString(client().performRequest(sql).getEntity()); String response = EntityUtils.toString(client().performRequest(sql).getEntity());
assertEquals("{\"columns\":[{\"name\":\"f\",\"type\":\"text\"}],\"rows\":[[\"2\"]]}", response); assertEquals("{\"columns\":[{\"name\":\"f\",\"type\":\"text\"}],\"rows\":[[\"2\"]]}", response);

View File

@ -110,7 +110,7 @@ public class RestSqlMultinodeIT extends ESRestTestCase {
expected.put("columns", singletonList(columnInfo(mode, "COUNT(1)", "long", JDBCType.BIGINT, 20))); expected.put("columns", singletonList(columnInfo(mode, "COUNT(1)", "long", JDBCType.BIGINT, 20)));
expected.put("rows", singletonList(singletonList(count))); expected.put("rows", singletonList(singletonList(count)));
Request request = new Request("POST", "/_xpack/sql"); Request request = new Request("POST", "/_sql");
if (false == mode.isEmpty()) { if (false == mode.isEmpty()) {
request.addParameter("mode", mode); request.addParameter("mode", mode);
} }

View File

@ -177,7 +177,7 @@ public class RestSqlSecurityIT extends SqlSecurityTestCase {
} }
private static Map<String, Object> runSql(@Nullable String asUser, String mode, HttpEntity entity) throws IOException { private static Map<String, Object> runSql(@Nullable String asUser, String mode, HttpEntity entity) throws IOException {
Request request = new Request("POST", "/_xpack/sql"); Request request = new Request("POST", "/_sql");
if (false == mode.isEmpty()) { if (false == mode.isEmpty()) {
request.addParameter("mode", mode); request.addParameter("mode", mode);
} }

View File

@ -314,7 +314,7 @@ public abstract class RestSqlTestCase extends ESRestTestCase implements ErrorsTe
} }
private Map<String, Object> runSql(String mode, HttpEntity sql, String suffix) throws IOException { private Map<String, Object> runSql(String mode, HttpEntity sql, String suffix) throws IOException {
Request request = new Request("POST", "/_xpack/sql" + suffix); Request request = new Request("POST", "/_sql" + suffix);
request.addParameter("error_trace", "true"); // Helps with debugging in case something crazy happens on the server. request.addParameter("error_trace", "true"); // Helps with debugging in case something crazy happens on the server.
request.addParameter("pretty", "true"); // Improves error reporting readability request.addParameter("pretty", "true"); // Improves error reporting readability
if (randomBoolean()) { if (randomBoolean()) {
@ -646,7 +646,7 @@ public abstract class RestSqlTestCase extends ESRestTestCase implements ErrorsTe
* rather than the {@code format} parameter. * rather than the {@code format} parameter.
*/ */
private Tuple<String, String> runSqlAsText(String suffix, HttpEntity entity, String accept) throws IOException { private Tuple<String, String> runSqlAsText(String suffix, HttpEntity entity, String accept) throws IOException {
Request request = new Request("POST", "/_xpack/sql" + suffix); Request request = new Request("POST", "/_sql" + suffix);
request.addParameter("error_trace", "true"); request.addParameter("error_trace", "true");
request.setEntity(entity); request.setEntity(entity);
RequestOptions.Builder options = request.getOptions().toBuilder(); RequestOptions.Builder options = request.getOptions().toBuilder();
@ -664,7 +664,7 @@ public abstract class RestSqlTestCase extends ESRestTestCase implements ErrorsTe
* rather than an {@code Accept} header. * rather than an {@code Accept} header.
*/ */
private Tuple<String, String> runSqlAsTextFormat(String sql, String format) throws IOException { private Tuple<String, String> runSqlAsTextFormat(String sql, String format) throws IOException {
Request request = new Request("POST", "/_xpack/sql"); Request request = new Request("POST", "/_sql");
request.addParameter("error_trace", "true"); request.addParameter("error_trace", "true");
request.addParameter("format", format); request.addParameter("format", format);
request.setJsonEntity("{\"query\":\"" + sql + "\"}"); request.setJsonEntity("{\"query\":\"" + sql + "\"}");

View File

@ -223,7 +223,7 @@ public abstract class RestSqlUsageTestCase extends ESRestTestCase {
} }
private Map<String, Object> getStats() throws UnsupportedOperationException, IOException { private Map<String, Object> getStats() throws UnsupportedOperationException, IOException {
Request request = new Request("GET", "/_xpack/sql/stats"); Request request = new Request("GET", "/_sql/stats");
Map<String, Object> responseAsMap; Map<String, Object> responseAsMap;
try (InputStream content = client().performRequest(request).getEntity().getContent()) { try (InputStream content = client().performRequest(request).getEntity().getContent()) {
responseAsMap = XContentHelper.convertToMap(JsonXContent.jsonXContent, content, false); responseAsMap = XContentHelper.convertToMap(JsonXContent.jsonXContent, content, false);
@ -233,7 +233,7 @@ public abstract class RestSqlUsageTestCase extends ESRestTestCase {
} }
private void runTranslate(String sql) throws IOException { private void runTranslate(String sql) throws IOException {
Request request = new Request("POST", "/_xpack/sql/translate"); Request request = new Request("POST", "/_sql/translate");
if (randomBoolean()) { if (randomBoolean()) {
// We default to JSON but we force it randomly for extra coverage // We default to JSON but we force it randomly for extra coverage
request.addParameter("format", "json"); request.addParameter("format", "json");
@ -267,7 +267,7 @@ public abstract class RestSqlUsageTestCase extends ESRestTestCase {
} }
private void runSql(String mode, String restClient, String sql) throws IOException { private void runSql(String mode, String restClient, String sql) throws IOException {
Request request = new Request("POST", "/_xpack/sql"); Request request = new Request("POST", "/_sql");
request.addParameter("error_trace", "true"); // Helps with debugging in case something crazy happens on the server. request.addParameter("error_trace", "true"); // Helps with debugging in case something crazy happens on the server.
request.addParameter("pretty", "true"); // Improves error reporting readability request.addParameter("pretty", "true"); // Improves error reporting readability
if (randomBoolean()) { if (randomBoolean()) {

View File

@ -47,7 +47,7 @@ public class JreHttpUrlConnection implements Closeable {
* error. * error.
*/ */
public static final String SQL_STATE_BAD_SERVER = "bad_server"; public static final String SQL_STATE_BAD_SERVER = "bad_server";
private static final String SQL_NOT_AVAILABLE_ERROR_MESSAGE = "request [/_xpack/sql] contains unrecognized parameter: [mode]"; private static final String SQL_NOT_AVAILABLE_ERROR_MESSAGE = "request [/_sql] contains unrecognized parameter: [mode]";
public static <R> R http(String path, String query, ConnectionConfiguration cfg, Function<JreHttpUrlConnection, R> handler) { public static <R> R http(String path, String query, ConnectionConfiguration cfg, Function<JreHttpUrlConnection, R> handler) {
final URI uriPath = cfg.baseUri().resolve(path); // update path if needed final URI uriPath = cfg.baseUri().resolve(path); // update path if needed

View File

@ -26,7 +26,10 @@ public final class Protocol {
/** /**
* SQL-related endpoints * SQL-related endpoints
*/ */
public static final String CLEAR_CURSOR_REST_ENDPOINT = "/_xpack/sql/close"; public static final String CLEAR_CURSOR_REST_ENDPOINT = "/_sql/close";
public static final String SQL_QUERY_REST_ENDPOINT = "/_xpack/sql"; public static final String CLEAR_CURSOR_DEPRECATED_REST_ENDPOINT = "/_xpack/sql/close";
public static final String SQL_STATS_REST_ENDPOINT = "/_xpack/sql/stats"; 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_STATS_REST_ENDPOINT = "/_sql/stats";
public static final String SQL_STATS_DEPRECATED_REST_ENDPOINT = "/_xpack/sql/stats";
} }

View File

@ -3,9 +3,12 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
package org.elasticsearch.xpack.sql.plugin; package org.elasticsearch.xpack.sql.plugin;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BaseRestHandler;
@ -21,11 +24,16 @@ import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.POST;
public class RestSqlClearCursorAction extends BaseRestHandler { public class RestSqlClearCursorAction extends BaseRestHandler {
public RestSqlClearCursorAction(Settings settings, RestController controller) {
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSqlClearCursorAction.class));
RestSqlClearCursorAction(Settings settings, RestController controller) {
super(settings); super(settings);
controller.registerHandler(POST, Protocol.CLEAR_CURSOR_REST_ENDPOINT, this); // TODO: remove deprecated endpoint in 8.0.0
controller.registerWithDeprecatedHandler(
POST, Protocol.CLEAR_CURSOR_REST_ENDPOINT, this,
POST, Protocol.CLEAR_CURSOR_DEPRECATED_REST_ENDPOINT, deprecationLogger);
} }
@Override @Override
@ -39,6 +47,7 @@ public class RestSqlClearCursorAction extends BaseRestHandler {
@Override @Override
public String getName() { public String getName() {
return "xpack_sql_clear_cursor_action"; return "sql_clear_cursor";
} }
} }

View File

@ -3,10 +3,13 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
package org.elasticsearch.xpack.sql.plugin; package org.elasticsearch.xpack.sql.plugin;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -37,12 +40,21 @@ import static org.elasticsearch.xpack.sql.proto.RequestInfo.CANVAS;
import static org.elasticsearch.xpack.sql.proto.RequestInfo.CLI; import static org.elasticsearch.xpack.sql.proto.RequestInfo.CLI;
public class RestSqlQueryAction extends BaseRestHandler { public class RestSqlQueryAction extends BaseRestHandler {
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSqlQueryAction.class));
private static String CLIENT_ID = "client.id"; private static String CLIENT_ID = "client.id";
public RestSqlQueryAction(Settings settings, RestController controller) { RestSqlQueryAction(Settings settings, RestController controller) {
super(settings); super(settings);
controller.registerHandler(GET, Protocol.SQL_QUERY_REST_ENDPOINT, this); // TODO: remove deprecated endpoint in 8.0.0
controller.registerHandler(POST, Protocol.SQL_QUERY_REST_ENDPOINT, this); controller.registerWithDeprecatedHandler(
GET, Protocol.SQL_QUERY_REST_ENDPOINT, this,
GET, Protocol.SQL_QUERY_DEPRECATED_REST_ENDPOINT, deprecationLogger);
// TODO: remove deprecated endpoint in 8.0.0
controller.registerWithDeprecatedHandler(
POST, Protocol.SQL_QUERY_REST_ENDPOINT, this,
POST, Protocol.SQL_QUERY_DEPRECATED_REST_ENDPOINT, deprecationLogger);
} }
@Override @Override
@ -131,6 +143,7 @@ public class RestSqlQueryAction extends BaseRestHandler {
@Override @Override
public String getName() { public String getName() {
return "xpack_sql_query_action"; return "sql_query";
} }
} }

View File

@ -6,7 +6,9 @@
package org.elasticsearch.xpack.sql.plugin; package org.elasticsearch.xpack.sql.plugin;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestController;
@ -20,14 +22,19 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
public class RestSqlStatsAction extends BaseRestHandler { public class RestSqlStatsAction extends BaseRestHandler {
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSqlStatsAction.class));
protected RestSqlStatsAction(Settings settings, RestController controller) { protected RestSqlStatsAction(Settings settings, RestController controller) {
super(settings); super(settings);
controller.registerHandler(GET, Protocol.SQL_STATS_REST_ENDPOINT, this); // TODO: remove deprecated endpoint in 8.0.0
controller.registerWithDeprecatedHandler(
GET, Protocol.SQL_STATS_REST_ENDPOINT, this,
GET, Protocol.SQL_STATS_DEPRECATED_REST_ENDPOINT, deprecationLogger);
} }
@Override @Override
public String getName() { public String getName() {
return "xpack_sql_stats_action"; return "sql_stats";
} }
@Override @Override

View File

@ -27,8 +27,8 @@ import static org.elasticsearch.rest.RestRequest.Method.POST;
public class RestSqlTranslateAction extends BaseRestHandler { public class RestSqlTranslateAction extends BaseRestHandler {
public RestSqlTranslateAction(Settings settings, RestController controller) { public RestSqlTranslateAction(Settings settings, RestController controller) {
super(settings); super(settings);
controller.registerHandler(GET, "/_xpack/sql/translate", this); controller.registerHandler(GET, "/_sql/translate", this);
controller.registerHandler(POST, "/_xpack/sql/translate", this); controller.registerHandler(POST, "/_sql/translate", this);
} }
@Override @Override

View File

@ -3,8 +3,8 @@
"documentation": "Clear SQL cursor", "documentation": "Clear SQL cursor",
"methods": [ "POST"], "methods": [ "POST"],
"url": { "url": {
"path": "/_xpack/sql/close", "path": "/_sql/close",
"paths": [ "/_xpack/sql/close" ], "paths": [ "/_sql/close" ],
"parts": {} "parts": {}
}, },
"body": { "body": {

View File

@ -3,8 +3,8 @@
"documentation": "Execute SQL", "documentation": "Execute SQL",
"methods": [ "POST", "GET" ], "methods": [ "POST", "GET" ],
"url": { "url": {
"path": "/_xpack/sql", "path": "/_sql",
"paths": [ "/_xpack/sql" ], "paths": [ "/_sql" ],
"parts": {}, "parts": {},
"params": { "params": {
"format": { "format": {

View File

@ -3,8 +3,8 @@
"documentation": "Translate SQL into Elasticsearch queries", "documentation": "Translate SQL into Elasticsearch queries",
"methods": [ "POST", "GET" ], "methods": [ "POST", "GET" ],
"url": { "url": {
"path": "/_xpack/sql/translate", "path": "/_sql/translate",
"paths": [ "/_xpack/sql/translate" ], "paths": [ "/_sql/translate" ],
"parts": {}, "parts": {},
"params": {} "params": {}
}, },

View File

@ -428,7 +428,12 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
client().performRequest(doc2); client().performRequest(doc2);
return; return;
} }
Request sqlRequest = new Request("POST", "/_xpack/sql"); final Request sqlRequest;
if (isRunningAgainstOldCluster()) {
sqlRequest = new Request("POST", "/_xpack/sql");
} else {
sqlRequest = new Request("POST", "/_sql");
}
sqlRequest.setJsonEntity("{\"query\":\"SELECT * FROM testsqlfailsonindexwithtwotypes\"}"); sqlRequest.setJsonEntity("{\"query\":\"SELECT * FROM testsqlfailsonindexwithtwotypes\"}");
ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(sqlRequest)); ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(sqlRequest));
assertEquals(400, e.getResponse().getStatusLine().getStatusCode()); assertEquals(400, e.getResponse().getStatusLine().getStatusCode());