1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-01 06:46:55 +03:00

fix(cmapi): MCOL-5962 Fix rollback in mcs cli and passing errors during broadcasting config

* fix(cmapi): ClusterControllerClient request error handling
* fix(cmapi): broadcast_new_config request error handling
* style(cmapi): logs
This commit is contained in:
mariadb-AlanMologorsky
2025-04-04 15:08:32 +03:00
committed by Alan Mologorsky
parent f04b189476
commit 10dec6ea94
3 changed files with 42 additions and 10 deletions

View File

@ -1,12 +1,14 @@
import requests import logging
from typing import Any, Dict, Optional, Union from typing import Any, Dict, Optional, Union
import pyotp import pyotp
import requests
from cmapi_server.controllers.dispatcher import _version from cmapi_server.controllers.dispatcher import _version
from cmapi_server.constants import ( from cmapi_server.constants import (
CMAPI_CONF_PATH, CURRENT_NODE_CMAPI_URL, SECRET_KEY, CMAPI_CONF_PATH, CURRENT_NODE_CMAPI_URL, SECRET_KEY,
) )
from cmapi_server.exceptions import CMAPIBasicError
from cmapi_server.helpers import get_config_parser, get_current_key from cmapi_server.helpers import get_config_parser, get_current_key
@ -146,5 +148,28 @@ class ClusterControllerClient:
response.raise_for_status() response.raise_for_status()
return response.json() return response.json()
# TODO: different handler for timeout exception? # TODO: different handler for timeout exception?
except requests.exceptions.RequestException as e: except requests.HTTPError as exc:
return {'error': str(e)} resp = exc.response
error_msg = str(exc)
if resp.status_code == 422:
# in this case we think cmapi server returned some value but
# had error during running endpoint handler code
try:
resp_json = response.json()
error_msg = resp_json.get('error', resp_json)
except requests.exceptions.JSONDecodeError:
error_msg = response.text
message = (
f'API client got an exception in request to {exc.request.url} '
f'with code {resp.status_code} and error: {error_msg}'
)
logging.error(message)
raise CMAPIBasicError(message)
except requests.exceptions.RequestException as exc:
message = (
'API client got an undefined error in request to '
f'{exc.request.url} with code {exc.response.status_code} and '
f'error: {str(exc)}'
)
logging.error(message)
raise CMAPIBasicError(message)

View File

@ -461,7 +461,7 @@ class ConfigController:
module_logger, func_name, module_logger, func_name,
( (
'Error while starting node. ' 'Error while starting node. '
f'Details: {err.message}.' f'Details: {err.message}'
), ),
exc_info=False exc_info=False
) )

View File

@ -357,35 +357,42 @@ def broadcast_new_config(
:raises CMAPIBasicError: If undefined error happened :raises CMAPIBasicError: If undefined error happened
""" """
url = f'https://{node}:8640/cmapi/{version}/node/config' url = f'https://{node}:8640/cmapi/{version}/node/config'
resp_json: dict = dict()
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
try: try:
async with session.put( async with session.put(
url, headers=headers, json=body, ssl=False, timeout=120 url, headers=headers, json=body, ssl=False, timeout=120
) as response: ) as response:
resp_json = await response.json(encoding='utf-8')
response.raise_for_status() response.raise_for_status()
logging.info(f'Node "{node}" config put successfull.') logging.info(f'Node {node} config put successfull.')
except aiohttp.ClientResponseError as err: except aiohttp.ClientResponseError as err:
# TODO: may be better to check if resp status is 422 cause
# it's like a signal that cmapi server raised it in
# most cases
error_msg = resp_json.get('error', resp_json)
message = ( message = (
f'Node "{node}" config put failed with status: ' f'Node {node} config put failed with status: '
f'"{err.status}" and message: {err.message}' f'{err.status} and err message: {error_msg}'
) )
logging.error(message) logging.error(message)
raise CMAPIBasicError(message) raise CMAPIBasicError(message)
except aiohttp.ClientError as err: except aiohttp.ClientError as err:
message = ( message = (
f'Node "{node}" config put failed with ClientError: ' f'Node {node} config put failed with ClientError: '
f'{str(err)}' f'{str(err)}'
) )
logging.error(message) logging.error(message)
raise CMAPIBasicError(message) raise CMAPIBasicError(message)
except asyncio.TimeoutError: except asyncio.TimeoutError:
message = f'Node "{node}" config put failed by Timeout: ' message = f'Node {node} config put failed by Timeout: '
logging.error(message) logging.error(message)
raise CMAPIBasicError(message) raise CMAPIBasicError(message)
except Exception as err: except Exception as err:
message = ( message = (
f'Node "{node}" config put failed by undefined exception: ' f'Node {node} config put failed by undefined exception: '
f'{str(err)}' f'{str(err)}'
) )
logging.error(message) logging.error(message)