Skip to content

Commit e1b19ca

Browse files
authored
minor changes for print refactoring (#14)
Co-authored-by: Atin Sood <asood@us.ibm.com>
1 parent 0f47b6d commit e1b19ca

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/codeflare_sdk/cluster/cluster.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@ def down(self, namespace='default'):
4141
oc.invoke("delete", ["AppWrapper", self.app_wrapper_yaml])
4242

4343
def status(self, print_to_console=True):
44-
cluster = _ray_cluster_status(self.config.name)
44+
cluster = _ray_cluster_status(self.config.name)
4545
if cluster:
4646
if print_to_console:
4747
pretty_print.print_clusters([cluster])
4848
return cluster.status
4949
else:
50+
if print_to_console:
51+
pretty_print.print_no_resources_found()
5052
return None
5153

5254
# checks whether the ray cluster is ready
53-
def is_ready(self):
55+
def is_ready(self, print_to_console=True):
5456
ready = False
5557
status = CodeFlareClusterStatus.UNKNOWN
5658
# check the app wrapper status
@@ -73,11 +75,13 @@ def is_ready(self):
7375
if cluster:
7476
if cluster.status == RayClusterStatus.READY:
7577
ready = True
76-
status = CodeFlareClusterStatus.READY
78+
status = CodeFlareClusterStatus.READY
7779
elif cluster.status in [RayClusterStatus.UNHEALTHY, RayClusterStatus.FAILED]:
7880
ready = False
7981
status = CodeFlareClusterStatus.FAILED
80-
82+
83+
if print_to_console:
84+
pretty_print.print_clusters([cluster])
8185
return status, ready
8286

8387

src/codeflare_sdk/utils/pretty_print.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,30 @@
55
from rich.panel import Panel
66
from rich import box
77
from typing import List
8-
from ..cluster.model import RayCluster, AppWrapper
8+
from ..cluster.model import RayCluster, AppWrapper, RayClusterStatus
99

10-
def _print_no_cluster_found():
10+
def print_no_resources_found():
11+
console = Console()
12+
console.print(Panel("[red]No resources found"))
13+
14+
15+
def print_appwrappers_status():
1116
pass
1217

1318
def print_clusters(clusters:List[RayCluster], verbose=True):
19+
if not clusters == 0:
20+
print_no_resources_found()
21+
return #shortcircuit
22+
1423
console = Console()
1524
title_printed = False
1625
#FIXME handle case where no clusters are found
1726
if len(clusters) == 0:
18-
_print_no_cluster_found()
27+
print_no_resources_found()
1928
return #exit early
2029

2130
for cluster in clusters:
22-
status = "Active :white_heavy_check_mark:" if cluster.status.lower() == 'ready' else "InActive :x:"
31+
status = "Active :white_heavy_check_mark:" if cluster.status == RayClusterStatus.READY else "InActive :x:"
2332
name = cluster.name
2433
dashboard = f"https://codeflare-raydashboard.research.ibm.com?rayclustername={name}"
2534
mincount = str(cluster.min_workers)
@@ -38,7 +47,7 @@ def print_clusters(clusters:List[RayCluster], verbose=True):
3847
table0.add_row("")
3948
table0.add_row("[bold underline]"+name,status)
4049
table0.add_row()
41-
table0.add_row(f"[bold]URI:[/bold] ray://{name}-head.codeflare.svc:1001")
50+
table0.add_row(f"[bold]URI:[/bold] ray://{name}-head-svc:1001") #format that is used to generate the name of the service
4251
table0.add_row()
4352
table0.add_row(f"[link={dashboard} blue underline]Dashboard:link:[/link]")
4453
table0.add_row("") #empty row for spacing

tests/test_clusters.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from codeflare_sdk.cluster.cluster import list_all_clusters, _app_wrapper_status
22
from codeflare_sdk.cluster.cluster import Cluster, ClusterConfiguration
3+
34
import time
45

56
def test_cluster_up():
@@ -21,3 +22,7 @@ def test_cluster_down():
2122
cluster = Cluster(ClusterConfiguration(name='raycluster-autoscaler'))
2223
cluster.down()
2324

25+
26+
def test_no_resources_found():
27+
from codeflare_sdk.utils import pretty_print
28+
pretty_print.print_no_resources_found()

0 commit comments

Comments
 (0)