2022-02-24 08:00:26 -08:00
|
|
|
from aiohttp.web import Request, Response
|
2022-03-18 09:12:09 -07:00
|
|
|
import json
|
2022-02-24 08:00:26 -08:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import ray.dashboard.utils as dashboard_utils
|
|
|
|
import ray.dashboard.optional_utils as optional_utils
|
|
|
|
|
|
|
|
from ray import serve
|
2022-03-18 09:12:09 -07:00
|
|
|
from ray.serve.api import (
|
|
|
|
Application,
|
|
|
|
get_deployment_statuses,
|
|
|
|
internal_get_global_client,
|
2022-02-25 06:41:07 -08:00
|
|
|
serve_application_status_to_schema,
|
2022-02-24 08:00:26 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
@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:
|
2022-03-18 09:12:09 -07:00
|
|
|
app = Application(list(serve.list_deployments().values()))
|
2022-02-24 08:00:26 -08:00
|
|
|
return Response(
|
2022-03-18 09:12:09 -07:00
|
|
|
text=json.dumps(app.to_dict()),
|
2022-02-25 06:41:07 -08:00
|
|
|
content_type="application/json",
|
|
|
|
)
|
|
|
|
|
|
|
|
@routes.get("/api/serve/deployments/status")
|
|
|
|
@optional_utils.init_ray_and_catch_exceptions(connect_to_serve=True)
|
|
|
|
async def get_all_deployment_statuses(self, req: Request) -> Response:
|
|
|
|
serve_application_status_schema = serve_application_status_to_schema(
|
|
|
|
get_deployment_statuses()
|
|
|
|
)
|
|
|
|
return Response(
|
2022-02-28 18:45:46 -08:00
|
|
|
text=serve_application_status_schema.json(),
|
2022-02-24 08:00:26 -08:00
|
|
|
content_type="application/json",
|
|
|
|
)
|
|
|
|
|
|
|
|
@routes.delete("/api/serve/deployments/")
|
|
|
|
@optional_utils.init_ray_and_catch_exceptions(connect_to_serve=True)
|
2022-02-25 06:41:07 -08:00
|
|
|
async def delete_serve_application(self, req: Request) -> Response:
|
2022-02-24 08:00:26 -08:00
|
|
|
serve.shutdown()
|
|
|
|
return Response()
|
|
|
|
|
|
|
|
@routes.put("/api/serve/deployments/")
|
|
|
|
@optional_utils.init_ray_and_catch_exceptions(connect_to_serve=True)
|
|
|
|
async def put_all_deployments(self, req: Request) -> Response:
|
2022-03-10 08:28:29 -08:00
|
|
|
app = Application.from_dict(await req.json())
|
2022-03-18 09:12:09 -07:00
|
|
|
serve.run(app, _blocking=False)
|
2022-02-24 08:00:26 -08:00
|
|
|
|
|
|
|
new_names = set()
|
2022-03-18 09:12:09 -07:00
|
|
|
for deployment in app.deployments.values():
|
2022-02-24 08:00:26 -08:00
|
|
|
new_names.add(deployment.name)
|
|
|
|
|
|
|
|
all_deployments = serve.list_deployments()
|
|
|
|
all_names = set(all_deployments.keys())
|
|
|
|
names_to_delete = all_names.difference(new_names)
|
2022-03-18 09:12:09 -07:00
|
|
|
internal_get_global_client().delete_deployments(names_to_delete)
|
2022-02-24 08:00:26 -08:00
|
|
|
|
|
|
|
return Response()
|
|
|
|
|
|
|
|
async def run(self, server):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_minimal_module():
|
|
|
|
return False
|