Skip to content

Commit 993cea1

Browse files
committed
refactor: ray and appwrapper modules
1 parent 2006e82 commit 993cea1

28 files changed

+192
-137
lines changed

src/codeflare_sdk/__init__.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
from .cluster import (
2-
AWManager,
1+
from .ray import (
32
Cluster,
43
ClusterConfiguration,
54
RayClusterStatus,
6-
AppWrapperStatus,
75
CodeFlareClusterStatus,
86
RayCluster,
9-
AppWrapper,
107
get_cluster,
118
list_all_queued,
129
list_all_clusters,
13-
view_clusters,
10+
AWManager,
11+
AppWrapperStatus,
12+
RayJobClient,
1413
)
1514

15+
from .cluster import view_clusters
16+
1617
from .common import (
1718
Authentication,
1819
KubeConfiguration,
1920
TokenAuthentication,
2021
KubeConfigFileAuthentication,
2122
)
2223

23-
from .job import RayJobClient
24-
25-
from .utils import generate_cert
26-
from .utils.demos import copy_demo_nbs
24+
from .common.utils import generate_cert
25+
from .common.utils.demos import copy_demo_nbs
2726

2827
from importlib.metadata import version, PackageNotFoundError
2928

src/codeflare_sdk/cluster/__init__.py

-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
from .model import (
2-
RayClusterStatus,
3-
AppWrapperStatus,
4-
CodeFlareClusterStatus,
5-
RayCluster,
6-
AppWrapper,
7-
)
8-
9-
from .cluster import (
10-
Cluster,
11-
ClusterConfiguration,
12-
get_cluster,
13-
list_all_queued,
14-
list_all_clusters,
15-
)
16-
171
from .widgets import (
182
view_clusters,
193
)
20-
21-
from .awload import AWManager

src/codeflare_sdk/cluster/widgets.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import ipywidgets as widgets
2727
from IPython.display import display, HTML, Javascript
2828
import pandas as pd
29-
from .config import ClusterConfiguration
30-
from .model import RayClusterStatus
29+
from ..ray.cluster.config import ClusterConfiguration
30+
from ..ray.cluster.status import RayClusterStatus
3131
from ..common import _kube_api_error_handling
3232
from ..common.kubernetes_cluster.auth import (
3333
config_check,
@@ -115,7 +115,7 @@ def view_clusters(namespace: str = None):
115115
)
116116
return # Exit function if not in Jupyter Notebook
117117

118-
from .cluster import get_current_namespace
118+
from ..ray.cluster.cluster import get_current_namespace
119119

120120
if not namespace:
121121
namespace = get_current_namespace()
@@ -278,7 +278,7 @@ def _on_ray_dashboard_button_click(
278278
"""
279279
_on_ray_dashboard_button_click handles the event when the Open Ray Dashboard button is clicked, opening the Ray Dashboard in a new tab
280280
"""
281-
from codeflare_sdk.cluster import Cluster
281+
from codeflare_sdk.ray.cluster import Cluster
282282

283283
cluster_name = classification_widget.value
284284
namespace = ray_clusters_df[ray_clusters_df["Name"] == classification_widget.value][
@@ -309,7 +309,7 @@ def _on_list_jobs_button_click(
309309
"""
310310
_on_list_jobs_button_click handles the event when the View Jobs button is clicked, opening the Ray Jobs Dashboard in a new tab
311311
"""
312-
from codeflare_sdk.cluster import Cluster
312+
from codeflare_sdk.ray.cluster import Cluster
313313

314314
cluster_name = classification_widget.value
315315
namespace = ray_clusters_df[ray_clusters_df["Name"] == classification_widget.value][
@@ -342,7 +342,7 @@ def _delete_cluster(
342342
_delete_cluster function deletes the cluster with the given name and namespace.
343343
It optionally waits for the cluster to be deleted.
344344
"""
345-
from .cluster import _check_aw_exists
345+
from ..ray.cluster.cluster import _check_aw_exists
346346

347347
try:
348348
config_check()
@@ -400,7 +400,7 @@ def _fetch_cluster_data(namespace):
400400
"""
401401
_fetch_cluster_data function fetches all clusters and their spec in a given namespace and returns a DataFrame.
402402
"""
403-
from .cluster import list_all_clusters
403+
from ..ray.cluster.cluster import list_all_clusters
404404

405405
rayclusters = list_all_clusters(namespace, False)
406406
if not rayclusters:

src/codeflare_sdk/utils/generate_cert.py renamed to src/codeflare_sdk/common/utils/generate_cert.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
from cryptography import x509
2020
from cryptography.x509.oid import NameOID
2121
import datetime
22-
from ..common.kubernetes_cluster.auth import (
22+
from ..kubernetes_cluster.auth import (
2323
config_check,
2424
get_api_client,
2525
)
2626
from kubernetes import client
27-
from ..common import _kube_api_error_handling
27+
from .. import _kube_api_error_handling
2828

2929

3030
def generate_ca_cert(days: int = 30):

src/codeflare_sdk/ray/__init__.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from .appwrapper import AppWrapper, AppWrapperStatus, AWManager
2+
3+
from .client import (
4+
RayJobClient,
5+
)
6+
7+
from .cluster import (
8+
Cluster,
9+
ClusterConfiguration,
10+
get_cluster,
11+
list_all_queued,
12+
list_all_clusters,
13+
RayClusterStatus,
14+
CodeFlareClusterStatus,
15+
RayCluster,
16+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from .awload import AWManager
2+
3+
from .status import (
4+
AppWrapperStatus,
5+
AppWrapper,
6+
)

src/codeflare_sdk/cluster/awload.py renamed to src/codeflare_sdk/ray/appwrapper/awload.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import yaml
2424

2525
from kubernetes import client
26-
from ..common import _kube_api_error_handling
27-
from ..common.kubernetes_cluster.auth import (
26+
from ...common import _kube_api_error_handling
27+
from ...common.kubernetes_cluster.auth import (
2828
config_check,
2929
get_api_client,
3030
)
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2022 IBM, Red Hat
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""
16+
The status sub-module defines Enums containing information for
17+
AppWrapper states, as well as dataclasses to store information for AppWrappers.
18+
"""
19+
20+
from dataclasses import dataclass
21+
from enum import Enum
22+
23+
24+
class AppWrapperStatus(Enum):
25+
"""
26+
Defines the possible reportable phases of an AppWrapper.
27+
"""
28+
29+
SUSPENDED = "suspended"
30+
RESUMING = "resuming"
31+
RUNNING = "running"
32+
RESETTING = "resetting"
33+
SUSPENDING = "suspending"
34+
SUCCEEDED = "succeeded"
35+
FAILED = "failed"
36+
TERMINATING = "terminating"
37+
38+
39+
@dataclass
40+
class AppWrapper:
41+
"""
42+
For storing information about an AppWrapper.
43+
"""
44+
45+
name: str
46+
status: AppWrapperStatus
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from .status import (
2+
RayClusterStatus,
3+
CodeFlareClusterStatus,
4+
RayCluster,
5+
)
6+
7+
from .cluster import (
8+
Cluster,
9+
ClusterConfiguration,
10+
get_cluster,
11+
list_all_queued,
12+
list_all_clusters,
13+
)

src/codeflare_sdk/cluster/cluster.py renamed to src/codeflare_sdk/ray/cluster/cluster.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,29 @@
2323

2424
from ray.job_submission import JobSubmissionClient
2525

26-
from ..common.kubernetes_cluster.auth import (
26+
from ...common.kubernetes_cluster.auth import (
2727
config_check,
2828
get_api_client,
2929
)
30-
from ..utils import pretty_print
31-
from ..utils.generate_yaml import (
30+
from . import pretty_print
31+
from .generate_yaml import (
3232
generate_appwrapper,
3333
head_worker_gpu_count_from_cluster,
3434
)
35-
from ..common import _kube_api_error_handling
36-
from ..utils.generate_yaml import is_openshift_cluster
35+
from ...common import _kube_api_error_handling
36+
from .generate_yaml import is_openshift_cluster
3737

3838
from .config import ClusterConfiguration
39-
from .model import (
40-
AppWrapper,
41-
AppWrapperStatus,
39+
from .status import (
4240
CodeFlareClusterStatus,
4341
RayCluster,
4442
RayClusterStatus,
4543
)
46-
from .widgets import (
44+
from ..appwrapper import (
45+
AppWrapper,
46+
AppWrapperStatus,
47+
)
48+
from ...cluster.widgets import (
4749
cluster_up_down_buttons,
4850
is_notebook,
4951
)

src/codeflare_sdk/utils/generate_yaml.py renamed to src/codeflare_sdk/ray/cluster/generate_yaml.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import os
2525
import uuid
2626
from kubernetes import client
27-
from ..common import _kube_api_error_handling
28-
from ..common.kubernetes_cluster.auth import (
27+
from ...common import _kube_api_error_handling
28+
from ...common.kubernetes_cluster.auth import (
2929
get_api_client,
3030
config_check,
3131
)

src/codeflare_sdk/utils/pretty_print.py renamed to src/codeflare_sdk/ray/cluster/pretty_print.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
from rich.panel import Panel
2525
from rich import box
2626
from typing import List
27-
from ..cluster.model import RayCluster, AppWrapper, RayClusterStatus
27+
from .status import RayCluster, RayClusterStatus
28+
from ..appwrapper.status import AppWrapper
2829

2930

3031
def print_no_resources_found():

src/codeflare_sdk/cluster/model.py renamed to src/codeflare_sdk/ray/cluster/status.py

+4-29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 IBM, Red Hat
1+
# Copyright 2024 IBM, Red Hat
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -13,9 +13,9 @@
1313
# limitations under the License.
1414

1515
"""
16-
The model sub-module defines Enums containing information for Ray cluster
17-
states and AppWrapper states, and CodeFlare cluster states, as well as
18-
dataclasses to store information for Ray clusters and AppWrappers.
16+
The status sub-module defines Enums containing information for Ray cluster
17+
states states, and CodeFlare cluster states, as well as
18+
dataclasses to store information for Ray clusters.
1919
"""
2020

2121
from dataclasses import dataclass, field
@@ -37,21 +37,6 @@ class RayClusterStatus(Enum):
3737
SUSPENDED = "suspended"
3838

3939

40-
class AppWrapperStatus(Enum):
41-
"""
42-
Defines the possible reportable phases of an AppWrapper.
43-
"""
44-
45-
SUSPENDED = "suspended"
46-
RESUMING = "resuming"
47-
RUNNING = "running"
48-
RESETTING = "resetting"
49-
SUSPENDING = "suspending"
50-
SUCCEEDED = "succeeded"
51-
FAILED = "failed"
52-
TERMINATING = "terminating"
53-
54-
5540
class CodeFlareClusterStatus(Enum):
5641
"""
5742
Defines the possible reportable states of a Codeflare cluster.
@@ -87,13 +72,3 @@ class RayCluster:
8772
dashboard: str
8873
worker_extended_resources: typing.Dict[str, int] = field(default_factory=dict)
8974
head_extended_resources: typing.Dict[str, int] = field(default_factory=dict)
90-
91-
92-
@dataclass
93-
class AppWrapper:
94-
"""
95-
For storing information about an AppWrapper.
96-
"""
97-
98-
name: str
99-
status: AppWrapperStatus

tests/demo_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
These were the old tests used during initial demo building, and they will soon be fully deprecated.
1717
"""
1818

19-
from codeflare_sdk.cluster.cluster import (
19+
from codeflare_sdk.ray.cluster.cluster import (
2020
list_all_clusters,
2121
list_all_queued,
2222
_app_wrapper_status,
2323
)
24-
from codeflare_sdk.cluster.cluster import Cluster, ClusterConfiguration
24+
from codeflare_sdk.ray.cluster.cluster import Cluster, ClusterConfiguration
2525

2626
import time
2727

@@ -53,7 +53,7 @@ def test_cluster_down():
5353

5454

5555
def test_no_resources_found():
56-
from codeflare_sdk.utils import pretty_print
56+
from codeflare_sdk.ray.cluster import pretty_print
5757

5858
pretty_print.print_no_resources_found()
5959

tests/e2e/mnist_raycluster_sdk_aw_kind_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from time import sleep
44

55
from codeflare_sdk import Cluster, ClusterConfiguration, TokenAuthentication
6-
from codeflare_sdk.job import RayJobClient
6+
from codeflare_sdk.ray.client import RayJobClient
77

88
import pytest
99

tests/e2e/mnist_raycluster_sdk_kind_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from time import sleep
44

55
from codeflare_sdk import Cluster, ClusterConfiguration, TokenAuthentication
6-
from codeflare_sdk.job import RayJobClient
6+
from codeflare_sdk.ray.client import RayJobClient
77

88
import pytest
99

tests/e2e/mnist_raycluster_sdk_oauth_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from time import sleep
44

55
from codeflare_sdk import Cluster, ClusterConfiguration, TokenAuthentication
6-
from codeflare_sdk.job import RayJobClient
6+
from codeflare_sdk.ray.client import RayJobClient
77

88
import pytest
99

0 commit comments

Comments
 (0)