Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
TrafalgarZZZ committed Aug 22, 2024
1 parent f3b5af6 commit 417fd8b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 16 deletions.
58 changes: 46 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ pip install git+https://github.com/fluid-cloudnative/fluid-client-python.git
```
(you may need to run `pip` with root permission: `sudo pip install git+https://github.com/fluid-cloudnative/fluid-client-python.git`)

Then import the package:
```python
import fluid
```

### Setuptools

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

Then import the package:
## Getting Started

Fluid Python SDK provides two types of "client SDK" for users with different expertises and preference.
- `fluid.FluidClient` (the recommended one) provides a more Pythonic interface with polished user experience.
- `fluid.FluidK8sClient` provides a low-level YAML-style interface for those who have rich experience in Kubernetes.

The following shows the same code example using two types of client SDK. The example simply creates a dataset and get its status.

### with `fluid.FluidClient`

```python
import fluid
```
import logging
import sys

## Getting Started
from fluid import FluidClient, ClientConfig

Please follow the [installation procedure](#installation--usage) and then run the following:
logger = logging.getLogger("fluidsdk")
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
logger.addHandler(stream_handler)
logger.setLevel(logging.INFO)

def main():
name = "demo"
namespace = "default"

client_config = ClientConfig(namespace=namespace)
fluid_client = FluidClient(client_config)


try:
fluid_client.create_dataset(name, "hbase", "https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/stable/", "/")
except Exception as e:
raise RuntimeError(f"Failed to create dataset: {e}")

logger.info(f"Dataset \"{namespace}/{name}\" created successfully")

try:
dataset = fluid_client.get_dataset(name, namespace)
except Exception as e:
raise RuntimeError(f"Error when getting dataset \"{namespace}/{name}\": {e}")
else:
logger.info(f"Dataset \"{namespace}/{name}\"'s phase is: {dataset.report_status(status_type='binding_status')['phase']}")

if __name__ == '__main__':
main()
```

The following is a code sample which creates a dataset and get its status.
### with `fluid.FluidK8sClient`

```python
import logging
Expand Down Expand Up @@ -75,7 +109,7 @@ def main():
spec=models.DatasetSpec(
mounts=[
models.Mount(
mount_point="https://mirrors.bit.edu.cn/apache/hbase/stable/",
mount_point="https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/stable/",
name="hbase",
path="/",
)
Expand Down
4 changes: 2 additions & 2 deletions examples/01_fluidapis/create_dataload.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ def create_dataload_and_wait_for_completion():


if __name__ == '__main__':
create_dataload()
# create_dataload_and_wait_for_completion()
# create_dataload()
create_dataload_and_wait_for_completion()
4 changes: 2 additions & 2 deletions examples/01_fluidapis/create_dataset_and_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def create_dataset_with_alluxio(fluid_client: FluidClient):
dataset_name = "demo"
try:
# Mounting WebUFS to Alluxio
fluid_client.create_dataset(dataset_name, "hbase", "https://mirrors.bit.edu.cn/apache/hbase/stable/", "/hbase")
fluid_client.create_dataset(dataset_name, "hbase", "https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/stable/", "/")
except Exception as e:
raise RuntimeError(f"Failed to create dataset: {e}")

Expand Down Expand Up @@ -150,7 +150,7 @@ def main_k8s_client():
spec=models.DatasetSpec(
mounts=[
models.Mount(
mount_point="https://mirrors.bit.edu.cn/apache/hbase/stable/",
mount_point="https://mirrors.tuna.tsinghua.edu.cn/apache/hbase/stable/",
name="hbase",
path="/",
)
Expand Down

0 comments on commit 417fd8b

Please sign in to comment.