pydantic_models.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. from enum import Enum
  2. from typing import Any, Dict, Optional
  3. from ray._common.pydantic_compat import PYDANTIC_INSTALLED, BaseModel, Field
  4. from ray.dashboard.modules.job.common import JobStatus
  5. from ray.util.annotations import PublicAPI
  6. # Pydantic is not part of the minimal Ray installation.
  7. if PYDANTIC_INSTALLED:
  8. @PublicAPI(stability="beta")
  9. class DriverInfo(BaseModel):
  10. """A class for recording information about the driver related to the job."""
  11. id: str = Field(..., description="The id of the driver")
  12. node_ip_address: str = Field(
  13. ..., description="The IP address of the node the driver is running on."
  14. )
  15. pid: str = Field(
  16. ..., description="The PID of the worker process the driver is using."
  17. )
  18. # TODO(aguo): Add node_id as a field.
  19. @PublicAPI(stability="beta")
  20. class JobType(str, Enum):
  21. """An enumeration for describing the different job types.
  22. NOTE:
  23. This field is still experimental and may change in the future.
  24. """
  25. #: A job that was initiated by the Ray Jobs API.
  26. SUBMISSION = "SUBMISSION"
  27. #: A job that was initiated by a driver script.
  28. DRIVER = "DRIVER"
  29. @PublicAPI(stability="beta")
  30. class JobDetails(BaseModel):
  31. """
  32. Job data with extra details about its driver and its submission.
  33. """
  34. type: JobType = Field(..., description="The type of job.")
  35. job_id: Optional[str] = Field(
  36. None,
  37. description="The job ID. An ID that is created for every job that is "
  38. "launched in Ray. This can be used to fetch data about jobs using Ray "
  39. "Core APIs.",
  40. )
  41. submission_id: Optional[str] = Field(
  42. None,
  43. description="A submission ID is an ID created for every job submitted via"
  44. "the Ray Jobs API. It can "
  45. "be used to fetch data about jobs using the Ray Jobs API.",
  46. )
  47. driver_info: Optional[DriverInfo] = Field(
  48. None,
  49. description="The driver related to this job. For jobs submitted via "
  50. "the Ray Jobs API, "
  51. "it is the last driver launched by that job submission, "
  52. "or None if there is no driver.",
  53. )
  54. # The following fields are copied from JobInfo.
  55. # TODO(aguo): Inherit from JobInfo once it's migrated to pydantic.
  56. status: JobStatus = Field(..., description="The status of the job.")
  57. entrypoint: str = Field(..., description="The entrypoint command for this job.")
  58. message: Optional[str] = Field(
  59. None, description="A message describing the status in more detail."
  60. )
  61. error_type: Optional[str] = Field(
  62. None, description="Internal error or user script error."
  63. )
  64. start_time: Optional[int] = Field(
  65. None,
  66. description="The time when the job was started. A Unix timestamp in ms.",
  67. )
  68. end_time: Optional[int] = Field(
  69. None,
  70. description="The time when the job moved into a terminal state. "
  71. "A Unix timestamp in ms.",
  72. )
  73. metadata: Optional[Dict[str, str]] = Field(
  74. None, description="Arbitrary user-provided metadata for the job."
  75. )
  76. runtime_env: Optional[Dict[str, Any]] = Field(
  77. None, description="The runtime environment for the job."
  78. )
  79. # the node info where the driver running on.
  80. # - driver_agent_http_address: this node's agent http address
  81. # - driver_node_id: this node's id.
  82. driver_agent_http_address: Optional[str] = Field(
  83. None,
  84. description="The HTTP address of the JobAgent on the node the job "
  85. "entrypoint command is running on.",
  86. )
  87. driver_node_id: Optional[str] = Field(
  88. None,
  89. description="The ID of the node the job entrypoint command is running on.",
  90. )
  91. driver_exit_code: Optional[int] = Field(
  92. None,
  93. description="The driver process exit code after the driver executed. "
  94. "Return None if driver doesn't finish executing.",
  95. )
  96. else:
  97. DriverInfo = None
  98. JobType = None
  99. JobDetails = None