Skip to content

Commit 0c86934

Browse files
authored
Merge pull request #554 from rtdip/develop
v0.8.7
2 parents 48bdc16 + d6f6186 commit 0c86934

File tree

2 files changed

+26
-58
lines changed

2 files changed

+26
-58
lines changed

src/sdk/python/rtdip_sdk/pipelines/utilities/azure/autoloader_resources.py

+19-58
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
)
2929
from azure.mgmt.storage import StorageManagementClient
3030
from azure.mgmt.storage.models import StorageQueue
31+
from azure.core.exceptions import ResourceNotFoundError
3132

3233

3334
class AzureAutoloaderResourcesUtility(UtilitiesInterface):
@@ -43,7 +44,6 @@ class AzureAutoloaderResourcesUtility(UtilitiesInterface):
4344
credential (TokenCredential): Credentials to authenticate with Storage Account
4445
event_subscription_name (str): Name of the Event Subscription
4546
queue_name (str): Name of the queue that will be used for the Endpoint of the Messages
46-
system_topic_name (optional, str): The system topic name. Defaults to the storage account name if not provided.
4747
"""
4848

4949
subscription_id: str
@@ -54,7 +54,6 @@ class AzureAutoloaderResourcesUtility(UtilitiesInterface):
5454
credential: TokenCredential
5555
event_subscription_name: str
5656
queue_name: str
57-
system_topic_name: str
5857

5958
def __init__(
6059
self,
@@ -66,7 +65,6 @@ def __init__(
6665
credential: TokenCredential,
6766
event_subscription_name: str,
6867
queue_name: str,
69-
system_topic_name: str = None,
7068
) -> None:
7169
self.subscription_id = subscription_id
7270
self.resource_group_name = resource_group_name
@@ -76,9 +74,6 @@ def __init__(
7674
self.credential = credential
7775
self.event_subscription_name = event_subscription_name
7876
self.queue_name = queue_name
79-
self.system_topic_name = (
80-
storage_account if system_topic_name is None else system_topic_name
81-
)
8277

8378
@staticmethod
8479
def system_type():
@@ -104,21 +99,16 @@ def execute(self) -> bool:
10499
credential=self.credential, subscription_id=self.subscription_id
105100
)
106101

107-
account_properties = storage_mgmt_client.storage_accounts.get_properties(
108-
resource_group_name=self.resource_group_name,
109-
account_name=self.storage_account,
110-
)
111-
112-
queue_response = storage_mgmt_client.queue.list(
113-
resource_group_name=self.resource_group_name,
114-
account_name=self.storage_account,
115-
)
116-
117-
queue_list = [
118-
queue for queue in queue_response if queue.name == self.queue_name
119-
]
102+
try:
103+
queue_response = storage_mgmt_client.queue.get(
104+
resource_group_name=self.resource_group_name,
105+
account_name=self.storage_account,
106+
queue_name=self.queue_name,
107+
)
108+
except ResourceNotFoundError:
109+
queue_response = None
120110

121-
if queue_list == []:
111+
if queue_response == None:
122112
storage_mgmt_client.queue.create(
123113
resource_group_name=self.resource_group_name,
124114
account_name=self.storage_account,
@@ -130,47 +120,18 @@ def execute(self) -> bool:
130120
credential=self.credential, subscription_id=self.subscription_id
131121
)
132122

133-
system_topic_response = eventgrid_client.system_topics.list_by_resource_group(
134-
resource_group_name=self.resource_group_name,
135-
filter="name eq '{}'".format(self.system_topic_name),
136-
)
137-
138123
source = "/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Storage/StorageAccounts/{}".format(
139124
self.subscription_id, self.resource_group_name, self.storage_account
140125
)
141126

142-
system_topic_list = [
143-
system_topic
144-
for system_topic in system_topic_response
145-
if system_topic.source == source
146-
]
147-
148-
if system_topic_list == []:
149-
eventgrid_client.system_topics.begin_create_or_update(
150-
resource_group_name=self.resource_group_name,
151-
system_topic_name=self.system_topic_name,
152-
system_topic_info=SystemTopic(
153-
location=account_properties.location,
154-
source=source,
155-
topic_type="Microsoft.Storage.StorageAccounts",
156-
),
157-
).result()
158-
159-
system_topic_event_subscription_response = (
160-
eventgrid_client.system_topic_event_subscriptions.list_by_system_topic(
161-
resource_group_name=self.resource_group_name,
162-
system_topic_name=self.system_topic_name,
163-
filter="name eq '{}'".format(self.event_subscription_name),
127+
try:
128+
event_subscription_response = eventgrid_client.event_subscriptions.get(
129+
scope=source, event_subscription_name=self.event_subscription_name
164130
)
165-
)
166-
167-
system_topic_event_subscription_list = [
168-
system_topic_event_subscription
169-
for system_topic_event_subscription in system_topic_event_subscription_response
170-
if system_topic_event_subscription.source == source
171-
]
131+
except ResourceNotFoundError:
132+
event_subscription_response = None
172133

173-
if system_topic_event_subscription_list == []:
134+
if event_subscription_response == None:
174135
event_subscription_destination = StorageQueueEventSubscriptionDestination(
175136
resource_id=source,
176137
queue_name=self.queue_name,
@@ -210,10 +171,10 @@ def execute(self) -> bool:
210171
retry_policy=retry_policy,
211172
)
212173

213-
eventgrid_client.system_topic_event_subscriptions.begin_create_or_update(
214-
resource_group_name=self.resource_group_name,
215-
system_topic_name=self.system_topic_name,
174+
eventgrid_client.event_subscriptions.begin_create_or_update(
175+
scope=source,
216176
event_subscription_name=self.event_subscription_name,
217177
event_subscription_info=event_subscription_info,
218178
).result()
179+
219180
return True

tests/sdk/python/rtdip_sdk/pipelines/utilities/azure/test_autoloader_resources.py

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class MockEventSubscription:
4040
def __init__(self) -> None: # NOSONAR
4141
pass
4242

43+
def get(self, **kwargs):
44+
return None
45+
4346
def list_by_system_topic(self, **kwargs):
4447
return []
4548

@@ -65,6 +68,9 @@ def __init__(self) -> None: # NOSONAR
6568
def create(self, **kwargs): # NOSONAR
6669
pass
6770

71+
def get(self, **kwargs):
72+
return None
73+
6874
def list(self, **kwargs):
6975
return []
7076

@@ -87,6 +93,7 @@ def __init__(self) -> None: # NOSONAR
8793
class MockEventGridClient:
8894
system_topics = MockSystemTopics()
8995
system_topic_event_subscriptions = MockEventSubscription()
96+
event_subscriptions = MockEventSubscription()
9097

9198
def __init__(self) -> None: # NOSONAR
9299
pass

0 commit comments

Comments
 (0)