Skip to content

Commit 6d652ca

Browse files
committed
Implement get logic for resources
Signed-off-by: dongyun.xzh <[email protected]>
1 parent c7a8e52 commit 6d652ca

19 files changed

+234
-73
lines changed

docs/Condition.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Condition explains the transitions on phase
44
## Properties
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
7-
**last_probe_time** | [**V1Time**](V1Time.md) | | [optional]
8-
**last_transition_time** | [**V1Time**](V1Time.md) | | [optional]
7+
**last_probe_time** | [**datetime**](V1Time.md) | | [optional]
8+
**last_transition_time** | [**datetime**](V1Time.md) | | [optional]
99
**message** | **str** | Message is a human-readable message indicating details about the transition | [optional]
1010
**reason** | **str** | Reason for the condition&#39;s last transition | [optional]
1111
**status** | **str** | Status of the condition, one of &#x60;True&#x60;, &#x60;False&#x60; or &#x60;Unknown&#x60; | [default to '']

docs/DatasetCondition.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Condition describes the state of the cache at a certain point.
44
## Properties
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
7-
**last_transition_time** | [**V1Time**](V1Time.md) | | [optional]
8-
**last_update_time** | [**V1Time**](V1Time.md) | | [optional]
7+
**last_transition_time** | [**datetime**](V1Time.md) | | [optional]
8+
**last_update_time** | [**datetime**](V1Time.md) | | [optional]
99
**message** | **str** | A human readable message indicating details about the transition. | [optional]
1010
**reason** | **str** | The reason for the condition&#39;s last transition. | [optional]
1111
**status** | **str** | Status of the condition, one of True, False, Unknown. | [default to '']

docs/Level.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Name | Type | Description | Notes
88
**low** | **str** | Ratio of low watermark of the tier (e.g. 0.7) | [optional]
99
**mediumtype** | **str** | Medium Type of the tier. One of the three types: &#x60;MEM&#x60;, &#x60;SSD&#x60;, &#x60;HDD&#x60; | [default to '']
1010
**path** | **str** | File paths to be used for the tier. Multiple paths are supported. Multiple paths should be separated with comma. For example: \&quot;/mnt/cache1,/mnt/cache2\&quot;. | [optional]
11-
**quota** | [**K8sIoApimachineryPkgApiResourceQuantity**](K8sIoApimachineryPkgApiResourceQuantity.md) | | [optional]
11+
**quota** | [**str**](Quantity.md) | | [optional]
1212
**quota_list** | **str** | QuotaList are quotas used to set quota on multiple paths. Quotas should be separated with comma. Quotas in this list will be set to paths with the same order in Path. For example, with Path defined with \&quot;/mnt/cache1,/mnt/cache2\&quot; and QuotaList set to \&quot;100Gi, 50Gi\&quot;, then we get 100GiB cache storage under \&quot;/mnt/cache1\&quot; and 50GiB under \&quot;/mnt/cache2\&quot;. Also note that num of quotas must be consistent with the num of paths defined in Path. | [optional]
1313
**volume_source** | [**VolumeSource**](VolumeSource.md) | | [optional]
1414
**volume_type** | **str** | VolumeType is the volume type of the tier. Should be one of the three types: &#x60;hostPath&#x60;, &#x60;emptyDir&#x60; and &#x60;volumeTemplate&#x60;. If not set, defaults to hostPath. | [optional] [default to '']

docs/OperationStatus.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ OperationStatus defines the observed state of operation
44
## Properties
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
7-
**conditions** | [**list[Condition]**](Condition.md) | Conditions consists of transition information on operation&#39;s Phase |
7+
**conditions** | [**list[Condition]**](Condition.md) | Conditions consists of transition information on operation&#39;s Phase |
88
**duration** | **str** | Duration tell user how much time was spent to operation | [default to '']
99
**infos** | **dict(str, str)** | Infos operation customized name-value | [optional]
10-
**last_schedule_time** | [**V1Time**](V1Time.md) | | [optional]
11-
**last_successful_time** | [**V1Time**](V1Time.md) | | [optional]
10+
**last_schedule_time** | [**datetime**](V1Time.md) | | [optional]
11+
**last_successful_time** | [**datetime**](V1Time.md) | | [optional]
1212
**phase** | **str** | Phase describes current phase of operation | [default to '']
1313
**waiting_for** | [**WaitingStatus**](WaitingStatus.md) | | [optional]
1414

