2022-03-18 09:12:09 -07:00
|
|
|
import json
|
2022-02-24 08:00:26 -08:00
|
|
|
import logging
|
|
|
|
|
2022-06-14 19:01:51 -07:00
|
|
|
from aiohttp.web import Request, Response
|
|
|
|
|
2022-02-24 08:00:26 -08:00
|
|
|
import ray.dashboard.optional_utils as optional_utils
|
2022-06-14 19:01:51 -07:00
|
|
|
import ray.dashboard.utils as dashboard_utils
|
2022-02-24 08:00:26 -08:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
logger.setLevel(logging.INFO)
|
|
|
|
|
|
|
|
routes = optional_utils.ClassMethodRouteTable
|
|
|
|
|
|
|
|
|
2022-04-18 10:25:21 -07:00
|
|
|
# NOTE (shrekris-anyscale): This class uses delayed imports for all
|
2022-07-06 20:30:33 +00:00
|
|
|
# Ray Serve-related modules. That way, users can use the Ray dashboard for
|
2022-04-18 10:25:21 -07:00
|
|
|
# non-Serve purposes without downloading Serve dependencies.
|
2022-07-06 20:30:33 +00:00
|
|
|
class ServeHead(dashboard_utils.DashboardHeadModule):
|
|
|
|
def __init__(self, dashboard_head):
|
|
|
|
super().__init__(dashboard_head)
|
2022-02-24 08:00:26 -08:00
|
|
|
|
|
|
|
@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-06-14 19:01:51 -07:00
|
|
|
from ray.serve.context import get_global_client
|
|
|
|
|
|
|
|
client = get_global_client()
|
2022-03-21 22:14:41 -07:00
|
|
|
|
2022-02-24 08:00:26 -08:00
|
|
|
return Response(
|
2022-06-14 19:01:51 -07:00
|
|
|
text=json.dumps(client.get_app_config()),
|
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:
|
2022-05-24 11:07:41 -07:00
|
|
|
from ray.serve.context import get_global_client
|
|
|
|
from ray.serve.schema import serve_status_to_schema
|
2022-03-21 22:14:41 -07:00
|
|
|
|
2022-06-13 10:31:28 -07:00
|
|
|
client = get_global_client()
|
2022-05-24 11:07:41 -07:00
|
|
|
|
|
|
|
serve_status_schema = serve_status_to_schema(client.get_serve_status())
|
2022-02-25 06:41:07 -08:00
|
|
|
return Response(
|
2022-05-24 11:07:41 -07:00
|
|
|
text=serve_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-03-21 22:14:41 -07:00
|
|
|
from ray import serve
|
|
|
|
|
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-06-02 11:06:53 -07:00
|
|
|
from ray.serve.context import get_global_client
|
|
|
|
from ray.serve.schema import ServeApplicationSchema
|
2022-03-21 22:14:41 -07:00
|
|
|
|
2022-06-02 11:06:53 -07:00
|
|
|
config = ServeApplicationSchema.parse_obj(await req.json())
|
2022-06-21 11:06:45 -07:00
|
|
|
get_global_client().deploy_app(config)
|
2022-02-24 08:00:26 -08:00
|
|
|
|
|
|
|
return Response()
|
|
|
|
|
|
|
|
async def run(self, server):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_minimal_module():
|
|
|
|
return False
|