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

Validate if car allows for using the bundled JDK #987

Merged
merged 11 commits into from
May 26, 2020

Conversation

hub-cap
Copy link
Contributor

@hub-cap hub-cap commented May 6, 2020

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

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
@hub-cap hub-cap added bug Something's wrong :misc Changes that don't affect users directly: linter fixes, test improvements, etc. labels May 6, 2020
@hub-cap hub-cap added this to the 2.0.1 milestone May 6, 2020
@hub-cap hub-cap self-assigned this May 6, 2020
@hub-cap
Copy link
Contributor Author

hub-cap commented May 6, 2020

@elasticmachine run tests

@hub-cap
Copy link
Contributor Author

hub-cap commented May 6, 2020

@elasticmachine update branch

@hub-cap
Copy link
Contributor Author

hub-cap commented May 6, 2020

@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?

Copy link
Member

@danielmitterdorfer danielmitterdorfer left a 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.

@@ -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): {}"
Copy link
Member

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.

@@ -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):
Copy link
Member

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 from cfg.opts("mechanic", "runtime.jdk")
  • provides_bundled_jdk determines whether this Elasticsearch version ships with a bundled JDK

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)
Copy link
Member

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)?

@@ -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)
Copy link
Member

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?

Copy link
Member

@danielmitterdorfer danielmitterdorfer left a 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.

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)
Copy link
Member

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.

@@ -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"),
Copy link
Member

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.

@@ -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"),
Copy link
Member

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.

@@ -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"),
Copy link
Member

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.

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"))
Copy link
Member

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.

Copy link
Member

@danielmitterdorfer danielmitterdorfer left a 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.

provides_bundled_jdk=True)

self.assertEqual(major, 12)
self.assertEqual(java_home, "/opt/jdk12")
self.assertEqual(major, resolve_jvm_path.return_value[0])
Copy link
Member

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.

Copy link
Contributor Author

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.

provides_bundled_jdk=True)

self.assertEqual(major, 8)
self.assertEqual(java_home, "/opt/jdk8")
self.assertEqual(major, resolve_jvm_path.return_value[0])
Copy link
Member

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.

@hub-cap
Copy link
Contributor Author

hub-cap commented May 20, 2020

Ive requested review again as I wasnt sure if u were meaning to approve it but just did comment, or not.

Copy link
Member

@danielmitterdorfer danielmitterdorfer left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM

@hub-cap hub-cap merged commit 3300015 into elastic:master May 26, 2020
@hub-cap hub-cap deleted the bundle_version_check branch May 26, 2020 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something's wrong :misc Changes that don't affect users directly: linter fixes, test improvements, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

using runtime-jdk=bundled prior to elasticsearch 7 results in elasticserach using java from the path
3 participants