Skip to content

Commit a1aa2cb

Browse files
authored
Update client's configuration methods with stable config api (#557)
* Update client's configuration methods with stable config api Signed-off-by: hunter007 <[email protected]> * Fix unit test error Signed-off-by: hunter007 <[email protected]> * merge master branch * Remove __adel__ because object has no __adel__ method Signed-off-by: hunter007 <[email protected]> * update comments Signed-off-by: hunter007 <[email protected]> --------- Signed-off-by: hunter007 <[email protected]>
1 parent 5c83ffb commit a1aa2cb

File tree

10 files changed

+1447
-321
lines changed

10 files changed

+1447
-321
lines changed

dapr/aio/clients/grpc/client.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ async def close(self):
148148
if self._channel:
149149
self._channel.close()
150150

151-
async def __del__(self):
152-
await self.close()
153-
154151
async def __aenter__(self) -> Self: # type: ignore
155152
return self
156153

@@ -925,7 +922,7 @@ async def get_configuration(
925922
store_name: str,
926923
keys: List[str],
927924
config_metadata: Optional[Dict[str, str]] = dict()) -> ConfigurationResponse:
928-
"""Gets value from a config store with a key
925+
"""Gets values from a config store with keys
929926
930927
The example gets value from a config store:
931928
from dapr.aio.clients import DaprClient
@@ -938,21 +935,19 @@ async def get_configuration(
938935
939936
Args:
940937
store_name (str): the state store name to get from
941-
keys (str): the keys of the key-value pairs to be gotten
938+
keys (List[str]): the keys of the key-value pairs to be gotten
942939
config_metadata (Dict[str, str], optional): Dapr metadata for configuration
943940
944941
Returns:
945942
:class:`ConfigurationResponse` gRPC metadata returned from callee
946943
and value obtained from the config store
947944
"""
948-
warn('The Get Configuration API is an Alpha version and is subject to change.',
949-
UserWarning, stacklevel=2)
950-
951945
if not store_name or len(store_name) == 0 or len(store_name.strip()) == 0:
952946
raise ValueError("Config store name cannot be empty to get the configuration")
947+
953948
req = api_v1.GetConfigurationRequest(
954949
store_name=store_name, keys=keys, metadata=config_metadata)
955-
call = self._stub.GetConfigurationAlpha1(req)
950+
call = self._stub.GetConfiguration(req)
956951
response = await call
957952
return ConfigurationResponse(
958953
items=response.items,
@@ -969,9 +964,9 @@ async def subscribe_configuration(
969964
The example gets value from a config store:
970965
from dapr.aio.clients import DaprClient
971966
async with DaprClient() as d:
972-
resp = await d.subscribe_config(
967+
resp = await d.subscribe_configuration(
973968
store_name='state_store'
974-
key='key_1',
969+
keys=['key_1'],
975970
handler=handler,
976971
config_metadata={"metakey": "metavalue"}
977972
)
@@ -985,11 +980,9 @@ async def subscribe_configuration(
985980
Returns:
986981
id (str): subscription id, which can be used to unsubscribe later
987982
"""
988-
warn('The Subscribe Configuration API is an Alpha version and is subject to change.',
989-
UserWarning, stacklevel=2)
990-
991983
if not store_name or len(store_name) == 0 or len(store_name.strip()) == 0:
992984
raise ValueError("Config store name cannot be empty to get the configuration")
985+
993986
configWatcher = ConfigurationWatcher()
994987
id = configWatcher.watch_configuration(self._stub, store_name, keys,
995988
handler, config_metadata)
@@ -1008,11 +1001,8 @@ async def unsubscribe_configuration(
10081001
Returns:
10091002
bool: True if unsubscribed successfully, False otherwise
10101003
"""
1011-
warn('The Unsubscribe Configuration API is an Alpha version and is subject to change.',
1012-
UserWarning, stacklevel=2)
10131004
req = api_v1.UnsubscribeConfigurationRequest(store_name=store_name, id=id)
1014-
call = self._stub.UnsubscribeConfigurationAlpha1(req)
1015-
response: UnsubscribeConfigurationResponse = await call
1005+
response: UnsubscribeConfigurationResponse = await self._stub.UnsubscribeConfiguration(req)
10161006
return response.ok
10171007

10181008
async def try_lock(
@@ -1066,7 +1056,7 @@ async def try_lock(
10661056
store_name=store_name,
10671057
resource_id=resource_id,
10681058
lock_owner=lock_owner,
1069-
expiryInSeconds=expiry_in_seconds)
1059+
expiry_in_seconds=expiry_in_seconds)
10701060
call = self._stub.TryLockAlpha1(req)
10711061
response = await call
10721062
return TryLockResponse(

dapr/clients/grpc/client.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -923,21 +923,18 @@ def get_configuration(
923923
924924
Args:
925925
store_name (str): the state store name to get from
926-
keys (str): the keys of the key-value pairs to be gotten
926+
keys (List[str]): the keys of the key-value pairs to be gotten
927927
config_metadata (Dict[str, str], optional): Dapr metadata for configuration
928928
929929
Returns:
930930
:class:`ConfigurationResponse` gRPC metadata returned from callee
931931
and value obtained from the config store
932932
"""
933-
warn('The Get Configuration API is an Alpha version and is subject to change.',
934-
UserWarning, stacklevel=2)
935-
936933
if not store_name or len(store_name) == 0 or len(store_name.strip()) == 0:
937934
raise ValueError("Config store name cannot be empty to get the configuration")
938935
req = api_v1.GetConfigurationRequest(
939936
store_name=store_name, keys=keys, metadata=config_metadata)
940-
response, call = self._stub.GetConfigurationAlpha1.with_call(req)
937+
response, call = self._stub.GetConfiguration.with_call(req)
941938
return ConfigurationResponse(
942939
items=response.items,
943940
headers=call.initial_metadata())
@@ -953,9 +950,9 @@ def subscribe_configuration(
953950
The example gets value from a config store:
954951
from dapr.clients import DaprClient
955952
with DaprClient() as d:
956-
resp = d.subscribe_config(
953+
resp = d.subscribe_configuration(
957954
store_name='state_store'
958-
key='key_1',
955+
keys=['key_1'],
959956
handler=handler,
960957
config_metadata={"metakey": "metavalue"}
961958
)
@@ -969,11 +966,10 @@ def subscribe_configuration(
969966
Returns:
970967
id (str): subscription id, which can be used to unsubscribe later
971968
"""
972-
warn('The Subscribe Configuration API is an Alpha version and is subject to change.',
973-
UserWarning, stacklevel=2)
974969

975970
if not store_name or len(store_name) == 0 or len(store_name.strip()) == 0:
976971
raise ValueError("Config store name cannot be empty to get the configuration")
972+
977973
configWatcher = ConfigurationWatcher()
978974
id = configWatcher.watch_configuration(self._stub, store_name, keys,
979975
handler, config_metadata)
@@ -992,10 +988,8 @@ def unsubscribe_configuration(
992988
Returns:
993989
bool: True if unsubscribed successfully, False otherwise
994990
"""
995-
warn('The Unsubscribe Configuration API is an Alpha version and is subject to change.',
996-
UserWarning, stacklevel=2)
997991
req = api_v1.UnsubscribeConfigurationRequest(store_name=store_name, id=id)
998-
response: UnsubscribeConfigurationResponse = self._stub.UnsubscribeConfigurationAlpha1(req)
992+
response: UnsubscribeConfigurationResponse = self._stub.UnsubscribeConfiguration(req)
999993
return response.ok
1000994

1001995
def try_lock(
@@ -1049,7 +1043,7 @@ def try_lock(
10491043
store_name=store_name,
10501044
resource_id=resource_id,
10511045
lock_owner=lock_owner,
1052-
expiryInSeconds=expiry_in_seconds)
1046+
expiry_in_seconds=expiry_in_seconds)
10531047
response, call = self._stub.TryLockAlpha1.with_call(req)
10541048
return TryLockResponse(
10551049
success=response.success,

dapr/proto/common/v1/common_pb2.py

Lines changed: 27 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dapr/proto/common/v1/common_pb2.pyi

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class InvokeRequest(google.protobuf.message.Message):
108108
"""Required. method is a method name which will be invoked by caller."""
109109
@property
110110
def data(self) -> google.protobuf.any_pb2.Any:
111-
"""Required. Bytes value or Protobuf message which caller sent.
111+
"""Required in unary RPCs. Bytes value or Protobuf message which caller sent.
112112
Dapr treats Any.value as bytes type if Any.type_url is unset.
113113
"""
114114
content_type: builtins.str
@@ -150,7 +150,7 @@ class InvokeResponse(google.protobuf.message.Message):
150150
CONTENT_TYPE_FIELD_NUMBER: builtins.int
151151
@property
152152
def data(self) -> google.protobuf.any_pb2.Any:
153-
"""Required. The content body of InvokeService response."""
153+
"""Required in unary RPCs. The content body of InvokeService response."""
154154
content_type: builtins.str
155155
"""Required. The type of data content."""
156156
def __init__(
@@ -164,6 +164,33 @@ class InvokeResponse(google.protobuf.message.Message):
164164

165165
global___InvokeResponse = InvokeResponse
166166

167+
class StreamPayload(google.protobuf.message.Message):
168+
"""Chunk of data sent in a streaming request or response.
169+
This is used in requests including InternalInvokeRequestStream.
170+
"""
171+
172+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
173+
174+
DATA_FIELD_NUMBER: builtins.int
175+
SEQ_FIELD_NUMBER: builtins.int
176+
data: builtins.bytes
177+
"""Data sent in the chunk.
178+
The amount of data included in each chunk is up to the discretion of the sender, and can be empty.
179+
Additionally, the amount of data doesn't need to be fixed and subsequent messages can send more, or less, data.
180+
Receivers must not make assumptions about the number of bytes they'll receive in each chunk.
181+
"""
182+
seq: builtins.int
183+
"""Sequence number. This is a counter that starts from 0 and increments by 1 on each chunk sent."""
184+
def __init__(
185+
self,
186+
*,
187+
data: builtins.bytes = ...,
188+
seq: builtins.int = ...,
189+
) -> None: ...
190+
def ClearField(self, field_name: typing_extensions.Literal["data", b"data", "seq", b"seq"]) -> None: ...
191+
192+
global___StreamPayload = StreamPayload
193+
167194
class StateItem(google.protobuf.message.Message):
168195
"""StateItem represents state key, value, and additional options to save state."""
169196

0 commit comments

Comments
 (0)