16
16
from __future__ import annotations
17
17
18
18
import re
19
+ from typing import Optional , Tuple
19
20
20
21
from hopsworks import client
21
22
from hopsworks .client .exceptions import RestAPIError
@@ -26,7 +27,15 @@ def __init__(self):
26
27
pass
27
28
28
29
def get_variable (self , variable : str ):
29
- """Get the configured value for a variable"""
30
+ """Get the configured value of a variable.
31
+
32
+ # Arguments
33
+ vairable: Name of the variable.
34
+ # Returns
35
+ The vairable's value
36
+ # Raises
37
+ `RestAPIError`: If unable to get the variable
38
+ """
30
39
31
40
_client = client .get_instance ()
32
41
@@ -35,7 +44,17 @@ def get_variable(self, variable: str):
35
44
36
45
return domain ["successMessage" ]
37
46
38
- def get_version (self , software : str ):
47
+ def get_version (self , software : str ) -> Optional [str ]:
48
+ """Get version of a software component.
49
+
50
+ # Arguments
51
+ software: Name of the software.
52
+ # Returns
53
+ The software's version, if the software is available, otherwise `None`.
54
+ # Raises
55
+ `RestAPIError`: If unable to get the version
56
+ """
57
+
39
58
_client = client .get_instance ()
40
59
path_params = [
41
60
"variables" ,
@@ -48,13 +67,31 @@ def get_version(self, software: str):
48
67
return entry ["version" ]
49
68
return None
50
69
51
- def parse_major_and_minor (self , backend_version ):
70
+ def parse_major_and_minor (self , backend_version : str ) -> Tuple [Optional [str ], Optional [str ]]:
71
+ """Extract major and minor version from full version.
72
+
73
+ # Arguments
74
+ backend_version: The full version.
75
+ # Returns
76
+ (major, minor): The pair of major and minor parts of the version, or (None, None) if the version format is incorrect.
77
+ """
78
+
52
79
version_pattern = r"(\d+)\.(\d+)"
53
80
matches = re .match (version_pattern , backend_version )
54
81
82
+ if matches is None :
83
+ return (None , None )
55
84
return matches .group (1 ), matches .group (2 )
56
85
57
- def get_flyingduck_enabled (self ):
86
+ def get_flyingduck_enabled (self ) -> bool :
87
+ """Check if Flying Duck is enabled on the backend.
88
+
89
+ # Returns
90
+ `True`: If flying duck is availalbe, `False` otherwise.
91
+ # Raises
92
+ `RestAPIError`: If unable to obtain the flag's value.
93
+ """
94
+
58
95
_client = client .get_instance ()
59
96
path_params = [
60
97
"variables" ,
@@ -64,7 +101,13 @@ def get_flyingduck_enabled(self):
64
101
resp = _client ._send_request ("GET" , path_params )
65
102
return resp ["successMessage" ] == "true"
66
103
67
- def get_loadbalancer_external_domain (self ):
104
+ def get_loadbalancer_external_domain (self ) -> str :
105
+ """Get domain of external loadbalancer.
106
+
107
+ # Returns
108
+ `str`: The domain of external loadbalancer, if it is set up, otherwise empty string `""`.
109
+ """
110
+
68
111
_client = client .get_instance ()
69
112
path_params = [
70
113
"variables" ,
@@ -77,7 +120,13 @@ def get_loadbalancer_external_domain(self):
77
120
except RestAPIError :
78
121
return ""
79
122
80
- def get_service_discovery_domain (self ):
123
+ def get_service_discovery_domain (self ) -> str :
124
+ """Get domain of service discovery server.
125
+
126
+ # Returns
127
+ `str`: The domain of service discovery server, if it is set up, otherwise empty string `""`.
128
+ """
129
+
81
130
_client = client .get_instance ()
82
131
path_params = [
83
132
"variables" ,
0 commit comments