1
1
from .config import ClusterConfiguration
2
- from ..utils .pretty_print import RayCluster
2
+ from ..utils .pretty_print import RayCluster , AppWrapper
3
3
from ..utils import pretty_print
4
4
import openshift as oc
5
5
from typing import List , Optional
@@ -14,17 +14,19 @@ def up(self):
14
14
pass
15
15
16
16
def down (self , name ):
17
+ # FIXME on what the exact details should be
18
+ # 1. delete the appwrapper and that should delete the cluster
17
19
pass
18
20
19
21
def status (self , print_to_console = True ):
20
22
cluster = _ray_cluster_status (self .config .name )
21
23
if cluster :
22
24
if print_to_console :
23
- pretty_print .print_clusters ([cluster ])
25
+ pretty_print .print_clusters ([cluster ])
24
26
return cluster .status
25
27
else :
26
28
return None
27
-
29
+
28
30
29
31
def list_all_clusters (print_to_console = True ):
30
32
clusters = _get_ray_clusters ()
@@ -41,17 +43,19 @@ def _get_appwrappers(namespace='default'):
41
43
return app_wrappers
42
44
43
45
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
+
44
52
def _ray_cluster_status (name , namespace = 'default' ) -> Optional [RayCluster ]:
45
-
53
+ # FIXME should we check the appwrapper first
46
54
with oc .project (namespace ), oc .timeout (10 * 60 ):
47
55
cluster = oc .selector (f'rayclusters/{ name } ' ).object ()
48
56
49
57
if cluster :
50
58
return _map_to_ray_cluster (cluster )
51
- else :
52
- return None
53
-
54
-
55
59
56
60
57
61
def _get_ray_clusters (namespace = 'default' ) -> List [RayCluster ]:
@@ -65,7 +69,7 @@ def _get_ray_clusters(namespace='default') -> List[RayCluster]:
65
69
return list_of_clusters
66
70
67
71
68
- def _map_to_ray_cluster (cluster ):
72
+ def _map_to_ray_cluster (cluster )-> RayCluster :
69
73
cluster_model = cluster .model
70
74
return RayCluster (
71
75
name = cluster .name (), status = cluster_model .status .state ,
@@ -77,3 +81,11 @@ def _map_to_ray_cluster(cluster):
77
81
0 ].template .spec .containers [0 ].resources .requests .memory ,
78
82
worker_cpu = cluster_model .spec .workerGroupSpecs [0 ].template .spec .containers [0 ].resources .limits .cpu ,
79
83
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