|
| 1 | +# Copyright 2016-2023. Couchbase, Inc. |
| 2 | +# All Rights Reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License") |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +from __future__ import annotations |
| 17 | + |
| 18 | +from asyncio import AbstractEventLoop |
| 19 | +from typing import TYPE_CHECKING, List |
| 20 | + |
| 21 | +from couchbase.management.logic.eventing_function_mgmt_req_builder import EventingFunctionMgmtRequestBuilder |
| 22 | +from couchbase.management.logic.eventing_function_mgmt_types import EventingFunction, EventingFunctionsStatus |
| 23 | + |
| 24 | +if TYPE_CHECKING: |
| 25 | + from acouchbase.logic.client_adapter import AsyncClientAdapter |
| 26 | + from couchbase.management.logic.eventing_function_mgmt_types import (DeployFunctionRequest, |
| 27 | + DropFunctionRequest, |
| 28 | + GetAllFunctionsRequest, |
| 29 | + GetFunctionRequest, |
| 30 | + GetFunctionsStatusRequest, |
| 31 | + PauseFunctionRequest, |
| 32 | + ResumeFunctionRequest, |
| 33 | + UndeployFunctionRequest, |
| 34 | + UpsertFunctionRequest) |
| 35 | + |
| 36 | + |
| 37 | +class AsyncEventingFunctionMgmtImpl: |
| 38 | + def __init__(self, client_adapter: AsyncClientAdapter) -> None: |
| 39 | + self._client_adapter = client_adapter |
| 40 | + self._request_builder = EventingFunctionMgmtRequestBuilder() |
| 41 | + |
| 42 | + @property |
| 43 | + def loop(self) -> AbstractEventLoop: |
| 44 | + """**INTERNAL**""" |
| 45 | + return self._client_adapter.loop |
| 46 | + |
| 47 | + @property |
| 48 | + def request_builder(self) -> EventingFunctionMgmtRequestBuilder: |
| 49 | + """**INTERNAL**""" |
| 50 | + return self._request_builder |
| 51 | + |
| 52 | + async def deploy_function(self, req: DeployFunctionRequest) -> None: |
| 53 | + """**INTERNAL**""" |
| 54 | + await self._client_adapter.execute_mgmt_request(req) |
| 55 | + |
| 56 | + async def drop_function(self, req: DropFunctionRequest) -> None: |
| 57 | + """**INTERNAL**""" |
| 58 | + await self._client_adapter.execute_mgmt_request(req) |
| 59 | + |
| 60 | + async def get_all_functions(self, req: GetAllFunctionsRequest) -> List[EventingFunction]: |
| 61 | + """**INTERNAL**""" |
| 62 | + ret = await self._client_adapter.execute_mgmt_request(req) |
| 63 | + functions = [] |
| 64 | + raw_functions = ret.raw_result.get('functions', None) |
| 65 | + if raw_functions: |
| 66 | + functions = [EventingFunction.from_server(f) for f in raw_functions] |
| 67 | + |
| 68 | + return functions |
| 69 | + |
| 70 | + async def get_function(self, req: GetFunctionRequest) -> EventingFunction: |
| 71 | + """**INTERNAL**""" |
| 72 | + ret = await self._client_adapter.execute_mgmt_request(req) |
| 73 | + raw_func = ret.raw_result.get('function', None) |
| 74 | + func = None |
| 75 | + if raw_func: |
| 76 | + func = EventingFunction.from_server(raw_func) |
| 77 | + return func |
| 78 | + |
| 79 | + async def get_functions_status(self, req: GetFunctionsStatusRequest) -> EventingFunctionsStatus: |
| 80 | + """**INTERNAL**""" |
| 81 | + ret = await self._client_adapter.execute_mgmt_request(req) |
| 82 | + raw_status = ret.raw_result.get('status', None) |
| 83 | + status = None |
| 84 | + if raw_status: |
| 85 | + status = EventingFunctionsStatus.from_server(raw_status) |
| 86 | + |
| 87 | + return status |
| 88 | + |
| 89 | + async def pause_function(self, req: PauseFunctionRequest) -> None: |
| 90 | + """**INTERNAL**""" |
| 91 | + await self._client_adapter.execute_mgmt_request(req) |
| 92 | + |
| 93 | + async def resume_function(self, req: ResumeFunctionRequest) -> None: |
| 94 | + """**INTERNAL**""" |
| 95 | + await self._client_adapter.execute_mgmt_request(req) |
| 96 | + |
| 97 | + async def undeploy_function(self, req: UndeployFunctionRequest) -> None: |
| 98 | + """**INTERNAL**""" |
| 99 | + await self._client_adapter.execute_mgmt_request(req) |
| 100 | + |
| 101 | + async def upsert_function(self, req: UpsertFunctionRequest) -> None: |
| 102 | + """**INTERNAL**""" |
| 103 | + await self._client_adapter.execute_mgmt_request(req) |
0 commit comments