Skip to content

Commit 43e0977

Browse files
mayoorahosler
andauthored
support to launch Aqua services without jupyterlab (#1075)
Co-authored-by: Allen Hosler <[email protected]>
1 parent 277cb8e commit 43e0977

File tree

8 files changed

+1469
-1
lines changed

8 files changed

+1469
-1
lines changed

Diff for: ads/aqua/extension/base_handler.py

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def __init__(
3737
except Exception:
3838
pass
3939

40+
def prepare(self, *args, **kwargs):
41+
"""The base class prepare is not required for Aqua"""
42+
pass
43+
4044
@staticmethod
4145
def serialize(obj: Any):
4246
"""Serialize the object.

Diff for: ads/aqua/server/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2025 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

Diff for: ads/aqua/server/__main__.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2025 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5+
6+
import os
7+
from logging import getLogger
8+
9+
from dotenv import load_dotenv
10+
11+
from ads.aqua.server.app import start_server
12+
13+
logger = getLogger(__name__)
14+
config_location = os.path.join(os.getcwd(), ".env")
15+
if os.path.exists(config_location):
16+
logger.info(f"Loading environment variables from {config_location}")
17+
load_dotenv(dotenv_path=config_location)
18+
logger.info("Environment variables loaded successfully")
19+
else:
20+
logger.warning(
21+
f"{config_location} not found. Consider using `.env` file to setup default environment variables"
22+
)
23+
24+
start_server()

Diff for: ads/aqua/server/app.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (c) 2025 Oracle and/or its affiliates.
4+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5+
6+
import os
7+
from logging import getLogger
8+
9+
import tornado.ioloop
10+
import tornado.web
11+
12+
from ads.aqua.extension import __handlers__
13+
14+
logger = getLogger(__name__)
15+
AQUA_PORT = "AQUA_PORT"
16+
AQUA_HOST = "AQUA_HOST"
17+
AQUA_PROCESS_COUNT = "AQUA_PROCESS_COUNT"
18+
AQUA_CORS_ENABLE = "AQUA_CORS_ENABLE"
19+
20+
URL_PATTERN = r"/aqua/"
21+
22+
23+
def prepare(self):
24+
self.set_header("Access-Control-Allow-Origin", "*")
25+
26+
27+
def make_app():
28+
# Patch the prepare method to allow CORS request
29+
if os.environ.get(AQUA_CORS_ENABLE, "0") == "1":
30+
for _, handler in __handlers__:
31+
handler.prepare = prepare
32+
handlers = [(URL_PATTERN + url, handler) for url, handler in __handlers__]
33+
# logger.debug(handlers)
34+
return tornado.web.Application(handlers)
35+
36+
37+
def start_server():
38+
app = make_app()
39+
server = tornado.httpserver.HTTPServer(app)
40+
port = int(os.environ.get(AQUA_PORT, 8080))
41+
host = os.environ.get(AQUA_HOST, "0.0.0.0")
42+
processes = int(os.environ.get(AQUA_PROCESS_COUNT, 0))
43+
server.bind(port=port, address=host)
44+
server.start(processes)
45+
logger.info(f"Starting the server from directory: {os.getcwd()}")
46+
logger.info(f"Aqua API server running on http://{host}:{port}")
47+
tornado.ioloop.IOLoop.current().start()

0 commit comments

Comments
 (0)