jeff-901 commented on a change in pull request #860: URL: https://github.com/apache/submarine/pull/860#discussion_r777804471
########## File path: submarine-sdk/pysubmarine/submarine/cli/serve/command.py ########## @@ -0,0 +1,124 @@ +""" + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +""" +import json +import time + +import click +from rich.console import Console +from rich.json import JSON as richJSON +from rich.panel import Panel + +from submarine.cli.config.config import loadConfig +from submarine.client.api.serve_client import ServeClient +from submarine.client.api_client import ApiException + +submarineCliConfig = loadConfig() +serveClient = ServeClient( + f"http://{submarineCliConfig.connection.hostname}:{submarineCliConfig.connection.port}" + if submarineCliConfig + else "http://localhost:32080" +) + +POLLING_INTERVAL = 1 # sec +TIMEOUT = 30 # sec + + [email protected]("serve") +def list_serve(): + """List serves""" + click.echo("The command is not supported yet.") # TODO(kuanhsun) + click.echo("list serve!") + + [email protected]("serve") [email protected]("model_name") [email protected]("model_version", type=int) +def get_serve(model_name: str, model_version: int): + """Get serve""" + click.echo("The command is not supported yet.") # TODO(kuanhsun) + click.echo(f"get serve! model name: {model_name}, model version: {model_version}") + + [email protected]("serve") [email protected]("model_name") [email protected]("model_version", type=int) +def create_serve(model_name: str, model_version: int): + """Create serve""" + console = Console() + try: + thread = serveClient.create_serve(model_name, model_version, async_req=True) + timeout = time.time() + TIMEOUT + with console.status( + f"[bold green] Creating Serve with name: {model_name}, version: {model_version}" + ): + while not thread.ready(): + time.sleep(POLLING_INTERVAL) + if time.time() > timeout: + console.print("[bold red] Timeout!") + return + result = thread.get() + click.echo(result) + + except ApiException as err: + if err.body is not None: + errbody = json.loads(err.body) + click.echo(f"[Api Error] {errbody['message']}") + else: + click.echo(f"[Api Error] {err}") + + [email protected]("serve") [email protected]("model_name") [email protected]("model_version", type=int) [email protected]("--wait", is_flag=True, default=False) +def delete_serve(model_name: str, model_version: int, wait: bool): + """Delete serve""" + console = Console() + try: + thread = serveClient.delete_serve(model_name, model_version, async_req=True) + timeout = time.time() + TIMEOUT + with console.status( + f"[bold green] Deleting Serve with name: {model_name}, version: {model_version}" + ): + while not thread.ready(): + time.sleep(POLLING_INTERVAL) + if time.time() > timeout: + console.print("[bold red] Timeout!") + return + + result = thread.get() + click.echo(result) + + if wait: + if result["status"] == "Deleted": + console.print( + f"[bold green] Serve: model name:{model_name}, version: {model_version}" Review comment: Maybe we can console "f"[bold green] Serve Deleted: model name:{model_name}, version: {model_version}"" -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
