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

Honor runtime JDK in provisioner #673

Merged
Show file tree
Hide file tree
Changes from all commits
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
43 changes: 43 additions & 0 deletions esrally/mechanic/java_resolver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import logging

from esrally import exceptions
from esrally.utils import jvm


def java_home(car, cfg):
def determine_runtime_jdks(car):
override_runtime_jdk = cfg.opts("mechanic", "runtime.jdk")
if override_runtime_jdk:
return [override_runtime_jdk]
else:
runtime_jdks = car.mandatory_var("runtime.jdk")
try:
return [int(v) for v in runtime_jdks.split(",")]
except ValueError:
raise exceptions.SystemSetupError(
"Car config key \"runtime.jdk\" is invalid: \"{}\" (must be int)".format(runtime_jdks))

logger = logging.getLogger(__name__)

runtime_jdk_versions = determine_runtime_jdks(car)
logger.info("Allowed JDK versions are %s.", runtime_jdk_versions)
major, java_home = jvm.resolve_path(runtime_jdk_versions)
logger.info("Detected JDK with major version [%s] in [%s].", major, java_home)
return major, java_home
22 changes: 2 additions & 20 deletions esrally/mechanic/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import shlex

from esrally import config, time, exceptions, client
from esrally.mechanic import telemetry, cluster
from esrally.mechanic import telemetry, cluster, java_resolver
from esrally.utils import process, jvm


Expand Down Expand Up @@ -298,7 +298,6 @@ def __init__(self, cfg, metrics_store, races_root_dir, clock=time.Clock):
self._clock = clock
self.races_root_dir = races_root_dir
self.keep_running = self.cfg.opts("mechanic", "keep.running")
self.override_runtime_jdk = self.cfg.opts("mechanic", "runtime.jdk")
self.logger = logging.getLogger(__name__)

def start(self, node_configurations):
Expand All @@ -317,7 +316,7 @@ def _start_node(self, node_configuration, node_count_on_host):
binary_path = node_configuration.binary_path
data_paths = node_configuration.data_paths
node_telemetry_dir = "%s/telemetry" % node_configuration.node_root_path
java_major_version, java_home = self._resolve_java_home(car)
java_major_version, java_home = java_resolver.java_home(car, self.cfg)

self.logger.info("Starting node [%s] based on car [%s].", node_name, car)

Expand Down Expand Up @@ -346,23 +345,6 @@ def _start_node(self, node_configuration, node_count_on_host):

return node

def _resolve_java_home(self, car):
runtime_jdk_versions = self._determine_runtime_jdks(car)
self.logger.info("Allowed JDK versions are %s.", runtime_jdk_versions)
major, java_home = jvm.resolve_path(runtime_jdk_versions)
self.logger.info("Detected JDK with major version [%s] in [%s].", major, java_home)
return major, java_home

def _determine_runtime_jdks(self, car):
if self.override_runtime_jdk:
return [self.override_runtime_jdk]
else:
runtime_jdks = car.mandatory_var("runtime.jdk")
try:
return [int(v) for v in runtime_jdks.split(",")]
except ValueError:
raise exceptions.SystemSetupError("Car config key \"runtime.jdk\" is invalid: \"{}\" (must be int)".format(runtime_jdks))

def _prepare_env(self, car, node_name, java_home, t):
env = {}
env.update(os.environ)
Expand Down
20 changes: 12 additions & 8 deletions esrally/mechanic/provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import jinja2

from esrally import exceptions
from esrally.mechanic import team
from esrally.mechanic import team, java_resolver
from esrally.utils import io, process, versions


Expand All @@ -37,8 +37,10 @@ def local_provisioner(cfg, car, plugins, cluster_settings, all_node_ips, target_
node_name = "%s-%d" % (node_name_prefix, node_id)
node_root_dir = "%s/%s" % (target_root, node_name)

es_installer = ElasticsearchInstaller(car, node_name, node_root_dir, all_node_ips, ip, http_port)
plugin_installers = [PluginInstaller(plugin) for plugin in plugins]
_, java_home = java_resolver.java_home(car, cfg)

es_installer = ElasticsearchInstaller(car, java_home, node_name, node_root_dir, all_node_ips, ip, http_port)
plugin_installers = [PluginInstaller(plugin, java_home) for plugin in plugins]

return BareProvisioner(cluster_settings, es_installer, plugin_installers, preserve, distribution_version=distribution_version)

Expand Down Expand Up @@ -220,8 +222,9 @@ def _provisioner_variables(self):


class ElasticsearchInstaller:
def __init__(self, car, node_name, node_root_dir, all_node_ips, ip, http_port, hook_handler_class=team.BootstrapHookHandler):
def __init__(self, car, java_home, node_name, node_root_dir, all_node_ips, ip, http_port, hook_handler_class=team.BootstrapHookHandler):
self.car = car
self.java_home = java_home
self.node_name = node_name
self.node_root_dir = node_root_dir
self.install_dir = "%s/install" % node_root_dir
Expand Down Expand Up @@ -254,7 +257,7 @@ def delete_pre_bundled_configuration(self):
shutil.rmtree(config_path)

def invoke_install_hook(self, phase, variables):
self.hook_handler.invoke(phase.name, variables=variables)
self.hook_handler.invoke(phase.name, variables=variables, env={"JAVA_HOME": self.java_home})

def cleanup(self, preserve):
cleanup(preserve, self.install_dir, self.data_paths)
Expand Down Expand Up @@ -307,8 +310,9 @@ def _data_paths(self):


class PluginInstaller:
def __init__(self, plugin, hook_handler_class=team.BootstrapHookHandler):
def __init__(self, plugin, java_home, hook_handler_class=team.BootstrapHookHandler):
self.plugin = plugin
self.java_home = java_home
self.hook_handler = hook_handler_class(self.plugin)
if self.hook_handler.can_load():
self.hook_handler.load()
Expand All @@ -323,7 +327,7 @@ def install(self, es_home_path, plugin_url=None):
self.logger.info("Installing [%s] into [%s]", self.plugin_name, es_home_path)
install_cmd = '%s install --batch "%s"' % (installer_binary_path, self.plugin_name)

return_code = process.run_subprocess_with_logging(install_cmd)
return_code = process.run_subprocess_with_logging(install_cmd, env={"JAVA_HOME": self.java_home})
# see: https://www.elastic.co/guide/en/elasticsearch/plugins/current/_other_command_line_parameters.html
if return_code == 0:
self.logger.info("Successfully installed [%s].", self.plugin_name)
Expand All @@ -337,7 +341,7 @@ def install(self, es_home_path, plugin_url=None):
(self.plugin_name, str(return_code)))

def invoke_install_hook(self, phase, variables):
self.hook_handler.invoke(phase.name, variables=variables)
self.hook_handler.invoke(phase.name, variables=variables, env={"JAVA_HOME": self.java_home})

@property
def variables(self):
Expand Down
Loading