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

[HWORKS-975] OpenSearchApi in hopsworks-api should not rely on ELASTIC_ENDPOINT #190

Merged
merged 9 commits into from
Jan 29, 2024
Merged
Changes from 4 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
23 changes: 21 additions & 2 deletions python/hopsworks/core/opensearch_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
# limitations under the License.
#

import os
from furl import furl

from hopsworks import client, constants
from hopsworks.core import variable_api
from hopsworks.client.exceptions import OpenSearchException


class OpenSearchApi:
Expand All @@ -28,9 +29,27 @@ def __init__(
):
self._project_id = project_id
self._project_name = project_name
self._variable_api = variable_api.VariableApi()

def _get_opensearch_url(self):
return os.environ[constants.ENV_VARS.ELASTIC_ENDPOINT_ENV_VAR]
if isinstance(client.get_instance(), client.external.Client):
external_domain = self._variable_api.get_variable(
"loadbalancer_external_domain"
)
if external_domain == "":
# fallback to use hostname of head node
external_domain = client.get_instance().host
return f"https://{external_domain}:9200"
else:
service_discovery_domain = self._variable_api.get_variable(
"service_discovery_domain"
)
if service_discovery_domain == "":
raise OpenSearchException(
"Client could not locate service_discovery_domain "
"in cluster configuration or variable is empty."
)
return f"https://rest.elastic.service.{service_discovery_domain}:9200"

def get_project_index(self, index):
"""
Expand Down
Loading