Skip to content

minor changes for print refactoring #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/codeflare_sdk/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ def down(self, namespace='default'):
oc.invoke("delete", ["AppWrapper", self.app_wrapper_yaml])

def status(self, print_to_console=True):
cluster = _ray_cluster_status(self.config.name)
cluster = _ray_cluster_status(self.config.name)
if cluster:
if print_to_console:
pretty_print.print_clusters([cluster])
return cluster.status
else:
if print_to_console:
pretty_print.print_no_resources_found()
return None

# checks whether the ray cluster is ready
def is_ready(self):
def is_ready(self, print_to_console=True):
ready = False
status = CodeFlareClusterStatus.UNKNOWN
# check the app wrapper status
Expand All @@ -73,11 +75,13 @@ def is_ready(self):
if cluster:
if cluster.status == RayClusterStatus.READY:
ready = True
status = CodeFlareClusterStatus.READY
status = CodeFlareClusterStatus.READY
elif cluster.status in [RayClusterStatus.UNHEALTHY, RayClusterStatus.FAILED]:
ready = False
status = CodeFlareClusterStatus.FAILED


if print_to_console:
pretty_print.print_clusters([cluster])
return status, ready


Expand Down
19 changes: 14 additions & 5 deletions src/codeflare_sdk/utils/pretty_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@
from rich.panel import Panel
from rich import box
from typing import List
from ..cluster.model import RayCluster, AppWrapper
from ..cluster.model import RayCluster, AppWrapper, RayClusterStatus

def _print_no_cluster_found():
def print_no_resources_found():
console = Console()
console.print(Panel("[red]No resources found"))


def print_appwrappers_status():
pass

def print_clusters(clusters:List[RayCluster], verbose=True):
if not clusters == 0:
print_no_resources_found()
return #shortcircuit

console = Console()
title_printed = False
#FIXME handle case where no clusters are found
if len(clusters) == 0:
_print_no_cluster_found()
print_no_resources_found()
return #exit early

for cluster in clusters:
status = "Active :white_heavy_check_mark:" if cluster.status.lower() == 'ready' else "InActive :x:"
status = "Active :white_heavy_check_mark:" if cluster.status == RayClusterStatus.READY else "InActive :x:"
name = cluster.name
dashboard = f"https://codeflare-raydashboard.research.ibm.com?rayclustername={name}"
mincount = str(cluster.min_workers)
Expand All @@ -38,7 +47,7 @@ def print_clusters(clusters:List[RayCluster], verbose=True):
table0.add_row("")
table0.add_row("[bold underline]"+name,status)
table0.add_row()
table0.add_row(f"[bold]URI:[/bold] ray://{name}-head.codeflare.svc:1001")
table0.add_row(f"[bold]URI:[/bold] ray://{name}-head-svc:1001") #format that is used to generate the name of the service
table0.add_row()
table0.add_row(f"[link={dashboard} blue underline]Dashboard:link:[/link]")
table0.add_row("") #empty row for spacing
Expand Down
5 changes: 5 additions & 0 deletions tests/test_clusters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from codeflare_sdk.cluster.cluster import list_all_clusters, _app_wrapper_status
from codeflare_sdk.cluster.cluster import Cluster, ClusterConfiguration

import time

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


def test_no_resources_found():
from codeflare_sdk.utils import pretty_print
pretty_print.print_no_resources_found()