Skip to content

Add functions for accessing ray job logs #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/codeflare_sdk/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from typing import List, Optional, Tuple

import openshift as oc
from ray.job_submission import JobSubmissionClient

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

def list_jobs(self) -> List:
"""
This method accesses the head ray node in your cluster and lists the running jobs.
"""
dashboard_route = self.cluster_dashboard_uri(namespace=self.config.namespace)
client = JobSubmissionClient(dashboard_route)
return client.list_jobs()

def job_status(self, job_id: str) -> str:
"""
This method accesses the head ray node in your cluster and returns the job status for the provided job id.
"""
dashboard_route = self.cluster_dashboard_uri(namespace=self.config.namespace)
client = JobSubmissionClient(dashboard_route)
return client.get_job_status(job_id)

def job_logs(self, job_id: str) -> str:
"""
This method accesses the head ray node in your cluster and returns the logs for the provided job id.
"""
dashboard_route = self.cluster_dashboard_uri(namespace=self.config.namespace)
client = JobSubmissionClient(dashboard_route)
return client.get_job_logs(job_id)


def get_current_namespace() -> str:
"""
Expand Down