diff --git a/src/commands/das_peer/__init__.py b/src/commands/das_peer/__init__.py deleted file mode 100644 index d831c61..0000000 --- a/src/commands/das_peer/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .das_peer_module import DasPeerModule - -__all__ = ["DasPeerModule"] diff --git a/src/commands/dbms_adapter/__init__.py b/src/commands/dbms_adapter/__init__.py new file mode 100644 index 0000000..aa97adb --- /dev/null +++ b/src/commands/dbms_adapter/__init__.py @@ -0,0 +1,3 @@ +from .dbms_adapter_module import DbmsAdapterModule + +__all__ = ["DbmsAdapterModule"] diff --git a/src/commands/dbms_adapter/das_peer/__init__.py b/src/commands/dbms_adapter/das_peer/__init__.py new file mode 100644 index 0000000..8fd36f3 --- /dev/null +++ b/src/commands/dbms_adapter/das_peer/__init__.py @@ -0,0 +1,3 @@ +from .das_peer_cli import DasPeerCli + +__all__ = ["DasPeerCli"] diff --git a/src/commands/das_peer/das_peer_cli.py b/src/commands/dbms_adapter/das_peer/das_peer_cli.py similarity index 96% rename from src/commands/das_peer/das_peer_cli.py rename to src/commands/dbms_adapter/das_peer/das_peer_cli.py index 991d28b..9eabb64 100644 --- a/src/commands/das_peer/das_peer_cli.py +++ b/src/commands/dbms_adapter/das_peer/das_peer_cli.py @@ -169,9 +169,9 @@ class DasPeerCli(CommandGroup): short_help = "Manage DAS peer server operations." help = """ - 'das-cli das-peer' commands provide control over the DAS peer server, + 'das-cli dbms-adapter das-peer' commands provide control over the DAS peer server, which acts as the main server in the DAS setup. - Using 'das-cli das-peer', you can start, stop, and restart the DAS peer + Using 'das-cli dbms-adapter das-peer', you can start, stop, and restart the DAS peer server container as needed to manage its operations and connectivity. """ diff --git a/src/commands/das_peer/das_peer_container_manager.py b/src/commands/dbms_adapter/das_peer/das_peer_container_manager.py similarity index 100% rename from src/commands/das_peer/das_peer_container_manager.py rename to src/commands/dbms_adapter/das_peer/das_peer_container_manager.py diff --git a/src/commands/dbms_adapter/dbms_adapter_cli.py b/src/commands/dbms_adapter/dbms_adapter_cli.py new file mode 100644 index 0000000..d137d9b --- /dev/null +++ b/src/commands/dbms_adapter/dbms_adapter_cli.py @@ -0,0 +1,42 @@ +from injector import inject + +from common import CommandGroup +from .das_peer.das_peer_cli import DasPeerCli +from .dbms_peer.dbms_peer_cli import DbmsPeerCli + + +class DbmsAdapterCli(CommandGroup): + name = "dbms-adapter" + + short_help = "Groups DBMS and DAS peer server commands for easier management." + + help = """ +The 'dbms-adapter' command group provides functionalities for managing both the DAS peer server +and DBMS peer client commands. It allows for organizing and executing operations related to +connecting a DBMS client to the DAS peer server. + +This command group includes: +- 'das-peer': Manages DAS peer server operations. +- 'dbms-peer': Manages DBMS peer client operations. + +.SH EXAMPLES + +To view all commands available in the dbms-adapter group: + +$ das-cli dbms-adapter --help + +""" + + @inject + def __init__( + self, + das_peer_cli: DasPeerCli, + dbms_peer: DbmsPeerCli, + ) -> None: + super().__init__() + self.add_commands( + [ + das_peer_cli.group, + dbms_peer.group, + ] + ) diff --git a/src/commands/das_peer/das_peer_module.py b/src/commands/dbms_adapter/dbms_adapter_module.py similarity index 80% rename from src/commands/das_peer/das_peer_module.py rename to src/commands/dbms_adapter/dbms_adapter_module.py index fd66bea..e0cb5c1 100644 --- a/src/commands/das_peer/das_peer_module.py +++ b/src/commands/dbms_adapter/dbms_adapter_module.py @@ -1,17 +1,17 @@ from common import Module -from .das_peer_cli import ( - DasPeerCli, - DasPeerContainerManager, - Settings, -) +from .dbms_adapter_cli import DbmsAdapterCli +from common import Module, Settings + +from .das_peer.das_peer_cli import DasPeerContainerManager +from .dbms_peer.dbms_peer_cli import DbmsPeerContainerManager from commands.db.redis_container_manager import RedisContainerManager from commands.db.mongodb_container_manager import MongodbContainerManager -class DasPeerModule(Module): - _instance = DasPeerCli +class DbmsAdapterModule(Module): + _instance = DbmsAdapterCli def __init__(self) -> None: super().__init__() @@ -31,6 +31,10 @@ def __init__(self) -> None: DasPeerContainerManager, self._das_peer_container_manager_factory, ), + ( + DbmsPeerContainerManager, + self._dbms_peer_container_manager_factory, + ), ] def _mongodb_container_manager_factory(self) -> MongodbContainerManager: @@ -82,3 +86,10 @@ def _das_peer_container_manager_factory(self) -> DasPeerContainerManager: "redis_port": redis_port, }, ) + + def _dbms_peer_container_manager_factory( + self, + ) -> DbmsPeerContainerManager: + container_name = self._settings.get("dbms_peer.container_name") + + return DbmsPeerContainerManager(container_name) diff --git a/src/commands/dbms_adapter/dbms_peer/__init__.py b/src/commands/dbms_adapter/dbms_peer/__init__.py new file mode 100644 index 0000000..0ea7198 --- /dev/null +++ b/src/commands/dbms_adapter/dbms_peer/__init__.py @@ -0,0 +1,3 @@ +from .dbms_peer_cli import DbmsPeerCli + +__all__ = ["DbmsPeerCli"] diff --git a/src/commands/dbms_peer/dbms_peer_cli.py b/src/commands/dbms_adapter/dbms_peer/dbms_peer_cli.py similarity index 94% rename from src/commands/dbms_peer/dbms_peer_cli.py rename to src/commands/dbms_adapter/dbms_peer/dbms_peer_cli.py index f4621a0..9ac24ca 100644 --- a/src/commands/dbms_peer/dbms_peer_cli.py +++ b/src/commands/dbms_adapter/dbms_peer/dbms_peer_cli.py @@ -14,7 +14,9 @@ from .dbms_peer_container_manager import DbmsPeerContainerManager -from commands.das_peer.das_peer_container_manager import DasPeerContainerManager +from commands.dbms_adapter.das_peer.das_peer_container_manager import ( + DasPeerContainerManager, +) class DbmsPeerRun(Command): @@ -23,7 +25,7 @@ class DbmsPeerRun(Command): short_help = "Runs the DBMS peer client to connect with DAS peer server." help = """ -'das-cli dbms-peer run' starts the DBMS peer client, enabling it to connect +'das-cli dbms-adapter dbms-peer run' starts the DBMS peer client, enabling it to connect to the DAS peer server and facilitate data synchronization. This command establishes a link to the DAS peer using the provided client database credentials and settings. @@ -58,7 +60,7 @@ class DbmsPeerRun(Command): To run the DBMS peer client with specified database and context: -$ das-cli dbms-peer run --client-hostname example.com --client-port 5432 \\ +$ das-cli dbms-adapter dbms-peer run --client-hostname example.com --client-port 5432 \\ --client-username user --client-password pass --context /path/to/context.json """ @@ -85,6 +87,8 @@ class DbmsPeerRun(Command): ["--client-password"], help="The password for authenticating to the client database.", type=str, + prompt=True, + hide_input=True, required=True, ), CommandOption( diff --git a/src/commands/dbms_peer/dbms_peer_container_manager.py b/src/commands/dbms_adapter/dbms_peer/dbms_peer_container_manager.py similarity index 100% rename from src/commands/dbms_peer/dbms_peer_container_manager.py rename to src/commands/dbms_adapter/dbms_peer/dbms_peer_container_manager.py diff --git a/src/commands/dbms_peer/__init__.py b/src/commands/dbms_peer/__init__.py deleted file mode 100644 index f8cd71c..0000000 --- a/src/commands/dbms_peer/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .dbms_peer_module import DbmsPeerModule - -__all__ = ["DbmsPeerModule"] diff --git a/src/commands/dbms_peer/dbms_peer_module.py b/src/commands/dbms_peer/dbms_peer_module.py deleted file mode 100644 index bffa3e2..0000000 --- a/src/commands/dbms_peer/dbms_peer_module.py +++ /dev/null @@ -1,87 +0,0 @@ -from common import Module - -from .dbms_peer_cli import ( - DbmsPeerCli, - DbmsPeerContainerManager, - Settings, -) - -from commands.db.redis_container_manager import RedisContainerManager -from commands.db.mongodb_container_manager import MongodbContainerManager - -from commands.das_peer.das_peer_container_manager import DasPeerContainerManager - - -class DbmsPeerModule(Module): - _instance = DbmsPeerCli - - def __init__(self) -> None: - super().__init__() - - self._settings = Settings() - - self._dependecy_injection = [ - ( - RedisContainerManager, - self._redis_container_manager_factory, - ), - ( - MongodbContainerManager, - self._mongodb_container_manager_factory, - ), - ( - DbmsPeerContainerManager, - self._dbms_peer_container_manager_factory, - ), - ( - DasPeerContainerManager, - self._das_peer_container_manager_factory, - ), - ] - - def _mongodb_container_manager_factory(self) -> MongodbContainerManager: - container_name = self._settings.get("mongodb.container_name") - - return MongodbContainerManager(container_name) - - def _redis_container_manager_factory(self) -> RedisContainerManager: - container_name = self._settings.get("redis.container_name") - - return RedisContainerManager(container_name) - - def _das_peer_container_manager_factory( - self, - ) -> DasPeerContainerManager: - container_name = self._settings.get("das_peer.container_name") - mongodb_nodes = self._settings.get("mongodb.nodes") - mongodb_hostname = ( - mongodb_nodes[0]["ip"] if mongodb_nodes else "host.docker.internal" - ) - mongodb_username = self._settings.get("mongodb.username") - mongodb_password = self._settings.get("mongodb.password") - mongodb_port = self._settings.get("mongodb.port") - redis_nodes = self._settings.get("redis.nodes") - redis_hostname = redis_nodes[0]["ip"] if redis_nodes else "host.docker.internal" - redis_port = self._settings.get("redis.port") - - adapter_server_port = self._settings.get("das_peer.port") - - return DasPeerContainerManager( - container_name, - options={ - "das_peer_port": adapter_server_port, - "mongodb_hostname": mongodb_hostname, - "mongodb_port": mongodb_port, - "mongodb_username": mongodb_username, - "mongodb_password": mongodb_password, - "redis_hostname": redis_hostname, - "redis_port": redis_port, - }, - ) - - def _dbms_peer_container_manager_factory( - self, - ) -> DbmsPeerContainerManager: - container_name = self._settings.get("dbms_peer.container_name") - - return DbmsPeerContainerManager(container_name) diff --git a/src/das_cli.py b/src/das_cli.py index 53e10a8..a9fd048 100644 --- a/src/das_cli.py +++ b/src/das_cli.py @@ -10,8 +10,7 @@ from commands.metta import MettaModule from commands.python_library import PythonLibraryModule from commands.release_notes import ReleaseNotesModule -from commands.das_peer import DasPeerModule -from commands.dbms_peer import DbmsPeerModule +from commands.dbms_adapter import DbmsAdapterModule MODULES = [ ConfigModule, @@ -23,8 +22,7 @@ MettaModule, PythonLibraryModule, ReleaseNotesModule, - DasPeerModule, - DbmsPeerModule, + DbmsAdapterModule, ]