Skip to content

Commit 10f3c1a

Browse files
authored
app wrappers statys and list (#15)
Co-authored-by: Atin Sood <[email protected]>
1 parent 921b3fb commit 10f3c1a

File tree

3 files changed

+47
-12
lines changed

3 files changed

+47
-12
lines changed

src/codeflare_sdk/cluster/cluster.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,15 @@ def list_all_clusters(print_to_console=True):
9292
return clusters
9393

9494

95-
# private methods
96-
97-
def _get_appwrappers(namespace='default'):
98-
with oc.project(namespace), oc.timeout(10*60):
99-
app_wrappers = oc.selector('appwrappers').qnames()
95+
def list_all_queued(print_to_console=True):
96+
app_wrappers = _get_app_wrappers(filter=[AppWrapperStatus.RUNNING, AppWrapperStatus.PENDING])
97+
if print_to_console:
98+
pretty_print.print_appwrappers_status(app_wrappers)
10099
return app_wrappers
100+
101+
102+
103+
# private methods
101104

102105

103106
def _app_wrapper_status(name, namespace='default') -> Optional[AppWrapper]:
@@ -127,6 +130,22 @@ def _get_ray_clusters(namespace='default') -> List[RayCluster]:
127130
return list_of_clusters
128131

129132

133+
134+
def _get_app_wrappers(filter:List[AppWrapperStatus], namespace='default') -> List[AppWrapper]:
135+
list_of_app_wrappers = []
136+
137+
with oc.project(namespace), oc.timeout(10*60):
138+
app_wrappers = oc.selector('appwrappers').objects()
139+
140+
for item in app_wrappers:
141+
app_wrapper = _map_to_app_wrapper(item)
142+
if filter and app_wrapper.status in filter:
143+
list_of_app_wrappers.append(app_wrapper)
144+
else:
145+
list_of_app_wrappers.append(app_wrapper)
146+
return list_of_app_wrappers
147+
148+
130149
def _map_to_ray_cluster(cluster) -> RayCluster:
131150
cluster_model = cluster.model
132151
return RayCluster(

src/codeflare_sdk/utils/pretty_print.py

+18-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,24 @@ def print_no_resources_found():
1212
console.print(Panel("[red]No resources found"))
1313

1414

15-
def print_appwrappers_status():
16-
pass
15+
def print_appwrappers_status(app_wrappers:List[AppWrapper]):
16+
if not app_wrappers == 0:
17+
print_no_resources_found()
18+
return #shortcircuit
19+
20+
console = Console()
21+
for app_wrapper in app_wrappers:
22+
name = app_wrapper.name
23+
status = app_wrapper.status.value
24+
25+
table = Table(box=None, title="[bold] :rocket: List of CodeFlare clusters in queue:rocket:")
26+
table.add_column("Name", style="cyan", no_wrap=True)
27+
table.add_column("Status", style="magenta")
28+
table.add_row("[bold underline]"+name,status)
29+
table.add_row("") #empty row for spacing
30+
console.print(Panel.fit(table))
31+
32+
1733

1834
def print_clusters(clusters:List[RayCluster], verbose=True):
1935
if not clusters == 0:
@@ -22,10 +38,6 @@ def print_clusters(clusters:List[RayCluster], verbose=True):
2238

2339
console = Console()
2440
title_printed = False
25-
#FIXME handle case where no clusters are found
26-
if len(clusters) == 0:
27-
print_no_resources_found()
28-
return #exit early
2941

3042
for cluster in clusters:
3143
status = "Active :white_heavy_check_mark:" if cluster.status == RayClusterStatus.READY else "InActive :x:"

tests/test_clusters.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from codeflare_sdk.cluster.cluster import list_all_clusters, _app_wrapper_status
1+
from codeflare_sdk.cluster.cluster import list_all_clusters, list_all_queued, _app_wrapper_status
22
from codeflare_sdk.cluster.cluster import Cluster, ClusterConfiguration
33

44
import time
@@ -26,3 +26,7 @@ def test_cluster_down():
2626
def test_no_resources_found():
2727
from codeflare_sdk.utils import pretty_print
2828
pretty_print.print_no_resources_found()
29+
30+
def test_list_app_wrappers():
31+
app_wrappers = list_all_queued()
32+

0 commit comments

Comments
 (0)