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: Handle uberjar scenario where the ES jdbc driver file is bundled in another jar #51856

Merged
merged 7 commits into from
Feb 7, 2020

Conversation

astefan
Copy link
Contributor

@astefan astefan commented Feb 4, 2020

Implementation for #50201

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/SQL)

@astefan astefan marked this pull request as ready for review February 4, 2020 14:38
@astefan astefan changed the title SQL: Handle uber-jar scenario where the ES jdbc driver file is bundled in another jar SQL: Handle uberjar scenario where the ES jdbc driver file is bundled in another jar Feb 4, 2020
Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left a comment.

maj = vers[0];
min = vers[1];
rev = vers[2];
}
} catch (Exception ex) {
throw new IllegalArgumentException("Detected Elasticsearch JDBC jar but cannot retrieve its version", ex);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a finally block to close the conn ?
(Maybe JarInputStream 's close() takes care of that, just wondering if we should be extra safe here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's needed to close the URLConnection (actually, the class doesn't have a method to close/terminate it), only its stream: https://docs.oracle.com/javase/tutorial/networking/urls/readingWriting.html

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Manifest manifest = jar.getManifest();
hash = manifest.getMainAttributes().getValue("Change");
ver = manifest.getMainAttributes().getValue("X-Compile-Elasticsearch-Version");
byte[] vers = from(ver);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is unmodified code, however, it's noteworthy that server/src/main/java/org/elasticsearch/Version.java parses ints, not bytes. Not sure if that's because it later does some int maths with the components, or because it reserves the possibility to use some tagging values at some point (like 7.2.222 for a special release). Just mentioning it, should we ever want to align this.

public void testVersionFromJarInJar() throws IOException {
Path dir = createTempDir();
Path jarPath = dir.resolve("foo.jar"); // simulated uberjar containing the jdbc driver
Path innerJarPath = dir.resolve("es-sql-jdbc.jar"); // simulated ES JDBC driver file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given it's a test, this is completely optional: extract the "es-sql-jdbc.jar" into a final var and reuse that below.

Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@astefan
Copy link
Contributor Author

astefan commented Feb 7, 2020

@elasticmachine update branch

@astefan astefan merged commit 6247b07 into elastic:master Feb 7, 2020
@astefan astefan deleted the 50201_impl branch February 7, 2020 01:07
astefan added a commit to astefan/elasticsearch that referenced this pull request Feb 7, 2020
astefan added a commit that referenced this pull request Feb 7, 2020
astefan added a commit that referenced this pull request Feb 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants