11from .config import ClusterConfiguration
2- from ..utils .pretty_print import RayCluster
2+ from ..utils .pretty_print import RayCluster , AppWrapper
33from ..utils import pretty_print
44import openshift as oc
55from typing import List , Optional
@@ -14,17 +14,19 @@ def up(self):
1414 pass
1515
1616 def down (self , name ):
17+ # FIXME on what the exact details should be
18+ # 1. delete the appwrapper and that should delete the cluster
1719 pass
1820
1921 def status (self , print_to_console = True ):
2022 cluster = _ray_cluster_status (self .config .name )
2123 if cluster :
2224 if print_to_console :
23- pretty_print .print_clusters ([cluster ])
25+ pretty_print .print_clusters ([cluster ])
2426 return cluster .status
2527 else :
2628 return None
27-
29+
2830
2931def list_all_clusters (print_to_console = True ):
3032 clusters = _get_ray_clusters ()
@@ -41,17 +43,19 @@ def _get_appwrappers(namespace='default'):
4143 return app_wrappers
4244
4345
46+ def _app_wrapper_status (name , namespace = 'default' ) -> Optional [AppWrapper ]:
47+ with oc .project (namespace ), oc .timeout (10 * 60 ):
48+ cluster = oc .selector (f'appwrapper/{ name } ' ).object ()
49+ if cluster :
50+ return _map_to_app_wrapper (cluster )
51+
4452def _ray_cluster_status (name , namespace = 'default' ) -> Optional [RayCluster ]:
45-
53+ # FIXME should we check the appwrapper first
4654 with oc .project (namespace ), oc .timeout (10 * 60 ):
4755 cluster = oc .selector (f'rayclusters/{ name } ' ).object ()
4856
4957 if cluster :
5058 return _map_to_ray_cluster (cluster )
51- else :
52- return None
53-
54-
5559
5660
5761def _get_ray_clusters (namespace = 'default' ) -> List [RayCluster ]:
@@ -65,7 +69,7 @@ def _get_ray_clusters(namespace='default') -> List[RayCluster]:
6569 return list_of_clusters
6670
6771
68- def _map_to_ray_cluster (cluster ):
72+ def _map_to_ray_cluster (cluster )-> RayCluster :
6973 cluster_model = cluster .model
7074 return RayCluster (
7175 name = cluster .name (), status = cluster_model .status .state ,
@@ -77,3 +81,11 @@ def _map_to_ray_cluster(cluster):
7781 0 ].template .spec .containers [0 ].resources .requests .memory ,
7882 worker_cpu = cluster_model .spec .workerGroupSpecs [0 ].template .spec .containers [0 ].resources .limits .cpu ,
7983 worker_gpu = 0 )
84+
85+
86+ def _map_to_app_wrapper (cluster )-> AppWrapper :
87+ cluster_model = cluster .model
88+ return AppWrapper (
89+ name = cluster .name (), status = cluster_model .status .state ,
90+ can_run = cluster_model .status .canrun ,
91+ job_state = cluster_model .status .queuejobstate )
0 commit comments