docs/RuntimeCondition.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Condition describes the state of the cache at a certain point.
44
## Properties
55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
7-
**last_probe_time** | [**V1Time**](V1Time.md) | | [optional]
8-
**last_transition_time** | [**V1Time**](V1Time.md) | | [optional]
7+
**last_probe_time** | [**datetime**](V1Time.md) | | [optional]
8+
**last_transition_time** | [**datetime**](V1Time.md) | | [optional]
99
**message** | **str** | A human readable message indicating details about the transition. | [optional]
1010
**reason** | **str** | The reason for the condition&#39;s last transition. | [optional]
1111
**status** | **str** | Status of the condition, one of True, False, Unknown. | [default to '']

docs/RuntimeStatus.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Name | Type | Description | Notes
2222
**master_number_ready** | **int** | The number of nodes that should be running the runtime worker pod and have zero or more of the runtime master pod running and ready. | [default to 0]
2323
**master_phase** | **str** | MasterPhase is the master running phase | [default to '']
2424
**master_reason** | **str** | Reason for Master&#39;s condition transition | [optional]
25-
**mount_time** | [**V1Time**](V1Time.md) | | [optional]
25+
**mount_time** | [**datetime**](V1Time.md) | | [optional]
2626
**mounts** | [**list[Mount]**](Mount.md) | MountPoints represents the mount points specified in the bounded dataset | [optional]
2727
**selector** | **str** | Selector is used for auto-scaling | [optional]
2828
**setup_duration** | **str** | Duration tell user how much time was spent to setup the runtime | [optional]
File renamed without changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import logging
2+
import sys
3+
4+
from fluid import models
5+
from fluid import FluidClient
6+
7+
logger = logging.getLogger("fluidsdk")
8+
stream_handler = logging.StreamHandler(sys.stdout)
9+
stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
10+
logger.addHandler(stream_handler)
11+
logger.setLevel(logging.INFO)
12+
13+
# Output detailed debug message for fluidsdk
14+
# logger.setLevel(logging.DEBUG)
15+
16+
namespace = "default"
17+
name = "demo"
18+
19+
20+
def main():
21+
fluid_client = FluidClient()
22+
try:
23+
dataset = fluid_client.get_dataset(name, namespace)
24+
except Exception as e:
25+
raise RuntimeError(f"Error when getting dataset \"{namespace}/{name}\": {e}")
26+
27+
assert type(dataset) == models.Dataset
28+
logger.info(f"Dataset \"{namespace}/{name}\"'s phase is: {dataset.status.phase}")
29+
30+
try:
31+
runtime = fluid_client.get_runtime(name, "alluxio", namespace)
32+
except Exception as e:
33+
raise RuntimeError(f"Error when getting runtime \"{namespace}/{name}\": {e}")
34+
assert type(runtime) == models.AlluxioRuntime
35+
logger.info(f"AlluxioRuntime \"{namespace}/{name}\"'s Master Phase is: {runtime.status.master_phase}")
36+
logger.info(f"AlluxioRuntime \"{namespace}/{name}\"'s Worker Phase is: {runtime.status.worker_phase}")
37+
logger.info(f"AlluxioRuntime \"{namespace}/{name}\"'s Fuse Phase is: {runtime.status.fuse_phase}")
38+
39+
40+
if __name__ == '__main__':
41+
main()

examples/get_dataset_status.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

