|
27 | 27 | CollectionDeleteError,
|
28 | 28 | CollectionKeyGeneratorsError,
|
29 | 29 | CollectionListError,
|
| 30 | + DatabaseCompactError, |
30 | 31 | DatabaseCreateError,
|
31 | 32 | DatabaseDeleteError,
|
32 | 33 | DatabaseListError,
|
|
44 | 45 | ServerAvailableOptionsGetError,
|
45 | 46 | ServerCheckAvailabilityError,
|
46 | 47 | ServerCurrentOptionsGetError,
|
| 48 | + ServerEchoError, |
47 | 49 | ServerEncryptionError,
|
48 | 50 | ServerEngineError,
|
| 51 | + ServerExecuteError, |
49 | 52 | ServerLicenseGetError,
|
50 | 53 | ServerLicenseSetError,
|
51 | 54 | ServerModeError,
|
52 | 55 | ServerModeSetError,
|
| 56 | + ServerReloadRoutingError, |
| 57 | + ServerShutdownError, |
| 58 | + ServerShutdownProgressError, |
53 | 59 | ServerStatusError,
|
54 | 60 | ServerTimeError,
|
55 | 61 | ServerTLSError,
|
@@ -2691,6 +2697,170 @@ def response_handler(resp: Response) -> None:
|
2691 | 2697 |
|
2692 | 2698 | await self._executor.execute(request, response_handler)
|
2693 | 2699 |
|
| 2700 | + async def shutdown(self, soft: Optional[bool] = None) -> None: |
| 2701 | + """Initiate server shutdown sequence. |
| 2702 | +
|
| 2703 | + Args: |
| 2704 | + soft (bool | None): If set to `True`, this initiates a soft shutdown. |
| 2705 | +
|
| 2706 | + Raises: |
| 2707 | + ServerShutdownError: If the operation fails. |
| 2708 | +
|
| 2709 | + References: |
| 2710 | + - `start-the-shutdown-sequence <https://docs.arangodb.com/stable/develop/http-api/administration/#start-the-shutdown-sequence>`__ |
| 2711 | + """ # noqa: E501 |
| 2712 | + params: Params = {} |
| 2713 | + if soft is not None: |
| 2714 | + params["soft"] = soft |
| 2715 | + |
| 2716 | + request = Request( |
| 2717 | + method=Method.DELETE, |
| 2718 | + endpoint="/_admin/shutdown", |
| 2719 | + params=params, |
| 2720 | + ) |
| 2721 | + |
| 2722 | + def response_handler(resp: Response) -> None: |
| 2723 | + if not resp.is_success: |
| 2724 | + raise ServerShutdownError(resp, request) |
| 2725 | + |
| 2726 | + await self._executor.execute(request, response_handler) |
| 2727 | + |
| 2728 | + async def shutdown_progress(self) -> Result[Json]: |
| 2729 | + """Query the soft shutdown progress. |
| 2730 | +
|
| 2731 | + Returns: |
| 2732 | + dict: Information about the shutdown progress. |
| 2733 | +
|
| 2734 | + Raises: |
| 2735 | + ServerShutdownProgressError: If the operation fails. |
| 2736 | +
|
| 2737 | + References: |
| 2738 | + - `query-the-soft-shutdown-progress <https://docs.arangodb.com/stable/develop/http-api/administration/#query-the-soft-shutdown-progress>`__ |
| 2739 | + """ # noqa: E501 |
| 2740 | + request = Request(method=Method.GET, endpoint="/_admin/shutdown") |
| 2741 | + |
| 2742 | + def response_handler(resp: Response) -> Json: |
| 2743 | + if not resp.is_success: |
| 2744 | + raise ServerShutdownProgressError(resp, request) |
| 2745 | + |
| 2746 | + result: Json = self.deserializer.loads(resp.raw_body) |
| 2747 | + return result |
| 2748 | + |
| 2749 | + return await self._executor.execute(request, response_handler) |
| 2750 | + |
| 2751 | + async def compact( |
| 2752 | + self, |
| 2753 | + change_level: Optional[bool] = None, |
| 2754 | + compact_bottom_most_level: Optional[bool] = None, |
| 2755 | + ) -> None: |
| 2756 | + """Compact all databases. This method requires superuser access. |
| 2757 | +
|
| 2758 | + Note: |
| 2759 | + This command can cause a full rewrite of all data in all databases, |
| 2760 | + which may take very long for large databases. |
| 2761 | +
|
| 2762 | + Args: |
| 2763 | + change_level (bool | None): Whether or not compacted data should be |
| 2764 | + moved to the minimum possible level. Default value is `False`. |
| 2765 | + compact_bottom_most_level (bool | None): Whether or not to compact the bottom-most level of data. |
| 2766 | + Default value is `False`. |
| 2767 | +
|
| 2768 | + Returns: |
| 2769 | + dict: Information about the compaction process. |
| 2770 | +
|
| 2771 | + Raises: |
| 2772 | + DatabaseCompactError: If the operation fails. |
| 2773 | +
|
| 2774 | + References: |
| 2775 | + - `compact-all-databases <https://docs.arangodb.com/stable/develop/http-api/administration/#compact-all-databases>`__ |
| 2776 | + """ # noqa: E501 |
| 2777 | + data = {} |
| 2778 | + if change_level is not None: |
| 2779 | + data["changeLevel"] = change_level |
| 2780 | + if compact_bottom_most_level is not None: |
| 2781 | + data["compactBottomMostLevel"] = compact_bottom_most_level |
| 2782 | + |
| 2783 | + request = Request( |
| 2784 | + method=Method.PUT, |
| 2785 | + endpoint="/_admin/compact", |
| 2786 | + data=self.serializer.dumps(data), |
| 2787 | + ) |
| 2788 | + |
| 2789 | + def response_handler(resp: Response) -> None: |
| 2790 | + if not resp.is_success: |
| 2791 | + raise DatabaseCompactError(resp, request) |
| 2792 | + |
| 2793 | + await self._executor.execute(request, response_handler) |
| 2794 | + |
| 2795 | + async def reload_routing(self) -> None: |
| 2796 | + """Reload the routing information. |
| 2797 | +
|
| 2798 | + Raises: |
| 2799 | + ServerReloadRoutingError: If the operation fails. |
| 2800 | +
|
| 2801 | + References: |
| 2802 | + - `reload-the-routing-table <https://docs.arangodb.com/stable/develop/http-api/administration/#reload-the-routing-table>`__ |
| 2803 | + """ # noqa: E501 |
| 2804 | + request = Request(method=Method.POST, endpoint="/_admin/routing/reload") |
| 2805 | + |
| 2806 | + def response_handler(resp: Response) -> None: |
| 2807 | + if not resp.is_success: |
| 2808 | + raise ServerReloadRoutingError(resp, request) |
| 2809 | + |
| 2810 | + await self._executor.execute(request, response_handler) |
| 2811 | + |
| 2812 | + async def echo(self, body: Optional[Json] = None) -> Result[Json]: |
| 2813 | + """Return an object with the servers request information. |
| 2814 | +
|
| 2815 | + Args: |
| 2816 | + body (dict | None): Optional body of the request. |
| 2817 | +
|
| 2818 | + Returns: |
| 2819 | + dict: Details of the request. |
| 2820 | +
|
| 2821 | + Raises: |
| 2822 | + ServerEchoError: If the operation fails. |
| 2823 | +
|
| 2824 | + References: |
| 2825 | + - `echo-a-request <https://docs.arangodb.com/stable/develop/http-api/administration/#echo-a-request>`__ |
| 2826 | + """ # noqa: E501 |
| 2827 | + data = body if body is not None else {} |
| 2828 | + request = Request(method=Method.POST, endpoint="/_admin/echo", data=data) |
| 2829 | + |
| 2830 | + def response_handler(resp: Response) -> Json: |
| 2831 | + if not resp.is_success: |
| 2832 | + raise ServerEchoError(resp, request) |
| 2833 | + result: Json = self.deserializer.loads(resp.raw_body) |
| 2834 | + return result |
| 2835 | + |
| 2836 | + return await self._executor.execute(request, response_handler) |
| 2837 | + |
| 2838 | + async def execute(self, command: str) -> Result[Any]: |
| 2839 | + """Execute raw Javascript command on the server. |
| 2840 | +
|
| 2841 | + Args: |
| 2842 | + command (str): Javascript command to execute. |
| 2843 | +
|
| 2844 | + Returns: |
| 2845 | + Return value of **command**, if any. |
| 2846 | +
|
| 2847 | + Raises: |
| 2848 | + ServerExecuteError: If the execution fails. |
| 2849 | +
|
| 2850 | + References: |
| 2851 | + - `execute-a-script <https://docs.arangodb.com/stable/develop/http-api/administration/#execute-a-script>`__ |
| 2852 | + """ # noqa: E501 |
| 2853 | + request = Request( |
| 2854 | + method=Method.POST, endpoint="/_admin/execute", data=command.encode("utf-8") |
| 2855 | + ) |
| 2856 | + |
| 2857 | + def response_handler(resp: Response) -> Any: |
| 2858 | + if not resp.is_success: |
| 2859 | + raise ServerExecuteError(resp, request) |
| 2860 | + return self.deserializer.loads(resp.raw_body) |
| 2861 | + |
| 2862 | + return await self._executor.execute(request, response_handler) |
| 2863 | + |
2694 | 2864 |
|
2695 | 2865 | class StandardDatabase(Database):
|
2696 | 2866 | """Standard database API wrapper.
|
|
0 commit comments