Skip to content

Commit 417fd8b

Browse files
committed
Update examples
1 parent f3b5af6 commit 417fd8b

File tree

3 files changed

+50
-16
lines changed

3 files changed

+50
-16
lines changed

README.md

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ pip install git+https://github.com/fluid-cloudnative/fluid-client-python.git
1414
```
1515
(you may need to run `pip` with root permission: `sudo pip install git+https://github.com/fluid-cloudnative/fluid-client-python.git`)
1616

17-
Then import the package:
18-
```python
19-
import fluid
20-
```
21-
2217
### Setuptools
2318

2419
Install via [Setuptools](http://pypi.python.org/pypi/setuptools).
@@ -28,16 +23,55 @@ python setup.py install --user
2823
```
2924
(or `sudo python setup.py install` to install the package for all users)
3025

31-
Then import the package:
26+
## Getting Started
27+
28+
Fluid Python SDK provides two types of "client SDK" for users with different expertises and preference.
29+
- `fluid.FluidClient` (the recommended one) provides a more Pythonic interface with polished user experience.
30+
- `fluid.FluidK8sClient` provides a low-level YAML-style interface for those who have rich experience in Kubernetes.
31+
32+
The following shows the same code example using two types of client SDK. The example simply creates a dataset and get its status.
33+
34+
### with `fluid.FluidClient`
35+
3236
```python
33-
import fluid
34-
```
37+
import logging
38+
import sys
3539

36-
## Getting Started
40+
from fluid import FluidClient, ClientConfig
3741

38-
Please follow the [installation procedure](#installation--usage) and then run the following:
42+
logger = logging.getLogger("fluidsdk")
43+
stream_handler = logging.StreamHandler(sys.stdout)
44+
stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
45+
logger.addHandler(stream_handler)
46+
logger.setLevel(logging.INFO)
47+
48+
def main():
49+
name = "demo"
50+
namespace = "default"
51+
52+
client_config = ClientConfig(namespace=namespace)
53+
fluid_client = FluidClient(client_config)
54+
55+
56+
try:
57+
fluid_client.create_dataset(name, "hbase", "https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/stable/", "/")
58+
except Exception as e:
59+
raise RuntimeError(f"Failed to create dataset: {e}")
60+
61+
logger.info(f"Dataset \"{namespace}/{name}\" created successfully")
62+
63+
try:
64+
dataset = fluid_client.get_dataset(name, namespace)
65+
except Exception as e:
66+
raise RuntimeError(f"Error when getting dataset \"{namespace}/{name}\": {e}")
67+
else:
68+
logger.info(f"Dataset \"{namespace}/{name}\"'s phase is: {dataset.report_status(status_type='binding_status')['phase']}")
69+
70+
if __name__ == '__main__':
71+
main()
72+
```
3973

40-
The following is a code sample which creates a dataset and get its status.
74+
### with `fluid.FluidK8sClient`
4175

4276
```python
4377
import logging
@@ -75,7 +109,7 @@ def main():
75109
spec=models.DatasetSpec(
76110
mounts=[
77111
models.Mount(
78-
mount_point="https://mirrors.bit.edu.cn/apache/hbase/stable/",
112+
mount_point="https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/stable/",
79113
name="hbase",
80114
path="/",
81115
)

examples/01_fluidapis/create_dataload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ def create_dataload_and_wait_for_completion():
7979

8080

8181
if __name__ == '__main__':
82-
create_dataload()
83-
# create_dataload_and_wait_for_completion()
82+
# create_dataload()
83+
create_dataload_and_wait_for_completion()

examples/01_fluidapis/create_dataset_and_runtime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def create_dataset_with_alluxio(fluid_client: FluidClient):
2323
dataset_name = "demo"
2424
try:
2525
# Mounting WebUFS to Alluxio
26-
fluid_client.create_dataset(dataset_name, "hbase", "https://mirrors.bit.edu.cn/apache/hbase/stable/", "/hbase")
26+
fluid_client.create_dataset(dataset_name, "hbase", "https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/stable/", "/")
2727
except Exception as e:
2828
raise RuntimeError(f"Failed to create dataset: {e}")
2929

@@ -150,7 +150,7 @@ def main_k8s_client():
150150
spec=models.DatasetSpec(
151151
mounts=[
152152
models.Mount(
153-
mount_point="https://mirrors.bit.edu.cn/apache/hbase/stable/",
153+
mount_point="https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/stable/",
154154
name="hbase",
155155
path="/",
156156
)

0 commit comments

Comments
 (0)