From ea9f1fea26d8083ebd6140e60d28175de7173b61 Mon Sep 17 00:00:00 2001 From: Anthony Mahanna Date: Fri, 1 Sep 2023 13:40:37 -0400 Subject: [PATCH] initial commit --- arango/database.py | 32 ++++++++++++++++++++++++++++++-- arango/exceptions.py | 4 ++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/arango/database.py b/arango/database.py index 875a04e0..bc6c0c91 100644 --- a/arango/database.py +++ b/arango/database.py @@ -52,6 +52,7 @@ ServerRoleError, ServerRunTestsError, ServerShutdownError, + ServerShutdownProgressError, ServerStatisticsError, ServerStatusError, ServerTimeError, @@ -471,14 +472,21 @@ def response_handler(resp: Response) -> Json: return self._execute(request, response_handler) - def shutdown(self) -> Result[bool]: # pragma: no cover + def shutdown(self, soft: bool = False) -> Result[bool]: # pragma: no cover """Initiate server shutdown sequence. + :param soft: If set to true, this initiates a soft shutdown. This is only + available on Coordinators. When issued, the Coordinator tracks a number + of ongoing operations, waits until all have finished, and then shuts + itself down normally. It will still accept new operations. + :type soft: bool :return: True if the server was shutdown successfully. :rtype: bool :raise arango.exceptions.ServerShutdownError: If shutdown fails. """ - request = Request(method="delete", endpoint="/_admin/shutdown") + request = Request( + method="delete", endpoint="/_admin/shutdown", params={"soft": soft} + ) def response_handler(resp: Response) -> bool: if not resp.is_success: @@ -487,6 +495,26 @@ def response_handler(resp: Response) -> bool: return self._execute(request, response_handler) + def shutdown_progress(self) -> Result[Json]: # pragma: no cover + """Query the soft shutdown progress. This call reports progress about a + soft Coordinator shutdown (DELETE /_admin/shutdown?soft=true). This API + is only available on Coordinators. + + :return: Information about the shutdown progress. + :rtype: dict + :raise arango.exceptions.ServerShutdownError: If shutdown fails. + """ + request = Request(method="get", endpoint="/_admin/shutdown") + + def response_handler(resp: Response) -> Json: + if not resp.is_success: + raise ServerShutdownProgressError(resp, request) + + result: Json = resp.body + return result + + return self._execute(request, response_handler) + def run_tests(self, tests: Sequence[str]) -> Result[Json]: # pragma: no cover """Run available unittests on the server. diff --git a/arango/exceptions.py b/arango/exceptions.py index f9b6de2d..3a65bed0 100644 --- a/arango/exceptions.py +++ b/arango/exceptions.py @@ -630,6 +630,10 @@ class ServerShutdownError(ArangoServerError): """Failed to initiate shutdown sequence.""" +class ServerShutdownProgressError(ArangoServerError): + """Failed to retrieve soft shutdown progress.""" + + class ServerRunTestsError(ArangoServerError): """Failed to execute server tests."""