-
Notifications
You must be signed in to change notification settings - Fork 313
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
Validate if car allows for using the bundled JDK #987
Conversation
When the bundled JDK was introduced, it was added to the car config file. This check uses the value from the car config to ensure that the bundled JDK is allowed to be used as specified by the config. If not, it throws an exception. Closes elastic#985
@elasticmachine run tests |
@elasticmachine update branch |
@danielmitterdorfer hey friend, this has passed CI checks and I would love a look. Im not 100% happy with where/how the check is, but I dont know if there is much we can do besides rely on a check everywhere this method is used, outside of the actual starting of the nodes. Is there possibly some other validation that is done before rally gets this deep into running? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I left a few suggestions.
esrally/mechanic/java_resolver.py
Outdated
@@ -39,6 +39,9 @@ def determine_runtime_jdks(): | |||
|
|||
runtime_jdk_versions = determine_runtime_jdks() | |||
if runtime_jdk_versions[0] == "bundled": | |||
if not allow_bundled_jvm: | |||
raise exceptions.SystemSetupError("The bundled JDK is not allowed with the selected car(s): {}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This decision does not depend on the chosen car but rather on the Elasticsearch version. How about we change the error message to:
This Elasticsearch version does not contain a bundled JDK. Please specify a different runtime JDK.
esrally/mechanic/java_resolver.py
Outdated
@@ -21,7 +21,7 @@ | |||
from esrally.utils import jvm | |||
|
|||
|
|||
def java_home(car_runtime_jdks, cfg): | |||
def java_home(car_runtime_jdks, allow_bundled_jvm, cfg): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we refactor the signature a bit? Ideally we could also get rid of the cfg
object here and pass the chosen runtime JDK directly. I propose the following signature:
def java_home(car_runtime_jdks, specified_runtime_jdk, provides_bundled_jdk)
where
specified_runtime_jdk
is derived fromcfg.opts("mechanic", "runtime.jdk")
provides_bundled_jdk
determines whether this Elasticsearch version ships with a bundled JDK
esrally/mechanic/provisioner.py
Outdated
self.build_type = build_type | ||
self.car_env = car_env | ||
self.car_runtime_jdks = car_runtime_jdks | ||
self.car_allow_bundled_jvm = convert.to_bool(car_allow_bundled_jvm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we call this variable car_provides_bundled_jdk
(and adapt all dependent variables and strings accordingly)?
tests/mechanic/java_resolver_test.py
Outdated
@@ -30,7 +30,7 @@ def test_resolves_java_home_for_default_runtime_jdk(self, resolve_jvm_path): | |||
cfg = config.Config() | |||
cfg.add(config.Scope.application, "mechanic", "runtime.jdk", None) | |||
|
|||
major, java_home = java_resolver.java_home("12,11,10,9,8", cfg) | |||
major, java_home = java_resolver.java_home("12,11,10,9,8", True, cfg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we switch to named parameters here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much better! I left a couple of comments but I think we're almost there.
esrally/mechanic/provisioner.py
Outdated
self.build_type = build_type | ||
self.car_env = car_env | ||
self.car_runtime_jdks = car_runtime_jdks | ||
self.car_provides_bundled_jdk = convert.to_bool(car_provides_bundled_jdk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move the conversion (i.e. convert.to_bool
to the call site(s)?) IMHO we should use the correct type bool
already in the constructor.
tests/mechanic/java_resolver_test.py
Outdated
@@ -30,7 +30,9 @@ def test_resolves_java_home_for_default_runtime_jdk(self, resolve_jvm_path): | |||
cfg = config.Config() | |||
cfg.add(config.Scope.application, "mechanic", "runtime.jdk", None) | |||
|
|||
major, java_home = java_resolver.java_home("12,11,10,9,8", cfg) | |||
major, java_home = java_resolver.java_home("12,11,10,9,8", | |||
specified_runtime_jdk=cfg.opts("mechanic", "runtime.jdk"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for the Config
object anymore and therefore we should simplify the test and only pass the actual value here.
tests/mechanic/java_resolver_test.py
Outdated
@@ -42,7 +44,9 @@ def test_resolves_java_home_for_specific_runtime_jdk(self, resolve_jvm_path): | |||
cfg = config.Config() | |||
cfg.add(config.Scope.application, "mechanic", "runtime.jdk", 8) | |||
|
|||
major, java_home = java_resolver.java_home("12,11,10,9,8", cfg) | |||
major, java_home = java_resolver.java_home("12,11,10,9,8", | |||
specified_runtime_jdk=cfg.opts("mechanic", "runtime.jdk"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for the Config
object anymore and therefore we should simplify the test and only pass the actual value here.
tests/mechanic/java_resolver_test.py
Outdated
@@ -53,9 +57,22 @@ def test_resolves_java_home_for_bundled_jdk(self): | |||
cfg = config.Config() | |||
cfg.add(config.Scope.application, "mechanic", "runtime.jdk", "bundled") | |||
|
|||
major, java_home = java_resolver.java_home("12,11,10,9,8", cfg) | |||
major, java_home = java_resolver.java_home("12,11,10,9,8", | |||
specified_runtime_jdk=cfg.opts("mechanic", "runtime.jdk"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for the Config
object anymore and therefore we should simplify the test and only pass the actual value here.
tests/mechanic/java_resolver_test.py
Outdated
cfg.add(config.Scope.application, "mechanic", "car.names", ["default"]) | ||
|
||
with self.assertRaises(exceptions.SystemSetupError) as ctx: | ||
java_resolver.java_home("12,11,10,9,8", specified_runtime_jdk=cfg.opts("mechanic", "runtime.jdk")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for the Config
object anymore and therefore we should simplify the test and only pass the actual value here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a comment about readability of test assertions but apart from that it looks fine.
tests/mechanic/java_resolver_test.py
Outdated
provides_bundled_jdk=True) | ||
|
||
self.assertEqual(major, 12) | ||
self.assertEqual(java_home, "/opt/jdk12") | ||
self.assertEqual(major, resolve_jvm_path.return_value[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the previous implementation was more readable, even if we duplicate code. However, the scope of duplication is within the test method so this is ok IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im fine w/ either. I just hate reusing strings in a test method in general, cuz things can get out of sync. I can revert.
tests/mechanic/java_resolver_test.py
Outdated
provides_bundled_jdk=True) | ||
|
||
self.assertEqual(major, 8) | ||
self.assertEqual(java_home, "/opt/jdk8") | ||
self.assertEqual(major, resolve_jvm_path.return_value[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the previous implementation was more readable, even if we duplicate code. However, the scope of duplication is within the test method so this is ok IMHO.
Ive requested review again as I wasnt sure if u were meaning to approve it but just did comment, or not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM
When the bundled JDK was introduced, it was added to the car config
file. This check uses the value from the car config to ensure that the
bundled JDK is allowed to be used as specified by the config. If not, it
throws an exception.
Closes #985