Skip to content

Commit 31e7f1a

Browse files
authoredAug 11, 2023
Stub ReadWriteSplittingPlugin (#76)
### Description Stub ReadWriteSplittingPlugin ### By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent ff41291 commit 31e7f1a

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed
 

‎aws_wrapper/plugin_service.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
from aws_wrapper.hostinfo import HostAvailability, HostInfo, HostRole
5050
from aws_wrapper.iam_plugin import IamAuthPluginFactory
5151
from aws_wrapper.plugin import CanReleaseResources
52+
from aws_wrapper.read_write_splitting_plugin import \
53+
ReadWriteSplittingPluginFactory
5254
from aws_wrapper.utils.cache_map import CacheMap
5355
from aws_wrapper.utils.messages import Messages
5456
from aws_wrapper.utils.notifications import (ConnectionEvent, HostEvent,
@@ -419,7 +421,8 @@ class PluginManager(CanReleaseResources):
419421
"aurora_connection_tracker": AuroraConnectionTrackerPluginFactory,
420422
"aurora_host_list": AuroraHostListPluginFactory,
421423
"host_monitoring": HostMonitoringPluginFactory,
422-
"failover": FailoverPluginFactory
424+
"failover": FailoverPluginFactory,
425+
"readWriteSplitting": ReadWriteSplittingPluginFactory
423426
}
424427

425428
def __init__(
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License").
4+
# You may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import annotations
16+
17+
from typing import TYPE_CHECKING
18+
19+
if TYPE_CHECKING:
20+
from aws_wrapper.host_list_provider import HostListProviderService
21+
from aws_wrapper.hostinfo import HostInfo
22+
from aws_wrapper.plugin_service import PluginService
23+
from aws_wrapper.utils.properties import Properties
24+
25+
from typing import Any, Callable, Set
26+
27+
from aws_wrapper.pep249 import Connection
28+
from aws_wrapper.plugin import Plugin, PluginFactory
29+
from aws_wrapper.utils.notifications import (ConnectionEvent,
30+
OldConnectionSuggestedAction)
31+
32+
33+
class ReadWriteSplittingPlugin(Plugin):
34+
_SUBSCRIBED_METHODS: Set[str] = {"init_host_provider",
35+
"connect",
36+
"notify_connection_changed",
37+
"Connection.set_read_only",
38+
"Connection.clear_warnings"}
39+
40+
def __init__(self, plugin_service: PluginService, props: Properties):
41+
self._plugin_service = plugin_service
42+
self._properties = props
43+
44+
@property
45+
def subscribed_methods(self) -> Set[str]:
46+
return self._SUBSCRIBED_METHODS
47+
48+
def init_host_provider(
49+
self,
50+
props: Properties,
51+
host_list_provider_service: HostListProviderService,
52+
init_host_provider_func: Callable):
53+
...
54+
55+
def connect(
56+
self,
57+
host_info: HostInfo,
58+
props: Properties,
59+
initial: bool,
60+
connect_func: Callable) -> Connection:
61+
return Connection()
62+
63+
def force_connect(
64+
self,
65+
host_info: HostInfo,
66+
props: Properties,
67+
initial: bool,
68+
force_connect_func: Callable) -> Connection:
69+
return Connection()
70+
71+
def notify_connection_changed(self, changes: Set[ConnectionEvent]) -> OldConnectionSuggestedAction:
72+
return OldConnectionSuggestedAction.NO_OPINION
73+
74+
def execute(self, target: type, method_name: str, execute_func: Callable, *args: Any) -> Any:
75+
...
76+
77+
78+
class ReadWriteSplittingPluginFactory(PluginFactory):
79+
def get_instance(self, plugin_service: PluginService, props: Properties) -> Plugin:
80+
return ReadWriteSplittingPlugin(plugin_service, props)

0 commit comments

Comments
 (0)
Please sign in to comment.