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: Remove dependency for server's Version from JDBC driver #30631

Merged
merged 2 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -41,7 +39,7 @@ public String getNodeName() {
return nodeName;
}

public Version getVersion() {
public String getVersion() {
return version;
}

Expand Down Expand Up @@ -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"));
}

Expand Down