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.
[serve] Add basic REST API to dashboard (ray-project#22257)
- Loading branch information
Showing
6 changed files
with
147 additions
and
58 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
Empty file.
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,76 @@ | ||
import aiohttp.web | ||
from aiohttp.web import Request, Response | ||
import json | ||
import logging | ||
from typing import Optional | ||
|
||
import ray.dashboard.utils as dashboard_utils | ||
import ray.dashboard.optional_utils as optional_utils | ||
|
||
from ray import serve | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.INFO) | ||
|
||
routes = optional_utils.ClassMethodRouteTable | ||
|
||
|
||
class ServeHead(dashboard_utils.DashboardHeadModule): | ||
def __init__(self, dashboard_head): | ||
super().__init__(dashboard_head) | ||
|
||
def _get_deployment_by_name(self, name: str) -> Optional[serve.api.Deployment]: | ||
try: | ||
return serve.get_deployment(name) | ||
except KeyError: | ||
return None | ||
|
||
@routes.get("/api/serve/deployments/") | ||
@optional_utils.init_ray_and_catch_exceptions(connect_to_serve=True) | ||
async def get_all_deployments(self, req: Request) -> Response: | ||
dict_response = { | ||
name: str(deployment) | ||
for name, deployment in serve.list_deployments().items() | ||
} | ||
|
||
return Response(text=json.dumps(dict_response), content_type="application/json") | ||
|
||
@routes.get("/api/serve/deployments/{name}") | ||
@optional_utils.init_ray_and_catch_exceptions(connect_to_serve=True) | ||
async def get_single_deployment(self, req: Request) -> Response: | ||
name = req.match_info["name"] | ||
deployment = self._get_deployment_by_name(name) | ||
if deployment is None: | ||
return Response( | ||
text=f"Deployment {name} does not exist.", | ||
status=aiohttp.web.HTTPNotFound.status_code, | ||
) | ||
return Response( | ||
text=json.dumps(str(deployment)), content_type="application/json" | ||
) | ||
|
||
@routes.delete("/api/serve/deployments/") | ||
@optional_utils.init_ray_and_catch_exceptions(connect_to_serve=True) | ||
async def delete_all_deployments(self, req: Request) -> Response: | ||
serve.shutdown() | ||
|
||
@routes.delete("/api/serve/deployments/{name}") | ||
@optional_utils.init_ray_and_catch_exceptions(connect_to_serve=True) | ||
async def delete_single_deployment(self, req: Request) -> Response: | ||
name = req.match_info["name"] | ||
deployment = self._get_deployment_by_name(name) | ||
if deployment is None: | ||
return Response( | ||
text=f"Deployment {name} does not exist.", | ||
status=aiohttp.web.HTTPNotFound.status_code, | ||
) | ||
|
||
deployment.delete() | ||
return Response() | ||
|
||
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
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
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