8000 ElasticSearch: Fix missing JRE in 5.x and 6.x by viren-nadkarni · Pull Request #12286 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

ElasticSearch: Fix missing JRE in 5.x and 6.x #12286

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

Merged
merged 7 commits into from
Feb 24, 2025
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
17 changes: 14 additions & 3 deletions localstack-core/localstack/services/opensearch/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,22 +675,33 @@ def _base_settings(self, dirs) -> CommandSettings:
settings = {
"http.port": self.port,
"http.publish_port": self.port,
"transport.port": "0",
"network.host": self.host,
"http.compression": "false",
"path.data": f'"{dirs.data}"',
"path.repo": f'"{dirs.backup}"',
"discovery.type": "single-node",
}

# This config option was renamed between 6.7 and 6.8, yet not documented as a breaking change
# See https://github.com/elastic/elasticsearch/blob/f220abaf/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java#L1349-L1353
if self.version.startswith("Elasticsearch_5.") or (
self.version.startswith("Elasticsearch_6.") and self.version != "Elasticsearch_6.8"
):
settings["transport.tcp.port"] = "0"
else:
settings["transport.port"] = "0"

# `discovery.type` had a different meaning in 5.x
if not self.version.startswith("Elasticsearch_5."):
settings["discovery.type"] = "single-node"

< 8000 /span> Copy link
Member Author

Choose a reason for hiding this comment

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

Required because ES refuses to start if any config is invalid or unknown

Choose a reason for hiding this comment

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

Thanks for the fix @viren-nadkarni willing to give it a try once is released, I'm facing the same issue

if os.path.exists(os.path.join(dirs.mods, "x-pack-ml")):
settings["xpack.ml.enabled"] = "false"

return settings

def _create_env_vars(self, directories: Directories) -> Dict:
return {
"JAVA_HOME": os.path.join(directories.install, "jdk"),
**elasticsearch_package.get_installer(self.version).get_java_env_vars(),
"ES_JAVA_OPTS": os.environ.get("ES_JAVA_OPTS", "-Xms200m -Xmx600m"),
"ES_TMPDIR": directories.tmp,
}
Expand Down
33 changes: 32 additions & 1 deletion localstack-core/localstack/services/opensearch/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
OPENSEARCH_PLUGIN_LIST,
)
from localstack.packages import InstallTarget, Package, PackageInstaller
from localstack.packages.java import java_package
from localstack.services.opensearch import versions
from localstack.utils.archives import download_and_extract_with_retry
from localstack.utils.files import chmod_r, load_file, mkdir, rm_rf, save_file
Expand All @@ -42,6 +43,8 @@ def __init__(self, default_version: str = OPENSEARCH_DEFAULT_VERSION):

def _get_installer(self, version: str) -> PackageInstaller:
if version in versions._prefixed_elasticsearch_install_versions:
if version.startswith("Elasticsearch_5.") or version.startswith("Elasticsearch_6."):
return ElasticsearchLegacyPackageInstaller(version)
return ElasticsearchPackageInstaller(version)
else:
return OpensearchPackageInstaller(version)
Expand Down Expand Up @@ -233,6 +236,12 @@ class ElasticsearchPackageInstaller(PackageInstaller):
def __init__(self, version: str):
super().__init__("elasticsearch", version)

def get_java_env_vars(self) -> dict[str, str]:
install_dir = self.get_installed_dir()
return {
"JAVA_HOME": os.path.join(install_dir, "jdk"),
}

def _install(self, target: InstallTarget):
# locally import to avoid having a dependency on ASF when starting the CLI
from localstack.aws.api.opensearch import EngineType
Expand Down Expand Up @@ -263,7 +272,7 @@ def _install(self, target: InstallTarget):
**java_system_properties_proxy(),
**java_system_properties_ssl(
os.path.join(install_dir, "jdk", "bin", "keytool"),
{"JAVA_HOME": os.path.join(install_dir, "jdk")},
self.get_java_env_vars(),
),
}
java_opts = system_properties_to_cli_args(sys_props)
Expand Down Expand Up @@ -336,5 +345,27 @@ def get_elasticsearch_install_version(self) -> str:
return versions.get_install_version(self.version)


class ElasticsearchLegacyPackageInstaller(ElasticsearchPackageInstaller):
"""
Specialised package installer for ElasticSearch 5.x and 6.x

It installs Java during setup because these releases of ES do not have a bundled JDK.
This should be removed after these versions are dropped in line with AWS EOL, scheduled for Nov 2026.
https://docs.aws.amazon.com/opensearch-service/latest/developerguide/what-is.html#choosing-version
"""

# ES 5.x and 6.x require Java 8
# See: https://www.elastic.co/guide/en/elasticsearch/reference/6.0/zip-targz.html
JAVA_VERSION = "8"

def _prepare_installation(self, target: InstallTarget) -> None:
java_package.get_installer(self.JAVA_VERSION).install(target)

def get_java_env_vars(self) -> dict[str, str]:
return {
"JAVA_HOME": java_package.get_installer(self.JAVA_VERSION).get_java_home(),
}


opensearch_package = OpensearchPackage(default_version=OPENSEARCH_DEFAULT_VERSION)
elasticsearch_package = OpensearchPackage(default_version=ELASTICSEARCH_DEFAULT_VERSION)
Loading
0