mirror of
https://github.com/wassname/ray.git
synced 2026-07-18 12:40:56 +08:00
Add job table to state API (#5076)
This commit is contained in:
committed by
Robert Nishihara
parent
53d5a8a45f
commit
c5253cc300
@@ -385,6 +385,76 @@ class GlobalState(object):
|
||||
|
||||
return _parse_client_table(self.redis_client)
|
||||
|
||||
def _job_table(self, job_id):
|
||||
"""Fetch and parse the job table information for a single job ID.
|
||||
|
||||
Args:
|
||||
job_id: A job ID or hex string to get information about.
|
||||
|
||||
Returns:
|
||||
A dictionary with information about the job ID in question.
|
||||
"""
|
||||
# Allow the argument to be either a JobID or a hex string.
|
||||
if not isinstance(job_id, ray.JobID):
|
||||
assert isinstance(job_id, str)
|
||||
job_id = ray.JobID(hex_to_binary(job_id))
|
||||
|
||||
# Return information about a single job ID.
|
||||
message = self.redis_client.execute_command(
|
||||
"RAY.TABLE_LOOKUP", gcs_utils.TablePrefix.Value("JOB"), "",
|
||||
job_id.binary())
|
||||
|
||||
if message is None:
|
||||
return {}
|
||||
|
||||
gcs_entry = gcs_utils.GcsEntry.FromString(message)
|
||||
|
||||
assert len(gcs_entry.entries) > 0
|
||||
|
||||
job_info = {}
|
||||
|
||||
for i in range(len(gcs_entry.entries)):
|
||||
entry = gcs_utils.JobTableData.FromString(gcs_entry.entries[i])
|
||||
assert entry.job_id == job_id.binary()
|
||||
job_info["JobID"] = job_id.hex()
|
||||
job_info["NodeManagerAddress"] = entry.node_manager_address
|
||||
job_info["DriverPid"] = entry.driver_pid
|
||||
if entry.is_dead:
|
||||
job_info["StopTime"] = entry.timestamp
|
||||
else:
|
||||
job_info["StartTime"] = entry.timestamp
|
||||
|
||||
return job_info
|
||||
|
||||
def job_table(self):
|
||||
"""Fetch and parse the Redis job table.
|
||||
|
||||
Returns:
|
||||
Information about the Ray jobs in the cluster,
|
||||
namely a list of dicts with keys:
|
||||
- "JobID" (identifier for the job),
|
||||
- "NodeManagerAddress" (IP address of the driver for this job),
|
||||
- "DriverPid" (process ID of the driver for this job),
|
||||
- "StartTime" (UNIX timestamp of the start time of this job),
|
||||
- "StopTime" (UNIX timestamp of the stop time of this job, if any)
|
||||
"""
|
||||
self._check_connected()
|
||||
|
||||
job_keys = self.redis_client.keys(gcs_utils.TablePrefix_JOB_string +
|
||||
"*")
|
||||
|
||||
job_ids_binary = {
|
||||
key[len(gcs_utils.TablePrefix_JOB_string):]
|
||||
for key in job_keys
|
||||
}
|
||||
|
||||
results = []
|
||||
|
||||
for job_id_binary in job_ids_binary:
|
||||
results.append(self._job_table(binary_to_hex(job_id_binary)))
|
||||
|
||||
return results
|
||||
|
||||
def _profile_table(self, batch_id):
|
||||
"""Get the profile events for a given batch of profile events.
|
||||
|
||||
@@ -982,6 +1052,20 @@ state = GlobalState()
|
||||
global_state = DeprecatedGlobalState()
|
||||
|
||||
|
||||
def jobs():
|
||||
"""Get a list of the jobs in the cluster.
|
||||
|
||||
Returns:
|
||||
Information from the job table, namely a list of dicts with keys:
|
||||
- "JobID" (identifier for the job),
|
||||
- "NodeManagerAddress" (IP address of the driver for this job),
|
||||
- "DriverPid" (process ID of the driver for this job),
|
||||
- "StartTime" (UNIX timestamp of the start time of this job),
|
||||
- "StopTime" (UNIX timestamp of the stop time of this job, if any)
|
||||
"""
|
||||
return state.job_table()
|
||||
|
||||
|
||||
def nodes():
|
||||
"""Get a list of the nodes in the cluster.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user