Skip to content

Commit c5a50ed

Browse files
authored
appwrapper status implemented (#2)
Co-authored-by: Atin Sood <[email protected]>
1 parent 5a1fc0b commit c5a50ed

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

src/codeflare_sdk/cluster/cluster.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from .config import ClusterConfiguration
2-
from ..utils.pretty_print import RayCluster
2+
from ..utils.pretty_print import RayCluster, AppWrapper
33
from ..utils import pretty_print
44
import openshift as oc
55
from typing import List, Optional
@@ -14,17 +14,19 @@ def up(self):
1414
pass
1515

1616
def down(self, name):
17+
# FIXME on what the exact details should be
18+
# 1. delete the appwrapper and that should delete the cluster
1719
pass
1820

1921
def status(self, print_to_console=True):
2022
cluster = _ray_cluster_status(self.config.name)
2123
if cluster:
2224
if print_to_console:
23-
pretty_print.print_clusters([cluster])
25+
pretty_print.print_clusters([cluster])
2426
return cluster.status
2527
else:
2628
return None
27-
29+
2830

2931
def list_all_clusters(print_to_console=True):
3032
clusters = _get_ray_clusters()
@@ -41,17 +43,19 @@ def _get_appwrappers(namespace='default'):
4143
return app_wrappers
4244

4345

46+
def _app_wrapper_status(name, namespace='default') -> Optional[AppWrapper]:
47+
with oc.project(namespace), oc.timeout(10*60):
48+
cluster = oc.selector(f'appwrapper/{name}').object()
49+
if cluster:
50+
return _map_to_app_wrapper(cluster)
51+
4452
def _ray_cluster_status(name, namespace='default') -> Optional[RayCluster]:
45-
53+
# FIXME should we check the appwrapper first
4654
with oc.project(namespace), oc.timeout(10*60):
4755
cluster = oc.selector(f'rayclusters/{name}').object()
4856

4957
if cluster:
5058
return _map_to_ray_cluster(cluster)
51-
else:
52-
return None
53-
54-
5559

5660

5761
def _get_ray_clusters(namespace='default') -> List[RayCluster]:
@@ -65,7 +69,7 @@ def _get_ray_clusters(namespace='default') -> List[RayCluster]:
6569
return list_of_clusters
6670

6771

68-
def _map_to_ray_cluster(cluster):
72+
def _map_to_ray_cluster(cluster)->RayCluster:
6973
cluster_model = cluster.model
7074
return RayCluster(
7175
name=cluster.name(), status=cluster_model.status.state,
@@ -77,3 +81,11 @@ def _map_to_ray_cluster(cluster):
7781
0].template.spec.containers[0].resources.requests.memory,
7882
worker_cpu=cluster_model.spec.workerGroupSpecs[0].template.spec.containers[0].resources.limits.cpu,
7983
worker_gpu=0)
84+
85+
86+
def _map_to_app_wrapper(cluster)->AppWrapper:
87+
cluster_model = cluster.model
88+
return AppWrapper(
89+
name=cluster.name(), status=cluster_model.status.state,
90+
can_run=cluster_model.status.canrun,
91+
job_state=cluster_model.status.queuejobstate)

src/codeflare_sdk/utils/pretty_print.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ class RayCluster:
2020
worker_cpu: int
2121
worker_gpu: int
2222

23+
@dataclass
24+
class AppWrapper:
25+
name: str
26+
status:str
27+
can_run: bool
28+
job_state: str
29+
30+
2331
def _print_no_cluster_found():
2432
pass
2533

tests/test_clusters.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from codeflare_sdk.cluster.cluster import list_all_clusters
1+
from codeflare_sdk.cluster.cluster import list_all_clusters, _app_wrapper_status
22
from codeflare_sdk.cluster.cluster import Cluster, ClusterConfiguration
33

44
#for now these tests assume that the cluster was already created
@@ -9,5 +9,7 @@ def test_cluster_status():
99
cluster = Cluster(ClusterConfiguration(name='raycluster-autoscaler'))
1010
cluster.status()
1111

12-
12+
def test_app_wrapper_status():
13+
print(_app_wrapper_status('raycluster-autoscaler'))
1314

15+

0 commit comments

Comments
 (0)