class_docstr: State API Client issues REST GET requests to the server for resource states.
class_docstr_tok: ["State","API","Client","issues","REST","GET","requests","to","the","server","for","resource","states","."]
docstr: Get resources states by id
  
  Args:
      resource_name: Resource names, i.e. 'workers', 'actors', 'nodes',
          'placement_groups', 'tasks', 'objects'.
          'jobs' and 'runtime-envs' are not supported yet.
      id: ID for the resource, i.e. 'node_id' for nodes.
      options: Get options. See `GetApiOptions` for details.
      _explain: Print the API information such as API
          latency or failed query information.
  
  Returns:
      None if not found, and if found:
      - ActorState for actors
      - PlacementGroupState for placement groups
      - NodeState for nodes
      - WorkerState for workers
      - TaskState for tasks
      - JobState for jobs
  
      Empty list for objects if not found, or list of ObjectState for objects
  
  Raises:
      This doesn't catch any exceptions raised when the underlying request
      call raises exceptions. For example, it could raise `requests.Timeout`
      when timeout occurs.
  
      ValueError:
          if the resource could not be GET by id, i.e. jobs and runtime-envs.
docstr_tok: ["Get","resources","states","by","id","Args",":","resource_name",":","Resource","names",",","i.e",".","'workers","'",",","'actors","'",",","'nodes","'",",","'placement_groups","'",",","'tasks","'",",","'objects","'",".","'jobs","'","and","'runtime-envs","'","are","not","supported","yet",".","id",":","ID","for","the","resource",",","i.e",".","'node_id","'","for","nodes",".","options",":","Get","options",".","See","`","GetApiOptions","`","for","details",".","_explain",":","Print","the","API","information","such","as","API","latency","or","failed","query","information",".","Returns",":","None","if","not","found",",","and","if","found",":","-","ActorState","for","actors","-","PlacementGroupState","for","placement","groups","-","NodeState","for","nodes","-","WorkerState","for","workers","-","TaskState","for","tasks","-","JobState","for","jobs","Empty","list","for","objects","if","not","found",",","or","list","of","ObjectState","for","objects","Raises",":","This","does","n't","catch","any","exceptions","raised","when","the","underlying","request","call","raises","exceptions",".","For","example",",","it","could","raise","`","requests.Timeout","`","when","timeout","occurs",".","ValueError",":","if","the","resource","could","not","be","GET","by","id",",","i.e",".","jobs","and","runtime-envs","."]
code: def get(
      self,
      resource: StateResource,
      id: str,
      options: Optional[GetApiOptions],
      _explain: bool = False,
  ) -> Optional[
      Union[
          ActorState,
          PlacementGroupState,
          NodeState,
          WorkerState,
          TaskState,
          List[ObjectState],
          JobState,
      ]
  ]:
      """Get resources states by id
  
      Args:
          resource_name: Resource names, i.e. 'workers', 'actors', 'nodes',
              'placement_groups', 'tasks', 'objects'.
              'jobs' and 'runtime-envs' are not supported yet.
          id: ID for the resource, i.e. 'node_id' for nodes.
          options: Get options. See `GetApiOptions` for details.
          _explain: Print the API information such as API
              latency or failed query information.
  
      Returns:
          None if not found, and if found:
          - ActorState for actors
          - PlacementGroupState for placement groups
          - NodeState for nodes
          - WorkerState for workers
          - TaskState for tasks
          - JobState for jobs
  
          Empty list for objects if not found, or list of ObjectState for objects
  
      Raises:
          This doesn't catch any exceptions raised when the underlying request
          call raises exceptions. For example, it could raise `requests.Timeout`
          when timeout occurs.
  
          ValueError:
              if the resource could not be GET by id, i.e. jobs and runtime-envs.
  
      """
      # TODO(rickyyx): Make GET not using filters on list operation
      params = self._make_param(options)
  
      RESOURCE_ID_KEY_NAME = {
          StateResource.NODES: "node_id",
          StateResource.ACTORS: "actor_id",
          StateResource.PLACEMENT_GROUPS: "placement_group_id",
          StateResource.WORKERS: "worker_id",
          StateResource.TASKS: "task_id",
          StateResource.OBJECTS: "object_id",
          StateResource.JOBS: "submission_id",
      }
      if resource not in RESOURCE_ID_KEY_NAME:
          raise ValueError(f"Can't get {resource.name} by id.")
  
      params["filter_keys"] = [RESOURCE_ID_KEY_NAME[resource]]
      params["filter_predicates"] = ["="]
      params["filter_values"] = [id]
      params["detail"] = True
      endpoint = f"/api/v0/{resource.value}"
  
      list_api_response = self._make_http_get_request(
          endpoint=endpoint,
          params=params,
          timeout=options.timeout,
          _explain=_explain,
      )
      result = list_api_response["result"]
  
      # Empty result
      if len(result) == 0:
          return None
  
      result = [dict_to_state(d, resource) for d in result]
      if resource == StateResource.OBJECTS:
          # NOTE(rickyyx):
          # There might be multiple object entries for a single object id
          # because a single object could be referenced at different places
          # e.g. pinned as local variable, used as parameter
          return result
  
      if resource == StateResource.TASKS:
          # There might be multiple task attempts given a task id due to
          # task retries.
          if len(result) == 1:
              return result[0]
          return result
  
      # For the rest of the resources, there should only be a single entry
      # for a particular id.
      assert len(result) == 1
      return result[0]
  
imports: import logging
  import threading
  import urllib
  import warnings
  from contextlib import contextmanager
  from dataclasses import fields
  from typing import Any, Dict, Generator, List, Optional, Tuple, Union
  import requests
  from ray.dashboard.modules.dashboard_sdk import SubmissionClient
  from ray.dashboard.utils import get_address_for_submission_client, ray_address_to_api_server_url
  from ray.util.annotations import DeveloperAPI
  from ray.util.state.common import DEFAULT_LIMIT, DEFAULT_RPC_TIMEOUT, ActorState, ClusterEventState, GetApiOptions, GetLogOptions, JobState, ListApiOptions, NodeState, ObjectState, PlacementGroupState, PredicateType, RuntimeEnvState, StateResource, SummaryApiOptions, SummaryResource, SupportedFilterType, TaskState, WorkerState, dict_to_state
  from ray.util.state.exception import RayStateApiException, ServerUnavailable
label_desc: Use image node_id 4 for calling the StateApiClient obj's underlying member method code with example usage: obj.get(resource, id, options, _explain) and returns: result, None, result, result, result