1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

feat(cmapi): MCOL-5133: Stage2 stand alone cli tool.

[fix] client class methods
[fix] Transaction management at endpoint handling level
[fix] add_node and set_mode methods to use TransactionManager
This commit is contained in:
mariadb-AlanMologorsky
2025-01-24 15:54:59 +03:00
committed by Leonid Fedorov
parent a60a5288d8
commit c40e4ba00d
4 changed files with 58 additions and 100 deletions

View File

@ -21,43 +21,45 @@ class ClusterControllerClient:
self.request_timeout = request_timeout
def start_cluster(
self, data: Optional[Dict[str, Any]] = None
self, extra: Dict[str, Any] = dict()
) -> Union[Dict[str, Any], Dict[str, str]]:
"""Start the cluster.
:return: The response from the API.
"""
return self._request('PUT', 'start', data)
return self._request('PUT', 'start', extra)
def shutdown_cluster(
self, data: Optional[Dict[str, Any]] = None
self, extra: Dict[str, Any] = dict()
) -> Union[Dict[str, Any], Dict[str, str]]:
"""Shutdown the cluster.
:return: The response from the API.
"""
return self._request('PUT', 'shutdown', data)
return self._request('PUT', 'shutdown', extra)
def set_mode(self, mode: str) -> Union[Dict[str, Any], Dict[str, str]]:
def set_mode(
self, mode: str, extra: Dict[str, Any] = dict()
) -> Union[Dict[str, Any], Dict[str, str]]:
"""Set the cluster mode.
:param mode: The mode to set.
:return: The response from the API.
"""
return self._request('PUT', 'mode-set', {'mode': mode})
return self._request('PUT', 'mode-set', {'mode': mode, **extra})
def add_node(
self, node_info: Dict[str, Any]
self, node_info: Dict[str, Any], extra: Dict[str, Any] = dict()
) -> Union[Dict[str, Any], Dict[str, str]]:
"""Add a node to the cluster.
:param node_info: Information about the node to add.
:return: The response from the API.
"""
return self._request('PUT', 'node', node_info)
return self._request('PUT', 'node', {**node_info, **extra})
def remove_node(
self, node_id: str
self, node_id: str, extra: Dict[str, Any] = dict()
) -> Union[Dict[str, Any], Dict[str, str]]:
"""Remove a node from the cluster.

View File

@ -25,8 +25,9 @@ from cmapi_server.helpers import (
system_ready, save_cmapi_conf_file, dequote, in_maintenance_state,
)
from cmapi_server.logging_management import change_loggers_level
from cmapi_server.managers.process import MCSProcessManager
from cmapi_server.managers.application import AppManager
from cmapi_server.managers.process import MCSProcessManager
from cmapi_server.managers.transaction import TransactionManager
from cmapi_server.node_manipulation import is_master, switch_node_maintenance
from mcs_node_control.models.dbrm import set_cluster_mode
from mcs_node_control.models.node_config import NodeConfig
@ -800,7 +801,11 @@ class ClusterController:
in_transaction = request_body.get('in_transaction', False)
try:
response = ClusterHandler.start(config, in_transaction)
if not in_transaction:
with TransactionManager():
response = ClusterHandler.start(config)
else:
response = ClusterHandler.start(config)
except CMAPIBasicError as err:
raise_422_error(module_logger, func_name, err.message)
@ -821,7 +826,11 @@ class ClusterController:
in_transaction = request_body.get('in_transaction', False)
try:
response = ClusterHandler.shutdown(config, in_transaction)
if not in_transaction:
with TransactionManager():
response = ClusterHandler.shutdown(config)
else:
response = ClusterHandler.shutdown(config)
except CMAPIBasicError as err:
raise_422_error(module_logger, func_name, err.message)
@ -840,9 +849,14 @@ class ClusterController:
request_body = request.json
mode = request_body.get('mode', 'readonly')
config = request_body.get('config', DEFAULT_MCS_CONF_PATH)
in_transaction = request_body.get('in_transaction', False)
try:
response = ClusterHandler.set_mode(mode, config=config)
if not in_transaction:
with TransactionManager():
response = ClusterHandler.set_mode(mode, config=config)
else:
response = ClusterHandler.set_mode(mode, config=config)
except CMAPIBasicError as err:
raise_422_error(module_logger, func_name, err.message)
@ -861,12 +875,17 @@ class ClusterController:
request_body = request.json
node = request_body.get('node', None)
config = request_body.get('config', DEFAULT_MCS_CONF_PATH)
in_transaction = request_body.get('in_transaction', False)
if node is None:
raise_422_error(module_logger, func_name, 'missing node argument')
try:
response = ClusterHandler.add_node(node, config)
if not in_transaction:
with TransactionManager():
response = ClusterHandler.add_node(node, config)
else:
response = ClusterHandler.add_node(node, config)
except CMAPIBasicError as err:
raise_422_error(module_logger, func_name, err.message)
@ -884,7 +903,8 @@ class ClusterController:
request_body = request.json
node = request_body.get('node', None)
config = request_body.get('config', DEFAULT_MCS_CONF_PATH)
response = {'timestamp': str(datetime.now())}
#TODO: for next release
in_transaction = request_body.get('in_transaction', False)
#TODO: add arguments verification decorator
if node is None: