1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-07 03:22:57 +03:00

feat(cmapi, mcs): MCOL-5525 Single start command for Single Node.

* feat(mcs): new mcs bootstrap-single-node command added into tools pane
This commit is contained in:
mariadb-AlanMologorsky
2025-04-08 15:44:57 +03:00
committed by Alan Mologorsky
parent 727627a012
commit 7c27d803ba
3 changed files with 43 additions and 3 deletions

View File

@@ -47,6 +47,9 @@ app.command(
'cspasswd', rich_help_panel='Tools commands', 'cspasswd', rich_help_panel='Tools commands',
short_help='Encrypt a Columnstore plaintext password.' short_help='Encrypt a Columnstore plaintext password.'
)(tools_commands.cspasswd) )(tools_commands.cspasswd)
app.command(
'bootstrap-single-node', rich_help_panel='Tools commands',
)(tools_commands.bootstrap_single_node)
@app.command( @app.command(

View File

@@ -14,6 +14,7 @@ from typing_extensions import Annotated
from cmapi_server.constants import ( from cmapi_server.constants import (
CMAPI_CONF_PATH, DEFAULT_MCS_CONF_PATH, REQUEST_TIMEOUT CMAPI_CONF_PATH, DEFAULT_MCS_CONF_PATH, REQUEST_TIMEOUT
) )
from cmapi_server.controllers.api_clients import ClusterControllerClient
from cmapi_server.exceptions import CMAPIBasicError from cmapi_server.exceptions import CMAPIBasicError
from cmapi_server.helpers import ( from cmapi_server.helpers import (
get_config_parser, get_current_key, get_version, build_url get_config_parser, get_current_key, get_version, build_url
@@ -21,7 +22,6 @@ from cmapi_server.helpers import (
from cmapi_server.managers.transaction import TransactionManager from cmapi_server.managers.transaction import TransactionManager
from mcs_cluster_tool.decorators import handle_output from mcs_cluster_tool.decorators import handle_output
from mcs_node_control.models.node_config import NodeConfig from mcs_node_control.models.node_config import NodeConfig
from cmapi_server.controllers.api_clients import ClusterControllerClient
logger = logging.getLogger('mcs_cli') logger = logging.getLogger('mcs_cli')

View File

@@ -1,15 +1,19 @@
import logging import logging
import os import os
import secrets
from datetime import datetime, timedelta
import typer import typer
from typing_extensions import Annotated from typing_extensions import Annotated
from cmapi_server.constants import ( from cmapi_server.constants import (
MCS_DATA_PATH, MCS_SECRETS_FILENAME MCS_DATA_PATH, MCS_SECRETS_FILENAME, REQUEST_TIMEOUT, TRANSACTION_TIMEOUT,
) )
from cmapi_server.controllers.api_clients import ClusterControllerClient
from cmapi_server.exceptions import CEJError from cmapi_server.exceptions import CEJError
from cmapi_server.handlers.cej import CEJPasswordHandler from cmapi_server.handlers.cej import CEJPasswordHandler
from cmapi_server.managers.transaction import TransactionManager
from mcs_cluster_tool.decorators import handle_output from mcs_cluster_tool.decorators import handle_output
@@ -112,4 +116,37 @@ def cspasswd(
typer.echo(cej_error.message, color='red') typer.echo(cej_error.message, color='red')
raise typer.Exit(code=1) raise typer.Exit(code=1)
typer.echo(f'Encoded password: {encoded_password}', color='green') typer.echo(f'Encoded password: {encoded_password}', color='green')
raise typer.Exit(code=0) raise typer.Exit(code=0)
@handle_output
def bootstrap_single_node(
key: Annotated[
str,
typer.Option(
'--api-key',
help='API key to set.',
)
] = ''
):
"""Bootstrap a single node (localhost) Columnstore instance."""
node = 'localhost'
client = ClusterControllerClient(request_timeout=REQUEST_TIMEOUT)
if not key:
# Generate API key if not provided
key = secrets.token_urlsafe(32)
# handle_output decorator will catch, show and log errors
api_key_set_resp = client.set_api_key(key)
# if operation takes minutes, then it is better to raise by timeout
with TransactionManager(
timeout=TRANSACTION_TIMEOUT, handle_signals=True,
extra_nodes=[node]
):
add_node_resp = client.add_node({'node': node})
result = {
'timestamp': str(datetime.now()),
'set_api_key_resp': api_key_set_resp,
'add_node_resp': add_node_resp,
}
return result