@@ -74,6 +74,12 @@ def __init__(self, ray_clusters_df: pd.DataFrame, namespace: str = None):
74
74
tooltip = "Open the Ray Dashboard in a new tab" ,
75
75
layout = widgets .Layout (width = "auto" ),
76
76
)
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
+ )
77
83
78
84
# Set up interactions
79
85
self ._initialize_callbacks ()
@@ -95,6 +101,7 @@ def _initialize_callbacks(self):
95
101
self .ray_dashboard_button .on_click (
96
102
lambda b : self ._on_ray_dashboard_button_click (b )
97
103
)
104
+ self .refresh_data_button .on_click (lambda b : self ._on_refresh_button_click (b ))
98
105
99
106
def _trigger_initial_display (self ):
100
107
"""
@@ -138,31 +145,17 @@ def _on_delete_button_click(self, b):
138
145
_on_delete_button_click handles the event when the Delete Button is clicked, deleting the selected cluster.
139
146
"""
140
147
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 ]
144
148
145
- _delete_cluster (cluster_name , namespace )
149
+ _delete_cluster (cluster_name , self . namespace )
146
150
147
151
with self .user_output :
148
152
self .user_output .clear_output ()
149
153
print (
150
- f"Cluster { cluster_name } in the { namespace } namespace was deleted successfully."
154
+ f"Cluster { cluster_name } in the { self . namespace } namespace was deleted successfully."
151
155
)
152
156
153
157
# 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 ()
158
+ self ._refresh_dataframe ()
166
159
167
160
def _on_list_jobs_button_click (self , b ):
168
161
"""
@@ -171,15 +164,12 @@ def _on_list_jobs_button_click(self, b):
171
164
from codeflare_sdk import Cluster
172
165
173
166
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 ]
177
167
178
168
# Suppress from Cluster Object initialisation widgets and outputs
179
169
with widgets .Output (), contextlib .redirect_stdout (
180
170
io .StringIO ()
181
171
), contextlib .redirect_stderr (io .StringIO ()):
182
- cluster = Cluster (ClusterConfiguration (cluster_name , namespace ))
172
+ cluster = Cluster (ClusterConfiguration (cluster_name , self . namespace ))
183
173
dashboard_url = cluster .cluster_dashboard_uri ()
184
174
185
175
with self .user_output :
@@ -197,15 +187,12 @@ def _on_ray_dashboard_button_click(self, b):
197
187
from codeflare_sdk import Cluster
198
188
199
189
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 ]
203
190
204
191
# Suppress from Cluster Object initialisation widgets and outputs
205
192
with widgets .Output (), contextlib .redirect_stdout (
206
193
io .StringIO ()
207
194
), contextlib .redirect_stderr (io .StringIO ()):
208
- cluster = Cluster (ClusterConfiguration (cluster_name , namespace ))
195
+ cluster = Cluster (ClusterConfiguration (cluster_name , self . namespace ))
209
196
dashboard_url = cluster .cluster_dashboard_uri ()
210
197
211
198
with self .user_output :
@@ -214,11 +201,42 @@ def _on_ray_dashboard_button_click(self, b):
214
201
with self .url_output :
215
202
display (Javascript (f'window.open("{ dashboard_url } ", "_blank");' ))
216
203
204
+ def _on_refresh_data_button_click (self , b ):
205
+ """
206
+ _on_refresh_button_click handles the event when the Refresh Data button is clicked, refreshing the list of Ray Clusters.
207
+ """
208
+ self .refresh_data_button .disabled = True
209
+ self ._refresh_dataframe ()
210
+ self .refresh_data_button .disabled = False
211
+
212
+ def _refresh_dataframe (self ):
213
+ """
214
+ _refresh_data function refreshes the list of Ray Clusters.
215
+ """
216
+ new_df = _fetch_cluster_data (self .namespace )
217
+ self .ray_clusters_df = new_df
218
+ if new_df .empty :
219
+ self .classification_widget .close ()
220
+ self .delete_button .close ()
221
+ self .list_jobs_button .close ()
222
+ self .ray_dashboard_button .close ()
223
+ self .refresh_data_button .close ()
224
+ with self .raycluster_data_output :
225
+ self .raycluster_data_output .clear_output ()
226
+ print (f"No clusters found in the { self .namespace } namespace." )
227
+ else :
228
+ self .classification_widget .options = new_df ["Name" ].tolist ()
229
+
217
230
def display_widgets (self ):
218
231
display (widgets .VBox ([self .classification_widget , self .raycluster_data_output ]))
219
232
display (
220
233
widgets .HBox (
221
- [self .delete_button , self .list_jobs_button , self .ray_dashboard_button ]
234
+ [
235
+ self .delete_button ,
236
+ self .list_jobs_button ,
237
+ self .ray_dashboard_button ,
238
+ self .refresh_data_button ,
239
+ ]
222
240
),
223
241
self .url_output ,
224
242
self .user_output ,
0 commit comments