@@ -656,10 +656,12 @@ def _fetch_cluster_data(namespace):
656656 return pd .DataFrame (data )
657657
658658
659- def list_cluster_details (namespace : str ):
659+ def list_cluster_details (namespace : str ): # TODO: or current namespace as default
660+ global df
660661 df = _fetch_cluster_data (namespace )
661662
662- my_output = widgets .Output ()
663+ outputs = widgets .Output ()
664+ data_output = widgets .Output ()
663665 if df ["Name" ].empty :
664666 print (f"No clusters found in the { namespace } namespace." )
665667 else :
@@ -670,22 +672,38 @@ def list_cluster_details(namespace: str):
670672
671673 def on_cluster_click (change ):
672674 new_value = change ["new" ]
673- my_output .clear_output ()
674- with my_output :
675+ data_output .clear_output ()
676+ df = _fetch_cluster_data (namespace )
677+ classification_widget .options = df ["Name" ].tolist ()
678+ with data_output :
675679 display (HTML (df [df ["Name" ]== new_value ][["Name" , "Namespace" , "Head GPUs" , "Head CPU Req~Lim" , "Head Memory Req~Lim" , "Worker GPUs" , "Worker CPU Req~Lim" , "Worker Memory Req~Lim" , "status" ]].to_html (escape = False , index = False , border = 2 )))
676680
677681 classification_widget .observe (on_cluster_click , names = "value" )
678- display (widgets .VBox ([classification_widget , my_output ]))
682+ display (widgets .VBox ([classification_widget , data_output ]))
679683
680684 def on_delete_button_clicked (b ):
685+ global df
681686 cluster_name = classification_widget .value
682687 namespace = df [df ["Name" ]== classification_widget .value ]["Namespace" ].values [0 ]
683688 delete_cluster (cluster_name , namespace )
684- my_output .clear_output ()
685- print (f"Cluster { cluster_name } in the { namespace } namespace was deleted successfully." )
689+
690+ sleep (3 ) # wait for the cluster to be deleted
691+ outputs .clear_output ()
692+ with outputs :
693+ print (f"Cluster { cluster_name } in the { namespace } namespace was deleted successfully." )
686694 # Refresh the dataframe
687- new_df = _fetch_cluster_data (namespace )
688- classification_widget .options = new_df ["Name" ].tolist ()
695+ df = _fetch_cluster_data (namespace )
696+ if df ["Name" ].empty :
697+ classification_widget .close ()
698+ delete_button .close ()
699+ list_jobs_button .close ()
700+ ray_dashboard_button .close ()
701+ data_output .clear_output ()
702+ with data_output :
703+ print (f"No clusters found in the { namespace } namespace." )
704+ else :
705+ classification_widget .options = df ["Name" ].tolist ()
706+
689707
690708
691709 # out Output widget is used to execute JavaScript code to open the Ray dashboard URL in a new browser tab
@@ -697,10 +715,11 @@ def on_ray_dashboard_button_clicked(b):
697715 cluster = Cluster (ClusterConfiguration (cluster_name , namespace ))
698716 dashboard_url = cluster .cluster_dashboard_uri ()
699717
700- my_output .clear_output ()
718+ outputs .clear_output ()
719+ with outputs :
720+ print (f"Opening Ray Dashboard for { cluster_name } cluster:\n { dashboard_url } " )
701721 with out :
702722 display (Javascript (f'window.open("{ dashboard_url } ", "_blank");' ))
703- print (f"Opening Ray Dashboard for { cluster_name } :\n { dashboard_url } " )
704723
705724 def on_list_jobs_button_clicked (b ):
706725 cluster_name = classification_widget .value
@@ -709,7 +728,9 @@ def on_list_jobs_button_clicked(b):
709728 cluster = Cluster (ClusterConfiguration (cluster_name , namespace ))
710729 dashboard_url = cluster .cluster_dashboard_uri ()
711730
712- my_output .clear_output ()
731+ outputs .clear_output ()
732+ with outputs :
733+ print (f"Opening Ray Jobs Dashboard for { cluster_name } cluster:\n { dashboard_url } /#/jobs" )
713734 with out :
714735 display (Javascript (f'window.open("{ dashboard_url } /#/jobs", "_blank");' ))
715736
@@ -723,17 +744,19 @@ def on_list_jobs_button_clicked(b):
723744 delete_button = widgets .Button (
724745 description = 'Delete Cluster' ,
725746 icon = 'trash' ,
747+ tooltip = "Delete the selected cluster"
726748 )
727749 delete_button .on_click (on_delete_button_clicked )
728750
729751 ray_dashboard_button = widgets .Button (
730752 description = 'Open Ray Dashboard' ,
731753 icon = 'dashboard' ,
754+ tooltip = "Open the Ray Dashboard in a new tab" ,
732755 layout = widgets .Layout (width = 'auto' ),
733756 )
734757 ray_dashboard_button .on_click (on_ray_dashboard_button_clicked )
735758
736- display (widgets .HBox ([delete_button , list_jobs_button , ray_dashboard_button ]), out )
759+ display (widgets .HBox ([delete_button , list_jobs_button , ray_dashboard_button ]), out , outputs )
737760
738761
739762
0 commit comments