Skip to content

Commit

Permalink
Merge branch 'main' of github.com:logicalclocks/hopsworks-api
Browse files Browse the repository at this point in the history
  • Loading branch information
aversey committed Jul 17, 2024
2 parents 67484a9 + dd4470a commit 640b360
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 13 deletions.
11 changes: 8 additions & 3 deletions python/hopsworks/client/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# limitations under the License.
#

import os
import base64
import requests
import os

from hopsworks.client import base, auth, exceptions
import requests
from hopsworks.client import auth, base, exceptions


class Client(base.Client):
Expand All @@ -41,6 +41,11 @@ def __init__(
self._port = port
self._base_url = "https://" + self._host + ":" + str(self._port)
self._project_name = project
if project is not None:
project_info = self._get_project_info(project)
self._project_id = str(project_info["projectId"])
else:
self._project_id = None

if api_key_value is not None:
api_key = api_key_value
Expand Down
14 changes: 11 additions & 3 deletions python/hopsworks/core/project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# limitations under the License.
#

from hopsworks import client, project, constants
import json

from hopsworks import client, constants, project
from hopsworks.client.exceptions import RestAPIError


Expand All @@ -27,8 +28,6 @@ def _exists(self, name: str):
name: Name of the project.
# Returns
`bool`: True if project exists, otherwise False
# Raises
`RestAPIError`: If unable to check the existence of the project
"""
try:
self._get_project(name)
Expand Down Expand Up @@ -111,3 +110,12 @@ def _create_project(
project = self._get_project(name)
print("Project created successfully, explore it at " + project.get_url())
return project

def get_client(self):
_client = client.get_instance()
path_params = [
"project",
_client._project_id,
"client",
]
return _client._send_request("GET", path_params, stream=True)
85 changes: 78 additions & 7 deletions python/hopsworks/core/variable_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2022 Logical Clocks AB
# Copyright 2022 Hopsworks AB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,16 +13,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import annotations

import re
from typing import Optional, Tuple

from hopsworks import client
from hopsworks.client.exceptions import RestAPIError


class VariableApi:
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 @@ -31,15 +44,73 @@ 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",
"versions",
]

path_params = ["variables", "versions"]
resp = _client._send_request("GET", path_params)

for entry in resp:
if entry["software"] == software:
return entry["version"]
return None

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) -> 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.
"""
return self.get_variable("enable_flyingduck") == "true"

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 `""`.
"""
try:
return self.get_variable("loadbalancer_external_domain")
except RestAPIError:
return ""

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 `""`.
"""
try:
return self.get_variable("service_discovery_domain")
except RestAPIError:
return ""

0 comments on commit 640b360

Please sign in to comment.