@@ -74,6 +74,12 @@ def __init__(self, ray_clusters_df: pd.DataFrame, namespace: str = None):
7474 tooltip = "Open the Ray Dashboard in a new tab" ,
7575 layout = widgets .Layout (width = "auto" ),
7676 )
77+ self .refresh_data_button = widgets .Button (
78+ description = "Refresh Data" ,
79+ icon = "refresh" ,
80+ tooltip = "Refresh the list of Ray Clusters" ,
81+ layout = widgets .Layout (width = "auto" , left = "1em" ),
82+ )
7783
7884 # Set up interactions
7985 self ._initialize_callbacks ()
@@ -95,6 +101,9 @@ def _initialize_callbacks(self):
95101 self .ray_dashboard_button .on_click (
96102 lambda b : self ._on_ray_dashboard_button_click (b )
97103 )
104+ self .refresh_data_button .on_click (
105+ lambda b : self ._on_refresh_data_button_click (b )
106+ )
98107
99108 def _trigger_initial_display (self ):
100109 """
@@ -138,31 +147,17 @@ def _on_delete_button_click(self, b):
138147 _on_delete_button_click handles the event when the Delete Button is clicked, deleting the selected cluster.
139148 """
140149 cluster_name = self .classification_widget .value
141- namespace = self .ray_clusters_df [
142- self .ray_clusters_df ["Name" ] == self .classification_widget .value
143- ]["Namespace" ].values [0 ]
144150
145- _delete_cluster (cluster_name , namespace )
151+ _delete_cluster (cluster_name , self . namespace )
146152
147153 with self .user_output :
148154 self .user_output .clear_output ()
149155 print (
150- f"Cluster { cluster_name } in the { namespace } namespace was deleted successfully."
156+ f"Cluster { cluster_name } in the { self . namespace } namespace was deleted successfully."
151157 )
152158
153159 # Refresh the dataframe
154- new_df = _fetch_cluster_data (namespace )
155- self .ray_clusters_df = new_df
156- if new_df .empty :
157- self .classification_widget .close ()
158- self .delete_button .close ()
159- self .list_jobs_button .close ()
160- self .ray_dashboard_button .close ()
161- with self .raycluster_data_output :
162- self .raycluster_data_output .clear_output ()
163- print (f"No clusters found in the { namespace } namespace." )
164- else :
165- self .classification_widget .options = new_df ["Name" ].tolist ()
160+ self ._refresh_dataframe ()
166161
167162 def _on_list_jobs_button_click (self , b ):
168163 """
@@ -171,15 +166,12 @@ def _on_list_jobs_button_click(self, b):
171166 from codeflare_sdk import Cluster
172167
173168 cluster_name = self .classification_widget .value
174- namespace = self .ray_clusters_df [
175- self .ray_clusters_df ["Name" ] == self .classification_widget .value
176- ]["Namespace" ].values [0 ]
177169
178170 # Suppress from Cluster Object initialisation widgets and outputs
179171 with widgets .Output (), contextlib .redirect_stdout (
180172 io .StringIO ()
181173 ), contextlib .redirect_stderr (io .StringIO ()):
182- cluster = Cluster (ClusterConfiguration (cluster_name , namespace ))
174+ cluster = Cluster (ClusterConfiguration (cluster_name , self . namespace ))
183175 dashboard_url = cluster .cluster_dashboard_uri ()
184176
185177 with self .user_output :
@@ -197,15 +189,12 @@ def _on_ray_dashboard_button_click(self, b):
197189 from codeflare_sdk import Cluster
198190
199191 cluster_name = self .classification_widget .value
200- namespace = self .ray_clusters_df [
201- self .ray_clusters_df ["Name" ] == self .classification_widget .value
202- ]["Namespace" ].values [0 ]
203192
204193 # Suppress from Cluster Object initialisation widgets and outputs
205194 with widgets .Output (), contextlib .redirect_stdout (
206195 io .StringIO ()
207196 ), contextlib .redirect_stderr (io .StringIO ()):
208- cluster = Cluster (ClusterConfiguration (cluster_name , namespace ))
197+ cluster = Cluster (ClusterConfiguration (cluster_name , self . namespace ))
209198 dashboard_url = cluster .cluster_dashboard_uri ()
210199
211200 with self .user_output :
@@ -214,11 +203,42 @@ def _on_ray_dashboard_button_click(self, b):
214203 with self .url_output :
215204 display (Javascript (f'window.open("{ dashboard_url } ", "_blank");' ))
216205
206+ def _on_refresh_data_button_click (self , b ):
207+ """
208+ _on_refresh_button_click handles the event when the Refresh Data button is clicked, refreshing the list of Ray Clusters.
209+ """
210+ self .refresh_data_button .disabled = True
211+ self ._refresh_dataframe ()
212+ self .refresh_data_button .disabled = False
213+
214+ def _refresh_dataframe (self ):
215+ """
216+ _refresh_data function refreshes the list of Ray Clusters.
217+ """
218+ new_df = _fetch_cluster_data (self .namespace )
219+ self .ray_clusters_df = new_df
220+ if new_df .empty :
221+ self .classification_widget .close ()
222+ self .delete_button .close ()
223+ self .list_jobs_button .close ()
224+ self .ray_dashboard_button .close ()
225+ self .refresh_data_button .close ()
226+ with self .raycluster_data_output :
227+ self .raycluster_data_output .clear_output ()
228+ print (f"No clusters found in the { self .namespace } namespace." )
229+ else :
230+ self .classification_widget .options = new_df ["Name" ].tolist ()
231+
217232 def display_widgets (self ):
218233 display (widgets .VBox ([self .classification_widget , self .raycluster_data_output ]))
219234 display (
220235 widgets .HBox (
221- [self .delete_button , self .list_jobs_button , self .ray_dashboard_button ]
236+ [
237+ self .delete_button ,
238+ self .list_jobs_button ,
239+ self .ray_dashboard_button ,
240+ self .refresh_data_button ,
241+ ]
222242 ),
223243 self .url_output ,
224244 self .user_output ,
0 commit comments