Skip to content

Commit 0d1a98f

Browse files
committed
SQL: Remove dependency for server's version from JDBC driver (#30631)
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
1 parent 3844e3f commit 0d1a98f

File tree

6 files changed

+13
-12
lines changed

6 files changed

+13
-12
lines changed

x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/JdbcHttpClient.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.elasticsearch.common.collect.Tuple;
99
import org.elasticsearch.common.unit.TimeValue;
1010
import org.elasticsearch.xpack.sql.client.HttpClient;
11+
import org.elasticsearch.xpack.sql.client.shared.Version;
1112
import org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcConfiguration;
1213
import org.elasticsearch.xpack.sql.jdbc.net.protocol.ColumnInfo;
1314
import org.elasticsearch.xpack.sql.jdbc.net.protocol.InfoResponse;
@@ -79,7 +80,8 @@ public InfoResponse serverInfo() throws SQLException {
7980

8081
private InfoResponse fetchServerInfo() throws SQLException {
8182
MainResponse mainResponse = httpClient.serverInfo();
82-
return new InfoResponse(mainResponse.getClusterName(), mainResponse.getVersion().major, mainResponse.getVersion().minor);
83+
Version version = Version.fromString(mainResponse.getVersion());
84+
return new InfoResponse(mainResponse.getClusterName(), version.major, version.minor);
8385
}
8486

8587
/**

x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/command/CliSession.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ public void checkConnection() throws ClientException {
6565
} catch (SQLException ex) {
6666
throw new ClientException(ex);
6767
}
68+
Version version = Version.fromString(response.getVersion());
6869
// TODO: We can relax compatibility requirement later when we have a better idea about protocol compatibility guarantees
69-
if (response.getVersion().major != Version.CURRENT.major || response.getVersion().minor != Version.CURRENT.minor) {
70+
if (version.major != Version.CURRENT.major || version.minor != Version.CURRENT.minor) {
7071
throw new ClientException("This alpha version of CLI is only compatible with Elasticsearch version " +
7172
Version.CURRENT.toString());
7273
}

x-pack/plugin/sql/sql-cli/src/main/java/org/elasticsearch/xpack/sql/cli/command/ServerInfoCliCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public boolean doHandle(CliTerminal terminal, CliSession cliSession, String line
3131
terminal.line()
3232
.text("Node:").em(info.getNodeName())
3333
.text(" Cluster:").em(info.getClusterName())
34-
.text(" Version:").em(info.getVersion().toString())
34+
.text(" Version:").em(info.getVersion())
3535
.ln();
3636
return true;
3737
}

x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/CliSessionTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class CliSessionTests extends ESTestCase {
2727

2828
public void testProperConnection() throws Exception {
2929
HttpClient httpClient = mock(HttpClient.class);
30-
when(httpClient.serverInfo()).thenReturn(new MainResponse(randomAlphaOfLength(5), org.elasticsearch.Version.CURRENT,
30+
when(httpClient.serverInfo()).thenReturn(new MainResponse(randomAlphaOfLength(5), org.elasticsearch.Version.CURRENT.toString(),
3131
ClusterName.DEFAULT.value(), UUIDs.randomBase64UUID(), Build.CURRENT));
3232
CliSession cliSession = new CliSession(httpClient);
3333
cliSession.checkConnection();
@@ -57,7 +57,7 @@ public void testWrongServerVersion() throws Exception {
5757

5858
}
5959
when(httpClient.serverInfo()).thenReturn(new MainResponse(randomAlphaOfLength(5),
60-
org.elasticsearch.Version.fromString(major + "." + minor + ".23"),
60+
org.elasticsearch.Version.fromString(major + "." + minor + ".23").toString(),
6161
ClusterName.DEFAULT.value(), UUIDs.randomBase64UUID(), Build.CURRENT));
6262
CliSession cliSession = new CliSession(httpClient);
6363
expectThrows(ClientException.class, cliSession::checkConnection);

x-pack/plugin/sql/sql-cli/src/test/java/org/elasticsearch/xpack/sql/cli/command/ServerInfoCliCommandTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void testShowInfo() throws Exception {
3535
TestTerminal testTerminal = new TestTerminal();
3636
HttpClient client = mock(HttpClient.class);
3737
CliSession cliSession = new CliSession(client);
38-
when(client.serverInfo()).thenReturn(new MainResponse("my_node", org.elasticsearch.Version.fromString("1.2.3"),
38+
when(client.serverInfo()).thenReturn(new MainResponse("my_node", "1.2.3",
3939
new ClusterName("my_cluster").value(), UUIDs.randomBase64UUID(), Build.CURRENT));
4040
ServerInfoCliCommand cliCommand = new ServerInfoCliCommand();
4141
assertTrue(cliCommand.handle(testTerminal, cliSession, "info"));

x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/MainResponse.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package org.elasticsearch.xpack.sql.proto;
88

99
import org.elasticsearch.Build;
10-
import org.elasticsearch.Version;
1110
import org.elasticsearch.common.ParseField;
1211
import org.elasticsearch.common.xcontent.ObjectParser;
1312
import org.elasticsearch.common.xcontent.XContentParser;
@@ -19,8 +18,7 @@
1918
*/
2019
public class MainResponse {
2120
private String nodeName;
22-
// TODO: Add parser for Version
23-
private Version version;
21+
private String version;
2422
private String clusterName;
2523
private String clusterUuid;
2624
// TODO: Add parser for Build
@@ -29,7 +27,7 @@ public class MainResponse {
2927
private MainResponse() {
3028
}
3129

32-
public MainResponse(String nodeName, Version version, String clusterName, String clusterUuid, Build build) {
30+
public MainResponse(String nodeName, String version, String clusterName, String clusterUuid, Build build) {
3331
this.nodeName = nodeName;
3432
this.version = version;
3533
this.clusterName = clusterName;
@@ -41,7 +39,7 @@ public String getNodeName() {
4139
return nodeName;
4240
}
4341

44-
public Version getVersion() {
42+
public String getVersion() {
4543
return version;
4644
}
4745

@@ -76,7 +74,7 @@ public Build getBuild() {
7674
(String) value.get("build_hash"),
7775
(String) value.get("build_date"),
7876
(boolean) value.get("build_snapshot"));
79-
response.version = Version.fromString((String) value.get("number"));
77+
response.version = (String) value.get("number");
8078
}, (parser, context) -> parser.map(), new ParseField("version"));
8179
}
8280

0 commit comments

Comments
 (0)