Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
fix: Remove unnecessary protocol arg in the "app" command (#156)
Browse files Browse the repository at this point in the history
* The "preopen" behavior is implemented by the manager and the client
  should not specify it.
* "tcppproxy" and "httpproxy" are the only API endpoints available.
* It is safe to assume the default protocol is "tcp" because internally
  both "tcp" and "http" proxies have the same implementation that
  transparently sends/recevies the TCP stream packets via the tunnel.

Backported-From: master
Backported-To: 20.03
  • Loading branch information
achimnol committed Feb 8, 2021
1 parent 99b349f commit d3ed294
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions changes/156.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove the legacy `-p/--protocol` option from the `app` command sicne it now works as the TCP protocol always
27 changes: 14 additions & 13 deletions src/ai/backend/client/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class WSProxy:
__slots__ = (
'api_session', 'session_name',
'app_name', 'protocol',
'app_name',
'args', 'envs',
'reader', 'writer',
)
Expand All @@ -33,7 +33,6 @@ def __init__(
api_session: AsyncSession,
session_name: str,
app_name: str,
protocol: str,
args: MutableMapping[str, Union[None, str, List[str]]],
envs: MutableMapping[str, str],
reader: asyncio.StreamReader,
Expand All @@ -42,15 +41,14 @@ def __init__(
self.api_session = api_session
self.session_name = session_name
self.app_name = app_name
self.protocol = protocol
self.args = args
self.envs = envs
self.reader = reader
self.writer = writer

async def run(self) -> None:
prefix = get_naming(self.api_session.api_version, 'path')
path = f"/stream/{prefix}/{self.session_name}/{self.protocol}proxy"
path = f"/stream/{prefix}/{self.session_name}/tcpproxy"
params = {'app': self.app_name}

if len(self.args.keys()) > 0:
Expand Down Expand Up @@ -145,7 +143,7 @@ def __init__(
session_name: str,
app_name: str,
*,
protocol: str = 'http',
protocol: str = 'tcp',
args: Sequence[str] = None,
envs: Sequence[str] = None,
) -> None:
Expand Down Expand Up @@ -192,10 +190,15 @@ async def handle_connection(
writer: asyncio.StreamWriter,
) -> None:
assert self.api_session is not None
p = WSProxy(self.api_session, self.session_name,
self.app_name, self.protocol,
self.args, self.envs,
reader, writer)
p = WSProxy(
self.api_session,
self.session_name,
self.app_name,
self.args,
self.envs,
reader,
writer,
)
try:
await p.run()
except asyncio.CancelledError:
Expand Down Expand Up @@ -258,15 +261,13 @@ async def __aexit__(self, *exc_info) -> None:
@main.command()
@click.argument('session_name', type=str, metavar='NAME')
@click.argument('app', type=str)
@click.option('-p', '--protocol', type=click.Choice(['http', 'tcp', 'preopen']), default='http',
help='The application-level protocol to use.')
@click.option('-b', '--bind', type=str, default='127.0.0.1:8080', metavar='[HOST:]PORT',
help='The IP/host address and the port number to bind this proxy.')
@click.option('--arg', type=str, multiple=True, metavar='"--option <value>"',
help='Add additional argument when starting service.')
@click.option('-e', '--env', type=str, multiple=True, metavar='"ENVNAME=envvalue"',
help='Add additional environment variable when starting service.')
def app(session_name, app, protocol, bind, arg, env):
def app(session_name, app, bind, arg, env):
"""
Run a local proxy to a service provided by Backend.AI compute sessions.
Expand All @@ -287,7 +288,7 @@ def app(session_name, app, protocol, bind, arg, env):
proxy_ctx = ProxyRunnerContext(
host, port,
session_name, app,
protocol=protocol,
protocol='tcp',
args=arg,
envs=env,
)
Expand Down

0 comments on commit d3ed294

Please sign in to comment.