Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions x-pack/plugin/sql/qa/no-sql/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
testClusters.integTest {
setting 'xpack.security.enabled', 'false'
setting 'xpack.sql.enabled', 'false'
setting 'xpack.license.self_generated.type', 'trial'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.sql.qa.no_sql;

import org.elasticsearch.xpack.sql.qa.jdbc.JdbcNoSqlTestCase;

public class JdbcNoSqlIT extends JdbcNoSqlTestCase {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.sql.qa.jdbc;

import java.sql.Connection;
import java.sql.SQLException;

public class JdbcNoSqlTestCase extends JdbcIntegrationTestCase {

public void testJdbcExceptionMessage() throws SQLException {
try (Connection c = esJdbc()) {
SQLException e = expectThrows(SQLException.class, () -> c.prepareStatement("SELECT * FROM bla").executeQuery());
assertTrue(e.getMessage().startsWith("X-Pack/SQL does not seem to be available on the Elasticsearch"
+ " node using the access path"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public class JreHttpUrlConnection implements Closeable {
* error.
*/
public static final String SQL_STATE_BAD_SERVER = "bad_server";
private static final String SQL_NOT_AVAILABLE_ERROR_MESSAGE = "request [" + SQL_QUERY_REST_ENDPOINT
+ "] contains unrecognized parameter: [mode]";
private static final String SQL_NOT_AVAILABLE_ERROR_MESSAGE = "Incorrect HTTP method for uri [" + SQL_QUERY_REST_ENDPOINT
+ "?error_trace] and method [POST], allowed:";

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
Expand Down Expand Up @@ -181,9 +181,8 @@ private <R> ResponseOrException<R> parserError() throws IOException {
if (type == null) {
// check if x-pack or sql are not available (x-pack not installed or sql not enabled)
// by checking the error message the server is sending back
if (con.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST
&& failure.reason().contains(SQL_NOT_AVAILABLE_ERROR_MESSAGE)) {
return new ResponseOrException<>(new SQLException("X-Pack/SQL do not seem to be available"
if (con.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST && failure.reason().contains(SQL_NOT_AVAILABLE_ERROR_MESSAGE)) {
return new ResponseOrException<>(new SQLException("X-Pack/SQL does not seem to be available"
+ " on the Elasticsearch node using the access path '"
+ con.getURL().getHost()
+ (con.getURL().getPort() > 0 ? ":" + con.getURL().getPort() : "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,15 @@ private static RemoteFailure parseResponseTopLevel(JsonParser parser) throws IOE
} else {
switch (fieldName) {
case "error":
if (token != JsonToken.START_OBJECT) {
throw new IOException("Expected [error] to be an object but was [" + token + "][" + parser.getText() + "]");
if (token != JsonToken.START_OBJECT && token != JsonToken.VALUE_STRING) {
throw new IOException("Expected [error] to be an object or string but was [" + token + "]["
+ parser.getText() + "]");
}
if (token == JsonToken.VALUE_STRING) {
exception = new RemoteFailure(StringUtils.EMPTY, parser.getText(), null, null, null, null);
} else {
exception = parseFailure(parser);
}
exception = parseFailure(parser);
continue;
case "status":
if (token != JsonToken.VALUE_NUMBER_INT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public void testNoError() {
public void testBogusError() {
IOException e = expectThrows(IOException.class, () -> parse("bogus_error.json"));
assertEquals(
"Can't parse error from Elasticsearch [Expected [error] to be an object but was [VALUE_STRING][bogus]] "
"Can't parse error from Elasticsearch [Expected [error] to be an object or string but was [START_ARRAY][[]] "
+ "at [line 1 col 12]. Response:\n"
+ "{ \"error\": \"bogus\" }",
+ "{ \"error\": [\"bogus\"] }",
e.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "error": "bogus" }
{ "error": ["bogus"] }