Skip to content

Commit

Permalink
fix: Forward path mapping rules to backend process (#11)
Browse files Browse the repository at this point in the history
When running the adaptor in daemon mode, pass the path mapping rules to the FrontendRunner so that it can forward them to the backend process.

---------

Signed-off-by: Alex Gerveshi <[email protected]>
  • Loading branch information
agerveshi authored Oct 10, 2023
1 parent 39d557c commit 60a7d45
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ __pycache__/
/build
/dist
_version.py
.vscode
8 changes: 7 additions & 1 deletion src/openjd/adaptor_runtime/_background/frontend_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ def __init__(
signal.signal(signal.SIGINT, self._sigint_handler)
signal.signal(signal.SIGTERM, self._sigint_handler)

def init(self, adaptor_module: ModuleType, init_data: dict = {}) -> None:
def init(
self, adaptor_module: ModuleType, init_data: dict = {}, path_mapping_data: dict = {}
) -> None:
"""
Creates the backend process then sends a heartbeat request to verify that it has started
successfully.
Args:
adaptor_module (ModuleType): The module of the adaptor running the runtime.
init_data (dict): Data to pass to the adaptor during initialization.
path_mapping_data (dict): Path mapping rules to make available to the adaptor while it's running.
"""
if adaptor_module.__package__ is None:
raise Exception(f"Adaptor module is not a package: {adaptor_module}")
Expand All @@ -85,6 +89,8 @@ def init(self, adaptor_module: ModuleType, init_data: dict = {}) -> None:
self._connection_file_path,
"--init-data",
json.dumps(init_data),
"--path-mapping-rules",
json.dumps(path_mapping_data),
]
try:
process = subprocess.Popen(
Expand Down
5 changes: 3 additions & 2 deletions src/openjd/adaptor_runtime/_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def start(self) -> None:
f"Adaptor module is not loaded: {self.adaptor_class.__module__}"
)

frontend.init(adaptor_module, init_data)
frontend.init(adaptor_module, init_data, path_mapping_data)
frontend.start()
elif subcommand == "run":
frontend.run(run_data)
Expand Down Expand Up @@ -241,6 +241,7 @@ def _build_argparser(self) -> ArgumentParser:
path_mapping_rules = ArgumentParser(add_help=False)
path_mapping_rules.add_argument(
"--path-mapping-rules",
default="",
required=False,
type=_load_data,
help=_CLI_HELP_TEXT["path_mapping_rules"],
Expand All @@ -266,7 +267,7 @@ def _build_argparser(self) -> ArgumentParser:
)

# "Hidden" command that actually runs the adaptor runtime in background mode
bg_subparser.add_parser("_serve", parents=[init_data, connection_file])
bg_subparser.add_parser("_serve", parents=[init_data, path_mapping_rules, connection_file])

bg_subparser.add_parser("start", parents=[init_data, path_mapping_rules, connection_file])
bg_subparser.add_parser("run", parents=[run_data, connection_file])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

from __future__ import annotations

import http.client as http_client
import json
import re
Expand Down Expand Up @@ -80,10 +82,11 @@ def test_initializes_backend_process(
adaptor_module.__package__ = "package"
conn_file_path = "/path"
init_data = {"init": "data"}
path_mapping_data: dict = {}
runner = FrontendRunner(conn_file_path)

# WHEN
runner.init(adaptor_module, init_data)
runner.init(adaptor_module, init_data, path_mapping_data)

# THEN
assert caplog.messages == [
Expand All @@ -104,6 +107,8 @@ def test_initializes_backend_process(
conn_file_path,
"--init-data",
json.dumps(init_data),
"--path-mapping-rules",
json.dumps(path_mapping_data),
],
shell=False,
close_fds=True,
Expand Down
2 changes: 1 addition & 1 deletion test/openjd/adaptor_runtime/unit/test_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def test_runs_background_start(

# THEN
_parse_args_mock.assert_called_once()
mock_magic_init.assert_called_once_with(mock_adaptor_module, {})
mock_magic_init.assert_called_once_with(mock_adaptor_module, {}, {})
mock_magic_start.assert_called_once_with(conn_file)
mock_start.assert_called_once_with()

Expand Down

0 comments on commit 60a7d45

Please sign in to comment.