Skip to content

Commit a698bab

Browse files
committed
PYCBC-1737: Migrate Eventing Function management away from Wrapper decorators
Changes ------- * Add eventing function mgmt types, request builder * Add eventing function mgmt impl for all 3 APIs * Update APIs eventing function manager classes to use impl and remove wrapper decorators * Remove pytest.skip() from eventing function mgmt tests Change-Id: Ie6f6c25899df22a477b1302c48905860b59d5582 Reviewed-on: https://review.couchbase.org/c/couchbase-python-client/+/239896 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Dimitris Christodoulou <dimitris.christodoulou@couchbase.com>
1 parent b07c60f commit a698bab

10 files changed

Lines changed: 2121 additions & 422 deletions

File tree

acouchbase/management/eventing.py

Lines changed: 182 additions & 215 deletions
Large diffs are not rendered by default.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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)

acouchbase/tests/eventingmgmt_t.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
TestEnvironment)
5555

5656

57-
@pytest.mark.skip(reason='Skip until PYCBC-1737')
5857
@pytest.mark.flaky(reruns=5)
5958
class EventingManagementTests:
6059

@@ -733,7 +732,6 @@ async def test_with_scope_and_collection(self, cb_env, evt_version):
733732
cb_env.validate_eventing_function(func)
734733

735734

736-
@pytest.mark.skip(reason='Skip until PYCBC-1737')
737735
@pytest.mark.flaky(reruns=3)
738736
class ScopeEventingManagementTests:
739737

0 commit comments

Comments
 (0)