forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Job Submission][refactor 2/N] introduce job agent (ray-project#28203)
- Loading branch information
1 parent
a31be7c
commit ce70b8b
Showing
6 changed files
with
661 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import aiohttp | ||
from aiohttp.web import Request, Response | ||
import dataclasses | ||
import json | ||
import logging | ||
import traceback | ||
|
||
import ray.dashboard.optional_utils as optional_utils | ||
import ray.dashboard.utils as dashboard_utils | ||
from ray.dashboard.modules.job.common import ( | ||
JobSubmitRequest, | ||
JobSubmitResponse, | ||
) | ||
from ray.dashboard.modules.job.job_manager import JobManager | ||
from ray.dashboard.modules.job.utils import parse_and_validate_request, find_job_by_ids | ||
|
||
|
||
routes = optional_utils.ClassMethodRouteTable | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class JobAgent(dashboard_utils.DashboardAgentModule): | ||
def __init__(self, dashboard_agent): | ||
super().__init__(dashboard_agent) | ||
self._job_manager = None | ||
self._gcs_job_info_stub = None | ||
|
||
@routes.post("/api/job_agent/jobs/") | ||
@optional_utils.init_ray_and_catch_exceptions() | ||
async def submit_job(self, req: Request) -> Response: | ||
result = await parse_and_validate_request(req, JobSubmitRequest) | ||
# Request parsing failed, returned with Response object. | ||
if isinstance(result, Response): | ||
return result | ||
else: | ||
submit_request = result | ||
|
||
request_submission_id = submit_request.submission_id or submit_request.job_id | ||
try: | ||
submission_id = await self.get_job_manager().submit_job( | ||
entrypoint=submit_request.entrypoint, | ||
submission_id=request_submission_id, | ||
runtime_env=submit_request.runtime_env, | ||
metadata=submit_request.metadata, | ||
_driver_on_current_node=False, | ||
) | ||
|
||
resp = JobSubmitResponse(job_id=submission_id, submission_id=submission_id) | ||
except (TypeError, ValueError): | ||
return Response( | ||
text=traceback.format_exc(), | ||
status=aiohttp.web.HTTPBadRequest.status_code, | ||
) | ||
except Exception: | ||
return Response( | ||
text=traceback.format_exc(), | ||
status=aiohttp.web.HTTPInternalServerError.status_code, | ||
) | ||
|
||
return Response( | ||
text=json.dumps(dataclasses.asdict(resp)), | ||
content_type="application/json", | ||
status=aiohttp.web.HTTPOk.status_code, | ||
) | ||
|
||
@routes.get("/api/job_agent/jobs/{job_or_submission_id}") | ||
@optional_utils.init_ray_and_catch_exceptions() | ||
async def get_job_info(self, req: Request) -> Response: | ||
job_or_submission_id = req.match_info["job_or_submission_id"] | ||
|
||
job = await find_job_by_ids( | ||
self._dashboard_agent.gcs_aio_client, | ||
self.get_job_manager(), | ||
job_or_submission_id, | ||
) | ||
if not job: | ||
return Response( | ||
text=f"Job {job_or_submission_id} does not exist", | ||
status=aiohttp.web.HTTPNotFound.status_code, | ||
) | ||
|
||
return Response( | ||
text=json.dumps(job.dict()), | ||
content_type="application/json", | ||
) | ||
|
||
def get_job_manager(self): | ||
if not self._job_manager: | ||
self._job_manager = JobManager(self._dashboard_agent.gcs_aio_client) | ||
return self._job_manager | ||
|
||
async def run(self, server): | ||
pass | ||
|
||
@staticmethod | ||
def is_minimal_module(): | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.