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
This commit is contained in:
parent
d912fa4357
commit
7b6d0faec2
|
@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.jdbc.net.client;
|
|||
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 class JdbcHttpClient {
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -65,8 +65,9 @@ public class CliSession {
|
|||
} 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());
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class ServerInfoCliCommand extends AbstractServerCliCommand {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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 class CliSessionTests extends ESTestCase {
|
|||
|
||||
}
|
||||
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);
|
||||
|
|
|
@ -35,7 +35,7 @@ public class ServerInfoCliCommandTests extends ESTestCase {
|
|||
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"));
|
||||
|
|
|
@ -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 @@ import java.util.Objects;
|
|||
*/
|
||||
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 class MainResponse {
|
|||
return nodeName;
|
||||
}
|
||||
|
||||
public Version getVersion() {
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
|
@ -76,7 +74,7 @@ public class MainResponse {
|
|||
(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"));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue