diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/management/_management_client_async.py b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/management/_management_client_async.py index 9ccb33683ab7..2712c0076987 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/aio/management/_management_client_async.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/aio/management/_management_client_async.py @@ -4,10 +4,10 @@ # -------------------------------------------------------------------------------------------- # pylint:disable=protected-access # pylint:disable=specify-parameter-names-in-call +# pylint:disable=too-many-lines import functools from typing import TYPE_CHECKING, Any, Union, cast from xml.etree.ElementTree import ElementTree -from datetime import timedelta from azure.core.async_paging import AsyncItemPaged from azure.core.exceptions import ResourceNotFoundError @@ -21,8 +21,6 @@ RuleDescriptionFeed, NamespacePropertiesEntry, CreateTopicBody, CreateTopicBodyContent, \ TopicDescriptionFeed, CreateSubscriptionBody, CreateSubscriptionBodyContent, CreateRuleBody, \ CreateRuleBodyContent, CreateQueueBody, CreateQueueBodyContent, \ - QueueDescription as InternalQueueDescription, TopicDescription as InternalTopicDescription, \ - SubscriptionDescription as InternalSubscriptionDescription, \ NamespaceProperties from ..._common.utils import parse_conn_str @@ -33,8 +31,8 @@ as ServiceBusManagementClientImpl from ...management import _constants as constants from ._shared_key_policy_async import AsyncServiceBusSharedKeyCredentialPolicy -from ...management._models import QueueRuntimeInfo, QueueDescription, TopicDescription, TopicRuntimeInfo, \ - SubscriptionDescription, SubscriptionRuntimeInfo, RuleDescription +from ...management._models import QueueRuntimeProperties, QueueProperties, TopicProperties, TopicRuntimeProperties, \ + SubscriptionProperties, SubscriptionRuntimeProperties, RuleProperties from ...management._xml_workaround_policy import ServiceBusXMLWorkaroundPolicy from ...management._handle_response_error import _handle_response_error from ...management._model_workaround import avoid_timedelta_overflow @@ -143,50 +141,120 @@ def from_connection_string(cls, conn_str: str, **kwargs) -> "ServiceBusManagemen endpoint = endpoint[endpoint.index("//")+2:] return cls(endpoint, ServiceBusSharedKeyCredential(shared_access_key_name, shared_access_key), **kwargs) - async def get_queue(self, queue_name: str, **kwargs) -> QueueDescription: + async def get_queue(self, queue_name: str, **kwargs) -> QueueProperties: """Get the properties of a queue. :param str queue_name: The name of the queue. - :rtype: ~azure.servicebus.management.QueueDescription + :rtype: ~azure.servicebus.management.QueueProperties """ entry_ele = await self._get_entity_element(queue_name, **kwargs) entry = QueueDescriptionEntry.deserialize(entry_ele) if not entry.content: raise ResourceNotFoundError("Queue '{}' does not exist".format(queue_name)) - queue_description = QueueDescription._from_internal_entity(queue_name, + queue_description = QueueProperties._from_internal_entity(queue_name, entry.content.queue_description) return queue_description - async def get_queue_runtime_info(self, queue_name: str, **kwargs) -> QueueRuntimeInfo: + async def get_queue_runtime_info(self, queue_name: str, **kwargs) -> QueueRuntimeProperties: """Get the runtime information of a queue. :param str queue_name: The name of the queue. - :rtype: ~azure.servicebus.management.QueueRuntimeInfo + :rtype: ~azure.servicebus.management.QueueRuntimeProperties """ entry_ele = await self._get_entity_element(queue_name, **kwargs) entry = QueueDescriptionEntry.deserialize(entry_ele) if not entry.content: raise ResourceNotFoundError("Queue {} does not exist".format(queue_name)) - runtime_info = QueueRuntimeInfo._from_internal_entity(queue_name, + runtime_info = QueueRuntimeProperties._from_internal_entity(queue_name, entry.content.queue_description) return runtime_info - async def create_queue(self, queue: Union[str, QueueDescription], **kwargs) -> QueueDescription: + async def create_queue(self, name: str, **kwargs) -> QueueProperties: """Create a queue. - :param queue: The queue name or a `QueueDescription` instance. When it's a str, it will be the name - of the created queue. Other properties of the created queue will have default values as defined by the - service. Use a `QueueDescription` if you want to set queue properties other than the queue name. - :type queue: Union[str, ~azure.servicebus.management.QueueDescription] - :rtype: ~azure.servicebus.management.QueueDescription + :param name: Name of the queue. + :type name: str + :keyword authorization_rules: Authorization rules for resource. + :type authorization_rules: list[~azure.servicebus.management.AuthorizationRule] + :keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the queue is + automatically deleted. The minimum duration is 5 minutes. + :type auto_delete_on_idle: ~datetime.timedelta + :keyword dead_lettering_on_message_expiration: A value that indicates whether this queue has dead + letter support when a message expires. + :type dead_lettering_on_message_expiration: bool + :keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is + the duration after which the message expires, starting from when the message is sent to Service + Bus. This is the default value used when TimeToLive is not set on a message itself. + :type default_message_time_to_live: ~datetime.timedelta + :keyword duplicate_detection_history_time_window: ISO 8601 timeSpan structure that defines the + duration of the duplicate detection history. The default value is 10 minutes. + :type duplicate_detection_history_time_window: ~datetime.timedelta + :keyword enable_batched_operations: Value that indicates whether server-side batched operations + are enabled. + :type enable_batched_operations: bool + :keyword enable_express: A value that indicates whether Express Entities are enabled. An express + queue holds a message in memory temporarily before writing it to persistent storage. + :type enable_express: bool + :keyword enable_partitioning: A value that indicates whether the queue is to be partitioned + across multiple message brokers. + :type enable_partitioning: bool + :keyword is_anonymous_accessible: A value indicating if the resource can be accessed without + authorization. + :type is_anonymous_accessible: bool + :keyword lock_duration: ISO 8601 timespan duration of a peek-lock; that is, the amount of time + that the message is locked for other receivers. The maximum value for LockDuration is 5 + minutes; the default value is 1 minute. + :type lock_duration: ~datetime.timedelta + :keyword max_delivery_count: The maximum delivery count. A message is automatically deadlettered + after this number of deliveries. Default value is 10. + :type max_delivery_count: int + :keyword max_size_in_megabytes: The maximum size of the queue in megabytes, which is the size of + memory allocated for the queue. + :type max_size_in_megabytes: int + :keyword requires_duplicate_detection: A value indicating if this queue requires duplicate + detection. + :type requires_duplicate_detection: bool + :keyword requires_session: A value that indicates whether the queue supports the concept of + sessions. + :type requires_session: bool + :keyword forward_to: The name of the recipient entity to which all the messages sent to the queue + are forwarded to. + :type forward_to: str + :keyword user_metadata: Custom metdata that user can associate with the description. Max length + is 1024 chars. + :type user_metadata: str + :keyword support_ordering: A value that indicates whether the queue supports ordering. + :type support_ordering: bool + :keyword forward_dead_lettered_messages_to: The name of the recipient entity to which all the + dead-lettered messages of this subscription are forwarded to. + :type forward_dead_lettered_messages_to: str + + :rtype: ~azure.servicebus.management.QueueProperties """ - try: - queue_name = queue.name # type: ignore - to_create = queue._to_internal_entity() # type: ignore - except AttributeError: - queue_name = queue # type: ignore - to_create = InternalQueueDescription() # Use an empty queue description. - + queue = QueueProperties( + name, + authorization_rules=kwargs.pop("authorization_rules", None), + auto_delete_on_idle=kwargs.pop("auto_delete_on_idle", None), + dead_lettering_on_message_expiration=kwargs.pop("dead_lettering_on_message_expiration", None), + default_message_time_to_live=kwargs.pop("default_message_time_to_live", None), + duplicate_detection_history_time_window=kwargs.pop("duplicate_detection_history_time_window", None), + entity_availability_status=kwargs.pop("entity_availability_status", None), + enable_batched_operations=kwargs.pop("enable_batched_operations", None), + enable_express=kwargs.pop("enable_express", None), + enable_partitioning=kwargs.pop("enable_partitioning", None), + is_anonymous_accessible=kwargs.pop("is_anonymous_accessible", None), + lock_duration=kwargs.pop("lock_duration", None), + max_delivery_count=kwargs.pop("max_delivery_count", None), + max_size_in_megabytes=kwargs.pop("max_size_in_megabytes", None), + requires_duplicate_detection=kwargs.pop("requires_duplicate_detection", None), + requires_session=kwargs.pop("requires_session", None), + status=kwargs.pop("status", None), + support_ordering=kwargs.pop("support_ordering", None), + forward_to=kwargs.pop("forward_to", None), + forward_dead_lettered_messages_to=kwargs.pop("forward_dead_lettered_messages_to", None), + user_metadata=kwargs.pop("user_metadata", None) + ) + to_create = queue._to_internal_entity() create_entity_body = CreateQueueBody( content=CreateQueueBodyContent( queue_description=to_create, # type: ignore @@ -197,49 +265,29 @@ async def create_queue(self, queue: Union[str, QueueDescription], **kwargs) -> Q entry_ele = cast( ElementTree, await self._impl.entity.put( - queue_name, # type: ignore + name, # type: ignore request_body, api_version=constants.API_VERSION, **kwargs) ) entry = QueueDescriptionEntry.deserialize(entry_ele) - result = QueueDescription._from_internal_entity(queue_name, + result = QueueProperties._from_internal_entity(name, entry.content.queue_description) return result - async def update_queue( - self, queue: QueueDescription, - *, - default_message_time_to_live: timedelta = None, - lock_duration: timedelta = None, - dead_lettering_on_message_expiration: bool = None, - duplicate_detection_history_time_window: timedelta = None, - max_delivery_count: int = None, - **kwargs) -> None: + async def update_queue(self, queue: QueueProperties, **kwargs) -> None: """Update a queue. - :param queue: The properties of this `QueueDescription` will be applied to the queue in - ServiceBus. Only a portion of properties can be updated. - Refer to https://docs.microsoft.com/en-us/rest/api/servicebus/update-queue. - :type queue: ~azure.servicebus.management.QueueDescription - :keyword timedelta default_message_time_to_live: The value you want to update to. - :keyword timedelta lock_duration: The value you want to update to. - :keyword bool dead_lettering_on_message_expiration: The value you want to update to. - :keyword timedelta duplicate_detection_history_time_window: The value you want to update to. - :keyword int max_delivery_count: The value you want to update to. + Before calling this method, you should use `get_queue`, `create_queue` or `list_queues` to get a + `QueueProperties` instance, then update the properties. Only a portion of properties can + be updated. Refer to https://docs.microsoft.com/en-us/rest/api/servicebus/update-queue. + + :param queue: The queue that is returned from `get_queue`, `create_queue` or `list_queues` and + has the updated properties. + :type queue: ~azure.servicebus.management.QueueProperties :rtype: None """ to_update = queue._to_internal_entity() - - to_update.default_message_time_to_live = default_message_time_to_live \ - or queue.default_message_time_to_live - to_update.lock_duration = lock_duration or queue.lock_duration - to_update.dead_lettering_on_message_expiration = dead_lettering_on_message_expiration \ - or queue.dead_lettering_on_message_expiration - to_update.duplicate_detection_history_time_window = duplicate_detection_history_time_window or \ - queue.duplicate_detection_history_time_window - to_update.max_delivery_count = max_delivery_count or queue.max_delivery_count - to_update.default_message_time_to_live = avoid_timedelta_overflow(to_update.default_message_time_to_live) to_update.auto_delete_on_idle = avoid_timedelta_overflow(to_update.auto_delete_on_idle) @@ -258,11 +306,11 @@ async def update_queue( **kwargs ) - async def delete_queue(self, queue: Union[str, QueueDescription], **kwargs) -> None: + async def delete_queue(self, queue: Union[str, QueueProperties], **kwargs) -> None: """Delete a queue. - :param Union[str, azure.servicebus.management.QueueDescription] queue: The name of the queue or - a `QueueDescription` with name. + :param Union[str, azure.servicebus.management.QueueProperties] queue: The name of the queue or + a `QueueProperties` with name. :rtype: None """ try: @@ -274,15 +322,15 @@ async def delete_queue(self, queue: Union[str, QueueDescription], **kwargs) -> N with _handle_response_error(): await self._impl.entity.delete(queue_name, api_version=constants.API_VERSION, **kwargs) - def list_queues(self, **kwargs) -> AsyncItemPaged[QueueDescription]: + def list_queues(self, **kwargs) -> AsyncItemPaged[QueueProperties]: """List the queues of a ServiceBus namespace. - :returns: An iterable (auto-paging) response of QueueDescription. - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.QueueDescription] + :returns: An iterable (auto-paging) response of QueueProperties. + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.QueueProperties] """ def entry_to_qd(entry): - qd = QueueDescription._from_internal_entity(entry.title, entry.content.queue_description) + qd = QueueProperties._from_internal_entity(entry.title, entry.content.queue_description) return qd extract_data = functools.partial( @@ -294,15 +342,15 @@ def entry_to_qd(entry): return AsyncItemPaged( get_next, extract_data) - def list_queues_runtime_info(self, **kwargs) -> AsyncItemPaged[QueueRuntimeInfo]: + def list_queues_runtime_info(self, **kwargs) -> AsyncItemPaged[QueueRuntimeProperties]: """List the runtime information of the queues in a ServiceBus namespace. - :returns: An iterable (auto-paging) response of QueueRuntimeInfo. - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.QueueRuntimeInfo] + :returns: An iterable (auto-paging) response of QueueRuntimeProperties. + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.QueueRuntimeProperties] """ def entry_to_qr(entry): - qd = QueueRuntimeInfo._from_internal_entity(entry.title, entry.content.queue_description) + qd = QueueRuntimeProperties._from_internal_entity(entry.title, entry.content.queue_description) return qd extract_data = functools.partial( @@ -314,7 +362,7 @@ def entry_to_qr(entry): return AsyncItemPaged( get_next, extract_data) - async def get_topic(self, topic_name: str, **kwargs) -> TopicDescription: + async def get_topic(self, topic_name: str, **kwargs) -> TopicProperties: """Get the properties of a topic. :param str topic_name: The name of the topic. @@ -324,37 +372,93 @@ async def get_topic(self, topic_name: str, **kwargs) -> TopicDescription: entry = TopicDescriptionEntry.deserialize(entry_ele) if not entry.content: raise ResourceNotFoundError("Topic '{}' does not exist".format(topic_name)) - topic_description = TopicDescription._from_internal_entity(topic_name, entry.content.topic_description) + topic_description = TopicProperties._from_internal_entity(topic_name, entry.content.topic_description) return topic_description - async def get_topic_runtime_info(self, topic_name: str, **kwargs) -> TopicRuntimeInfo: + async def get_topic_runtime_info(self, topic_name: str, **kwargs) -> TopicRuntimeProperties: """Get the runtime information of a topic. :param str topic_name: The name of the topic. - :rtype: ~azure.servicebus.management.TopicRuntimeInfo + :rtype: ~azure.servicebus.management.TopicRuntimeProperties """ entry_ele = await self._get_entity_element(topic_name, **kwargs) entry = TopicDescriptionEntry.deserialize(entry_ele) if not entry.content: raise ResourceNotFoundError("Topic {} does not exist".format(topic_name)) - topic_description = TopicRuntimeInfo._from_internal_entity(topic_name, entry.content.topic_description) + topic_description = TopicRuntimeProperties._from_internal_entity(topic_name, entry.content.topic_description) return topic_description - async def create_topic(self, topic: Union[str, TopicDescription], **kwargs) -> TopicDescription: + async def create_topic(self, name: str, **kwargs) -> TopicProperties: """Create a topic. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic name or a `TopicDescription` - instance. When it's a str, it will be the name of the created topic. Other properties of the created topic - will have default values as defined by the service. - Use a `TopicDescription` if you want to set queue properties other than the queue name. - :rtype: ~azure.servicebus.management.TopicDescription + :param name: Name of the topic. + :type name: str + :keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is + the duration after which the message expires, starting from when the message is sent to Service + Bus. This is the default value used when TimeToLive is not set on a message itself. + :type default_message_time_to_live: ~datetime.timedelta + :keyword max_size_in_megabytes: The maximum size of the topic in megabytes, which is the size of + memory allocated for the topic. + :type max_size_in_megabytes: long + :keyword requires_duplicate_detection: A value indicating if this topic requires duplicate + detection. + :type requires_duplicate_detection: bool + :keyword duplicate_detection_history_time_window: ISO 8601 timeSpan structure that defines the + duration of the duplicate detection history. The default value is 10 minutes. + :type duplicate_detection_history_time_window: ~datetime.timedelta + :keyword enable_batched_operations: Value that indicates whether server-side batched operations + are enabled. + :type enable_batched_operations: bool + :keyword size_in_bytes: The size of the topic, in bytes. + :type size_in_bytes: int + :keyword filtering_messages_before_publishing: Filter messages before publishing. + :type filtering_messages_before_publishing: bool + :keyword is_anonymous_accessible: A value indicating if the resource can be accessed without + authorization. + :type is_anonymous_accessible: bool + :keyword authorization_rules: Authorization rules for resource. + :type authorization_rules: + list[~azure.servicebus.management.AuthorizationRule] + :keyword support_ordering: A value that indicates whether the topic supports ordering. + :type support_ordering: bool + :keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the topic is + automatically deleted. The minimum duration is 5 minutes. + :type auto_delete_on_idle: ~datetime.timedelta + :keyword enable_partitioning: A value that indicates whether the topic is to be partitioned + across multiple message brokers. + :type enable_partitioning: bool + :keyword enable_subscription_partitioning: A value that indicates whether the topic's + subscription is to be partitioned. + :type enable_subscription_partitioning: bool + :keyword enable_express: A value that indicates whether Express Entities are enabled. An express + queue holds a message in memory temporarily before writing it to persistent storage. + :type enable_express: bool + :keyword user_metadata: Metadata associated with the topic. + :type user_metadata: str + + :rtype: ~azure.servicebus.management.TopicProperties """ - try: - topic_name = topic.name # type: ignore - to_create = topic._to_internal_entity() # type: ignore - except AttributeError: - topic_name = topic # type: ignore - to_create = InternalTopicDescription() # Use an empty topic description. + + topic = TopicProperties( + name, + default_message_time_to_live=kwargs.pop("default_message_time_to_live", None), + max_size_in_megabytes=kwargs.pop("max_size_in_megabytes", None), + requires_duplicate_detection=kwargs.pop("requires_duplicate_detection", None), + duplicate_detection_history_time_window=kwargs.pop("duplicate_detection_history_time_window", None), + enable_batched_operations=kwargs.pop("enable_batched_operations", None), + size_in_bytes=kwargs.pop("size_in_bytes", None), + is_anonymous_accessible=kwargs.pop("is_anonymous_accessible", None), + authorization_rules=kwargs.pop("authorization_rules", None), + status=kwargs.pop("status", None), + support_ordering=kwargs.pop("support_ordering", None), + auto_delete_on_idle=kwargs.pop("auto_delete_on_idle", None), + enable_partitioning=kwargs.pop("enable_partitioning", None), + entity_availability_status=kwargs.pop("entity_availability_status", None), + enable_subscription_partitioning=kwargs.pop("enable_subscription_partitioning", None), + enable_express=kwargs.pop("enable_express", None), + user_metadata=kwargs.pop("user_metadata", None) + ) + to_create = topic._to_internal_entity() create_entity_body = CreateTopicBody( content=CreateTopicBodyContent( @@ -366,39 +470,28 @@ async def create_topic(self, topic: Union[str, TopicDescription], **kwargs) -> T entry_ele = cast( ElementTree, await self._impl.entity.put( - topic_name, # type: ignore + name, # type: ignore request_body, api_version=constants.API_VERSION, **kwargs) ) entry = TopicDescriptionEntry.deserialize(entry_ele) - result = TopicDescription._from_internal_entity(topic_name, entry.content.topic_description) + result = TopicProperties._from_internal_entity(name, entry.content.topic_description) return result - async def update_topic( - self, topic: TopicDescription, - *, - default_message_time_to_live: timedelta = None, - duplicate_detection_history_time_window: timedelta = None, - **kwargs) -> None: + async def update_topic(self, topic: TopicProperties, **kwargs) -> None: """Update a topic. - Before calling this method, you should use `get_topic` to get a `TopicDescription` instance, then use the - keyword arguments to update the properties you want to update. - Only a portion of properties can be updated. + Before calling this method, you should use `get_topic`, `create_topic` or `list_topics` to get a + `TopicProperties` instance, then update the properties. Only a portion of properties can be updated. Refer to https://docs.microsoft.com/en-us/rest/api/servicebus/update-topic. - :param ~azure.servicebus.management.TopicDescription topic: The topic to be updated. - :keyword timedelta default_message_time_to_live: The value you want to update to. - :keyword timedelta duplicate_detection_history_time_window: The value you want to update to. + :param topic: The topic that is returned from `get_topic`, `create_topic`, or `list_topics` + and has the updated properties. + :type topic: ~azure.servicebus.management.TopicProperties :rtype: None """ to_update = topic._to_internal_entity() - to_update.default_message_time_to_live = default_message_time_to_live or \ - topic.default_message_time_to_live - to_update.duplicate_detection_history_time_window = duplicate_detection_history_time_window or \ - topic.duplicate_detection_history_time_window - to_update.default_message_time_to_live = avoid_timedelta_overflow(to_update.default_message_time_to_live) to_update.auto_delete_on_idle = avoid_timedelta_overflow(to_update.auto_delete_on_idle) @@ -417,10 +510,10 @@ async def update_topic( **kwargs ) - async def delete_topic(self, topic: Union[str, TopicDescription], **kwargs) -> None: + async def delete_topic(self, topic: Union[str, TopicProperties], **kwargs) -> None: """Delete a topic. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic to be deleted. + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic to be deleted. :rtype: None """ try: @@ -429,14 +522,14 @@ async def delete_topic(self, topic: Union[str, TopicDescription], **kwargs) -> N topic_name = topic await self._impl.entity.delete(topic_name, api_version=constants.API_VERSION, **kwargs) - def list_topics(self, **kwargs) -> AsyncItemPaged[TopicDescription]: + def list_topics(self, **kwargs) -> AsyncItemPaged[TopicProperties]: """List the topics of a ServiceBus namespace. - :returns: An iterable (auto-paging) response of TopicDescription. - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.TopicDescription] + :returns: An iterable (auto-paging) response of TopicProperties. + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.TopicProperties] """ def entry_to_topic(entry): - topic = TopicDescription._from_internal_entity(entry.title, entry.content.topic_description) + topic = TopicProperties._from_internal_entity(entry.title, entry.content.topic_description) return topic extract_data = functools.partial( @@ -448,14 +541,14 @@ def entry_to_topic(entry): return AsyncItemPaged( get_next, extract_data) - def list_topics_runtime_info(self, **kwargs) -> AsyncItemPaged[TopicRuntimeInfo]: + def list_topics_runtime_info(self, **kwargs) -> AsyncItemPaged[TopicRuntimeProperties]: """List the topics runtime information of a ServiceBus namespace. - :returns: An iterable (auto-paging) response of TopicRuntimeInfo. - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.TopicRuntimeInfo] + :returns: An iterable (auto-paging) response of TopicRuntimeProperties. + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.TopicRuntimeProperties] """ def entry_to_topic(entry): - topic = TopicRuntimeInfo._from_internal_entity(entry.title, entry.content.topic_description) + topic = TopicRuntimeProperties._from_internal_entity(entry.title, entry.content.topic_description) return topic extract_data = functools.partial( @@ -468,13 +561,13 @@ def entry_to_topic(entry): get_next, extract_data) async def get_subscription( - self, topic: Union[str, TopicDescription], subscription_name: str, **kwargs - ) -> SubscriptionDescription: + self, topic: Union[str, TopicProperties], subscription_name: str, **kwargs + ) -> SubscriptionProperties: """Get the properties of a topic subscription. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. :param str subscription_name: name of the subscription. - :rtype: ~azure.servicebus.management.SubscriptionDescription + :rtype: ~azure.servicebus.management.SubscriptionProperties """ try: topic_name = topic.name # type: ignore @@ -485,18 +578,18 @@ async def get_subscription( if not entry.content: raise ResourceNotFoundError( "Subscription('Topic: {}, Subscription: {}') does not exist".format(subscription_name, topic_name)) - subscription = SubscriptionDescription._from_internal_entity( + subscription = SubscriptionProperties._from_internal_entity( entry.title, entry.content.subscription_description) return subscription async def get_subscription_runtime_info( - self, topic: Union[str, TopicDescription], subscription_name: str, **kwargs - ) -> SubscriptionRuntimeInfo: + self, topic: Union[str, TopicProperties], subscription_name: str, **kwargs + ) -> SubscriptionRuntimeProperties: """Get a topic subscription runtime info. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. :param str subscription_name: name of the subscription. - :rtype: ~azure.servicebus.management.SubscriptionRuntimeInfo + :rtype: ~azure.servicebus.management.SubscriptionRuntimeProperties """ try: topic_name = topic.name # type: ignore @@ -507,32 +600,78 @@ async def get_subscription_runtime_info( if not entry.content: raise ResourceNotFoundError( "Subscription('Topic: {}, Subscription: {}') does not exist".format(subscription_name, topic_name)) - subscription = SubscriptionRuntimeInfo._from_internal_entity( + subscription = SubscriptionRuntimeProperties._from_internal_entity( entry.title, entry.content.subscription_description) return subscription async def create_subscription( - self, topic: Union[str, TopicDescription], subscription: Union[str, SubscriptionDescription], **kwargs - ) -> SubscriptionDescription: + self, topic: Union[str, TopicProperties], name: str, **kwargs + ) -> SubscriptionProperties: """Create a topic subscription. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that will own the + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that will own the to-be-created subscription. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription name or a - `SubscriptionDescription` instance. When it's a str, it will be the name of the created subscription. - Other properties of the created subscription will have default values as defined by the service. - :rtype: ~azure.servicebus.management.SubscriptionDescription + :param name: Name of the subscription. + :type name: str + :keyword lock_duration: ISO 8601 timespan duration of a peek-lock; that is, the amount of time + that the message is locked for other receivers. The maximum value for LockDuration is 5 + minutes; the default value is 1 minute. + :type lock_duration: ~datetime.timedelta + :keyword requires_session: A value that indicates whether the queue supports the concept of + sessions. + :type requires_session: bool + :keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is + the duration after which the message expires, starting from when the message is sent to Service + Bus. This is the default value used when TimeToLive is not set on a message itself. + :type default_message_time_to_live: ~datetime.timedelta + :keyword dead_lettering_on_message_expiration: A value that indicates whether this subscription + has dead letter support when a message expires. + :type dead_lettering_on_message_expiration: bool + :keyword dead_lettering_on_filter_evaluation_exceptions: A value that indicates whether this + subscription has dead letter support when a message expires. + :type dead_lettering_on_filter_evaluation_exceptions: bool + :keyword max_delivery_count: The maximum delivery count. A message is automatically deadlettered + after this number of deliveries. Default value is 10. + :type max_delivery_count: int + :keyword enable_batched_operations: Value that indicates whether server-side batched operations + are enabled. + :type enable_batched_operations: bool + :keyword forward_to: The name of the recipient entity to which all the messages sent to the + subscription are forwarded to. + :type forward_to: str + :keyword user_metadata: Metadata associated with the subscription. Maximum number of characters + is 1024. + :type user_metadata: str + :keyword forward_dead_lettered_messages_to: The name of the recipient entity to which all the + messages sent to the subscription are forwarded to. + :type forward_dead_lettered_messages_to: str + :keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the subscription is + automatically deleted. The minimum duration is 5 minutes. + :type auto_delete_on_idle: ~datetime.timedelta + :rtype: ~azure.servicebus.management.SubscriptionProperties """ try: topic_name = topic.name # type: ignore except AttributeError: topic_name = topic - try: - subscription_name = subscription.name # type: ignore - to_create = subscription._to_internal_entity() # type: ignore - except AttributeError: - subscription_name = subscription # type: ignore - to_create = InternalSubscriptionDescription() # Use an empty queue description. + subscription = SubscriptionProperties( + name, + lock_duration=kwargs.pop("lock_duration", None), + requires_session=kwargs.pop("requires_session", None), + default_message_time_to_live=kwargs.pop("default_message_time_to_live", None), + dead_lettering_on_message_expiration=kwargs.pop("dead_lettering_on_message_expiration", None), + dead_lettering_on_filter_evaluation_exceptions= + kwargs.pop("dead_lettering_on_filter_evaluation_exceptions", None), + max_delivery_count=kwargs.pop("max_delivery_count", None), + enable_batched_operations=kwargs.pop("enable_batched_operations", None), + status=kwargs.pop("status", None), + forward_to=kwargs.pop("forward_to", None), + user_metadata=kwargs.pop("user_metadata", None), + forward_dead_lettered_messages_to=kwargs.pop("forward_dead_lettered_messages_to", None), + auto_delete_on_idle=kwargs.pop("auto_delete_on_idle", None), + entity_availability_status=kwargs.pop("entity_availability_status", None), + ) + to_create = subscription._to_internal_entity() # type: ignore # pylint:disable=protected-access create_entity_body = CreateSubscriptionBody( content=CreateSubscriptionBodyContent( @@ -545,26 +684,26 @@ async def create_subscription( ElementTree, await self._impl.subscription.put( topic_name, - subscription_name, # type: ignore + name, # type: ignore request_body, api_version=constants.API_VERSION, **kwargs) ) entry = SubscriptionDescriptionEntry.deserialize(entry_ele) - result = SubscriptionDescription._from_internal_entity( - subscription_name, entry.content.subscription_description) + result = SubscriptionProperties._from_internal_entity( + name, entry.content.subscription_description) return result async def update_subscription( - self, topic: Union[str, TopicDescription], subscription: SubscriptionDescription, **kwargs + self, topic: Union[str, TopicProperties], subscription: SubscriptionProperties, **kwargs ) -> None: """Update a subscription. - Before calling this method, you should use `get_subscription` to get a `SubscriptionDescription` instance, - then update the related attributes and call this method. - Only a portion of properties can be updated. + Before calling this method, you should use `get_subscription`, `update_subscription` or `list_subscription` + to get a `SubscriptionProperties` instance, then update the properties. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :param ~azure.servicebus.management.SubscriptionDescription subscription: The subscription to be updated. + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :param ~azure.servicebus.management.SubscriptionProperties subscription: The subscription that is returned + from `get_subscription`, `update_subscription` or `list_subscription` and has the updated properties. :rtype: None """ try: @@ -594,12 +733,12 @@ async def update_subscription( ) async def delete_subscription( - self, topic: Union[str, TopicDescription], subscription: Union[str, SubscriptionDescription], **kwargs + self, topic: Union[str, TopicProperties], subscription: Union[str, SubscriptionProperties], **kwargs ) -> None: """Delete a topic subscription. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.SubscriptionProperties] subscription: The subscription to be deleted. :rtype: None """ @@ -614,12 +753,12 @@ async def delete_subscription( await self._impl.subscription.delete(topic_name, subscription_name, api_version=constants.API_VERSION, **kwargs) def list_subscriptions( - self, topic: Union[str, TopicDescription], **kwargs) -> AsyncItemPaged[SubscriptionDescription]: + self, topic: Union[str, TopicProperties], **kwargs) -> AsyncItemPaged[SubscriptionProperties]: """List the subscriptions of a ServiceBus Topic. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :returns: An iterable (auto-paging) response of SubscriptionDescription. - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.SubscriptionDescription] + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :returns: An iterable (auto-paging) response of SubscriptionProperties. + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.SubscriptionProperties] """ try: topic_name = topic.name # type: ignore @@ -627,7 +766,7 @@ def list_subscriptions( topic_name = topic def entry_to_subscription(entry): - subscription = SubscriptionDescription._from_internal_entity( + subscription = SubscriptionProperties._from_internal_entity( entry.title, entry.content.subscription_description) return subscription @@ -641,12 +780,12 @@ def entry_to_subscription(entry): get_next, extract_data) def list_subscriptions_runtime_info( - self, topic: Union[str, TopicDescription], **kwargs) -> AsyncItemPaged[SubscriptionRuntimeInfo]: + self, topic: Union[str, TopicProperties], **kwargs) -> AsyncItemPaged[SubscriptionRuntimeProperties]: """List the subscriptions runtime information of a ServiceBus. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :returns: An iterable (auto-paging) response of SubscriptionRuntimeInfo. - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.SubscriptionRuntimeInfo] + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :returns: An iterable (auto-paging) response of SubscriptionRuntimeProperties. + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.SubscriptionRuntimeProperties] """ try: topic_name = topic.name # type: ignore @@ -654,7 +793,7 @@ def list_subscriptions_runtime_info( topic_name = topic def entry_to_subscription(entry): - subscription = SubscriptionRuntimeInfo._from_internal_entity( + subscription = SubscriptionRuntimeProperties._from_internal_entity( entry.title, entry.content.subscription_description) return subscription @@ -668,15 +807,15 @@ def entry_to_subscription(entry): get_next, extract_data) async def get_rule( - self, topic: Union[str, TopicDescription], subscription: Union[str, SubscriptionDescription], - rule_name: str, **kwargs) -> RuleDescription: + self, topic: Union[str, TopicProperties], subscription: Union[str, SubscriptionProperties], + rule_name: str, **kwargs) -> RuleProperties: """Get the properties of a topic subscription rule. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription that + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.SubscriptionProperties] subscription: The subscription that owns the rule. :param str rule_name: Name of the rule. - :rtype: ~azure.servicebus.management.RuleDescription + :rtype: ~azure.servicebus.management.RuleProperties """ try: topic_name = topic.name # type: ignore @@ -692,22 +831,28 @@ async def get_rule( raise ResourceNotFoundError( "Rule('Topic: {}, Subscription: {}, Rule {}') does not exist".format( subscription_name, topic_name, rule_name)) - rule_description = RuleDescription._from_internal_entity(rule_name, entry.content.rule_description) + rule_description = RuleProperties._from_internal_entity(rule_name, entry.content.rule_description) deserialize_rule_key_values(entry_ele, rule_description) # to remove after #3535 is released. return rule_description async def create_rule( - self, topic: Union[str, TopicDescription], subscription: Union[str, SubscriptionDescription], - rule: RuleDescription, **kwargs) -> RuleDescription: + self, topic: Union[str, TopicProperties], subscription: Union[str, SubscriptionProperties], + name: str, **kwargs) -> RuleProperties: """Create a rule for a topic subscription. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that will own the + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that will own the to-be-created subscription rule. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription that + :param Union[str, ~azure.servicebus.management.SubscriptionProperties] subscription: The subscription that will own the to-be-created rule. - :param ~azure.servicebus.management.RuleDescription rule: The rule to be created. - Other properties of the created rule will have default values as defined by the service. - :rtype: ~azure.servicebus.management.RuleDescription + :param name: Name of the rule. + :type name: str + :keyword filter: The filter of the rule. + :type filter: Union[~azure.servicebus.management.CorrelationRuleFilter, + ~azure.servicebus.management.SqlRuleFilter] + :keyword action: The action of the rule. + :type action: Optional[~azure.servicebus.management.SqlRuleAction] + + :rtype: ~azure.servicebus.management.RuleProperties """ try: topic_name = topic.name # type: ignore @@ -717,7 +862,12 @@ async def create_rule( subscription_name = subscription.name # type: ignore except AttributeError: subscription_name = subscription - rule_name = rule.name + rule = RuleProperties( + name, + filter=kwargs.pop("filter", None), + action=kwargs.pop("action", None), + created_at=None + ) to_create = rule._to_internal_entity() create_entity_body = CreateRuleBody( @@ -731,26 +881,26 @@ async def create_rule( entry_ele = await self._impl.rule.put( topic_name, subscription_name, # type: ignore - rule_name, + name, request_body, api_version=constants.API_VERSION, **kwargs) entry = RuleDescriptionEntry.deserialize(entry_ele) - result = RuleDescription._from_internal_entity(rule_name, entry.content.rule_description) + result = RuleProperties._from_internal_entity(name, entry.content.rule_description) deserialize_rule_key_values(entry_ele, result) # to remove after #3535 is released. return result async def update_rule( - self, topic: Union[str, TopicDescription], subscription: Union[str, SubscriptionDescription], - rule: RuleDescription, **kwargs) -> None: + self, topic: Union[str, TopicProperties], subscription: Union[str, SubscriptionProperties], + rule: RuleProperties, **kwargs) -> None: """Update a rule. - Before calling this method, you should use `get_rule` to get a `RuleDescription` instance, - then update the related attributes and call this method. - Only a portion of properties can be updated. + Before calling this method, you should use `get_rule`, `create_rule` or `list_rules` to get a `RuleProperties` + instance, then update the properties. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription that + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.SubscriptionProperties] subscription: The subscription that owns this rule. - :param ~azure.servicebus.management.RuleDescription rule: The rule to be updated. + :param ~azure.servicebus.management.RuleProperties rule: The rule that is returned from `get_rule`, + `create_rule`, or `list_rules` and has the updated properties. :rtype: None """ @@ -784,14 +934,14 @@ async def update_rule( ) async def delete_rule( - self, topic: Union[str, TopicDescription], subscription: Union[str, SubscriptionDescription], - rule: Union[str, RuleDescription], **kwargs) -> None: + self, topic: Union[str, TopicProperties], subscription: Union[str, SubscriptionProperties], + rule: Union[str, RuleProperties], **kwargs) -> None: """Delete a topic subscription rule. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription that + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.SubscriptionProperties] subscription: The subscription that owns the topic. - :param Union[str, ~azure.servicebus.management.RuleDescription] rule: The to-be-deleted rule. + :param Union[str, ~azure.servicebus.management.RuleProperties] rule: The to-be-deleted rule. :rtype: None """ try: @@ -810,15 +960,15 @@ async def delete_rule( topic_name, subscription_name, rule_name, api_version=constants.API_VERSION, **kwargs) def list_rules( - self, topic: Union[str, TopicDescription], subscription: Union[str, SubscriptionDescription], **kwargs - ) -> AsyncItemPaged[RuleDescription]: + self, topic: Union[str, TopicProperties], subscription: Union[str, SubscriptionProperties], **kwargs + ) -> AsyncItemPaged[RuleProperties]: """List the rules of a topic subscription. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription that + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.SubscriptionProperties] subscription: The subscription that owns the rules. - :returns: An iterable (auto-paging) response of RuleDescription. - :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.RuleDescription] + :returns: An iterable (auto-paging) response of RuleProperties. + :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.servicebus.management.RuleProperties] """ try: topic_name = topic.name # type: ignore @@ -834,7 +984,7 @@ def entry_to_rule(ele, entry): `ele` will be removed after #3535 is released. """ rule = entry.content.rule_description - rule_description = RuleDescription._from_internal_entity(entry.title, rule) + rule_description = RuleProperties._from_internal_entity(entry.title, rule) deserialize_rule_key_values(ele, rule_description) # to remove after #3535 is released. return rule_description diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/management/__init__.py b/sdk/servicebus/azure-servicebus/azure/servicebus/management/__init__.py index b6941307ef95..41f9230c874e 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/management/__init__.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/management/__init__.py @@ -8,8 +8,8 @@ AccessRights, EntityAvailabilityStatus, EntityStatus, \ NamespaceProperties, MessagingSku, NamespaceType -from ._models import QueueRuntimeInfo, QueueDescription, TopicRuntimeInfo, TopicDescription, \ - SubscriptionDescription, SubscriptionRuntimeInfo, RuleDescription, \ +from ._models import QueueRuntimeProperties, QueueProperties, TopicRuntimeProperties, TopicProperties, \ + SubscriptionRuntimeProperties, SubscriptionProperties, RuleProperties, \ TrueRuleFilter, FalseRuleFilter, SqlRuleFilter, CorrelationRuleFilter, \ SqlRuleAction @@ -17,16 +17,16 @@ 'ServiceBusManagementClient', 'AuthorizationRule', 'MessageCountDetails', - 'QueueDescription', - 'QueueRuntimeInfo', - 'TopicDescription', - 'TopicRuntimeInfo', - 'SubscriptionDescription', - 'SubscriptionRuntimeInfo', + 'QueueProperties', + 'QueueRuntimeProperties', + 'TopicProperties', + 'TopicRuntimeProperties', + 'SubscriptionProperties', + 'SubscriptionRuntimeProperties', 'AccessRights', 'EntityAvailabilityStatus', 'EntityStatus', - 'RuleDescription', + 'RuleProperties', 'CorrelationRuleFilter', 'SqlRuleFilter', 'TrueRuleFilter', 'FalseRuleFilter', 'SqlRuleAction', 'NamespaceProperties', 'MessagingSku', 'NamespaceType', diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/management/_management_client.py b/sdk/servicebus/azure-servicebus/azure/servicebus/management/_management_client.py index ff74e6d94779..56aaeed2e111 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/management/_management_client.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/management/_management_client.py @@ -4,6 +4,7 @@ # -------------------------------------------------------------------------------------------- # pylint:disable=protected-access # pylint:disable=specify-parameter-names-in-call +# pylint:disable=too-many-lines import functools from typing import TYPE_CHECKING, Dict, Any, Union, cast from xml.etree.ElementTree import ElementTree @@ -19,10 +20,7 @@ QueueDescriptionEntry, SubscriptionDescriptionFeed, SubscriptionDescriptionEntry, RuleDescriptionEntry, \ RuleDescriptionFeed, NamespacePropertiesEntry, CreateTopicBody, CreateTopicBodyContent, \ TopicDescriptionFeed, CreateSubscriptionBody, CreateSubscriptionBodyContent, CreateRuleBody, \ - CreateRuleBodyContent, CreateQueueBody, CreateQueueBodyContent, \ - QueueDescription as InternalQueueDescription, TopicDescription as InternalTopicDescription, \ - SubscriptionDescription as InternalSubscriptionDescription, \ - NamespaceProperties + CreateRuleBodyContent, CreateQueueBody, CreateQueueBodyContent, NamespaceProperties from ._utils import extract_data_template, get_next_template, deserialize_rule_key_values, serialize_rule_key_values, \ extract_rule_data_template from ._xml_workaround_policy import ServiceBusXMLWorkaroundPolicy @@ -35,8 +33,8 @@ from ._generated._service_bus_management_client import ServiceBusManagementClient as ServiceBusManagementClientImpl from ._model_workaround import avoid_timedelta_overflow from . import _constants as constants -from ._models import QueueRuntimeInfo, QueueDescription, TopicDescription, TopicRuntimeInfo, \ - SubscriptionDescription, SubscriptionRuntimeInfo, RuleDescription +from ._models import QueueRuntimeProperties, QueueProperties, TopicProperties, TopicRuntimeProperties, \ + SubscriptionProperties, SubscriptionRuntimeProperties, RuleProperties from ._handle_response_error import _handle_response_error if TYPE_CHECKING: @@ -138,50 +136,120 @@ def from_connection_string(cls, conn_str, **kwargs): return cls(endpoint, ServiceBusSharedKeyCredential(shared_access_key_name, shared_access_key), **kwargs) def get_queue(self, queue_name, **kwargs): - # type: (str, Any) -> QueueDescription + # type: (str, Any) -> QueueProperties """Get the properties of a queue. :param str queue_name: The name of the queue. - :rtype: ~azure.servicebus.management.QueueDescription + :rtype: ~azure.servicebus.management.QueueProperties """ entry_ele = self._get_entity_element(queue_name, **kwargs) entry = QueueDescriptionEntry.deserialize(entry_ele) if not entry.content: raise ResourceNotFoundError("Queue '{}' does not exist".format(queue_name)) - queue_description = QueueDescription._from_internal_entity(queue_name, entry.content.queue_description) + queue_description = QueueProperties._from_internal_entity(queue_name, entry.content.queue_description) return queue_description def get_queue_runtime_info(self, queue_name, **kwargs): - # type: (str, Any) -> QueueRuntimeInfo + # type: (str, Any) -> QueueRuntimeProperties """Get the runtime information of a queue. :param str queue_name: The name of the queue. - :rtype: ~azure.servicebus.management.QueueRuntimeInfo + :rtype: ~azure.servicebus.management.QueueRuntimeProperties """ entry_ele = self._get_entity_element(queue_name, **kwargs) entry = QueueDescriptionEntry.deserialize(entry_ele) if not entry.content: raise ResourceNotFoundError("Queue {} does not exist".format(queue_name)) - runtime_info = QueueRuntimeInfo._from_internal_entity(queue_name, entry.content.queue_description) + runtime_info = QueueRuntimeProperties._from_internal_entity(queue_name, entry.content.queue_description) return runtime_info - def create_queue(self, queue, **kwargs): - # type: (Union[str, QueueDescription], Any) -> QueueDescription + def create_queue(self, name, **kwargs): + # type: (str, Any) -> QueueProperties """Create a queue. - :param queue: The queue name or a `QueueDescription` instance. When it's a str, it will be the name - of the created queue. Other properties of the created queue will have default values as defined by the - service. Use a `QueueDescription` if you want to set queue properties other than the queue name. - :type queue: Union[str, ~azure.servicebus.management.QueueDescription] - :rtype: ~azure.servicebus.management.QueueDescription + :param name: Name of the queue. + :type name: str + :keyword authorization_rules: Authorization rules for resource. + :type authorization_rules: list[~azure.servicebus.management.AuthorizationRule] + :keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the queue is + automatically deleted. The minimum duration is 5 minutes. + :type auto_delete_on_idle: ~datetime.timedelta + :keyword dead_lettering_on_message_expiration: A value that indicates whether this queue has dead + letter support when a message expires. + :type dead_lettering_on_message_expiration: bool + :keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is + the duration after which the message expires, starting from when the message is sent to Service + Bus. This is the default value used when TimeToLive is not set on a message itself. + :type default_message_time_to_live: ~datetime.timedelta + :keyword duplicate_detection_history_time_window: ISO 8601 timeSpan structure that defines the + duration of the duplicate detection history. The default value is 10 minutes. + :type duplicate_detection_history_time_window: ~datetime.timedelta + :keyword enable_batched_operations: Value that indicates whether server-side batched operations + are enabled. + :type enable_batched_operations: bool + :keyword enable_express: A value that indicates whether Express Entities are enabled. An express + queue holds a message in memory temporarily before writing it to persistent storage. + :type enable_express: bool + :keyword enable_partitioning: A value that indicates whether the queue is to be partitioned + across multiple message brokers. + :type enable_partitioning: bool + :keyword is_anonymous_accessible: A value indicating if the resource can be accessed without + authorization. + :type is_anonymous_accessible: bool + :keyword lock_duration: ISO 8601 timespan duration of a peek-lock; that is, the amount of time + that the message is locked for other receivers. The maximum value for LockDuration is 5 + minutes; the default value is 1 minute. + :type lock_duration: ~datetime.timedelta + :keyword max_delivery_count: The maximum delivery count. A message is automatically deadlettered + after this number of deliveries. Default value is 10. + :type max_delivery_count: int + :keyword max_size_in_megabytes: The maximum size of the queue in megabytes, which is the size of + memory allocated for the queue. + :type max_size_in_megabytes: int + :keyword requires_duplicate_detection: A value indicating if this queue requires duplicate + detection. + :type requires_duplicate_detection: bool + :keyword requires_session: A value that indicates whether the queue supports the concept of + sessions. + :type requires_session: bool + :keyword forward_to: The name of the recipient entity to which all the messages sent to the queue + are forwarded to. + :type forward_to: str + :keyword user_metadata: Custom metdata that user can associate with the description. Max length + is 1024 chars. + :type user_metadata: str + :keyword support_ordering: A value that indicates whether the queue supports ordering. + :type support_ordering: bool + :keyword forward_dead_lettered_messages_to: The name of the recipient entity to which all the + dead-lettered messages of this subscription are forwarded to. + :type forward_dead_lettered_messages_to: str + + :rtype: ~azure.servicebus.management.QueueProperties """ - try: - queue_name = queue.name # type: ignore - to_create = queue._to_internal_entity() # type: ignore # pylint:disable=protected-access - except AttributeError: - queue_name = queue # type: ignore - to_create = InternalQueueDescription() # Use an empty queue description. - + queue = QueueProperties( + name, + authorization_rules=kwargs.pop("authorization_rules", None), + auto_delete_on_idle=kwargs.pop("auto_delete_on_idle", None), + dead_lettering_on_message_expiration=kwargs.pop("dead_lettering_on_message_expiration", None), + default_message_time_to_live=kwargs.pop("default_message_time_to_live", None), + duplicate_detection_history_time_window=kwargs.pop("duplicate_detection_history_time_window", None), + entity_availability_status=kwargs.pop("entity_availability_status", None), + enable_batched_operations=kwargs.pop("enable_batched_operations", None), + enable_express=kwargs.pop("enable_express", None), + enable_partitioning=kwargs.pop("enable_partitioning", None), + is_anonymous_accessible=kwargs.pop("is_anonymous_accessible", None), + lock_duration=kwargs.pop("lock_duration", None), + max_delivery_count=kwargs.pop("max_delivery_count", None), + max_size_in_megabytes=kwargs.pop("max_size_in_megabytes", None), + requires_duplicate_detection=kwargs.pop("requires_duplicate_detection", None), + requires_session=kwargs.pop("requires_session", None), + status=kwargs.pop("status", None), + support_ordering=kwargs.pop("support_ordering", None), + forward_to=kwargs.pop("forward_to", None), + forward_dead_lettered_messages_to=kwargs.pop("forward_dead_lettered_messages_to", None), + user_metadata=kwargs.pop("user_metadata", None) + ) + to_create = queue._to_internal_entity() create_entity_body = CreateQueueBody( content=CreateQueueBodyContent( queue_description=to_create, # type: ignore @@ -192,44 +260,30 @@ def create_queue(self, queue, **kwargs): entry_ele = cast( ElementTree, self._impl.entity.put( - queue_name, # type: ignore + name, # type: ignore request_body, api_version=constants.API_VERSION, **kwargs) ) entry = QueueDescriptionEntry.deserialize(entry_ele) - result = QueueDescription._from_internal_entity(queue_name, entry.content.queue_description) + result = QueueProperties._from_internal_entity(name, entry.content.queue_description) return result def update_queue(self, queue, **kwargs): - # type: (QueueDescription, Any) -> None + # type: (QueueProperties, Any) -> None """Update a queue. - Before calling this method, you should use `get_queue` to get a `QueueDescription` instance, then use the - keyword arguments to update the properties you want to update. - Only a portion of properties can be updated. - Refer to https://docs.microsoft.com/en-us/rest/api/servicebus/update-queue. - - :param queue: The queue to be updated. - :type queue: ~azure.servicebus.management.QueueDescription - :keyword timedelta default_message_time_to_live: The value you want to update to. - :keyword timedelta lock_duration: The value you want to update to. - :keyword bool dead_lettering_on_message_expiration: The value you want to update to. - :keyword timedelta duplicate_detection_history_time_window: The value you want to update to. - :keyword int max_delivery_count: The value you want to update to. + Before calling this method, you should use `get_queue`, `create_queue` or `list_queues` to get a + `QueueProperties` instance, then update the properties. Only a portion of properties can + be updated. Refer to https://docs.microsoft.com/en-us/rest/api/servicebus/update-queue. + + :param queue: The queue that is returned from `get_queue`, `create_queue` or `list_queues` and + has the updated properties. + :type queue: ~azure.servicebus.management.QueueProperties :rtype: None """ to_update = queue._to_internal_entity() - to_update.default_message_time_to_live = kwargs.get( - "default_message_time_to_live") or queue.default_message_time_to_live - to_update.lock_duration = kwargs.get("lock_duration") or queue.lock_duration - to_update.dead_lettering_on_message_expiration = kwargs.get( - "dead_lettering_on_message_expiration") or queue.dead_lettering_on_message_expiration - to_update.duplicate_detection_history_time_window = kwargs.get( - "duplicate_detection_history_time_window") or queue.duplicate_detection_history_time_window - to_update.max_delivery_count = kwargs.get("max_delivery_count") or queue.max_delivery_count - to_update.default_message_time_to_live = avoid_timedelta_overflow(to_update.default_message_time_to_live) to_update.auto_delete_on_idle = avoid_timedelta_overflow(to_update.auto_delete_on_idle) @@ -249,11 +303,11 @@ def update_queue(self, queue, **kwargs): ) def delete_queue(self, queue, **kwargs): - # type: (Union[str, QueueDescription], Any) -> None + # type: (Union[str, QueueProperties], Any) -> None """Delete a queue. - :param Union[str, azure.servicebus.management.QueueDescription] queue: The name of the queue or - a `QueueDescription` with name. + :param Union[str, azure.servicebus.management.QueueProperties] queue: The name of the queue or + a `QueueProperties` with name. :rtype: None """ try: @@ -268,15 +322,15 @@ def delete_queue(self, queue, **kwargs): api_version=constants.API_VERSION, **kwargs) def list_queues(self, **kwargs): - # type: (Any) -> ItemPaged[QueueDescription] + # type: (Any) -> ItemPaged[QueueProperties] """List the queues of a ServiceBus namespace. - :returns: An iterable (auto-paging) response of QueueDescription. - :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.QueueDescription] + :returns: An iterable (auto-paging) response of QueueProperties. + :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.QueueProperties] """ def entry_to_qd(entry): - qd = QueueDescription._from_internal_entity(entry.title, entry.content.queue_description) + qd = QueueProperties._from_internal_entity(entry.title, entry.content.queue_description) return qd extract_data = functools.partial( @@ -289,15 +343,15 @@ def entry_to_qd(entry): get_next, extract_data) def list_queues_runtime_info(self, **kwargs): - # type: (Any) -> ItemPaged[QueueRuntimeInfo] + # type: (Any) -> ItemPaged[QueueRuntimeProperties] """List the runtime information of the queues in a ServiceBus namespace. - :returns: An iterable (auto-paging) response of QueueRuntimeInfo. - :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.QueueRuntimeInfo] + :returns: An iterable (auto-paging) response of QueueRuntimeProperties. + :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.QueueRuntimeProperties] """ def entry_to_qr(entry): - qd = QueueRuntimeInfo._from_internal_entity(entry.title, entry.content.queue_description) + qd = QueueRuntimeProperties._from_internal_entity(entry.title, entry.content.queue_description) return qd extract_data = functools.partial( @@ -310,49 +364,104 @@ def entry_to_qr(entry): get_next, extract_data) def get_topic(self, topic_name, **kwargs): - # type: (str, Any) -> TopicDescription + # type: (str, Any) -> TopicProperties """Get the properties of a topic. :param str topic_name: The name of the topic. - :rtype: ~azure.servicebus.management.TopicDescription + :rtype: ~azure.servicebus.management.TopicProperties """ entry_ele = self._get_entity_element(topic_name, **kwargs) entry = TopicDescriptionEntry.deserialize(entry_ele) if not entry.content: raise ResourceNotFoundError("Topic '{}' does not exist".format(topic_name)) - topic_description = TopicDescription._from_internal_entity(topic_name, entry.content.topic_description) + topic_description = TopicProperties._from_internal_entity(topic_name, entry.content.topic_description) return topic_description def get_topic_runtime_info(self, topic_name, **kwargs): - # type: (str, Any) -> TopicRuntimeInfo + # type: (str, Any) -> TopicRuntimeProperties """Get a the runtime information of a topic. :param str topic_name: The name of the topic. - :rtype: ~azure.servicebus.management.TopicRuntimeInfo + :rtype: ~azure.servicebus.management.TopicRuntimeProperties """ entry_ele = self._get_entity_element(topic_name, **kwargs) entry = TopicDescriptionEntry.deserialize(entry_ele) if not entry.content: raise ResourceNotFoundError("Topic {} does not exist".format(topic_name)) - topic_description = TopicRuntimeInfo._from_internal_entity(topic_name, entry.content.topic_description) + topic_description = TopicRuntimeProperties._from_internal_entity(topic_name, entry.content.topic_description) return topic_description - def create_topic(self, topic, **kwargs): - # type: (Union[str, TopicDescription], Any) -> TopicDescription + def create_topic(self, name, **kwargs): + # type: (str, Any) -> TopicProperties """Create a topic. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic name or a `TopicDescription` - instance. When it's a str, it will be the name of the created topic. Other properties of the created topic - will have default values as defined by the service. - Use a `TopicDescription` if you want to set queue properties other than the queue name. - :rtype: ~azure.servicebus.management.TopicDescription + :param name: Name of the topic. + :type name: str + :keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is + the duration after which the message expires, starting from when the message is sent to Service + Bus. This is the default value used when TimeToLive is not set on a message itself. + :type default_message_time_to_live: ~datetime.timedelta + :keyword max_size_in_megabytes: The maximum size of the topic in megabytes, which is the size of + memory allocated for the topic. + :type max_size_in_megabytes: long + :keyword requires_duplicate_detection: A value indicating if this topic requires duplicate + detection. + :type requires_duplicate_detection: bool + :keyword duplicate_detection_history_time_window: ISO 8601 timeSpan structure that defines the + duration of the duplicate detection history. The default value is 10 minutes. + :type duplicate_detection_history_time_window: ~datetime.timedelta + :keyword enable_batched_operations: Value that indicates whether server-side batched operations + are enabled. + :type enable_batched_operations: bool + :keyword size_in_bytes: The size of the topic, in bytes. + :type size_in_bytes: int + :keyword filtering_messages_before_publishing: Filter messages before publishing. + :type filtering_messages_before_publishing: bool + :keyword is_anonymous_accessible: A value indicating if the resource can be accessed without + authorization. + :type is_anonymous_accessible: bool + :keyword authorization_rules: Authorization rules for resource. + :type authorization_rules: + list[~azure.servicebus.management.AuthorizationRule] + :keyword support_ordering: A value that indicates whether the topic supports ordering. + :type support_ordering: bool + :keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the topic is + automatically deleted. The minimum duration is 5 minutes. + :type auto_delete_on_idle: ~datetime.timedelta + :keyword enable_partitioning: A value that indicates whether the topic is to be partitioned + across multiple message brokers. + :type enable_partitioning: bool + :keyword enable_subscription_partitioning: A value that indicates whether the topic's + subscription is to be partitioned. + :type enable_subscription_partitioning: bool + :keyword enable_express: A value that indicates whether Express Entities are enabled. An express + queue holds a message in memory temporarily before writing it to persistent storage. + :type enable_express: bool + :keyword user_metadata: Metadata associated with the topic. + :type user_metadata: str + + :rtype: ~azure.servicebus.management.TopicProperties """ - try: - topic_name = topic.name # type: ignore - to_create = topic._to_internal_entity() # type: ignore # pylint:disable=protected-access - except AttributeError: - topic_name = topic # type: ignore - to_create = InternalTopicDescription() # Use an empty topic description. + topic = TopicProperties( + name, + default_message_time_to_live=kwargs.pop("default_message_time_to_live", None), + max_size_in_megabytes=kwargs.pop("max_size_in_megabytes", None), + requires_duplicate_detection=kwargs.pop("requires_duplicate_detection", None), + duplicate_detection_history_time_window=kwargs.pop("duplicate_detection_history_time_window", None), + enable_batched_operations=kwargs.pop("enable_batched_operations", None), + size_in_bytes=kwargs.pop("size_in_bytes", None), + is_anonymous_accessible=kwargs.pop("is_anonymous_accessible", None), + authorization_rules=kwargs.pop("authorization_rules", None), + status=kwargs.pop("status", None), + support_ordering=kwargs.pop("support_ordering", None), + auto_delete_on_idle=kwargs.pop("auto_delete_on_idle", None), + enable_partitioning=kwargs.pop("enable_partitioning", None), + entity_availability_status=kwargs.pop("entity_availability_status", None), + enable_subscription_partitioning=kwargs.pop("enable_subscription_partitioning", None), + enable_express=kwargs.pop("enable_express", None), + user_metadata=kwargs.pop("user_metadata", None) + ) + to_create = topic._to_internal_entity() create_entity_body = CreateTopicBody( content=CreateTopicBodyContent( @@ -364,25 +473,24 @@ def create_topic(self, topic, **kwargs): entry_ele = cast( ElementTree, self._impl.entity.put( - topic_name, # type: ignore + name, # type: ignore request_body, api_version=constants.API_VERSION, **kwargs) ) entry = TopicDescriptionEntry.deserialize(entry_ele) - result = TopicDescription._from_internal_entity(topic_name, entry.content.topic_description) + result = TopicProperties._from_internal_entity(name, entry.content.topic_description) return result def update_topic(self, topic, **kwargs): - # type: (TopicDescription, Any) -> None + # type: (TopicProperties, Any) -> None """Update a topic. - Before calling this method, you should use `get_topic` to get a `TopicDescription` instance, then use the - keyword arguments to update the properties you want to update. - Only a portion of properties can be updated. + Before calling this method, you should use `get_topic`, `create_topic` or `list_topics` to get a + `TopicProperties` instance, then update the properties. Only a portion of properties can be updated. Refer to https://docs.microsoft.com/en-us/rest/api/servicebus/update-topic. - :param ~azure.servicebus.management.TopicDescription topic: The topic to be updated. - :keyword timedelta default_message_time_to_live: The value you want to update to. - :keyword timedelta duplicate_detection_history_time_window: The value you want to update to. + :param topic: The topic that is returned from `get_topic`, `create_topic`, or `list_topics` + and has the updated properties. + :type topic: ~azure.servicebus.management.TopicProperties :rtype: None """ @@ -412,10 +520,10 @@ def update_topic(self, topic, **kwargs): ) def delete_topic(self, topic, **kwargs): - # type: (Union[str, TopicDescription], Any) -> None + # type: (Union[str, TopicProperties], Any) -> None """Delete a topic. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic to be deleted. + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic to be deleted. :rtype: None """ try: @@ -425,14 +533,14 @@ def delete_topic(self, topic, **kwargs): self._impl.entity.delete(topic_name, api_version=constants.API_VERSION, **kwargs) def list_topics(self, **kwargs): - # type: (Any) -> ItemPaged[TopicDescription] + # type: (Any) -> ItemPaged[TopicProperties] """List the topics of a ServiceBus namespace. - :returns: An iterable (auto-paging) response of TopicDescription. - :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.TopicDescription] + :returns: An iterable (auto-paging) response of TopicProperties. + :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.TopicProperties] """ def entry_to_topic(entry): - topic = TopicDescription._from_internal_entity(entry.title, entry.content.topic_description) + topic = TopicProperties._from_internal_entity(entry.title, entry.content.topic_description) return topic extract_data = functools.partial( @@ -445,14 +553,14 @@ def entry_to_topic(entry): get_next, extract_data) def list_topics_runtime_info(self, **kwargs): - # type: (Any) -> ItemPaged[TopicRuntimeInfo] + # type: (Any) -> ItemPaged[TopicRuntimeProperties] """List the topics runtime information of a ServiceBus namespace. - :returns: An iterable (auto-paging) response of TopicRuntimeInfo. - :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.TopicRuntimeInfo] + :returns: An iterable (auto-paging) response of TopicRuntimeProperties. + :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.TopicRuntimeProperties] """ def entry_to_topic(entry): - topic = TopicRuntimeInfo._from_internal_entity(entry.title, entry.content.topic_description) + topic = TopicRuntimeProperties._from_internal_entity(entry.title, entry.content.topic_description) return topic extract_data = functools.partial( @@ -465,12 +573,12 @@ def entry_to_topic(entry): get_next, extract_data) def get_subscription(self, topic, subscription_name, **kwargs): - # type: (Union[str, TopicDescription], str, Any) -> SubscriptionDescription + # type: (Union[str, TopicProperties], str, Any) -> SubscriptionProperties """Get the properties of a topic subscription. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. :param str subscription_name: name of the subscription. - :rtype: ~azure.servicebus.management.SubscriptionDescription + :rtype: ~azure.servicebus.management.SubscriptionProperties """ try: topic_name = topic.name # type: ignore @@ -481,17 +589,17 @@ def get_subscription(self, topic, subscription_name, **kwargs): if not entry.content: raise ResourceNotFoundError( "Subscription('Topic: {}, Subscription: {}') does not exist".format(subscription_name, topic_name)) - subscription = SubscriptionDescription._from_internal_entity( + subscription = SubscriptionProperties._from_internal_entity( entry.title, entry.content.subscription_description) return subscription def get_subscription_runtime_info(self, topic, subscription_name, **kwargs): - # type: (Union[str, TopicDescription], str, Any) -> SubscriptionRuntimeInfo + # type: (Union[str, TopicProperties], str, Any) -> SubscriptionRuntimeProperties """Get a topic subscription runtime info. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. :param str subscription_name: name of the subscription. - :rtype: ~azure.servicebus.management.SubscriptionRuntimeInfo + :rtype: ~azure.servicebus.management.SubscriptionRuntimeProperties """ try: topic_name = topic.name # type: ignore @@ -502,31 +610,77 @@ def get_subscription_runtime_info(self, topic, subscription_name, **kwargs): if not entry.content: raise ResourceNotFoundError( "Subscription('Topic: {}, Subscription: {}') does not exist".format(subscription_name, topic_name)) - subscription = SubscriptionRuntimeInfo._from_internal_entity( + subscription = SubscriptionRuntimeProperties._from_internal_entity( entry.title, entry.content.subscription_description) return subscription - def create_subscription(self, topic, subscription, **kwargs): - # type: (Union[str, TopicDescription], Union[str, SubscriptionDescription], Any) -> SubscriptionDescription + def create_subscription(self, topic, name, **kwargs): + # type: (Union[str, TopicProperties], str, Any) -> SubscriptionProperties """Create a topic subscription. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that will own the + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that will own the to-be-created subscription. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription name or a - `SubscriptionDescription` instance. When it's a str, it will be the name of the created subscription. - Other properties of the created subscription will have default values as defined by the service. - :rtype: ~azure.servicebus.management.SubscriptionDescription + :param name: Name of the subscription. + :type name: str + :keyword lock_duration: ISO 8601 timespan duration of a peek-lock; that is, the amount of time + that the message is locked for other receivers. The maximum value for LockDuration is 5 + minutes; the default value is 1 minute. + :type lock_duration: ~datetime.timedelta + :keyword requires_session: A value that indicates whether the queue supports the concept of + sessions. + :type requires_session: bool + :keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is + the duration after which the message expires, starting from when the message is sent to Service + Bus. This is the default value used when TimeToLive is not set on a message itself. + :type default_message_time_to_live: ~datetime.timedelta + :keyword dead_lettering_on_message_expiration: A value that indicates whether this subscription + has dead letter support when a message expires. + :type dead_lettering_on_message_expiration: bool + :keyword dead_lettering_on_filter_evaluation_exceptions: A value that indicates whether this + subscription has dead letter support when a message expires. + :type dead_lettering_on_filter_evaluation_exceptions: bool + :keyword max_delivery_count: The maximum delivery count. A message is automatically deadlettered + after this number of deliveries. Default value is 10. + :type max_delivery_count: int + :keyword enable_batched_operations: Value that indicates whether server-side batched operations + are enabled. + :type enable_batched_operations: bool + :keyword forward_to: The name of the recipient entity to which all the messages sent to the + subscription are forwarded to. + :type forward_to: str + :keyword user_metadata: Metadata associated with the subscription. Maximum number of characters + is 1024. + :type user_metadata: str + :keyword forward_dead_lettered_messages_to: The name of the recipient entity to which all the + messages sent to the subscription are forwarded to. + :type forward_dead_lettered_messages_to: str + :keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the subscription is + automatically deleted. The minimum duration is 5 minutes. + :type auto_delete_on_idle: ~datetime.timedelta + :rtype: ~azure.servicebus.management.SubscriptionProperties """ try: topic_name = topic.name # type: ignore except AttributeError: topic_name = topic - try: - subscription_name = subscription.name # type: ignore - to_create = subscription._to_internal_entity() # type: ignore # pylint:disable=protected-access - except AttributeError: - subscription_name = subscription # type: ignore - to_create = InternalSubscriptionDescription() # Use an empty queue description. + subscription = SubscriptionProperties( + name, + lock_duration=kwargs.pop("lock_duration", None), + requires_session=kwargs.pop("requires_session", None), + default_message_time_to_live=kwargs.pop("default_message_time_to_live", None), + dead_lettering_on_message_expiration=kwargs.pop("dead_lettering_on_message_expiration", None), + dead_lettering_on_filter_evaluation_exceptions= + kwargs.pop("dead_lettering_on_filter_evaluation_exceptions", None), + max_delivery_count=kwargs.pop("max_delivery_count", None), + enable_batched_operations=kwargs.pop("enable_batched_operations", None), + status=kwargs.pop("status", None), + forward_to=kwargs.pop("forward_to", None), + user_metadata=kwargs.pop("user_metadata", None), + forward_dead_lettered_messages_to=kwargs.pop("forward_dead_lettered_messages_to", None), + auto_delete_on_idle=kwargs.pop("auto_delete_on_idle", None), + entity_availability_status=kwargs.pop("entity_availability_status", None), + ) + to_create = subscription._to_internal_entity() # type: ignore # pylint:disable=protected-access create_entity_body = CreateSubscriptionBody( content=CreateSubscriptionBodyContent( @@ -539,25 +693,25 @@ def create_subscription(self, topic, subscription, **kwargs): ElementTree, self._impl.subscription.put( topic_name, - subscription_name, # type: ignore + name, # type: ignore request_body, api_version=constants.API_VERSION, **kwargs) ) entry = SubscriptionDescriptionEntry.deserialize(entry_ele) - result = SubscriptionDescription._from_internal_entity( - subscription_name, entry.content.subscription_description) + result = SubscriptionProperties._from_internal_entity( + name, entry.content.subscription_description) return result def update_subscription(self, topic, subscription, **kwargs): - # type: (Union[str, TopicDescription], SubscriptionDescription, Any) -> None + # type: (Union[str, TopicProperties], SubscriptionProperties, Any) -> None """Update a subscription. - Before calling this method, you should use `get_subscription` to get a `SubscriptionDescription` instance, - then update the related attributes and call this method. - Only a portion of properties can be updated. + Before calling this method, you should use `get_subscription`, `update_subscription` or `list_subscription` + to get a `SubscriptionProperties` instance, then update the properties. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :param ~azure.servicebus.management.SubscriptionDescription subscription: The subscription to be updated. + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :param ~azure.servicebus.management.SubscriptionProperties subscription: The subscription that is returned + from `get_subscription`, `update_subscription` or `list_subscription` and has the updated properties. :rtype: None """ try: @@ -587,11 +741,11 @@ def update_subscription(self, topic, subscription, **kwargs): ) def delete_subscription(self, topic, subscription, **kwargs): - # type: (Union[str, TopicDescription], Union[str, SubscriptionDescription], Any) -> None + # type: (Union[str, TopicProperties], Union[str, SubscriptionProperties], Any) -> None """Delete a topic subscription. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription to + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.SubscriptionProperties] subscription: The subscription to be deleted. :rtype: None """ @@ -606,12 +760,12 @@ def delete_subscription(self, topic, subscription, **kwargs): self._impl.subscription.delete(topic_name, subscription_name, api_version=constants.API_VERSION, **kwargs) def list_subscriptions(self, topic, **kwargs): - # type: (Union[str, TopicDescription], Any) -> ItemPaged[SubscriptionDescription] + # type: (Union[str, TopicProperties], Any) -> ItemPaged[SubscriptionProperties] """List the subscriptions of a ServiceBus Topic. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :returns: An iterable (auto-paging) response of SubscriptionDescription. - :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.SubscriptionDescription] + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :returns: An iterable (auto-paging) response of SubscriptionProperties. + :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.SubscriptionProperties] """ try: topic_name = topic.name # type: ignore @@ -619,7 +773,7 @@ def list_subscriptions(self, topic, **kwargs): topic_name = topic def entry_to_subscription(entry): - subscription = SubscriptionDescription._from_internal_entity( + subscription = SubscriptionProperties._from_internal_entity( entry.title, entry.content.subscription_description) return subscription @@ -633,12 +787,12 @@ def entry_to_subscription(entry): get_next, extract_data) def list_subscriptions_runtime_info(self, topic, **kwargs): - # type: (Union[str, TopicDescription], Any) -> ItemPaged[SubscriptionRuntimeInfo] + # type: (Union[str, TopicProperties], Any) -> ItemPaged[SubscriptionRuntimeProperties] """List the subscriptions runtime information of a ServiceBus Topic. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :returns: An iterable (auto-paging) response of SubscriptionRuntimeInfo. - :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.SubscriptionRuntimeInfo] + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :returns: An iterable (auto-paging) response of SubscriptionRuntimeProperties. + :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.SubscriptionRuntimeProperties] """ try: topic_name = topic.name # type: ignore @@ -646,7 +800,7 @@ def list_subscriptions_runtime_info(self, topic, **kwargs): topic_name = topic def entry_to_subscription(entry): - subscription = SubscriptionRuntimeInfo._from_internal_entity( + subscription = SubscriptionRuntimeProperties._from_internal_entity( entry.title, entry.content.subscription_description) return subscription @@ -660,14 +814,14 @@ def entry_to_subscription(entry): get_next, extract_data) def get_rule(self, topic, subscription, rule_name, **kwargs): - # type: (Union[str, TopicDescription], Union[str, SubscriptionDescription], str, Any) -> RuleDescription + # type: (Union[str, TopicProperties], Union[str, SubscriptionProperties], str, Any) -> RuleProperties """Get the properties of a topic subscription rule. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription that + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.SubscriptionProperties] subscription: The subscription that owns the rule. :param str rule_name: Name of the rule. - :rtype: ~azure.servicebus.management.RuleDescription + :rtype: ~azure.servicebus.management.RuleProperties """ try: topic_name = topic.name # type: ignore @@ -683,21 +837,29 @@ def get_rule(self, topic, subscription, rule_name, **kwargs): raise ResourceNotFoundError( "Rule('Topic: {}, Subscription: {}, Rule {}') does not exist".format( subscription_name, topic_name, rule_name)) - rule_description = RuleDescription._from_internal_entity(rule_name, entry.content.rule_description) + rule_description = RuleProperties._from_internal_entity(rule_name, entry.content.rule_description) deserialize_rule_key_values(entry_ele, rule_description) # to remove after #3535 is released. return rule_description - def create_rule(self, topic, subscription, rule, **kwargs): - # type: (Union[str, TopicDescription], Union[str, SubscriptionDescription], RuleDescription, Any) -> RuleDescription # pylint:disable=line-too-long + def create_rule(self, topic, subscription, name, **kwargs): + # type: (Union[str, TopicProperties], Union[str, SubscriptionProperties], str, Any) -> RuleProperties """Create a rule for a topic subscription. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that will own the + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that will own the to-be-created subscription rule. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription that + :param Union[str, ~azure.servicebus.management.SubscriptionProperties] subscription: The subscription that will own the to-be-created rule. - :param azure.servicebus.management.RuleDescription rule: The rule to be created. - :rtype: ~azure.servicebus.management.RuleDescription + :param name: Name of the rule. + :type name: str + :keyword filter: The filter of the rule. + :type filter: Union[~azure.servicebus.management.CorrelationRuleFilter, + ~azure.servicebus.management.SqlRuleFilter] + :keyword action: The action of the rule. + :type action: Optional[~azure.servicebus.management.SqlRuleAction] + + :rtype: ~azure.servicebus.management.RuleProperties """ + try: topic_name = topic.name # type: ignore except AttributeError: @@ -706,7 +868,12 @@ def create_rule(self, topic, subscription, rule, **kwargs): subscription_name = subscription.name # type: ignore except AttributeError: subscription_name = subscription - rule_name = rule.name + rule = RuleProperties( + name, + filter=kwargs.pop("filter", None), + action=kwargs.pop("action", None), + created_at=None + ) to_create = rule._to_internal_entity() create_entity_body = CreateRuleBody( @@ -720,25 +887,25 @@ def create_rule(self, topic, subscription, rule, **kwargs): entry_ele = self._impl.rule.put( topic_name, subscription_name, # type: ignore - rule_name, + name, request_body, api_version=constants.API_VERSION, **kwargs) entry = RuleDescriptionEntry.deserialize(entry_ele) - result = RuleDescription._from_internal_entity(rule_name, entry.content.rule_description) + result = RuleProperties._from_internal_entity(name, entry.content.rule_description) deserialize_rule_key_values(entry_ele, result) # to remove after #3535 is released. return result def update_rule(self, topic, subscription, rule, **kwargs): - # type: (Union[str, TopicDescription], Union[str, SubscriptionDescription], RuleDescription, Any) -> None + # type: (Union[str, TopicProperties], Union[str, SubscriptionProperties], RuleProperties, Any) -> None """Update a rule. - Before calling this method, you should use `get_rule` to get a `RuleDescription` instance, - then update the related attributes and call this method. - Only a portion of properties can be updated. + Before calling this method, you should use `get_rule`, `create_rule` or `list_rules` to get a `RuleProperties` + instance, then update the properties. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription that + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.SubscriptionProperties] subscription: The subscription that owns this rule. - :param ~azure.servicebus.management.RuleDescription rule: The rule to be updated. + :param ~azure.servicebus.management.RuleProperties rule: The rule that is returned from `get_rule`, + `create_rule`, or `list_rules` and has the updated properties. :rtype: None """ @@ -772,13 +939,13 @@ def update_rule(self, topic, subscription, rule, **kwargs): ) def delete_rule(self, topic, subscription, rule, **kwargs): - # type: (Union[str, TopicDescription], Union[str, SubscriptionDescription], Union[str, RuleDescription], Any) -> None # pylint:disable=line-too-long + # type: (Union[str, TopicProperties], Union[str, SubscriptionProperties], Union[str, RuleProperties], Any) -> None # pylint:disable=line-too-long """Delete a topic subscription rule. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription that + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.SubscriptionProperties] subscription: The subscription that owns the topic. - :param Union[str, ~azure.servicebus.management.RuleDescription] rule: The to-be-deleted rule. + :param Union[str, ~azure.servicebus.management.RuleProperties] rule: The to-be-deleted rule. :rtype: None """ try: @@ -796,14 +963,14 @@ def delete_rule(self, topic, subscription, rule, **kwargs): self._impl.rule.delete(topic_name, subscription_name, rule_name, api_version=constants.API_VERSION, **kwargs) def list_rules(self, topic, subscription, **kwargs): - # type: (Union[str, TopicDescription], Union[str, SubscriptionDescription], Any) -> ItemPaged[RuleDescription] + # type: (Union[str, TopicProperties], Union[str, SubscriptionProperties], Any) -> ItemPaged[RuleProperties] """List the rules of a topic subscription. - :param Union[str, ~azure.servicebus.management.TopicDescription] topic: The topic that owns the subscription. - :param Union[str, ~azure.servicebus.management.SubscriptionDescription] subscription: The subscription that + :param Union[str, ~azure.servicebus.management.TopicProperties] topic: The topic that owns the subscription. + :param Union[str, ~azure.servicebus.management.SubscriptionProperties] subscription: The subscription that owns the rules. - :returns: An iterable (auto-paging) response of RuleDescription. - :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.RuleDescription] + :returns: An iterable (auto-paging) response of RuleProperties. + :rtype: ~azure.core.paging.ItemPaged[~azure.servicebus.management.RuleProperties] """ try: topic_name = topic.name # type: ignore @@ -819,7 +986,7 @@ def entry_to_rule(ele, entry): `ele` will be removed after https://github.com/Azure/autorest/issues/3535 is released. """ rule = entry.content.rule_description - rule_description = RuleDescription._from_internal_entity(entry.title, rule) + rule_description = RuleProperties._from_internal_entity(entry.title, rule) deserialize_rule_key_values(ele, rule_description) # to remove after #3535 is released. return rule_description diff --git a/sdk/servicebus/azure-servicebus/azure/servicebus/management/_models.py b/sdk/servicebus/azure-servicebus/azure/servicebus/management/_models.py index 687cefee36f1..dc21c2e1ae13 100644 --- a/sdk/servicebus/azure-servicebus/azure/servicebus/management/_models.py +++ b/sdk/servicebus/azure-servicebus/azure/servicebus/management/_models.py @@ -3,10 +3,12 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- # pylint:disable=protected-access +# pylint:disable=too-many-lines +import functools from collections import OrderedDict from copy import deepcopy from datetime import datetime, timedelta -from typing import Type, Dict, Any, Union, Optional +from typing import Type, Dict, Any, Union, Optional, List from msrest.serialization import Model from ._generated.models import QueueDescription as InternalQueueDescription, \ @@ -25,70 +27,135 @@ adjust_attribute_map() -class QueueDescription(object): # pylint:disable=too-many-instance-attributes - """Description of a Service Bus queue resource. +def extract_kwarg_template(kwargs, extraction_missing_args, name): + try: + return kwargs[name] + except KeyError: + extraction_missing_args.append(name) - :param name: Name of the queue. + +def validate_extraction_missing_args(extraction_missing_args): + if extraction_missing_args: + raise TypeError('__init__() missing {} required keyword arguments: {}'.format( + len(extraction_missing_args), + ' and '.join(["'" + e + "'" for e in extraction_missing_args]))) + + +class DictMixin(object): + + def __setitem__(self, key, item): + self.__dict__[key] = item + + def __getitem__(self, key): + return self.__dict__[key] + + def __repr__(self): + return str(self) + + def __len__(self): + return len(self.keys()) + + def __delitem__(self, key): + self.__dict__[key] = None + + def __eq__(self, other): + """Compare objects by comparing all attributes.""" + if isinstance(other, self.__class__): + return self.__dict__ == other.__dict__ + return False + + def __ne__(self, other): + """Compare objects by comparing all attributes.""" + return not self.__eq__(other) + + def __str__(self): + return str({k: v for k, v in self.__dict__.items() if not k.startswith('_')}) + + def has_key(self, k): + return k in self.__dict__ + + def update(self, *args, **kwargs): + return self.__dict__.update(*args, **kwargs) + + def keys(self): + return [k for k in self.__dict__ if not k.startswith('_')] + + def values(self): + return [v for k, v in self.__dict__.items() if not k.startswith('_')] + + def items(self): + return [(k, v) for k, v in self.__dict__.items() if not k.startswith('_')] + + def get(self, key, default=None): + if key in self.__dict__: + return self.__dict__[key] + return default + + +class QueueProperties(DictMixin): # pylint:disable=too-many-instance-attributes + """Properties of a Service Bus queue resource. + + :ivar name: Name of the queue. :type name: str - :keyword authorization_rules: Authorization rules for resource. + :ivar authorization_rules: Authorization rules for resource. :type authorization_rules: list[~azure.servicebus.management.AuthorizationRule] - :keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the queue is + :ivar auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the queue is automatically deleted. The minimum duration is 5 minutes. :type auto_delete_on_idle: ~datetime.timedelta - :keyword dead_lettering_on_message_expiration: A value that indicates whether this queue has dead + :ivar dead_lettering_on_message_expiration: A value that indicates whether this queue has dead letter support when a message expires. :type dead_lettering_on_message_expiration: bool - :keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is + :ivar default_message_time_to_live: ISO 8601 default message timespan to live value. This is the duration after which the message expires, starting from when the message is sent to Service Bus. This is the default value used when TimeToLive is not set on a message itself. :type default_message_time_to_live: ~datetime.timedelta - :keyword duplicate_detection_history_time_window: ISO 8601 timeSpan structure that defines the + :ivar duplicate_detection_history_time_window: ISO 8601 timeSpan structure that defines the duration of the duplicate detection history. The default value is 10 minutes. :type duplicate_detection_history_time_window: ~datetime.timedelta - :keyword entity_availability_status: Availibility status of the entity. Possible values include: + :ivar entity_availability_status: Availibility status of the entity. Possible values include: "Available", "Limited", "Renaming", "Restoring", "Unknown". :type entity_availability_status: str or ~azure.servicebus.management.EntityAvailabilityStatus - :keyword enable_batched_operations: Value that indicates whether server-side batched operations + :ivar enable_batched_operations: Value that indicates whether server-side batched operations are enabled. :type enable_batched_operations: bool - :keyword enable_express: A value that indicates whether Express Entities are enabled. An express + :ivar enable_express: A value that indicates whether Express Entities are enabled. An express queue holds a message in memory temporarily before writing it to persistent storage. :type enable_express: bool - :keyword enable_partitioning: A value that indicates whether the queue is to be partitioned + :ivar enable_partitioning: A value that indicates whether the queue is to be partitioned across multiple message brokers. :type enable_partitioning: bool - :keyword is_anonymous_accessible: A value indicating if the resource can be accessed without + :ivar is_anonymous_accessible: A value indicating if the resource can be accessed without authorization. :type is_anonymous_accessible: bool - :keyword lock_duration: ISO 8601 timespan duration of a peek-lock; that is, the amount of time + :ivar lock_duration: ISO 8601 timespan duration of a peek-lock; that is, the amount of time that the message is locked for other receivers. The maximum value for LockDuration is 5 minutes; the default value is 1 minute. :type lock_duration: ~datetime.timedelta - :keyword max_delivery_count: The maximum delivery count. A message is automatically deadlettered + :ivar max_delivery_count: The maximum delivery count. A message is automatically deadlettered after this number of deliveries. Default value is 10. :type max_delivery_count: int - :keyword max_size_in_megabytes: The maximum size of the queue in megabytes, which is the size of + :ivar max_size_in_megabytes: The maximum size of the queue in megabytes, which is the size of memory allocated for the queue. :type max_size_in_megabytes: int - :keyword requires_duplicate_detection: A value indicating if this queue requires duplicate + :ivar requires_duplicate_detection: A value indicating if this queue requires duplicate detection. :type requires_duplicate_detection: bool - :keyword requires_session: A value that indicates whether the queue supports the concept of + :ivar requires_session: A value that indicates whether the queue supports the concept of sessions. :type requires_session: bool - :keyword status: Status of a Service Bus resource. Possible values include: "Active", "Creating", + :ivar status: Status of a Service Bus resource. Possible values include: "Active", "Creating", "Deleting", "Disabled", "ReceiveDisabled", "Renaming", "Restoring", "SendDisabled", "Unknown". :type status: str or ~azure.servicebus.management.EntityStatus - :keyword forward_to: The name of the recipient entity to which all the messages sent to the queue + :ivar forward_to: The name of the recipient entity to which all the messages sent to the queue are forwarded to. :type forward_to: str - :keyword user_metadata: Custom metdata that user can associate with the description. Max length + :ivar user_metadata: Custom metdata that user can associate with the description. Max length is 1024 chars. :type user_metadata: str - :keyword support_ordering: A value that indicates whether the queue supports ordering. + :ivar support_ordering: A value that indicates whether the queue supports ordering. :type support_ordering: bool - :keyword forward_dead_lettered_messages_to: The name of the recipient entity to which all the + :ivar forward_dead_lettered_messages_to: The name of the recipient entity to which all the dead-lettered messages of this subscription are forwarded to. :type forward_dead_lettered_messages_to: str """ @@ -102,55 +169,60 @@ def __init__( self.name = name self._internal_qd = None # type: Optional[InternalQueueDescription] - self.authorization_rules = kwargs.get('authorization_rules', None) - self.auto_delete_on_idle = kwargs.get('auto_delete_on_idle', None) - self.dead_lettering_on_message_expiration = kwargs.get('dead_lettering_on_message_expiration', None) - self.default_message_time_to_live = kwargs.get('default_message_time_to_live', None) - self.duplicate_detection_history_time_window = kwargs.get('duplicate_detection_history_time_window', None) - self.entity_availability_status = kwargs.get('entity_availability_status', None) - self.enable_batched_operations = kwargs.get('enable_batched_operations', None) - self.enable_express = kwargs.get('enable_express', None) - self.enable_partitioning = kwargs.get('enable_partitioning', None) - self.is_anonymous_accessible = kwargs.get('is_anonymous_accessible', None) - self.lock_duration = kwargs.get('lock_duration', None) - self.max_delivery_count = kwargs.get('max_delivery_count', None) - self.max_size_in_megabytes = kwargs.get('max_size_in_megabytes', None) - self.requires_duplicate_detection = kwargs.get('requires_duplicate_detection', None) - self.requires_session = kwargs.get('requires_session', None) - self.status = kwargs.get('status', None) - self.support_ordering = kwargs.get('support_ordering', None) - self.forward_to = kwargs.get('forward_to', None) - self.user_metadata = kwargs.get('user_metadata', None) - self.forward_dead_lettered_messages_to = kwargs.get('forward_dead_lettered_messages_to', None) + extraction_missing_args = [] # type: List[str] + extract_kwarg = functools.partial(extract_kwarg_template, kwargs, extraction_missing_args) + + self.authorization_rules = extract_kwarg('authorization_rules') + self.auto_delete_on_idle = extract_kwarg('auto_delete_on_idle') + self.dead_lettering_on_message_expiration = extract_kwarg('dead_lettering_on_message_expiration') + self.default_message_time_to_live = extract_kwarg('default_message_time_to_live') + self.duplicate_detection_history_time_window = extract_kwarg('duplicate_detection_history_time_window') + self.entity_availability_status = extract_kwarg('entity_availability_status') + self.enable_batched_operations = extract_kwarg('enable_batched_operations') + self.enable_express = extract_kwarg('enable_express') + self.enable_partitioning = extract_kwarg('enable_partitioning') + self.is_anonymous_accessible = extract_kwarg('is_anonymous_accessible') + self.lock_duration = extract_kwarg('lock_duration') + self.max_delivery_count = extract_kwarg('max_delivery_count') + self.max_size_in_megabytes = extract_kwarg('max_size_in_megabytes') + self.requires_duplicate_detection = extract_kwarg('requires_duplicate_detection') + self.requires_session = extract_kwarg('requires_session') + self.status = extract_kwarg('status') + self.support_ordering = extract_kwarg('support_ordering') + self.forward_to = extract_kwarg('forward_to') + self.user_metadata = extract_kwarg('user_metadata') + self.forward_dead_lettered_messages_to = extract_kwarg('forward_dead_lettered_messages_to') + + validate_extraction_missing_args(extraction_missing_args) @classmethod def _from_internal_entity(cls, name, internal_qd): - # type: (str, InternalQueueDescription) -> QueueDescription - qd = cls(name) + # type: (str, InternalQueueDescription) -> QueueProperties + qd = cls( + name, + authorization_rules=internal_qd.authorization_rules, + auto_delete_on_idle=internal_qd.auto_delete_on_idle, + dead_lettering_on_message_expiration=internal_qd.dead_lettering_on_message_expiration, + default_message_time_to_live=internal_qd.default_message_time_to_live, + duplicate_detection_history_time_window=internal_qd.duplicate_detection_history_time_window, + entity_availability_status=internal_qd.entity_availability_status, + enable_batched_operations=internal_qd.enable_batched_operations, + enable_express=internal_qd.enable_express, + enable_partitioning=internal_qd.enable_partitioning, + is_anonymous_accessible=internal_qd.is_anonymous_accessible, + lock_duration=internal_qd.lock_duration, + max_delivery_count=internal_qd.max_delivery_count, + max_size_in_megabytes=internal_qd.max_size_in_megabytes, + requires_duplicate_detection=internal_qd.requires_duplicate_detection, + requires_session=internal_qd.requires_session, + status=internal_qd.status, + support_ordering=internal_qd.support_ordering, + forward_to=internal_qd.forward_to, + forward_dead_lettered_messages_to=internal_qd.forward_dead_lettered_messages_to, + user_metadata=internal_qd.user_metadata + ) qd._internal_qd = deepcopy(internal_qd) # pylint:disable=protected-access - - qd.authorization_rules = internal_qd.authorization_rules - qd.auto_delete_on_idle = internal_qd.auto_delete_on_idle - qd.dead_lettering_on_message_expiration = internal_qd.dead_lettering_on_message_expiration - qd.default_message_time_to_live = internal_qd.default_message_time_to_live - qd.duplicate_detection_history_time_window = internal_qd.duplicate_detection_history_time_window - qd.entity_availability_status = internal_qd.entity_availability_status - qd.enable_batched_operations = internal_qd.enable_batched_operations - qd.enable_express = internal_qd.enable_express - qd.enable_partitioning = internal_qd.enable_partitioning - qd.is_anonymous_accessible = internal_qd.is_anonymous_accessible - qd.lock_duration = internal_qd.lock_duration - qd.max_delivery_count = internal_qd.max_delivery_count - qd.max_size_in_megabytes = internal_qd.max_size_in_megabytes - qd.requires_duplicate_detection = internal_qd.requires_duplicate_detection - qd.requires_session = internal_qd.requires_session - qd.status = internal_qd.status - qd.support_ordering = internal_qd.support_ordering - qd.forward_to = internal_qd.forward_to - qd.forward_dead_lettered_messages_to = internal_qd.forward_dead_lettered_messages_to - qd.user_metadata = internal_qd.user_metadata - return qd def _to_internal_entity(self): @@ -182,111 +254,165 @@ def _to_internal_entity(self): return self._internal_qd -class QueueRuntimeInfo(object): - """Service Bus queue metrics. - - :ivar name: Name of the queue. - :type name: str - :ivar accessed_at: Last time a message was sent, or the last time there was a receive request - to this queue. - :type accessed_at: ~datetime.datetime - :ivar created_at: The exact time the queue was created. - :type created_at: ~datetime.datetime - :ivar updated_at: The exact time a message was updated in the queue. - :type updated_at: ~datetime.datetime - :ivar size_in_bytes: The size of the queue, in bytes. - :type size_in_bytes: int - :ivar message_count: The number of messages in the queue. - :type message_count: int - :ivar message_count_details: Details about the message counts in entity. - :type message_count_details: ~azure.servicebus.management.MessageCountDetails +class QueueRuntimeProperties(object): + """Service Bus queue runtime properties. """ - def __init__( self, - name, - **kwargs ): - # type: (str, Any) -> None - self.name = name + self._name = None self._internal_qr = None # type: Optional[InternalQueueDescription] - self.accessed_at = kwargs.get('accessed_at', None) - self.created_at = kwargs.get('created_at', None) - self.updated_at = kwargs.get('updated_at', None) - self.size_in_bytes = kwargs.get('size_in_bytes', None) - self.message_count = kwargs.get('message_count', None) - self.message_count_details = kwargs.get('message_count_details', None) - @classmethod def _from_internal_entity(cls, name, internal_qr): - # type: (str, InternalQueueDescription) -> QueueRuntimeInfo - qr = cls(name) + # type: (str, InternalQueueDescription) -> QueueRuntimeProperties + qr = cls() + qr._name = name qr._internal_qr = deepcopy(internal_qr) # pylint:disable=protected-access + return qr - qr.accessed_at = internal_qr.accessed_at - qr.created_at = internal_qr.created_at - qr.updated_at = internal_qr.updated_at - qr.size_in_bytes = internal_qr.size_in_bytes - qr.message_count = internal_qr.message_count - qr.message_count_details = internal_qr.message_count_details + @property + def name(self): + """Name of the queue. - return qr + :rtype: str + """ + return self._name + + @property + def accessed_at(self): + """Last time a message was sent, or the last time there was a receive request to this queue. + + :rtype: ~datetime.datetime + """ + return self._internal_qr.accessed_at + + @property + def created_at(self): + """The exact time the queue was created. + + :rtype: ~datetime.datetime + """ + return self._internal_qr.created_at + + @property + def updated_at(self): + """The exact the entity was updated. + + :rtype: ~datetime.datetime + """ + return self._internal_qr.updated_at + + @property + def size_in_bytes(self): + """The size of the queue, in bytes. + + :rtype: int + """ + return self._internal_qr.size_in_bytes + @property + def total_message_count(self): + """Total number of messages. -class TopicDescription(object): # pylint:disable=too-many-instance-attributes - """Description of a Service Bus topic resource. + :rtype: int + """ + return self._internal_qr.message_count - :param name: Name of the topic. + @property + def active_message_count(self): + """Number of active messages in the queue, topic, or subscription. + + :rtype: int + """ + return self._internal_qr.message_count_details.active_message_count + + @property + def dead_letter_message_count(self): + """Number of messages that are dead lettered. + + :rtype: int + """ + return self._internal_qr.message_count_details.dead_letter_message_count + + @property + def scheduled_message_count(self): + """Number of scheduled messages. + + :rtype: int + """ + return self._internal_qr.message_count_details.scheduled_message_count + + @property + def transfer_dead_letter_message_count(self): + """Number of messages transferred into dead letters. + + :rtype: int + """ + return self._internal_qr.message_count_details.transfer_dead_letter_message_count + + @property + def transfer_message_count(self): + """Number of messages transferred to another queue, topic, or subscription. + + :rtype: int + """ + return self._internal_qr.message_count_details.transfer_message_count + + +class TopicProperties(DictMixin): # pylint:disable=too-many-instance-attributes + """Properties of a Service Bus topic resource. + + :ivar name: Name of the topic. :type name: str - :keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is + :ivar default_message_time_to_live: ISO 8601 default message timespan to live value. This is the duration after which the message expires, starting from when the message is sent to Service Bus. This is the default value used when TimeToLive is not set on a message itself. :type default_message_time_to_live: ~datetime.timedelta - :keyword max_size_in_megabytes: The maximum size of the topic in megabytes, which is the size of + :ivar max_size_in_megabytes: The maximum size of the topic in megabytes, which is the size of memory allocated for the topic. :type max_size_in_megabytes: long - :keyword requires_duplicate_detection: A value indicating if this topic requires duplicate + :ivar requires_duplicate_detection: A value indicating if this topic requires duplicate detection. :type requires_duplicate_detection: bool - :keyword duplicate_detection_history_time_window: ISO 8601 timeSpan structure that defines the + :ivar duplicate_detection_history_time_window: ISO 8601 timeSpan structure that defines the duration of the duplicate detection history. The default value is 10 minutes. :type duplicate_detection_history_time_window: ~datetime.timedelta - :keyword enable_batched_operations: Value that indicates whether server-side batched operations + :ivar enable_batched_operations: Value that indicates whether server-side batched operations are enabled. :type enable_batched_operations: bool - :keyword size_in_bytes: The size of the topic, in bytes. + :ivar size_in_bytes: The size of the topic, in bytes. :type size_in_bytes: int - :keyword filtering_messages_before_publishing: Filter messages before publishing. + :ivar filtering_messages_before_publishing: Filter messages before publishing. :type filtering_messages_before_publishing: bool - :keyword is_anonymous_accessible: A value indicating if the resource can be accessed without + :ivar is_anonymous_accessible: A value indicating if the resource can be accessed without authorization. :type is_anonymous_accessible: bool - :keyword authorization_rules: Authorization rules for resource. + :ivar authorization_rules: Authorization rules for resource. :type authorization_rules: - list[~azure.servicebus.management._generated.models.AuthorizationRule] - :keyword status: Status of a Service Bus resource. Possible values include: "Active", "Creating", + list[~azure.servicebus.management.AuthorizationRule] + :ivar status: Status of a Service Bus resource. Possible values include: "Active", "Creating", "Deleting", "Disabled", "ReceiveDisabled", "Renaming", "Restoring", "SendDisabled", "Unknown". - :type status: str or ~azure.servicebus.management._generated.models.EntityStatus - :keyword support_ordering: A value that indicates whether the topic supports ordering. + :type status: str or ~azure.servicebus.management.EntityStatus + :ivar support_ordering: A value that indicates whether the topic supports ordering. :type support_ordering: bool - :keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the topic is + :ivar auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the topic is automatically deleted. The minimum duration is 5 minutes. :type auto_delete_on_idle: ~datetime.timedelta - :keyword enable_partitioning: A value that indicates whether the topic is to be partitioned + :ivar enable_partitioning: A value that indicates whether the topic is to be partitioned across multiple message brokers. :type enable_partitioning: bool - :keyword entity_availability_status: Availability status of the entity. Possible values include: + :ivar entity_availability_status: Availability status of the entity. Possible values include: "Available", "Limited", "Renaming", "Restoring", "Unknown". :type entity_availability_status: str or - ~azure.servicebus.management._generated.models.EntityAvailabilityStatus - :keyword enable_subscription_partitioning: A value that indicates whether the topic's + ~azure.servicebus.management.EntityAvailabilityStatus + :ivar enable_subscription_partitioning: A value that indicates whether the topic's subscription is to be partitioned. :type enable_subscription_partitioning: bool - :keyword enable_express: A value that indicates whether Express Entities are enabled. An express + :ivar enable_express: A value that indicates whether Express Entities are enabled. An express queue holds a message in memory temporarily before writing it to persistent storage. :type enable_express: bool - :keyword user_metadata: Metadata associated with the topic. + :ivar user_metadata: Metadata associated with the topic. :type user_metadata: str """ def __init__( @@ -298,47 +424,52 @@ def __init__( self.name = name self._internal_td = None # type: Optional[InternalTopicDescription] - self.default_message_time_to_live = kwargs.get('default_message_time_to_live', None) - self.max_size_in_megabytes = kwargs.get('max_size_in_megabytes', None) - self.requires_duplicate_detection = kwargs.get('requires_duplicate_detection', None) - self.duplicate_detection_history_time_window = kwargs.get('duplicate_detection_history_time_window', None) - self.enable_batched_operations = kwargs.get('enable_batched_operations', None) - self.size_in_bytes = kwargs.get('size_in_bytes', None) - self.is_anonymous_accessible = kwargs.get('is_anonymous_accessible', None) - self.authorization_rules = kwargs.get('authorization_rules', None) - self.status = kwargs.get('status', None) - self.support_ordering = kwargs.get('support_ordering', None) - self.auto_delete_on_idle = kwargs.get('auto_delete_on_idle', None) - self.enable_partitioning = kwargs.get('enable_partitioning', None) - self.entity_availability_status = kwargs.get('entity_availability_status', None) - self.enable_subscription_partitioning = kwargs.get('enable_subscription_partitioning', None) - self.enable_express = kwargs.get('enable_express', None) - self.user_metadata = kwargs.get('user_metadata', None) + extraction_missing_args = [] # type: List[str] + extract_kwarg = functools.partial(extract_kwarg_template, kwargs, extraction_missing_args) + + self.default_message_time_to_live = extract_kwarg('default_message_time_to_live') + self.max_size_in_megabytes = extract_kwarg('max_size_in_megabytes') + self.requires_duplicate_detection = extract_kwarg('requires_duplicate_detection') + self.duplicate_detection_history_time_window = extract_kwarg('duplicate_detection_history_time_window') + self.enable_batched_operations = extract_kwarg('enable_batched_operations') + self.size_in_bytes = extract_kwarg('size_in_bytes') + self.is_anonymous_accessible = extract_kwarg('is_anonymous_accessible') + self.authorization_rules = extract_kwarg('authorization_rules') + self.status = extract_kwarg('status') + self.support_ordering = extract_kwarg('support_ordering') + self.auto_delete_on_idle = extract_kwarg('auto_delete_on_idle') + self.enable_partitioning = extract_kwarg('enable_partitioning') + self.entity_availability_status = extract_kwarg('entity_availability_status') + self.enable_subscription_partitioning = extract_kwarg('enable_subscription_partitioning') + self.enable_express = extract_kwarg('enable_express') + self.user_metadata = extract_kwarg('user_metadata') + + validate_extraction_missing_args(extraction_missing_args) @classmethod def _from_internal_entity(cls, name, internal_td): - # type: (str, InternalTopicDescription) -> TopicDescription - qd = cls(name) - qd._internal_td = deepcopy(internal_td) - - qd.default_message_time_to_live = internal_td.default_message_time_to_live - qd.max_size_in_megabytes = internal_td.max_size_in_megabytes - qd.requires_duplicate_detection = internal_td.requires_duplicate_detection - qd.duplicate_detection_history_time_window = internal_td.duplicate_detection_history_time_window - qd.enable_batched_operations = internal_td.enable_batched_operations - qd.size_in_bytes = internal_td.size_in_bytes - qd.is_anonymous_accessible = internal_td.is_anonymous_accessible - qd.authorization_rules = internal_td.authorization_rules - qd.status = internal_td.status - qd.support_ordering = internal_td.support_ordering - qd.auto_delete_on_idle = internal_td.auto_delete_on_idle - qd.enable_partitioning = internal_td.enable_partitioning - qd.entity_availability_status = internal_td.entity_availability_status - qd.enable_subscription_partitioning = internal_td.enable_subscription_partitioning - qd.enable_express = internal_td.enable_express - qd.user_metadata = internal_td.user_metadata - - return qd + # type: (str, InternalTopicDescription) -> TopicProperties + td = cls( + name, + default_message_time_to_live=internal_td.default_message_time_to_live, + max_size_in_megabytes=internal_td.max_size_in_megabytes, + requires_duplicate_detection=internal_td.requires_duplicate_detection, + duplicate_detection_history_time_window=internal_td.duplicate_detection_history_time_window, + enable_batched_operations=internal_td.enable_batched_operations, + size_in_bytes=internal_td.size_in_bytes, + is_anonymous_accessible=internal_td.is_anonymous_accessible, + authorization_rules=internal_td.authorization_rules, + status=internal_td.status, + support_ordering=internal_td.support_ordering, + auto_delete_on_idle=internal_td.auto_delete_on_idle, + enable_partitioning=internal_td.enable_partitioning, + entity_availability_status=internal_td.entity_availability_status, + enable_subscription_partitioning=internal_td.enable_subscription_partitioning, + enable_express=internal_td.enable_express, + user_metadata=internal_td.user_metadata + ) + td._internal_td = deepcopy(internal_td) + return td def _to_internal_entity(self): # type: () -> InternalTopicDescription @@ -364,139 +495,174 @@ def _to_internal_entity(self): return self._internal_td -class TopicRuntimeInfo(object): - """Description of a Service Bus topic resource. - - :ivar str name: - :ivar created_at: The exact time the queue was created. - :type created_at: ~datetime.datetime - :ivar updated_at: The exact time a message was updated in the queue. - :type updated_at: ~datetime.datetime - :ivar accessed_at: Last time a message was sent, or the last time there was a receive request - to this queue. - :type accessed_at: ~datetime.datetime - :ivar message_count_details: Details about the message counts in queue. - :type message_count_details: ~azure.servicebus.management._generated.models.MessageCountDetails - :ivar subscription_count: The number of subscriptions in the topic. - :type subscription_count: int +class TopicRuntimeProperties(object): + """Runtime properties of a Service Bus topic resource. """ def __init__( self, - name, - **kwargs ): - # type: (str, Any) -> None - self.name = name + self._name = None self._internal_td = None # type: Optional[InternalTopicDescription] - self.created_at = kwargs.get('created_at', None) - self.updated_at = kwargs.get('updated_at', None) - self.accessed_at = kwargs.get('accessed_at', None) - self.message_count_details = kwargs.get('message_count_details', None) - self.subscription_count = kwargs.get('subscription_count', None) @classmethod def _from_internal_entity(cls, name, internal_td): - # type: (str, InternalTopicDescription) -> TopicRuntimeInfo - qd = cls(name) + # type: (str, InternalTopicDescription) -> TopicRuntimeProperties + qd = cls() + qd._name = name qd._internal_td = internal_td + return qd - qd.created_at = internal_td.created_at - qd.updated_at = internal_td.updated_at - qd.accessed_at = internal_td.accessed_at - qd.message_count_details = internal_td.message_count_details - qd.subscription_count = internal_td.subscription_count + @property + def name(self): + """The name of the topic. - return qd + :rtype: str + """ + return self._name + + @property + def accessed_at(self): + """Last time a message was sent, or the last time there was a receive request + + :rtype: ~datetime.datetime + """ + return self._internal_td.accessed_at + + @property + def created_at(self): + """The exact time the queue was created. + + :rtype: ~datetime.datetime + """ + return self._internal_td.created_at + + @property + def updated_at(self): + """The exact time the entity was updated. + :rtype: ~datetime.datetime + """ + return self._internal_td.updated_at -class SubscriptionDescription(object): # pylint:disable=too-many-instance-attributes - """Description of a Service Bus queue resource. + @property + def size_in_bytes(self): + """The current size of the entity in bytes. - :param name: Name of the subscription. + :rtype: int + """ + return self._internal_td.size_in_bytes + + @property + def subscription_count(self): + """The number of subscriptions in the topic. + + :rtype: int + """ + return self._internal_td.subscription_count + + @property + def scheduled_message_count(self): + """Number of scheduled messages. + + :rtype: int + """ + return self._internal_td.message_count_details.scheduled_message_count + + +class SubscriptionProperties(DictMixin): # pylint:disable=too-many-instance-attributes + """Properties of a Service Bus topic subscription resource. + + :ivar name: Name of the subscription. :type name: str - :keyword lock_duration: ISO 8601 timespan duration of a peek-lock; that is, the amount of time + :ivar lock_duration: ISO 8601 timespan duration of a peek-lock; that is, the amount of time that the message is locked for other receivers. The maximum value for LockDuration is 5 minutes; the default value is 1 minute. :type lock_duration: ~datetime.timedelta - :keyword requires_session: A value that indicates whether the queue supports the concept of + :ivar requires_session: A value that indicates whether the queue supports the concept of sessions. :type requires_session: bool - :keyword default_message_time_to_live: ISO 8601 default message timespan to live value. This is + :ivar default_message_time_to_live: ISO 8601 default message timespan to live value. This is the duration after which the message expires, starting from when the message is sent to Service Bus. This is the default value used when TimeToLive is not set on a message itself. :type default_message_time_to_live: ~datetime.timedelta - :keyword dead_lettering_on_message_expiration: A value that indicates whether this subscription + :ivar dead_lettering_on_message_expiration: A value that indicates whether this subscription has dead letter support when a message expires. :type dead_lettering_on_message_expiration: bool - :keyword dead_lettering_on_filter_evaluation_exceptions: A value that indicates whether this + :ivar dead_lettering_on_filter_evaluation_exceptions: A value that indicates whether this subscription has dead letter support when a message expires. :type dead_lettering_on_filter_evaluation_exceptions: bool - :keyword max_delivery_count: The maximum delivery count. A message is automatically deadlettered + :ivar max_delivery_count: The maximum delivery count. A message is automatically deadlettered after this number of deliveries. Default value is 10. :type max_delivery_count: int - :keyword enable_batched_operations: Value that indicates whether server-side batched operations + :ivar enable_batched_operations: Value that indicates whether server-side batched operations are enabled. :type enable_batched_operations: bool - :keyword status: Status of a Service Bus resource. Possible values include: "Active", "Creating", + :ivar status: Status of a Service Bus resource. Possible values include: "Active", "Creating", "Deleting", "Disabled", "ReceiveDisabled", "Renaming", "Restoring", "SendDisabled", "Unknown". - :type status: str or ~azure.servicebus.management._generated.models.EntityStatus - :keyword forward_to: The name of the recipient entity to which all the messages sent to the + :type status: str or ~azure.servicebus.management.EntityStatus + :ivar forward_to: The name of the recipient entity to which all the messages sent to the subscription are forwarded to. :type forward_to: str - :keyword user_metadata: Metadata associated with the subscription. Maximum number of characters + :ivar user_metadata: Metadata associated with the subscription. Maximum number of characters is 1024. :type user_metadata: str - :keyword forward_dead_lettered_messages_to: The name of the recipient entity to which all the + :ivar forward_dead_lettered_messages_to: The name of the recipient entity to which all the messages sent to the subscription are forwarded to. :type forward_dead_lettered_messages_to: str - :keyword auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the subscription is + :ivar auto_delete_on_idle: ISO 8601 timeSpan idle interval after which the subscription is automatically deleted. The minimum duration is 5 minutes. :type auto_delete_on_idle: ~datetime.timedelta - :keyword entity_availability_status: Availability status of the entity. Possible values include: + :ivar entity_availability_status: Availability status of the entity. Possible values include: "Available", "Limited", "Renaming", "Restoring", "Unknown". :type entity_availability_status: str or - ~azure.servicebus.management._generated.models.EntityAvailabilityStatus + ~azure.servicebus.management.EntityAvailabilityStatus """ def __init__(self, name, **kwargs): # type: (str, Any) -> None self.name = name self._internal_sd = None # type: Optional[InternalSubscriptionDescription] - self.lock_duration = kwargs.get('lock_duration', None) - self.requires_session = kwargs.get('requires_session', None) - self.default_message_time_to_live = kwargs.get('default_message_time_to_live', None) - self.dead_lettering_on_message_expiration = kwargs.get('dead_lettering_on_message_expiration', None) - self.dead_lettering_on_filter_evaluation_exceptions = kwargs.get( - 'dead_lettering_on_filter_evaluation_exceptions', None) - self.max_delivery_count = kwargs.get('max_delivery_count', None) - self.enable_batched_operations = kwargs.get('enable_batched_operations', None) - self.status = kwargs.get('status', None) - self.forward_to = kwargs.get('forward_to', None) - self.user_metadata = kwargs.get('user_metadata', None) - self.forward_dead_lettered_messages_to = kwargs.get('forward_dead_lettered_messages_to', None) - self.auto_delete_on_idle = kwargs.get('auto_delete_on_idle', None) - self.entity_availability_status = kwargs.get('entity_availability_status', None) + extraction_missing_args = [] # type: List[str] + extract_kwarg = functools.partial(extract_kwarg_template, kwargs, extraction_missing_args) + + self.lock_duration = extract_kwarg('lock_duration') + self.requires_session = extract_kwarg('requires_session') + self.default_message_time_to_live = extract_kwarg('default_message_time_to_live') + self.dead_lettering_on_message_expiration = extract_kwarg('dead_lettering_on_message_expiration') + self.dead_lettering_on_filter_evaluation_exceptions = extract_kwarg( + 'dead_lettering_on_filter_evaluation_exceptions') + self.max_delivery_count = extract_kwarg('max_delivery_count') + self.enable_batched_operations = extract_kwarg('enable_batched_operations') + self.status = extract_kwarg('status') + self.forward_to = extract_kwarg('forward_to') + self.user_metadata = extract_kwarg('user_metadata') + self.forward_dead_lettered_messages_to = extract_kwarg('forward_dead_lettered_messages_to') + self.auto_delete_on_idle = extract_kwarg('auto_delete_on_idle') + self.entity_availability_status = extract_kwarg('entity_availability_status') + + validate_extraction_missing_args(extraction_missing_args) @classmethod def _from_internal_entity(cls, name, internal_subscription): - # type: (str, InternalSubscriptionDescription) -> SubscriptionDescription - subscription = cls(name) + # type: (str, InternalSubscriptionDescription) -> SubscriptionProperties + subscription = cls( + name, + lock_duration=internal_subscription.lock_duration, + requires_session=internal_subscription.requires_session, + default_message_time_to_live=internal_subscription.default_message_time_to_live, + dead_lettering_on_message_expiration=internal_subscription.dead_lettering_on_message_expiration, + dead_lettering_on_filter_evaluation_exceptions= + internal_subscription.dead_lettering_on_filter_evaluation_exceptions, + max_delivery_count=internal_subscription.max_delivery_count, + enable_batched_operations=internal_subscription.enable_batched_operations, + status=internal_subscription.status, + forward_to=internal_subscription.forward_to, + user_metadata=internal_subscription.user_metadata, + forward_dead_lettered_messages_to=internal_subscription.forward_dead_lettered_messages_to, + auto_delete_on_idle=internal_subscription.auto_delete_on_idle, + entity_availability_status=internal_subscription.entity_availability_status + ) subscription._internal_sd = deepcopy(internal_subscription) - subscription.lock_duration = internal_subscription.lock_duration - subscription.requires_session = internal_subscription.requires_session - subscription.default_message_time_to_live = internal_subscription.default_message_time_to_live - subscription.dead_lettering_on_message_expiration = internal_subscription.dead_lettering_on_message_expiration - subscription.dead_lettering_on_filter_evaluation_exceptions = \ - internal_subscription.dead_lettering_on_filter_evaluation_exceptions - subscription.max_delivery_count = internal_subscription.max_delivery_count - subscription.enable_batched_operations = internal_subscription.enable_batched_operations - subscription.status = internal_subscription.status - subscription.forward_to = internal_subscription.forward_to - subscription.user_metadata = internal_subscription.user_metadata - subscription.forward_dead_lettered_messages_to = internal_subscription.forward_dead_lettered_messages_to - subscription.auto_delete_on_idle = internal_subscription.auto_delete_on_idle - subscription.entity_availability_status = internal_subscription.entity_availability_status - return subscription def _to_internal_entity(self): @@ -521,83 +687,137 @@ def _to_internal_entity(self): return self._internal_sd -class SubscriptionRuntimeInfo(object): - """Description of a Service Bus queue resource. - - :ivar str name: - :ivar created_at: The exact time the queue was created. - :type created_at: ~datetime.datetime - :ivar updated_at: The exact time a message was updated in the queue. - :type updated_at: ~datetime.datetime - :ivar accessed_at: Last time a message was sent, or the last time there was a receive request - to this queue. - :type accessed_at: ~datetime.datetime - :ivar message_count: The number of messages in the subscription. - :type message_count: int - :ivar message_count_details: Details about the message counts in queue. - :type message_count_details: ~azure.servicebus.management._generated.models.MessageCountDetails +class SubscriptionRuntimeProperties(object): + """Runtime properties of a Service Bus topic subscription resource. """ - def __init__(self, name, **kwargs): - # type: (str, Any) -> None + def __init__(self): self._internal_sd = None # type: Optional[InternalSubscriptionDescription] - self.name = name - - self.message_count = kwargs.get('message_count', None) - self.created_at = kwargs.get('created_at', None) - self.updated_at = kwargs.get('updated_at', None) - self.accessed_at = kwargs.get('accessed_at', None) - self.message_count_details = kwargs.get('message_count_details', None) + self._name = None @classmethod def _from_internal_entity(cls, name, internal_subscription): - # type: (str, InternalSubscriptionDescription) -> SubscriptionRuntimeInfo - subscription = cls(name) + # type: (str, InternalSubscriptionDescription) -> SubscriptionRuntimeProperties + subscription = cls() + subscription._name = name subscription._internal_sd = internal_subscription - subscription.message_count = internal_subscription.message_count - subscription.created_at = internal_subscription.created_at - subscription.updated_at = internal_subscription.updated_at - subscription.accessed_at = internal_subscription.accessed_at - subscription.message_count_details = internal_subscription.message_count_details return subscription + @property + def name(self): + """Name of subscription + + :rtype: str + """ + return self._name + + @property + def accessed_at(self): + """Last time a message was sent, or the last time there was a receive request + + :rtype: ~datetime.datetime + """ + return self._internal_sd.accessed_at + + @property + def created_at(self): + """The exact time the subscription was created. + + :rtype: ~datetime.datetime + """ + return self._internal_sd.created_at + + @property + def updated_at(self): + """The exact time the entity is updated. + + :rtype: ~datetime.datetime + """ + return self._internal_sd.updated_at + + @property + def total_message_count(self): + """The number of messages in the subscription. + + :rtype: int + """ + return self._internal_sd.message_count + + @property + def active_message_count(self): + """Number of active messages in the subscription. + + :rtype: int + """ + return self._internal_sd.message_count_details.active_message_count -class RuleDescription(object): - """Description of a topic subscription rule. + @property + def dead_letter_message_count(self): + """Number of messages that are dead lettered. + + :rtype: int + """ + return self._internal_sd.message_count_details.dead_letter_message_count + + @property + def transfer_dead_letter_message_count(self): + """Number of messages transferred into dead letters. + + :rtype: int + """ + return self._internal_sd.message_count_details.transfer_dead_letter_message_count + + @property + def transfer_message_count(self): + """Number of messages transferred to another queue, topic, or subscription. + + :rtype: int + """ + return self._internal_sd.message_count_details.transfer_message_count + + +class RuleProperties(DictMixin): + """Properties of a topic subscription rule. :param name: Name of the rule. :type name: str - :keyword filter: The filter of the rule. - :type filter: Union[~azure.servicebus.management.models.CorrelationRuleFilter, - ~azure.servicebus.management.models.SqlRuleFilter] - :keyword action: The action of the rule. - :type action: Optional[~azure.servicebus.management.models.SqlRuleAction] - :keyword created_at: The exact time the rule was created. + :ivar filter: The filter of the rule. + :type filter: Union[~azure.servicebus.management.CorrelationRuleFilter, + ~azure.servicebus.management.SqlRuleFilter] + :ivar action: The action of the rule. + :type action: Optional[~azure.servicebus.management.SqlRuleAction] + :ivar created_at: The exact time the rule was created. :type created_at: ~datetime.datetime """ def __init__(self, name, **kwargs): # type: (str, Any) -> None - self.filter = kwargs.get('filter', None) - self.action = kwargs.get('action', None) - self.created_at = kwargs.get('created_at', None) - self.name = name + self.name = name self._internal_rule = None # type: Optional[InternalRuleDescription] + extraction_missing_args = [] # type: List[str] + extract_kwarg = functools.partial(extract_kwarg_template, kwargs, extraction_missing_args) + + self.filter = extract_kwarg('filter') + self.action = extract_kwarg('action') + self.created_at = extract_kwarg('created_at') + + validate_extraction_missing_args(extraction_missing_args) + @classmethod def _from_internal_entity(cls, name, internal_rule): - # type: (str, InternalRuleDescription) -> RuleDescription - rule = cls(name) + # type: (str, InternalRuleDescription) -> RuleProperties + rule = cls( + name, + filter=RULE_CLASS_MAPPING[type(internal_rule.filter)]._from_internal_entity(internal_rule.filter) + if internal_rule.filter and isinstance(internal_rule.filter, tuple(RULE_CLASS_MAPPING.keys())) else None, + action=RULE_CLASS_MAPPING[type(internal_rule.action)]._from_internal_entity(internal_rule.action) + if internal_rule.action and isinstance(internal_rule.action, tuple(RULE_CLASS_MAPPING.keys())) else None, + created_at=internal_rule.created_at + ) rule._internal_rule = deepcopy(internal_rule) - - rule.filter = RULE_CLASS_MAPPING[type(internal_rule.filter)]._from_internal_entity(internal_rule.filter) \ - if internal_rule.filter and isinstance(internal_rule.filter, tuple(RULE_CLASS_MAPPING.keys())) else None - rule.action = RULE_CLASS_MAPPING[type(internal_rule.action)]._from_internal_entity(internal_rule.action) \ - if internal_rule.action and isinstance(internal_rule.action, tuple(RULE_CLASS_MAPPING.keys())) else None - rule.created_at = internal_rule.created_at - return rule def _to_internal_entity(self): diff --git a/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_queues_async.py b/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_queues_async.py index 2e7b3817f617..c5cff6fa891d 100644 --- a/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_queues_async.py +++ b/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_queues_async.py @@ -9,7 +9,7 @@ import msrest from azure.core.exceptions import HttpResponseError, ResourceNotFoundError, ResourceExistsError from azure.servicebus.aio.management import ServiceBusManagementClient -from azure.servicebus.management import QueueDescription +from azure.servicebus.management import QueueProperties from azure.servicebus.aio import ServiceBusSharedKeyCredential from azure.servicebus._common.utils import utc_now @@ -213,14 +213,9 @@ async def test_async_mgmt_queue_create_with_invalid_name(self, servicebus_namesp with pytest.raises(msrest.exceptions.ValidationError): await mgmt_service.create_queue(Exception()) - with pytest.raises(msrest.exceptions.ValidationError): - await mgmt_service.create_queue(QueueDescription(name=Exception())) - with pytest.raises(msrest.exceptions.ValidationError): await mgmt_service.create_queue('') - with pytest.raises(msrest.exceptions.ValidationError): - await mgmt_service.create_queue(QueueDescription(name='')) @CachedResourceGroupPreparer(name_prefix='servicebustest') @CachedServiceBusNamespacePreparer(name_prefix='servicebustest') @@ -228,7 +223,7 @@ async def test_async_mgmt_queue_create_with_queue_description(self, servicebus_n mgmt_service = ServiceBusManagementClient.from_connection_string(servicebus_namespace_connection_string) await clear_queues(mgmt_service) queue_name = "dkldf" - await mgmt_service.create_queue(QueueDescription(name=queue_name, + await mgmt_service.create_queue(queue_name, auto_delete_on_idle=datetime.timedelta(minutes=10), dead_lettering_on_message_expiration=True, default_message_time_to_live=datetime.timedelta(minutes=11), @@ -243,7 +238,7 @@ async def test_async_mgmt_queue_create_with_queue_description(self, servicebus_n #requires_duplicate_detection=True, requires_session=True, support_ordering=True - )) + ) try: queue = await mgmt_service.get_queue(queue_name) assert queue.name == queue_name @@ -392,16 +387,15 @@ async def test_async_mgmt_queue_list_runtime_info_basic(self, servicebus_namespa info = queues_infos[0] assert info.size_in_bytes == 0 + assert info.created_at is not None assert info.accessed_at is not None assert info.updated_at is not None - assert info.message_count == 0 - - assert info.message_count_details - assert info.message_count_details.active_message_count == 0 - assert info.message_count_details.dead_letter_message_count == 0 - assert info.message_count_details.transfer_dead_letter_message_count == 0 - assert info.message_count_details.transfer_message_count == 0 - assert info.message_count_details.scheduled_message_count == 0 + assert info.total_message_count == 0 + assert info.active_message_count == 0 + assert info.dead_letter_message_count == 0 + assert info.transfer_dead_letter_message_count == 0 + assert info.transfer_message_count == 0 + assert info.scheduled_message_count == 0 await mgmt_service.delete_queue("test_queue") queues_infos = await async_pageable_to_list(mgmt_service.list_queues_runtime_info()) @@ -435,14 +429,12 @@ async def test_async_mgmt_queue_get_runtime_info_basic(self, servicebus_namespac assert queue_runtime_info.created_at is not None assert queue_runtime_info.accessed_at is not None assert queue_runtime_info.updated_at is not None - assert queue_runtime_info.message_count == 0 - - assert queue_runtime_info.message_count_details - assert queue_runtime_info.message_count_details.active_message_count == 0 - assert queue_runtime_info.message_count_details.dead_letter_message_count == 0 - assert queue_runtime_info.message_count_details.transfer_dead_letter_message_count == 0 - assert queue_runtime_info.message_count_details.transfer_message_count == 0 - assert queue_runtime_info.message_count_details.scheduled_message_count == 0 + assert queue_runtime_info.total_message_count == 0 + assert queue_runtime_info.active_message_count == 0 + assert queue_runtime_info.dead_letter_message_count == 0 + assert queue_runtime_info.transfer_dead_letter_message_count == 0 + assert queue_runtime_info.transfer_message_count == 0 + assert queue_runtime_info.scheduled_message_count == 0 await mgmt_service.delete_queue("test_queue") @CachedResourceGroupPreparer(name_prefix='servicebustest') diff --git a/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_rules_async.py b/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_rules_async.py index b01eed309925..dc91b2ce9cf3 100644 --- a/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_rules_async.py +++ b/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_rules_async.py @@ -10,7 +10,7 @@ import msrest from azure.servicebus.aio.management import ServiceBusManagementClient -from azure.servicebus.management import RuleDescription, CorrelationRuleFilter, SqlRuleFilter, TrueRuleFilter, SqlRuleAction +from azure.servicebus.management import RuleProperties, CorrelationRuleFilter, SqlRuleFilter, TrueRuleFilter, SqlRuleAction from azure.servicebus.management._constants import INT32_MAX_VALUE from utilities import get_logger from azure.core.exceptions import HttpResponseError, ResourceExistsError @@ -48,21 +48,18 @@ async def test_async_mgmt_rule_create(self, servicebus_namespace_connection_stri sql_rule_action = SqlRuleAction(sql_expression="SET Priority = @param", parameters={ "@param": datetime(2020, 7, 5, 11, 12, 13), }) - rule_1 = RuleDescription(name=rule_name_1, filter=correlation_fitler, action=sql_rule_action) sql_filter = SqlRuleFilter("Priority = @param1", parameters={ "@param1": "str1", }) - rule_2 = RuleDescription(name=rule_name_2, filter=sql_filter) bool_filter = TrueRuleFilter() - rule_3 = RuleDescription(name=rule_name_3, filter=bool_filter) try: await mgmt_service.create_topic(topic_name) await mgmt_service.create_subscription(topic_name, subscription_name) - await mgmt_service.create_rule(topic_name, subscription_name, rule_1) + await mgmt_service.create_rule(topic_name, subscription_name, rule_name_1, filter=correlation_fitler, action=sql_rule_action) rule_desc = await mgmt_service.get_rule(topic_name, subscription_name, rule_name_1) rule_properties = rule_desc.filter.properties assert type(rule_desc.filter) == CorrelationRuleFilter @@ -76,13 +73,13 @@ async def test_async_mgmt_rule_create(self, servicebus_namespace_connection_stri assert rule_properties["key_datetime"] == datetime(2020, 7, 5, 11, 12, 13) assert rule_properties["key_duration"] == timedelta(days=1, hours=2, minutes=3) - await mgmt_service.create_rule(topic_name, subscription_name, rule_2) + await mgmt_service.create_rule(topic_name, subscription_name, rule_name_2, filter=sql_filter) rule_desc = await mgmt_service.get_rule(topic_name, subscription_name, rule_name_2) assert type(rule_desc.filter) == SqlRuleFilter assert rule_desc.filter.sql_expression == "Priority = @param1" assert rule_desc.filter.parameters["@param1"] == "str1" - await mgmt_service.create_rule(topic_name, subscription_name, rule_3) + await mgmt_service.create_rule(topic_name, subscription_name, rule_name_3, filter=bool_filter) rule_desc = await mgmt_service.get_rule(topic_name, subscription_name, rule_name_3) assert type(rule_desc.filter) == TrueRuleFilter @@ -102,13 +99,12 @@ async def test_async_mgmt_rule_create_duplicate(self, servicebus_namespace_conne subscription_name = 'kkaqo' rule_name = 'rule' sql_filter = SqlRuleFilter("Priority = 'low'") - rule = RuleDescription(name=rule_name, filter=sql_filter) try: await mgmt_service.create_topic(topic_name) await mgmt_service.create_subscription(topic_name, subscription_name) - await mgmt_service.create_rule(topic_name, subscription_name, rule) + await mgmt_service.create_rule(topic_name, subscription_name, rule_name, filter=sql_filter) with pytest.raises(ResourceExistsError): - await mgmt_service.create_rule(topic_name, subscription_name, rule) + await mgmt_service.create_rule(topic_name, subscription_name, rule_name, filter=sql_filter) finally: await mgmt_service.delete_rule(topic_name, subscription_name, rule_name) await mgmt_service.delete_subscription(topic_name, subscription_name) @@ -123,12 +119,11 @@ async def test_async_mgmt_rule_update_success(self, servicebus_namespace_connect subscription_name = "eqkovc" rule_name = 'rule' sql_filter = SqlRuleFilter("Priority = 'low'") - rule = RuleDescription(name=rule_name, filter=sql_filter) try: topic_description = await mgmt_service.create_topic(topic_name) subscription_description = await mgmt_service.create_subscription(topic_description, subscription_name) - await mgmt_service.create_rule(topic_name, subscription_name, rule) + await mgmt_service.create_rule(topic_name, subscription_name, rule_name, filter=sql_filter) rule_desc = await mgmt_service.get_rule(topic_name, subscription_name, rule_name) @@ -161,12 +156,11 @@ async def test_async_mgmt_rule_update_invalid(self, servicebus_namespace_connect subscription_name = "eqkovc" rule_name = 'rule' sql_filter = SqlRuleFilter("Priority = 'low'") - rule = RuleDescription(name=rule_name, filter=sql_filter) try: topic_description = await mgmt_service.create_topic(topic_name) subscription_description = await mgmt_service.create_subscription(topic_name, subscription_name) - await mgmt_service.create_rule(topic_name, subscription_name, rule) + await mgmt_service.create_rule(topic_name, subscription_name, rule_name, filter=sql_filter) rule_desc = await mgmt_service.get_rule(topic_name, subscription_name, rule_name) @@ -209,9 +203,6 @@ async def test_async_mgmt_rule_list_and_delete(self, servicebus_namespace_connec sql_filter_1 = SqlRuleFilter("Priority = 'low'") sql_filter_2 = SqlRuleFilter("Priority = 'middle'") sql_filter_3 = SqlRuleFilter("Priority = 'high'") - rule_1 = RuleDescription(name=rule_name_1, filter=sql_filter_1) - rule_2 = RuleDescription(name=rule_name_2, filter=sql_filter_2) - rule_3 = RuleDescription(name=rule_name_3, filter=sql_filter_3) try: await mgmt_service.create_topic(topic_name) @@ -220,9 +211,9 @@ async def test_async_mgmt_rule_list_and_delete(self, servicebus_namespace_connec rules = await async_pageable_to_list(mgmt_service.list_rules(topic_name, subscription_name)) assert len(rules) == 1 # by default there is a True filter - await mgmt_service.create_rule(topic_name, subscription_name, rule_1) - await mgmt_service.create_rule(topic_name, subscription_name, rule_2) - await mgmt_service.create_rule(topic_name, subscription_name, rule_3) + await mgmt_service.create_rule(topic_name, subscription_name, rule_name_1, filter=sql_filter_1) + await mgmt_service.create_rule(topic_name, subscription_name, rule_name_2, filter=sql_filter_2) + await mgmt_service.create_rule(topic_name, subscription_name, rule_name_3, filter=sql_filter_3) rules = await async_pageable_to_list(mgmt_service.list_rules(topic_name, subscription_name)) assert len(rules) == 3 + 1 diff --git a/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_subscriptions_async.py b/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_subscriptions_async.py index 24f580f9ddff..50425f6b6048 100644 --- a/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_subscriptions_async.py +++ b/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_subscriptions_async.py @@ -9,7 +9,7 @@ import msrest from azure.servicebus.aio.management import ServiceBusManagementClient -from azure.servicebus.management import SubscriptionDescription +from azure.servicebus.management import SubscriptionProperties from utilities import get_logger from azure.core.exceptions import HttpResponseError, ResourceExistsError @@ -55,16 +55,14 @@ async def test_async_mgmt_subscription_create_with_subscription_description(self await mgmt_service.create_topic(topic_name) await mgmt_service.create_subscription( topic_name, - SubscriptionDescription( - name=subscription_name, - auto_delete_on_idle=datetime.timedelta(minutes=10), - dead_lettering_on_message_expiration=True, - default_message_time_to_live=datetime.timedelta(minutes=11), - enable_batched_operations=True, - lock_duration=datetime.timedelta(seconds=13), - max_delivery_count=14, - requires_session=True - ) + name=subscription_name, + auto_delete_on_idle=datetime.timedelta(minutes=10), + dead_lettering_on_message_expiration=True, + default_message_time_to_live=datetime.timedelta(minutes=11), + enable_batched_operations=True, + lock_duration=datetime.timedelta(seconds=13), + max_delivery_count=14, + requires_session=True ) subscription = await mgmt_service.get_subscription(topic_name, subscription_name) assert subscription.name == subscription_name @@ -257,13 +255,12 @@ async def test_async_mgmt_subscription_list_runtime_info(self, servicebus_namesp assert info.accessed_at is not None assert info.updated_at is not None - - assert info.message_count_details - assert info.message_count_details.active_message_count == 0 - assert info.message_count_details.dead_letter_message_count == 0 - assert info.message_count_details.transfer_dead_letter_message_count == 0 - assert info.message_count_details.transfer_message_count == 0 - assert info.message_count_details.scheduled_message_count == 0 + assert info.created_at is not None + assert info.total_message_count == 0 + assert info.active_message_count == 0 + assert info.dead_letter_message_count == 0 + assert info.transfer_dead_letter_message_count == 0 + assert info.transfer_message_count == 0 await mgmt_service.delete_subscription(topic_name, subscription_name) subs_infos = await async_pageable_to_list(mgmt_service.list_subscriptions_runtime_info(topic_name)) @@ -288,13 +285,11 @@ async def test_async_mgmt_subscription_get_runtime_info_basic(self, servicebus_n assert sub_runtime_info.created_at is not None assert sub_runtime_info.accessed_at is not None assert sub_runtime_info.updated_at is not None - - assert sub_runtime_info.message_count_details - assert sub_runtime_info.message_count_details.active_message_count == 0 - assert sub_runtime_info.message_count_details.dead_letter_message_count == 0 - assert sub_runtime_info.message_count_details.transfer_dead_letter_message_count == 0 - assert sub_runtime_info.message_count_details.transfer_message_count == 0 - assert sub_runtime_info.message_count_details.scheduled_message_count == 0 + assert sub_runtime_info.total_message_count == 0 + assert sub_runtime_info.active_message_count == 0 + assert sub_runtime_info.dead_letter_message_count == 0 + assert sub_runtime_info.transfer_dead_letter_message_count == 0 + assert sub_runtime_info.transfer_message_count == 0 await mgmt_service.delete_subscription(topic_name, subscription_name) await mgmt_service.delete_topic(topic_name) diff --git a/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_topics_async.py b/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_topics_async.py index 8ba94bb00659..868c7c50ec27 100644 --- a/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_topics_async.py +++ b/sdk/servicebus/azure-servicebus/tests/async_tests/mgmt_tests/test_mgmt_topics_async.py @@ -9,7 +9,7 @@ import msrest from azure.servicebus.aio.management import ServiceBusManagementClient -from azure.servicebus.management import TopicDescription +from azure.servicebus.management import TopicProperties from utilities import get_logger from azure.core.exceptions import HttpResponseError, ResourceExistsError @@ -49,18 +49,16 @@ async def test_async_mgmt_topic_create_with_topic_description(self, servicebus_n topic_name = "iweidk" try: await mgmt_service.create_topic( - TopicDescription( - name=topic_name, - auto_delete_on_idle=datetime.timedelta(minutes=10), - default_message_time_to_live=datetime.timedelta(minutes=11), - duplicate_detection_history_time_window=datetime.timedelta(minutes=12), - enable_batched_operations=True, - enable_express=True, - enable_partitioning=True, - enable_subscription_partitioning=True, - is_anonymous_accessible=True, - max_size_in_megabytes=3072 - ) + name=topic_name, + auto_delete_on_idle=datetime.timedelta(minutes=10), + default_message_time_to_live=datetime.timedelta(minutes=11), + duplicate_detection_history_time_window=datetime.timedelta(minutes=12), + enable_batched_operations=True, + enable_express=True, + enable_partitioning=True, + enable_subscription_partitioning=True, + is_anonymous_accessible=True, + max_size_in_megabytes=3072 ) topic = await mgmt_service.get_topic(topic_name) assert topic.name == topic_name @@ -238,13 +236,8 @@ async def test_async_mgmt_topic_list_runtime_info(self, servicebus_namespace_con assert info.accessed_at is not None assert info.updated_at is not None assert info.subscription_count is 0 - - assert info.message_count_details - assert info.message_count_details.active_message_count == 0 - assert info.message_count_details.dead_letter_message_count == 0 - assert info.message_count_details.transfer_dead_letter_message_count == 0 - assert info.message_count_details.transfer_message_count == 0 - assert info.message_count_details.scheduled_message_count == 0 + assert info.size_in_bytes == 0 + assert info.scheduled_message_count == 0 await mgmt_service.delete_topic("test_topic") topics_infos = await async_pageable_to_list(mgmt_service.list_topics_runtime_info()) @@ -265,12 +258,7 @@ async def test_async_mgmt_topic_get_runtime_info_basic(self, servicebus_namespac assert topic_runtime_info.accessed_at is not None assert topic_runtime_info.updated_at is not None assert topic_runtime_info.subscription_count is 0 - - assert topic_runtime_info.message_count_details - assert topic_runtime_info.message_count_details.active_message_count == 0 - assert topic_runtime_info.message_count_details.dead_letter_message_count == 0 - assert topic_runtime_info.message_count_details.transfer_dead_letter_message_count == 0 - assert topic_runtime_info.message_count_details.transfer_message_count == 0 - assert topic_runtime_info.message_count_details.scheduled_message_count == 0 + assert topic_runtime_info.size_in_bytes == 0 + assert topic_runtime_info.scheduled_message_count == 0 finally: await mgmt_service.delete_topic("test_topic") diff --git a/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_queues.py b/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_queues.py index 38bef724f6c0..ee6fcc8baeeb 100644 --- a/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_queues.py +++ b/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_queues.py @@ -11,7 +11,7 @@ import functools import msrest -from azure.servicebus.management import ServiceBusManagementClient, QueueDescription +from azure.servicebus.management import ServiceBusManagementClient, QueueProperties from azure.servicebus._common.utils import utc_now from utilities import get_logger from azure.core.exceptions import HttpResponseError, ServiceRequestError, ResourceNotFoundError, ResourceExistsError @@ -221,14 +221,10 @@ def test_mgmt_queue_create_with_invalid_name(self, servicebus_namespace_connecti with pytest.raises(msrest.exceptions.ValidationError): mgmt_service.create_queue(Exception()) - with pytest.raises(msrest.exceptions.ValidationError): - mgmt_service.create_queue(QueueDescription(name=Exception())) with pytest.raises(msrest.exceptions.ValidationError): mgmt_service.create_queue('') - with pytest.raises(msrest.exceptions.ValidationError): - mgmt_service.create_queue(QueueDescription(name='')) @pytest.mark.liveTest @CachedResourceGroupPreparer(name_prefix='servicebustest') @@ -238,24 +234,25 @@ def test_mgmt_queue_create_with_queue_description(self, servicebus_namespace_con clear_queues(mgmt_service) queue_name = "iweidk" - #TODO: Why don't we have an input model (queueOptions? as superclass of QueueDescription?) and output model to not show these params? + #TODO: Why don't we have an input model (queueOptions? as superclass of QueueProperties?) and output model to not show these params? #TODO: This fails with the following: E msrest.exceptions.DeserializationError: Find several XML 'prefix:DeadLetteringOnMessageExpiration' where it was not expected .tox\whl\lib\site-packages\msrest\serialization.py:1262: DeserializationError - mgmt_service.create_queue(QueueDescription(name=queue_name, - auto_delete_on_idle=datetime.timedelta(minutes=10), - dead_lettering_on_message_expiration=True, - default_message_time_to_live=datetime.timedelta(minutes=11), - duplicate_detection_history_time_window=datetime.timedelta(minutes=12), - enable_batched_operations=True, - enable_express=True, - enable_partitioning=True, - is_anonymous_accessible=True, - lock_duration=datetime.timedelta(seconds=13), - max_delivery_count=14, - max_size_in_megabytes=3072, - #requires_duplicate_detection=True, - requires_session=True, - support_ordering=True - )) + mgmt_service.create_queue( + queue_name, + auto_delete_on_idle=datetime.timedelta(minutes=10), + dead_lettering_on_message_expiration=True, + default_message_time_to_live=datetime.timedelta(minutes=11), + duplicate_detection_history_time_window=datetime.timedelta(minutes=12), + enable_batched_operations=True, + enable_express=True, + enable_partitioning=True, + is_anonymous_accessible=True, + lock_duration=datetime.timedelta(seconds=13), + max_delivery_count=14, + max_size_in_megabytes=3072, + #requires_duplicate_detection=True, + requires_session=True, + support_ordering=True + ) try: queue = mgmt_service.get_queue(queue_name) assert queue.name == queue_name @@ -409,14 +406,13 @@ def test_mgmt_queue_list_runtime_info_basic(self, servicebus_namespace_connectio assert info.size_in_bytes == 0 assert info.accessed_at is not None assert info.updated_at is not None - assert info.message_count == 0 + assert info.total_message_count == 0 - assert info.message_count_details - assert info.message_count_details.active_message_count == 0 - assert info.message_count_details.dead_letter_message_count == 0 - assert info.message_count_details.transfer_dead_letter_message_count == 0 - assert info.message_count_details.transfer_message_count == 0 - assert info.message_count_details.scheduled_message_count == 0 + assert info.active_message_count == 0 + assert info.dead_letter_message_count == 0 + assert info.transfer_dead_letter_message_count == 0 + assert info.transfer_message_count == 0 + assert info.scheduled_message_count == 0 mgmt_service.delete_queue("test_queue") queues_infos = list(mgmt_service.list_queues_runtime_info()) @@ -451,14 +447,13 @@ def test_mgmt_queue_get_runtime_info_basic(self, servicebus_namespace_connection assert queue_runtime_info.created_at is not None assert queue_runtime_info.accessed_at is not None assert queue_runtime_info.updated_at is not None - assert queue_runtime_info.message_count == 0 - - assert queue_runtime_info.message_count_details - assert queue_runtime_info.message_count_details.active_message_count == 0 - assert queue_runtime_info.message_count_details.dead_letter_message_count == 0 - assert queue_runtime_info.message_count_details.transfer_dead_letter_message_count == 0 - assert queue_runtime_info.message_count_details.transfer_message_count == 0 - assert queue_runtime_info.message_count_details.scheduled_message_count == 0 + assert queue_runtime_info.total_message_count == 0 + + assert queue_runtime_info.active_message_count == 0 + assert queue_runtime_info.dead_letter_message_count == 0 + assert queue_runtime_info.transfer_dead_letter_message_count == 0 + assert queue_runtime_info.transfer_message_count == 0 + assert queue_runtime_info.scheduled_message_count == 0 finally: mgmt_service.delete_queue("test_queue") @@ -475,3 +470,6 @@ def test_mgmt_queue_get_runtime_info_negative(self, servicebus_namespace_connect with pytest.raises(ResourceNotFoundError): mgmt_service.get_queue_runtime_info("non_existing_queue") + def test_queue_properties_constructor(self): + with pytest.raises(TypeError): + QueueProperties("randomname") diff --git a/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_rules.py b/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_rules.py index 9acc0e3f894e..7c87fb983564 100644 --- a/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_rules.py +++ b/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_rules.py @@ -8,7 +8,7 @@ from datetime import datetime, timedelta import msrest -from azure.servicebus.management import ServiceBusManagementClient, RuleDescription, CorrelationRuleFilter, SqlRuleFilter, TrueRuleFilter, FalseRuleFilter, SqlRuleAction +from azure.servicebus.management import ServiceBusManagementClient, RuleProperties, CorrelationRuleFilter, SqlRuleFilter, TrueRuleFilter, FalseRuleFilter, SqlRuleAction from azure.servicebus.management._constants import INT32_MAX_VALUE from utilities import get_logger from azure.core.exceptions import HttpResponseError, ResourceExistsError @@ -46,21 +46,18 @@ def test_mgmt_rule_create(self, servicebus_namespace_connection_string, **kwargs sql_rule_action = SqlRuleAction(sql_expression="SET Priority = @param", parameters={ "@param": datetime(2020, 7, 5, 11, 12, 13), }) - rule_1 = RuleDescription(name=rule_name_1, filter=correlation_fitler, action=sql_rule_action) sql_filter = SqlRuleFilter("Priority = @param1", parameters={ "@param1": "str1", }) - rule_2 = RuleDescription(name=rule_name_2, filter=sql_filter) bool_filter = TrueRuleFilter() - rule_3 = RuleDescription(name=rule_name_3, filter=bool_filter) try: mgmt_service.create_topic(topic_name) mgmt_service.create_subscription(topic_name, subscription_name) - mgmt_service.create_rule(topic_name, subscription_name, rule_1) + mgmt_service.create_rule(topic_name, subscription_name, rule_name_1, filter=correlation_fitler, action=sql_rule_action) rule_desc = mgmt_service.get_rule(topic_name, subscription_name, rule_name_1) rule_properties = rule_desc.filter.properties assert type(rule_desc.filter) == CorrelationRuleFilter @@ -75,13 +72,13 @@ def test_mgmt_rule_create(self, servicebus_namespace_connection_string, **kwargs assert rule_properties["key_duration"] == timedelta(days=1, hours=2, minutes=3) - mgmt_service.create_rule(topic_name, subscription_name, rule_2) + mgmt_service.create_rule(topic_name, subscription_name, rule_name_2, filter=sql_filter) rule_desc = mgmt_service.get_rule(topic_name, subscription_name, rule_name_2) assert type(rule_desc.filter) == SqlRuleFilter assert rule_desc.filter.sql_expression == "Priority = @param1" assert rule_desc.filter.parameters["@param1"] == "str1" - mgmt_service.create_rule(topic_name, subscription_name, rule_3) + mgmt_service.create_rule(topic_name, subscription_name, rule_name_3, filter=bool_filter) rule_desc = mgmt_service.get_rule(topic_name, subscription_name, rule_name_3) assert type(rule_desc.filter) == TrueRuleFilter @@ -117,13 +114,12 @@ def test_mgmt_rule_create_duplicate(self, servicebus_namespace_connection_string subscription_name = 'kkaqo' rule_name = 'rule' sql_filter = SqlRuleFilter("Priority = 'low'") - rule = RuleDescription(name=rule_name, filter=sql_filter) try: mgmt_service.create_topic(topic_name) mgmt_service.create_subscription(topic_name, subscription_name) - mgmt_service.create_rule(topic_name, subscription_name, rule) + mgmt_service.create_rule(topic_name, subscription_name, rule_name, filter=sql_filter) with pytest.raises(ResourceExistsError): - mgmt_service.create_rule(topic_name, subscription_name, rule) + mgmt_service.create_rule(topic_name, subscription_name, rule_name, filter=sql_filter) finally: mgmt_service.delete_rule(topic_name, subscription_name, rule_name) mgmt_service.delete_subscription(topic_name, subscription_name) @@ -138,12 +134,11 @@ def test_mgmt_rule_update_success(self, servicebus_namespace_connection_string, subscription_name = "eqkovc" rule_name = 'rule' sql_filter = SqlRuleFilter("Priority = 'low'") - rule = RuleDescription(name=rule_name, filter=sql_filter) try: topic_description = mgmt_service.create_topic(topic_name) subscription_description = mgmt_service.create_subscription(topic_description, subscription_name) - mgmt_service.create_rule(topic_name, subscription_name, rule) + mgmt_service.create_rule(topic_name, subscription_name, rule_name, filter=sql_filter) rule_desc = mgmt_service.get_rule(topic_name, subscription_name, rule_name) @@ -176,12 +171,11 @@ def test_mgmt_rule_update_invalid(self, servicebus_namespace_connection_string, subscription_name = "eqkovc" rule_name = 'rule' sql_filter = SqlRuleFilter("Priority = 'low'") - rule = RuleDescription(name=rule_name, filter=sql_filter) try: topic_description = mgmt_service.create_topic(topic_name) subscription_description = mgmt_service.create_subscription(topic_name, subscription_name) - mgmt_service.create_rule(topic_name, subscription_name, rule) + mgmt_service.create_rule(topic_name, subscription_name, rule_name, filter=sql_filter) rule_desc = mgmt_service.get_rule(topic_name, subscription_name, rule_name) @@ -224,9 +218,6 @@ def test_mgmt_rule_list_and_delete(self, servicebus_namespace_connection_string) sql_filter_1 = SqlRuleFilter("Priority = 'low'") sql_filter_2 = SqlRuleFilter("Priority = 'middle'") sql_filter_3 = SqlRuleFilter("Priority = 'high'") - rule_1 = RuleDescription(name=rule_name_1, filter=sql_filter_1) - rule_2 = RuleDescription(name=rule_name_2, filter=sql_filter_2) - rule_3 = RuleDescription(name=rule_name_3, filter=sql_filter_3) try: mgmt_service.create_topic(topic_name) @@ -235,9 +226,9 @@ def test_mgmt_rule_list_and_delete(self, servicebus_namespace_connection_string) rules = list(mgmt_service.list_rules(topic_name, subscription_name)) assert len(rules) == 1 # by default there is a True filter - mgmt_service.create_rule(topic_name, subscription_name, rule_1) - mgmt_service.create_rule(topic_name, subscription_name, rule_2) - mgmt_service.create_rule(topic_name, subscription_name, rule_3) + mgmt_service.create_rule(topic_name, subscription_name, rule_name_1, filter=sql_filter_1) + mgmt_service.create_rule(topic_name, subscription_name, rule_name_2, filter=sql_filter_2) + mgmt_service.create_rule(topic_name, subscription_name, rule_name_3, filter=sql_filter_3) rules = list(mgmt_service.list_rules(topic_name, subscription_name)) assert len(rules) == 3 + 1 @@ -262,3 +253,7 @@ def test_mgmt_rule_list_and_delete(self, servicebus_namespace_connection_string) finally: mgmt_service.delete_subscription(topic_name, subscription_name) mgmt_service.delete_topic(topic_name) + + def test_rule_properties_constructor(self): + with pytest.raises(TypeError): + RuleProperties("randomname") diff --git a/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_subscriptions.py b/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_subscriptions.py index 675a46ec7bd5..a545702d9158 100644 --- a/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_subscriptions.py +++ b/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_subscriptions.py @@ -8,7 +8,7 @@ import datetime import msrest -from azure.servicebus.management import ServiceBusManagementClient, SubscriptionDescription +from azure.servicebus.management import ServiceBusManagementClient, SubscriptionProperties from utilities import get_logger from azure.core.exceptions import HttpResponseError, ResourceExistsError @@ -54,16 +54,14 @@ def test_mgmt_subscription_create_with_subscription_description(self, servicebus mgmt_service.create_topic(topic_name) mgmt_service.create_subscription( topic_name, - SubscriptionDescription( - name=subscription_name, - auto_delete_on_idle=datetime.timedelta(minutes=10), - dead_lettering_on_message_expiration=True, - default_message_time_to_live=datetime.timedelta(minutes=11), - enable_batched_operations=True, - lock_duration=datetime.timedelta(seconds=13), - max_delivery_count=14, - requires_session=True - ) + name=subscription_name, + auto_delete_on_idle=datetime.timedelta(minutes=10), + dead_lettering_on_message_expiration=True, + default_message_time_to_live=datetime.timedelta(minutes=11), + enable_batched_operations=True, + lock_duration=datetime.timedelta(seconds=13), + max_delivery_count=14, + requires_session=True ) subscription = mgmt_service.get_subscription(topic_name, subscription_name) assert subscription.name == subscription_name @@ -257,12 +255,10 @@ def test_mgmt_subscription_list_runtime_info(self, servicebus_namespace_connecti assert info.accessed_at is not None assert info.updated_at is not None - assert info.message_count_details - assert info.message_count_details.active_message_count == 0 - assert info.message_count_details.dead_letter_message_count == 0 - assert info.message_count_details.transfer_dead_letter_message_count == 0 - assert info.message_count_details.transfer_message_count == 0 - assert info.message_count_details.scheduled_message_count == 0 + assert info.active_message_count == 0 + assert info.dead_letter_message_count == 0 + assert info.transfer_dead_letter_message_count == 0 + assert info.transfer_message_count == 0 mgmt_service.delete_subscription(topic_name, subscription_name) subs_infos = list(mgmt_service.list_subscriptions_runtime_info(topic_name)) @@ -288,12 +284,14 @@ def test_mgmt_subscription_get_runtime_info_basic(self, servicebus_namespace_con assert sub_runtime_info.accessed_at is not None assert sub_runtime_info.updated_at is not None - assert sub_runtime_info.message_count_details - assert sub_runtime_info.message_count_details.active_message_count == 0 - assert sub_runtime_info.message_count_details.dead_letter_message_count == 0 - assert sub_runtime_info.message_count_details.transfer_dead_letter_message_count == 0 - assert sub_runtime_info.message_count_details.transfer_message_count == 0 - assert sub_runtime_info.message_count_details.scheduled_message_count == 0 + assert sub_runtime_info.active_message_count == 0 + assert sub_runtime_info.dead_letter_message_count == 0 + assert sub_runtime_info.transfer_dead_letter_message_count == 0 + assert sub_runtime_info.transfer_message_count == 0 mgmt_service.delete_subscription(topic_name, subscription_name) mgmt_service.delete_topic(topic_name) + + def test_subscription_properties_constructor(self): + with pytest.raises(TypeError): + SubscriptionProperties("randomname") diff --git a/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_topics.py b/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_topics.py index 515bae56b09f..30135906288f 100644 --- a/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_topics.py +++ b/sdk/servicebus/azure-servicebus/tests/mgmt_tests/test_mgmt_topics.py @@ -8,7 +8,7 @@ import datetime import msrest -from azure.servicebus.management import ServiceBusManagementClient, TopicDescription +from azure.servicebus.management import ServiceBusManagementClient, TopicProperties from utilities import get_logger from azure.core.exceptions import HttpResponseError, ResourceExistsError @@ -48,18 +48,16 @@ def test_mgmt_topic_create_with_topic_description(self, servicebus_namespace_con topic_name = "iweidk" try: mgmt_service.create_topic( - TopicDescription( - name=topic_name, - auto_delete_on_idle=datetime.timedelta(minutes=10), - default_message_time_to_live=datetime.timedelta(minutes=11), - duplicate_detection_history_time_window=datetime.timedelta(minutes=12), - enable_batched_operations=True, - enable_express=True, - enable_partitioning=True, - enable_subscription_partitioning=True, - is_anonymous_accessible=True, - max_size_in_megabytes=3072 - ) + name=topic_name, + auto_delete_on_idle=datetime.timedelta(minutes=10), + default_message_time_to_live=datetime.timedelta(minutes=11), + duplicate_detection_history_time_window=datetime.timedelta(minutes=12), + enable_batched_operations=True, + enable_express=True, + enable_partitioning=True, + enable_subscription_partitioning=True, + is_anonymous_accessible=True, + max_size_in_megabytes=3072 ) topic = mgmt_service.get_topic(topic_name) assert topic.name == topic_name @@ -239,12 +237,8 @@ def test_mgmt_topic_list_runtime_info(self, servicebus_namespace_connection_stri assert info.updated_at is not None assert info.subscription_count is 0 - assert info.message_count_details - assert info.message_count_details.active_message_count == 0 - assert info.message_count_details.dead_letter_message_count == 0 - assert info.message_count_details.transfer_dead_letter_message_count == 0 - assert info.message_count_details.transfer_message_count == 0 - assert info.message_count_details.scheduled_message_count == 0 + assert info.size_in_bytes == 0 + assert info.scheduled_message_count == 0 mgmt_service.delete_topic("test_topic") topics_infos = list(mgmt_service.list_topics_runtime_info()) @@ -263,12 +257,11 @@ def test_mgmt_topic_get_runtime_info_basic(self, servicebus_namespace_connection assert topic_runtime_info.created_at is not None assert topic_runtime_info.accessed_at is not None assert topic_runtime_info.updated_at is not None + assert topic_runtime_info.size_in_bytes == 0 assert topic_runtime_info.subscription_count is 0 - - assert topic_runtime_info.message_count_details - assert topic_runtime_info.message_count_details.active_message_count == 0 - assert topic_runtime_info.message_count_details.dead_letter_message_count == 0 - assert topic_runtime_info.message_count_details.transfer_dead_letter_message_count == 0 - assert topic_runtime_info.message_count_details.transfer_message_count == 0 - assert topic_runtime_info.message_count_details.scheduled_message_count == 0 + assert topic_runtime_info.scheduled_message_count == 0 mgmt_service.delete_topic("test_topic") + + def test_topic_properties_constructor(self): + with pytest.raises(TypeError): + TopicProperties("randomname")