Skip to content

Commit

Permalink
Add docs to variable_api
Browse files Browse the repository at this point in the history
  • Loading branch information
aversey committed Jul 5, 2024
1 parent 90c2321 commit a41fa23
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions python/hopsworks/core/variable_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from __future__ import annotations

import re
from typing import Optional, Tuple

from hopsworks import client
from hopsworks.client.exceptions import RestAPIError
Expand All @@ -26,7 +27,15 @@ def __init__(self):
pass

def get_variable(self, variable: str):
"""Get the configured value for a variable"""
"""Get the configured value of a variable.
# Arguments
vairable: Name of the variable.
# Returns
The vairable's value
# Raises
`RestAPIError`: If unable to get the variable
"""

_client = client.get_instance()

Expand All @@ -35,7 +44,17 @@ def get_variable(self, variable: str):

return domain["successMessage"]

def get_version(self, software: str):
def get_version(self, software: str) -> Optional[str]:
"""Get version of a software component.
# Arguments
software: Name of the software.
# Returns
The software's version, if the software is available, otherwise `None`.
# Raises
`RestAPIError`: If unable to get the version
"""

_client = client.get_instance()
path_params = [
"variables",
Expand All @@ -48,13 +67,31 @@ def get_version(self, software: str):
return entry["version"]
return None

def parse_major_and_minor(self, backend_version):
def parse_major_and_minor(self, backend_version: str) -> Tuple[Optional[str], Optional[str]]:
"""Extract major and minor version from full version.
# Arguments
backend_version: The full version.
# Returns
(major, minor): The pair of major and minor parts of the version, or (None, None) if the version format is incorrect.
"""

version_pattern = r"(\d+)\.(\d+)"
matches = re.match(version_pattern, backend_version)

if matches is None:
return (None, None)
return matches.group(1), matches.group(2)

def get_flyingduck_enabled(self):
def get_flyingduck_enabled(self) -> bool:
"""Check if Flying Duck is enabled on the backend.
# Returns
`True`: If flying duck is availalbe, `False` otherwise.
# Raises
`RestAPIError`: If unable to obtain the flag's value.
"""

_client = client.get_instance()
path_params = [
"variables",
Expand All @@ -64,7 +101,13 @@ def get_flyingduck_enabled(self):
resp = _client._send_request("GET", path_params)
return resp["successMessage"] == "true"

def get_loadbalancer_external_domain(self):
def get_loadbalancer_external_domain(self) -> str:
"""Get domain of external loadbalancer.
# Returns
`str`: The domain of external loadbalancer, if it is set up, otherwise empty string `""`.
"""

_client = client.get_instance()
path_params = [
"variables",
Expand All @@ -77,7 +120,13 @@ def get_loadbalancer_external_domain(self):
except RestAPIError:
return ""

def get_service_discovery_domain(self):
def get_service_discovery_domain(self) -> str:
"""Get domain of service discovery server.
# Returns
`str`: The domain of service discovery server, if it is set up, otherwise empty string `""`.
"""

_client = client.get_instance()
path_params = [
"variables",
Expand Down

0 comments on commit a41fa23

Please sign in to comment.