From 3bdf3c4ae815c5eb739394e51f049b12656965cd Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Tue, 15 May 2018 15:08:44 -0400 Subject: [PATCH] SQL: Remove dependency for server's version from JDBC driver Removes dependency for server's version from the JDBC driver code. This should allow us to dramatically reduce driver's size by removing the server dependency from the driver. Relates #29856 --- .../xpack/sql/jdbc/net/client/JdbcHttpClient.java | 4 +++- .../xpack/sql/cli/command/CliSession.java | 3 ++- .../xpack/sql/cli/command/ServerInfoCliCommand.java | 2 +- .../elasticsearch/xpack/sql/cli/CliSessionTests.java | 4 ++-- .../sql/cli/command/ServerInfoCliCommandTests.java | 2 +- .../elasticsearch/xpack/sql/proto/MainResponse.java | 10 ++++------ 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/JdbcHttpClient.java b/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/JdbcHttpClient.java index 89ee78e0bae9e..17afc34efffe6 100644 --- a/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/JdbcHttpClient.java +++ b/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/JdbcHttpClient.java @@ -8,6 +8,7 @@ import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.xpack.sql.client.HttpClient; +import org.elasticsearch.xpack.sql.client.shared.Version; import org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcConfiguration; import org.elasticsearch.xpack.sql.jdbc.net.protocol.ColumnInfo; import org.elasticsearch.xpack.sql.jdbc.net.protocol.InfoResponse; @@ -79,7 +80,8 @@ public InfoResponse serverInfo() throws SQLException { private InfoResponse fetchServerInfo() throws SQLException { MainResponse mainResponse = httpClient.serverInfo(); - return new InfoResponse(mainResponse.getClusterName(), mainResponse.getVersion().major, mainResponse.getVersion().minor); + Version version = Version.fromString(mainResponse.getVersion()); + return new InfoResponse(mainResponse.getClusterName(), version.major, version.minor); } /** diff --git a/x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/command/CliSession.java b/x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/command/CliSession.java index 8e030f36dd042..fc89e3939cc35 100644 --- a/x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/command/CliSession.java +++ b/x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/command/CliSession.java @@ -65,8 +65,9 @@ public void checkConnection() throws ClientException { } catch (SQLException ex) { throw new ClientException(ex); } + Version version = Version.fromString(response.getVersion()); // TODO: We can relax compatibility requirement later when we have a better idea about protocol compatibility guarantees - if (response.getVersion().major != Version.CURRENT.major || response.getVersion().minor != Version.CURRENT.minor) { + if (version.major != Version.CURRENT.major || version.minor != Version.CURRENT.minor) { throw new ClientException("This alpha version of CLI is only compatible with Elasticsearch version " + Version.CURRENT.toString()); } diff --git a/x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/command/ServerInfoCliCommand.java b/x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/command/ServerInfoCliCommand.java index e637386f9798f..9e7b75102ec6f 100644 --- a/x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/command/ServerInfoCliCommand.java +++ b/x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/command/ServerInfoCliCommand.java @@ -31,7 +31,7 @@ public boolean doHandle(CliTerminal terminal, CliSession cliSession, String line terminal.line() .text("Node:").em(info.getNodeName()) .text(" Cluster:").em(info.getClusterName()) - .text(" Version:").em(info.getVersion().toString()) + .text(" Version:").em(info.getVersion()) .ln(); return true; } diff --git a/x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/CliSessionTests.java b/x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/CliSessionTests.java index e5643ad443a59..265051a5a58df 100644 --- a/x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/CliSessionTests.java +++ b/x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/CliSessionTests.java @@ -27,7 +27,7 @@ public class CliSessionTests extends ESTestCase { public void testProperConnection() throws Exception { HttpClient httpClient = mock(HttpClient.class); - when(httpClient.serverInfo()).thenReturn(new MainResponse(randomAlphaOfLength(5), org.elasticsearch.Version.CURRENT, + when(httpClient.serverInfo()).thenReturn(new MainResponse(randomAlphaOfLength(5), org.elasticsearch.Version.CURRENT.toString(), ClusterName.DEFAULT.value(), UUIDs.randomBase64UUID(), Build.CURRENT)); CliSession cliSession = new CliSession(httpClient); cliSession.checkConnection(); @@ -57,7 +57,7 @@ public void testWrongServerVersion() throws Exception { } when(httpClient.serverInfo()).thenReturn(new MainResponse(randomAlphaOfLength(5), - org.elasticsearch.Version.fromString(major + "." + minor + ".23"), + org.elasticsearch.Version.fromString(major + "." + minor + ".23").toString(), ClusterName.DEFAULT.value(), UUIDs.randomBase64UUID(), Build.CURRENT)); CliSession cliSession = new CliSession(httpClient); expectThrows(ClientException.class, cliSession::checkConnection); diff --git a/x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/command/ServerInfoCliCommandTests.java b/x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/command/ServerInfoCliCommandTests.java index e99cb2fb7f7e2..6c9d4933a9912 100644 --- a/x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/command/ServerInfoCliCommandTests.java +++ b/x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/command/ServerInfoCliCommandTests.java @@ -35,7 +35,7 @@ public void testShowInfo() throws Exception { TestTerminal testTerminal = new TestTerminal(); HttpClient client = mock(HttpClient.class); CliSession cliSession = new CliSession(client); - when(client.serverInfo()).thenReturn(new MainResponse("my_node", org.elasticsearch.Version.fromString("1.2.3"), + when(client.serverInfo()).thenReturn(new MainResponse("my_node", "1.2.3", new ClusterName("my_cluster").value(), UUIDs.randomBase64UUID(), Build.CURRENT)); ServerInfoCliCommand cliCommand = new ServerInfoCliCommand(); assertTrue(cliCommand.handle(testTerminal, cliSession, "info")); diff --git a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/MainResponse.java b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/MainResponse.java index 73b6cbc529ec6..c8bb0c51f7fe7 100644 --- a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/MainResponse.java +++ b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/MainResponse.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.sql.proto; import org.elasticsearch.Build; -import org.elasticsearch.Version; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentParser; @@ -19,8 +18,7 @@ */ public class MainResponse { private String nodeName; - // TODO: Add parser for Version - private Version version; + private String version; private String clusterName; private String clusterUuid; // TODO: Add parser for Build @@ -29,7 +27,7 @@ public class MainResponse { private MainResponse() { } - public MainResponse(String nodeName, Version version, String clusterName, String clusterUuid, Build build) { + public MainResponse(String nodeName, String version, String clusterName, String clusterUuid, Build build) { this.nodeName = nodeName; this.version = version; this.clusterName = clusterName; @@ -41,7 +39,7 @@ public String getNodeName() { return nodeName; } - public Version getVersion() { + public String getVersion() { return version; } @@ -76,7 +74,7 @@ public Build getBuild() { (String) value.get("build_hash"), (String) value.get("build_date"), (boolean) value.get("build_snapshot")); - response.version = Version.fromString((String) value.get("number")); + response.version = (String) value.get("number"); }, (parser, context) -> parser.map(), new ParseField("version")); }