Skip to content

Commit 2eb8c1a

Browse files
authoredJan 16, 2023
add inital ray commands (#47)
1 parent 0ff65b0 commit 2eb8c1a

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed
 

‎src/codeflare_sdk/cluster/cluster.py

+29-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from typing import List, Optional, Tuple
2323

2424
import openshift as oc
25+
from ray.job_submission import JobSubmissionClient
2526

2627
from ..utils import pretty_print
2728
from ..utils.generate_yaml import generate_appwrapper
@@ -140,9 +141,11 @@ def cluster_dashboard_uri(self, namespace: str = "default") -> str:
140141
try:
141142
with oc.project(namespace):
142143
route = oc.invoke(
143-
"get", ["route", "-o", "jsonpath='{$.items[0].spec.host}'"]
144+
"get", ["route", "-o", "jsonpath='{$.items[*].spec.host}'"]
144145
)
145-
route = route.out().strip().strip("'")
146+
route = route.out().split(" ")
147+
route = [x for x in route if f"ray-dashboard-{self.config.name}" in x]
148+
route = route[0].strip().strip("'")
146149
return f"http://{route}"
147150
except:
148151
return "Dashboard route not available yet. Did you run cluster.up()?"
@@ -200,6 +203,30 @@ def is_ready(self, print_to_console: bool = True):
200203
pretty_print.print_clusters([cluster])
201204
return status, ready
202205

206+
def list_jobs(self) -> List:
207+
"""
208+
This method accesses the head ray node in your cluster and lists the running jobs.
209+
"""
210+
dashboard_route = self.cluster_dashboard_uri(namespace=self.config.namespace)
211+
client = JobSubmissionClient(dashboard_route)
212+
return client.list_jobs()
213+
214+
def job_status(self, job_id: str) -> str:
215+
"""
216+
This method accesses the head ray node in your cluster and returns the job status for the provided job id.
217+
"""
218+
dashboard_route = self.cluster_dashboard_uri(namespace=self.config.namespace)
219+
client = JobSubmissionClient(dashboard_route)
220+
return client.get_job_status(job_id)
221+
222+
def job_logs(self, job_id: str) -> str:
223+
"""
224+
This method accesses the head ray node in your cluster and returns the logs for the provided job id.
225+
"""
226+
dashboard_route = self.cluster_dashboard_uri(namespace=self.config.namespace)
227+
client = JobSubmissionClient(dashboard_route)
228+
return client.get_job_logs(job_id)
229+
203230

204231
def get_current_namespace() -> str:
205232
"""

0 commit comments

Comments
 (0)