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:
Igor Motov 2018-05-16 15:07:14 -04:00 committed by GitHub
parent d912fa4357
commit 7b6d0faec2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 12 deletions

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.jdbc.net.client;
import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.xpack.sql.client.HttpClient; 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.jdbc.JdbcConfiguration;
import org.elasticsearch.xpack.sql.jdbc.net.protocol.ColumnInfo; import org.elasticsearch.xpack.sql.jdbc.net.protocol.ColumnInfo;
import org.elasticsearch.xpack.sql.jdbc.net.protocol.InfoResponse; import org.elasticsearch.xpack.sql.jdbc.net.protocol.InfoResponse;
@ -79,7 +80,8 @@ public class JdbcHttpClient {
private InfoResponse fetchServerInfo() throws SQLException { private InfoResponse fetchServerInfo() throws SQLException {
MainResponse mainResponse = httpClient.serverInfo(); 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);
} }
/** /**

View File

@ -65,8 +65,9 @@ public class CliSession {
} catch (SQLException ex) { } catch (SQLException ex) {
throw new ClientException(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 // 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 " + throw new ClientException("This alpha version of CLI is only compatible with Elasticsearch version " +
Version.CURRENT.toString()); Version.CURRENT.toString());
} }

View File

@ -31,7 +31,7 @@ public class ServerInfoCliCommand extends AbstractServerCliCommand {
terminal.line() terminal.line()
.text("Node:").em(info.getNodeName()) .text("Node:").em(info.getNodeName())
.text(" Cluster:").em(info.getClusterName()) .text(" Cluster:").em(info.getClusterName())
.text(" Version:").em(info.getVersion().toString()) .text(" Version:").em(info.getVersion())
.ln(); .ln();
return true; return true;
} }

View File

@ -27,7 +27,7 @@ public class CliSessionTests extends ESTestCase {
public void testProperConnection() throws Exception { public void testProperConnection() throws Exception {
HttpClient httpClient = mock(HttpClient.class); 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)); ClusterName.DEFAULT.value(), UUIDs.randomBase64UUID(), Build.CURRENT));
CliSession cliSession = new CliSession(httpClient); CliSession cliSession = new CliSession(httpClient);
cliSession.checkConnection(); cliSession.checkConnection();
@ -57,7 +57,7 @@ public class CliSessionTests extends ESTestCase {
} }
when(httpClient.serverInfo()).thenReturn(new MainResponse(randomAlphaOfLength(5), 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)); ClusterName.DEFAULT.value(), UUIDs.randomBase64UUID(), Build.CURRENT));
CliSession cliSession = new CliSession(httpClient); CliSession cliSession = new CliSession(httpClient);
expectThrows(ClientException.class, cliSession::checkConnection); expectThrows(ClientException.class, cliSession::checkConnection);

View File

@ -35,7 +35,7 @@ public class ServerInfoCliCommandTests extends ESTestCase {
TestTerminal testTerminal = new TestTerminal(); TestTerminal testTerminal = new TestTerminal();
HttpClient client = mock(HttpClient.class); HttpClient client = mock(HttpClient.class);
CliSession cliSession = new CliSession(client); 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)); new ClusterName("my_cluster").value(), UUIDs.randomBase64UUID(), Build.CURRENT));
ServerInfoCliCommand cliCommand = new ServerInfoCliCommand(); ServerInfoCliCommand cliCommand = new ServerInfoCliCommand();
assertTrue(cliCommand.handle(testTerminal, cliSession, "info")); assertTrue(cliCommand.handle(testTerminal, cliSession, "info"));

View File

@ -7,7 +7,6 @@
package org.elasticsearch.xpack.sql.proto; package org.elasticsearch.xpack.sql.proto;
import org.elasticsearch.Build; import org.elasticsearch.Build;
import org.elasticsearch.Version;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -19,8 +18,7 @@ import java.util.Objects;
*/ */
public class MainResponse { public class MainResponse {
private String nodeName; private String nodeName;
// TODO: Add parser for Version private String version;
private Version version;
private String clusterName; private String clusterName;
private String clusterUuid; private String clusterUuid;
// TODO: Add parser for Build // TODO: Add parser for Build
@ -29,7 +27,7 @@ public class MainResponse {
private 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.nodeName = nodeName;
this.version = version; this.version = version;
this.clusterName = clusterName; this.clusterName = clusterName;
@ -41,7 +39,7 @@ public class MainResponse {
return nodeName; return nodeName;
} }
public Version getVersion() { public String getVersion() {
return version; return version;
} }
@ -76,7 +74,7 @@ public class MainResponse {
(String) value.get("build_hash"), (String) value.get("build_hash"),
(String) value.get("build_date"), (String) value.get("build_date"),
(boolean) value.get("build_snapshot")); (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")); }, (parser, context) -> parser.map(), new ParseField("version"));
} }