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
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
5 changes: 1 addition & 4 deletions python/hopsworks/core/kafka_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,6 @@ def get_default_config(self):
# Raises
`RestAPIError`: If unable to get the kafka configuration.
"""
_client = client.get_instance()
if type(_client) == Client:
_client.download_certs(self._project_name)

config = {
constants.KAFKA_SSL_CONFIG.SECURITY_PROTOCOL_CONFIG: self._get_security_protocol(),
Expand All @@ -368,7 +365,7 @@ def get_default_config(self):
constants.KAFKA_CONSUMER_CONFIG.GROUP_ID_CONFIG: "my-group-id",
constants.KAFKA_SSL_CONFIG.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG: "none",
}

_client = client.get_instance()
if type(_client) == Client:
config[constants.KAFKA_PRODUCER_CONFIG.BOOTSTRAP_SERVERS_CONFIG] = ",".join(
[
Expand Down
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
6 changes: 6 additions & 0 deletions python/hopsworks/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def get_kafka_api(self):
# Returns
`KafkaApi`: The Kafka Api handle
"""
_client = client.get_instance()
if type(_client) == Client:
_client.download_certs(self.name)
return self._kafka_api

def get_opensearch_api(self):
Expand All @@ -184,6 +187,9 @@ def get_opensearch_api(self):
# Returns
`OpenSearchApi`: The OpenSearch Api handle
"""
_client = client.get_instance()
if type(_client) == Client:
_client.download_certs(self.name)
return self._opensearch_api

def get_jobs_api(self):
Expand Down
Loading