Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DE-672] GET /_admin/shutdown #280

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions arango/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
ServerRoleError,
ServerRunTestsError,
ServerShutdownError,
ServerShutdownProgressError,
ServerStatisticsError,
ServerStatusError,
ServerTimeError,
Expand Down Expand Up @@ -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:
Expand All @@ -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.

Expand Down
4 changes: 4 additions & 0 deletions arango/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
Loading