fluid/api/fluid_client.py

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,86 @@ def create_data_operation(self, data_op: constants.DATA_OPERATION_MODELS_TYPE, n
136136

137137
logger.debug(f"{data_op.kind} \"{namespace}/{data_op.metadata.name}\" created successfully")
138138

139-
def get_dataset_status(self, name, namespace=None):
140-
pass
139+
def get_dataset(self, name, namespace=None, timeout=constants.DEFAULT_TIMEOUT) -> models.Dataset:
140+
namespace = namespace or self.namespace
141141

142-
def get_runtime_status(self, name, runtime_type, namespace=None):
143-
pass
142+
try:
143+
thread = self.custom_api.get_namespaced_custom_object(
144+
constants.GROUP,
145+
constants.VERSION,
146+
namespace,
147+
constants.FLUID_CRD_PARAMETERS[constants.DATASET_KIND]["plural"],
148+
name,
149+
async_req=True
150+
)
151+
response = utils.FakeResponse(thread.get(timeout=timeout))
152+
dataset = self.api_client.deserialize(response, models.Dataset)
153+
except multiprocessing.TimeoutError:
154+
raise TimeoutError(
155+
f"TimeoutError: Timed out when getting dataset \"{namespace}/{name}\""
156+
)
157+
except Exception as e:
158+
raise RuntimeError(
159+
f"RuntimeError: Failed to get dataset \"{namespace}/{name}\": {e}"
160+
)
161+
return dataset
144162

145-
def get_data_operation_status(self, name, data_op_type, namespace=None):
146-
pass
163+
def get_runtime(self, name, runtime_type, namespace=None,
164+
timeout=constants.DEFAULT_TIMEOUT) -> constants.RUNTIME_MODELS_TYPE:
165+
namespace = namespace or self.namespace
166+
runtime_kind = utils.infer_runtime_kind(runtime_type)
167+
if runtime_kind is None:
168+
raise ValueError(
169+
f"runtime_type is not supported, supported types: {list(constants.RUNTIME_PARAMETERS.keys())}")
170+
try:
171+
thread = self.custom_api.get_namespaced_custom_object(
172+
constants.GROUP,
173+
constants.VERSION,
174+
namespace,
175+
constants.RUNTIME_PARAMETERS[runtime_kind]["plural"],
176+
name,
177+
async_req=True
178+
)
179+
response = utils.FakeResponse(thread.get(timeout=timeout))
180+
runtime = self.api_client.deserialize(response, constants.RUNTIME_PARAMETERS[runtime_kind]["model"])
181+
except multiprocessing.TimeoutError:
182+
raise TimeoutError(
183+
f"TimeoutError: Timed out when getting runtime \"{namespace}/{name}\""
184+
)
185+
except Exception as e:
186+
raise RuntimeError(
187+
f"RuntimeError: Failed to get runtime \"{namespace}/{name}\": {e}"
188+
)
189+
190+
return runtime
191+
192+
def get_data_operation(self, name, data_op_type, namespace=None, timeout=constants.DEFAULT_TIMEOUT):
193+
namespace = namespace or self.namespace
194+
data_op_kind = utils.infer_data_operation_kind(data_op_type)
195+
if data_op_kind is None:
196+
raise ValueError(
197+
f"data_op_type is not supported, supported types: {list(constants.DATA_OPERATION_PARAMETERS.keys())}")
198+
199+
try:
200+
thread = self.custom_api.get_namespaced_custom_object(
201+
constants.GROUP,
202+
constants.VERSION,
203+
namespace,
204+
constants.DATA_OPERATION_PARAMETERS[data_op_kind]["plural"],
205+
name,
206+
async_req=True
207+
)
208+
response = utils.FakeResponse(thread.get(timeout=timeout))
209+
data_op = self.api_client.deserialize(response, constants.DATA_OPERATION_PARAMETERS[data_op_kind]["model"])
210+
except multiprocessing.TimeoutError:
211+
raise TimeoutError(
212+
f"TimeoutError: Timed out when getting data operation \"{namespace}/{name}\""
213+
)
214+
except Exception as e:
215+
raise RuntimeError(
216+
f"RuntimeError: Failed to get data operation \"{namespace}/{name}\": {e}"
217+
)
218+
return data_op
147219

148220
def delete(self, name, namespace=None, version=constants.VERSION):
149221
pass

fluid/constants/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
from fluid import models
1818

19+
DEFAULT_TIMEOUT = 120
20+
1921
GROUP = "data.fluid.io"
2022
VERSION = "v1alpha1"
2123
API_VERSION = f"{GROUP}/{VERSION}"

fluid/models/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
Generated by: https://openapi-generator.tech
1111
"""
1212

13-
1413
from __future__ import absolute_import
1514

15+
# Import Kubernetes models.
16+
from kubernetes.client import *
17+
1618
# import models into model package
1719
from fluid.models.api_gateway_status import APIGatewayStatus
1820
from fluid.models.alluxio_comp_template_spec import AlluxioCompTemplateSpec

fluid/models/condition.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class Condition(object):
3333
and the value is json key in definition.
3434
"""
3535
openapi_types = {
36-
'last_probe_time': 'V1Time',
37-
'last_transition_time': 'V1Time',
36+
'last_probe_time': 'datetime',
37+
'last_transition_time': 'datetime',
3838
'message': 'str',
3939
'reason': 'str',
4040
'status': 'str',
@@ -81,7 +81,7 @@ def last_probe_time(self):
8181
8282
8383
:return: The last_probe_time of this Condition. # noqa: E501
84-
:rtype: V1Time
84+
:rtype: datetime
8585
"""
8686
return self._last_probe_time
8787

@@ -91,7 +91,7 @@ def last_probe_time(self, last_probe_time):
9191
9292
9393
:param last_probe_time: The last_probe_time of this Condition. # noqa: E501
94-
:type: V1Time
94+
:type: datetime
9595
"""
9696

9797
self._last_probe_time = last_probe_time
@@ -102,7 +102,7 @@ def last_transition_time(self):
102102
103103
104104
:return: The last_transition_time of this Condition. # noqa: E501
105-
:rtype: V1Time
105+
:rtype: datetime
106106
"""
107107
return self._last_transition_time
108108

@@ -112,7 +112,7 @@ def last_transition_time(self, last_transition_time):
112112
113113
114114
:param last_transition_time: The last_transition_time of this Condition. # noqa: E501
115-
:type: V1Time
115+
:type: datetime
116116
"""
117117

118118
self._last_transition_time = last_transition_time

fluid/models/dataset_condition.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class DatasetCondition(object):
3333
and the value is json key in definition.
3434
"""
3535
openapi_types = {
36-
'last_transition_time': 'V1Time',
37-
'last_update_time': 'V1Time',
36+
'last_transition_time': 'datetime',
37+
'last_update_time': 'datetime',
3838
'message': 'str',
3939
'reason': 'str',
4040
'status': 'str',
@@ -81,7 +81,7 @@ def last_transition_time(self):
8181
8282
8383
:return: The last_transition_time of this DatasetCondition. # noqa: E501
84-
:rtype: V1Time
84+
:rtype: datetime
8585
"""
8686
return self._last_transition_time
8787

@@ -91,7 +91,7 @@ def last_transition_time(self, last_transition_time):
9191
9292
9393
:param last_transition_time: The last_transition_time of this DatasetCondition. # noqa: E501
94-
:type: V1Time
94+
:type: datetime
9595
"""
9696

9797
self._last_transition_time = last_transition_time
@@ -102,7 +102,7 @@ def last_update_time(self):
102102
103103
104104
:return: The last_update_time of this DatasetCondition. # noqa: E501
105-
:rtype: V1Time
105+
:rtype: datetime
106106
"""
107107
return self._last_update_time
108108

@@ -112,7 +112,7 @@ def last_update_time(self, last_update_time):
112112
113113
114114
:param last_update_time: The last_update_time of this DatasetCondition. # noqa: E501
115-
:type: V1Time
115+
:type: datetime
116116
"""
117117

118118
self._last_update_time = last_update_time

fluid/models/level.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Level(object):
3737
'low': 'str',
3838
'mediumtype': 'str',
3939
'path': 'str',
40-
'quota': 'K8sIoApimachineryPkgApiResourceQuantity',
40+
'quota': 'str',
4141
'quota_list': 'str',
4242
'volume_source': 'VolumeSource',
4343
'volume_type': 'str'
@@ -186,7 +186,7 @@ def quota(self):
186186
187187
188188
:return: The quota of this Level. # noqa: E501
189-
:rtype: K8sIoApimachineryPkgApiResourceQuantity
189+
:rtype: str
190190
"""
191191
return self._quota
192192

@@ -196,7 +196,7 @@ def quota(self, quota):
196196
197197
198198
:param quota: The quota of this Level. # noqa: E501
199-
:type: K8sIoApimachineryPkgApiResourceQuantity
199+
:type: str
200200
"""
201201

202202
self._quota = quota

0 commit comments

Comments
 (0)