Skip to content

Commit

Permalink
Adding 3.12.2 features
Browse files Browse the repository at this point in the history
  • Loading branch information
apetenchea committed Sep 8, 2024
1 parent d8ea7cc commit 83129c2
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 4 deletions.
55 changes: 55 additions & 0 deletions arango/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ClusterServerRoleError,
ClusterServerStatisticsError,
ClusterServerVersionError,
ClusterVpackSortMigrationError,
)
from arango.formatter import format_body
from arango.request import Request
Expand Down Expand Up @@ -444,3 +445,57 @@ def response_handler(resp: Response) -> bool:
return result

return self._execute(request, response_handler)

def vpack_sort_migration_status(self) -> Result[Json]:
"""Query the status of the vpack sorting migration.
:return: Status of the VPack sort migration.
:rtype: dict
"""
request = Request(
method="get", endpoint="/_admin/cluster/vpackSortMigration/status"
)

def response_handler(resp: Response) -> Json:
if not resp.is_success:
raise ClusterVpackSortMigrationError(resp, request)
result: Json = resp.body["result"]
return result

return self._execute(request, response_handler)

def vpack_sort_migration_index_check(self) -> Result[Json]:
"""Check for indexes impacted by the sorting behavior before 3.12.2.
:return: Status of indexes.
:rtype: dict
"""
request = Request(
method="get", endpoint="/_admin/cluster/vpackSortMigration/check"
)

def response_handler(resp: Response) -> Json:
if not resp.is_success:
raise ClusterVpackSortMigrationError(resp, request)
result: Json = resp.body["result"]
return result

return self._execute(request, response_handler)

def migrate_vpack_sorting(self) -> Result[Json]:
"""Migrate instances to the new VPack sorting behavior.
:return: Status of the VPack sort migration.
:rtype: dict
"""
request = Request(
method="put", endpoint="/_admin/cluster/vpackSortMigration/migrate"
)

def response_handler(resp: Response) -> Json:
if not resp.is_success:
raise ClusterVpackSortMigrationError(resp, request)
result: Json = resp.body["result"]
return result

return self._execute(request, response_handler)
17 changes: 15 additions & 2 deletions arango/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,20 +935,26 @@ def response_handler(resp: Response) -> Json:

return self._execute(request, response_handler)

def log_levels(self, server_id: Optional[str] = None) -> Result[Json]:
def log_levels(
self, server_id: Optional[str] = None, with_appenders: Optional[bool] = None
) -> Result[Json]:
"""Return current logging levels.
:param server_id: Forward log level to a specific server. This makes it
easier to adjust the log levels in clusters because DB-Servers require
JWT authentication whereas Coordinators also support authentication
using usernames and passwords.
:type server_id: str
:param with_appenders: Include appenders in the response.
:type with_appenders: bool
:return: Current logging levels.
:rtype: dict
"""
params: Params = {}
if server_id is not None:
params["serverId"] = server_id
if with_appenders is not None:
params["withAppenders"] = with_appenders

request = Request(method="get", endpoint="/_admin/log/level", params=params)

Expand All @@ -961,7 +967,10 @@ def response_handler(resp: Response) -> Json:
return self._execute(request, response_handler)

def set_log_levels(
self, server_id: Optional[str] = None, **kwargs: Dict[str, Any]
self,
server_id: Optional[str] = None,
with_appenders: Optional[bool] = None,
**kwargs: Dict[str, Any],
) -> Result[Json]:
"""Set the logging levels.
Expand All @@ -983,6 +992,8 @@ def set_log_levels(
JWT authentication whereas Coordinators also support authentication
using usernames and passwords.
:type server_id: str | None
:param with_appenders: Include appenders in the request.
:type with_appenders: bool | None
:param kwargs: Logging levels.
:type kwargs: Dict[str, Any]
:return: New logging levels.
Expand All @@ -991,6 +1002,8 @@ def set_log_levels(
params: Params = {}
if server_id is not None:
params["serverId"] = server_id
if with_appenders is not None:
params["withAppenders"] = with_appenders

request = Request(
method="put", endpoint="/_admin/log/level", params=params, data=kwargs
Expand Down
4 changes: 4 additions & 0 deletions arango/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,10 @@ class ClusterRebalanceError(ArangoServerError):
"""Failed to execute cluster re-balancing operation (load/set)."""


class ClusterVpackSortMigrationError(ArangoServerError):
"""Failed to execute vpack sort migration request."""


##################
# JWT Exceptions #
##################
Expand Down
24 changes: 24 additions & 0 deletions tests/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import warnings

import pytest
from packaging import version

from arango.errno import DATABASE_NOT_FOUND, FORBIDDEN
from arango.exceptions import (
Expand All @@ -16,6 +17,7 @@
ClusterServerRoleError,
ClusterServerStatisticsError,
ClusterServerVersionError,
ClusterVpackSortMigrationError,
)
from tests.helpers import assert_raises

Expand Down Expand Up @@ -235,3 +237,25 @@ def test_cluster_rebalance(sys_db, bad_db, cluster):
with assert_raises(ClusterRebalanceError) as err:
bad_db.cluster.rebalance()
assert err.value.error_code == FORBIDDEN


def test_vpack_sort_migration(sys_db, bad_db, db_version, cluster):
if not cluster:
pytest.skip("Only tested in a cluster setup")
if db_version < version.parse("3.12.2"):
pytest.skip("vpackSortMigration is only tested in 3.12.2+")

sys_db.cluster.vpack_sort_migration_status()
with assert_raises(ClusterVpackSortMigrationError) as err:
bad_db.cluster.vpack_sort_migration_status()
assert err.value.error_code == FORBIDDEN

sys_db.cluster.vpack_sort_migration_index_check()
with assert_raises(ClusterVpackSortMigrationError) as err:
bad_db.cluster.vpack_sort_migration_index_check()
assert err.value.error_code == FORBIDDEN

sys_db.cluster.migrate_vpack_sorting()
with assert_raises(ClusterVpackSortMigrationError) as err:
bad_db.cluster.migrate_vpack_sorting()
assert err.value.error_code == FORBIDDEN
7 changes: 5 additions & 2 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def test_database_misc_methods(client, sys_db, db, bad_db, cluster, secret, db_v
assert err.value.error_code in {11, 1228}

# Test get server required database version
version = db.required_db_version()
assert isinstance(version, str)
required_version = db.required_db_version()
assert isinstance(required_version, str)

# Test get server target version with bad database
with assert_raises(ServerRequiredDBVersionError):
Expand Down Expand Up @@ -252,6 +252,9 @@ def test_database_misc_methods(client, sys_db, db, bad_db, cluster, secret, db_v
# Test get log levels
default_log_levels = sys_db.log_levels()
assert isinstance(default_log_levels, dict)
if db_version >= version.parse("3.12.2"):
log_levels_with_appenders = sys_db.log_levels(with_appenders=True)
assert isinstance(log_levels_with_appenders, dict)

# Test get log levels with bad database
with assert_raises(ServerLogLevelError) as err:
Expand Down

0 comments on commit 83129c2

Please sign in to comment.