Skip to content

Commit 6e4e4ff

Browse files
refactor: ray and appwrapper modules
Signed-off-by: Bobbins228 <mcampbel@redhat.com>
1 parent 730b0ed commit 6e4e4ff

29 files changed

+202
-145
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

+10-8
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@
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,
3434
get_api_client,
3535
)
3636

3737

38-
def cluster_up_down_buttons(cluster: "codeflare_sdk.cluster.Cluster") -> widgets.Button:
38+
def cluster_up_down_buttons(
39+
cluster: "codeflare_sdk.ray.cluster.cluster.Cluster",
40+
) -> widgets.Button:
3941
"""
4042
The cluster_up_down_buttons function returns two button widgets for a create and delete button.
4143
The function uses the appwrapper bool to distinguish between resource type for the tool tip.
@@ -115,7 +117,7 @@ def view_clusters(namespace: str = None):
115117
)
116118
return # Exit function if not in Jupyter Notebook
117119

118-
from .cluster import get_current_namespace
120+
from ..ray.cluster.cluster import get_current_namespace
119121

120122
if not namespace:
121123
namespace = get_current_namespace()
@@ -278,7 +280,7 @@ def _on_ray_dashboard_button_click(
278280
"""
279281
_on_ray_dashboard_button_click handles the event when the Open Ray Dashboard button is clicked, opening the Ray Dashboard in a new tab
280282
"""
281-
from codeflare_sdk.cluster import Cluster
283+
from codeflare_sdk.ray.cluster import Cluster
282284

283285
cluster_name = classification_widget.value
284286
namespace = ray_clusters_df[ray_clusters_df["Name"] == classification_widget.value][
@@ -309,7 +311,7 @@ def _on_list_jobs_button_click(
309311
"""
310312
_on_list_jobs_button_click handles the event when the View Jobs button is clicked, opening the Ray Jobs Dashboard in a new tab
311313
"""
312-
from codeflare_sdk.cluster import Cluster
314+
from codeflare_sdk.ray.cluster import Cluster
313315

314316
cluster_name = classification_widget.value
315317
namespace = ray_clusters_df[ray_clusters_df["Name"] == classification_widget.value][
@@ -342,7 +344,7 @@ def _delete_cluster(
342344
_delete_cluster function deletes the cluster with the given name and namespace.
343345
It optionally waits for the cluster to be deleted.
344346
"""
345-
from .cluster import _check_aw_exists
347+
from ..ray.cluster.cluster import _check_aw_exists
346348

347349
try:
348350
config_check()
@@ -400,7 +402,7 @@ def _fetch_cluster_data(namespace):
400402
"""
401403
_fetch_cluster_data function fetches all clusters and their spec in a given namespace and returns a DataFrame.
402404
"""
403-
from .cluster import list_all_clusters
405+
from ..ray.cluster.cluster import list_all_clusters
404406

405407
rayclusters = list_all_clusters(namespace, False)
406408
if not rayclusters:
File renamed without changes.
File renamed without changes.

src/codeflare_sdk/utils/generate_cert.py 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 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 2024 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
File renamed without changes.
File renamed without changes.
+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 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
)
File renamed without changes.

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

+7-7
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
)
@@ -80,7 +80,7 @@ def is_kind_cluster():
8080

8181
def update_names(
8282
cluster_yaml: dict,
83-
cluster: "codeflare_sdk.cluster.Cluster",
83+
cluster: "codeflare_sdk.ray.cluster.cluster.Cluster",
8484
):
8585
metadata = cluster_yaml.get("metadata")
8686
metadata["name"] = cluster.config.name
@@ -135,7 +135,7 @@ def update_resources(
135135

136136

137137
def head_worker_gpu_count_from_cluster(
138-
cluster: "codeflare_sdk.cluster.Cluster",
138+
cluster: "codeflare_sdk.ray.cluster.cluster.Cluster",
139139
) -> typing.Tuple[int, int]:
140140
head_gpus = 0
141141
worker_gpus = 0
@@ -155,7 +155,7 @@ def head_worker_gpu_count_from_cluster(
155155

156156

157157
def head_worker_resources_from_cluster(
158-
cluster: "codeflare_sdk.cluster.Cluster",
158+
cluster: "codeflare_sdk.ray.cluster.cluster.Cluster",
159159
) -> typing.Tuple[dict, dict]:
160160
to_return = {}, {}
161161
for k in cluster.config.head_extended_resource_requests.keys():
@@ -178,7 +178,7 @@ def head_worker_resources_from_cluster(
178178

179179
def update_nodes(
180180
ray_cluster_dict: dict,
181-
cluster: "codeflare_sdk.cluster.Cluster",
181+
cluster: "codeflare_sdk.ray.cluster.cluster.Cluster",
182182
):
183183
head = ray_cluster_dict.get("spec").get("headGroupSpec")
184184
worker = ray_cluster_dict.get("spec").get("workerGroupSpecs")[0]
@@ -325,7 +325,7 @@ def write_user_yaml(user_yaml, output_file_name):
325325
print(f"Written to: {output_file_name}")
326326

327327

328-
def generate_appwrapper(cluster: "codeflare_sdk.cluster.Cluster"):
328+
def generate_appwrapper(cluster: "codeflare_sdk.ray.cluster.cluster.Cluster"):
329329
cluster_yaml = read_template(cluster.config.template)
330330
appwrapper_name, _ = gen_names(cluster.config.name)
331331
update_names(

src/codeflare_sdk/utils/pretty_print.py 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 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

0 commit comments

Comments
 (0)