Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: handle X-Pack or X-Pack SQL not being available in a more graceful way #34736

Merged
merged 9 commits into from
Oct 25, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ 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 [/_xpack/sql] contains unrecognized parameter: [mode]";

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 @@ -176,6 +177,19 @@ private <R> ResponseOrException<R> parserError() throws IOException {
}
SqlExceptionType type = SqlExceptionType.fromRemoteFailureType(failure.type());
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"
+ " on the Elasticsearch node using the access path '"
+ con.getURL().getHost()
+ (con.getURL().getPort() > 0 ? ":" + con.getURL().getPort() : "")
+ "'."
+ " Please verify X-Pack is installed and SQL enabled. Alternatively, check if any proxy is interfering"
+ " the communication to Elasticsearch",
SQL_STATE_BAD_SERVER));
}
return new ResponseOrException<>(new SQLException("Server sent bad type ["
+ failure.type() + "]. Original type was [" + failure.reason() + "]. ["
+ failure.remoteTrace() + "]", SQL_STATE_BAD_SERVER));
Expand Down