0
# Migration and Monitoring
1
2
Standard to Premium namespace migration operations and operational monitoring through operation listings and private networking. This includes migrating existing Standard namespaces to Premium tier for enhanced performance and features, as well as monitoring Service Bus operations.
3
4
## Capabilities
5
6
### Standard to Premium Migration
7
8
Migrate existing Standard tier namespaces to Premium tier with minimal downtime and preserved configurations.
9
10
```python { .api }
11
def list(
12
self,
13
resource_group_name: str,
14
namespace_name: str
15
) -> ItemPaged[MigrationConfigProperties]:
16
"""List migration configurations for a namespace.
17
18
Args:
19
resource_group_name (str): Name of the resource group.
20
namespace_name (str): Name of the source namespace.
21
22
Returns:
23
ItemPaged[MigrationConfigProperties]: Iterable of migration configurations.
24
"""
25
26
def create_and_start_migration(
27
self,
28
resource_group_name: str,
29
namespace_name: str,
30
config_name: str,
31
parameters: MigrationConfigProperties
32
) -> LROPoller[MigrationConfigProperties]:
33
"""Create and start a migration from Standard to Premium namespace.
34
35
Args:
36
resource_group_name (str): Name of the resource group.
37
namespace_name (str): Name of the source Standard namespace.
38
config_name (str): Name of the migration configuration.
39
parameters (MigrationConfigProperties): Migration configuration parameters.
40
41
Returns:
42
LROPoller[MigrationConfigProperties]: Long-running operation poller for the migration.
43
"""
44
45
def get(
46
self,
47
resource_group_name: str,
48
namespace_name: str,
49
config_name: str
50
) -> MigrationConfigProperties:
51
"""Get migration configuration details.
52
53
Args:
54
resource_group_name (str): Name of the resource group.
55
namespace_name (str): Name of the source namespace.
56
config_name (str): Name of the migration configuration.
57
58
Returns:
59
MigrationConfigProperties: The migration configuration.
60
"""
61
62
def delete(
63
self,
64
resource_group_name: str,
65
namespace_name: str,
66
config_name: str
67
) -> None:
68
"""Delete a migration configuration.
69
70
Args:
71
resource_group_name (str): Name of the resource group.
72
namespace_name (str): Name of the source namespace.
73
config_name (str): Name of the migration configuration.
74
"""
75
76
def complete_migration(
77
self,
78
resource_group_name: str,
79
namespace_name: str,
80
config_name: str
81
) -> None:
82
"""Complete the migration process.
83
84
Args:
85
resource_group_name (str): Name of the resource group.
86
namespace_name (str): Name of the source namespace.
87
config_name (str): Name of the migration configuration.
88
89
Note:
90
This finalizes the migration and makes the Premium namespace the primary.
91
"""
92
93
def revert(
94
self,
95
resource_group_name: str,
96
namespace_name: str,
97
config_name: str
98
) -> None:
99
"""Revert a migration back to the Standard namespace.
100
101
Args:
102
resource_group_name (str): Name of the resource group.
103
namespace_name (str): Name of the source namespace.
104
config_name (str): Name of the migration configuration.
105
"""
106
```
107
108
### Operations Monitoring
109
110
List and monitor available Service Bus management operations and their status.
111
112
```python { .api }
113
def list(self) -> ItemPaged[Operation]:
114
"""List available Service Bus management operations.
115
116
Returns:
117
ItemPaged[Operation]: Iterable of available operations.
118
"""
119
```
120
121
## Usage Examples
122
123
### Setting Up Standard to Premium Migration
124
125
```python
126
from azure.mgmt.servicebus import ServiceBusManagementClient
127
from azure.mgmt.servicebus.models import MigrationConfigProperties, SBNamespace, SBSku
128
from azure.identity import DefaultAzureCredential
129
130
client = ServiceBusManagementClient(DefaultAzureCredential(), subscription_id)
131
132
# First, create a Premium namespace in the same region as the Standard namespace
133
premium_namespace_params = SBNamespace(
134
location="East US", # Same location as Standard namespace
135
sku=SBSku(
136
name="Premium",
137
tier="Premium",
138
capacity=1 # 1, 2, or 4 messaging units
139
),
140
tags={"migration": "target", "tier": "premium"}
141
)
142
143
premium_namespace = client.namespaces.create_or_update(
144
resource_group_name="my-resource-group",
145
namespace_name="my-premium-namespace",
146
parameters=premium_namespace_params
147
)
148
149
print(f"Premium namespace created: {premium_namespace.name}")
150
151
# Configure the migration
152
migration_config = MigrationConfigProperties(
153
target_namespace="/subscriptions/{subscription-id}/resourceGroups/my-resource-group/providers/Microsoft.ServiceBus/namespaces/my-premium-namespace",
154
post_migration_name="my-standard-namespace-migrated"
155
)
156
157
# Start the migration (this is a long-running operation)
158
migration_poller = client.migration_configs.create_and_start_migration(
159
resource_group_name="my-resource-group",
160
namespace_name="my-standard-namespace", # Source Standard namespace
161
config_name="$default", # Standard configuration name
162
parameters=migration_config
163
)
164
165
print("Migration started...")
166
167
# Wait for migration to complete
168
migration_result = migration_poller.result()
169
print(f"Migration configuration: {migration_result.provisioning_state}")
170
```
171
172
### Monitoring Migration Progress
173
174
```python
175
import time
176
from azure.mgmt.servicebus.models import ProvisioningStateDR
177
178
def monitor_migration_progress(resource_group_name, namespace_name, config_name="$default"):
179
"""Monitor the progress of a Standard to Premium migration"""
180
181
while True:
182
try:
183
migration_status = client.migration_configs.get(
184
resource_group_name=resource_group_name,
185
namespace_name=namespace_name,
186
config_name=config_name
187
)
188
189
print(f"Migration Status: {migration_status.provisioning_state}")
190
print(f"Target Namespace: {migration_status.target_namespace}")
191
print(f"Pending Operations: {migration_status.pending_replication_operations_count}")
192
193
if migration_status.provisioning_state == "Succeeded":
194
print("Migration preparation completed successfully!")
195
print("You can now complete the migration or revert if needed.")
196
break
197
elif migration_status.provisioning_state == "Failed":
198
print("Migration failed!")
199
break
200
else:
201
print("Migration in progress...")
202
time.sleep(30) # Wait 30 seconds before checking again
203
204
except Exception as e:
205
print(f"Error monitoring migration: {e}")
206
break
207
208
# Monitor the migration
209
monitor_migration_progress("my-resource-group", "my-standard-namespace")
210
```
211
212
### Completing the Migration
213
214
```python
215
# Once migration preparation is complete, you need to complete the migration
216
try:
217
# Complete the migration - this switches traffic to the Premium namespace
218
client.migration_configs.complete_migration(
219
resource_group_name="my-resource-group",
220
namespace_name="my-standard-namespace",
221
config_name="$default"
222
)
223
224
print("Migration completed successfully!")
225
print("Traffic is now directed to the Premium namespace.")
226
print("The Standard namespace is renamed with the post_migration_name.")
227
228
# Verify the migration completion
229
migration_status = client.migration_configs.get(
230
resource_group_name="my-resource-group",
231
namespace_name="my-standard-namespace",
232
config_name="$default"
233
)
234
235
print(f"Final migration state: {migration_status.provisioning_state}")
236
237
except Exception as e:
238
print(f"Failed to complete migration: {e}")
239
```
240
241
### Reverting a Migration
242
243
```python
244
# If you need to revert the migration back to the Standard namespace
245
try:
246
# Revert the migration - this switches traffic back to Standard namespace
247
client.migration_configs.revert(
248
resource_group_name="my-resource-group",
249
namespace_name="my-standard-namespace",
250
config_name="$default"
251
)
252
253
print("Migration reverted successfully!")
254
print("Traffic is now directed back to the Standard namespace.")
255
256
# Check the status
257
migration_status = client.migration_configs.get(
258
resource_group_name="my-resource-group",
259
namespace_name="my-standard-namespace",
260
config_name="$default"
261
)
262
263
print(f"Revert state: {migration_status.provisioning_state}")
264
265
except Exception as e:
266
print(f"Failed to revert migration: {e}")
267
```
268
269
### Managing Migration Lifecycle
270
271
```python
272
def manage_complete_migration_lifecycle():
273
"""Complete migration lifecycle management"""
274
275
try:
276
# 1. List existing migration configurations
277
migrations = client.migration_configs.list(
278
resource_group_name="my-resource-group",
279
namespace_name="my-standard-namespace"
280
)
281
282
print("Existing migrations:")
283
for migration in migrations:
284
print(f"- Config: {migration.name}")
285
print(f" State: {migration.provisioning_state}")
286
print(f" Target: {migration.target_namespace}")
287
288
# 2. Create Premium namespace if it doesn't exist
289
premium_params = SBNamespace(
290
location="East US",
291
sku=SBSku(name="Premium", tier="Premium", capacity=1)
292
)
293
294
try:
295
premium_ns = client.namespaces.create_or_update(
296
resource_group_name="my-resource-group",
297
namespace_name="migration-target-premium",
298
parameters=premium_params
299
)
300
print(f"Premium namespace ready: {premium_ns.name}")
301
except Exception as e:
302
print(f"Premium namespace may already exist: {e}")
303
304
# 3. Start migration
305
migration_config = MigrationConfigProperties(
306
target_namespace="/subscriptions/{subscription-id}/resourceGroups/my-resource-group/providers/Microsoft.ServiceBus/namespaces/migration-target-premium",
307
post_migration_name="original-standard-backup"
308
)
309
310
migration_poller = client.migration_configs.create_and_start_migration(
311
resource_group_name="my-resource-group",
312
namespace_name="my-standard-namespace",
313
config_name="$default",
314
parameters=migration_config
315
)
316
317
# 4. Wait for preparation to complete
318
migration_result = migration_poller.result()
319
print(f"Migration preparation: {migration_result.provisioning_state}")
320
321
# 5. In a real scenario, you would test the Premium namespace here
322
# before completing the migration
323
324
# 6. Complete the migration
325
client.migration_configs.complete_migration(
326
resource_group_name="my-resource-group",
327
namespace_name="my-standard-namespace",
328
config_name="$default"
329
)
330
331
print("Migration completed successfully!")
332
333
# 7. Clean up migration configuration after completion
334
time.sleep(60) # Wait for completion to settle
335
336
client.migration_configs.delete(
337
resource_group_name="my-resource-group",
338
namespace_name="my-standard-namespace",
339
config_name="$default"
340
)
341
342
print("Migration configuration cleaned up")
343
344
except Exception as e:
345
print(f"Migration lifecycle error: {e}")
346
347
# Try to revert if something went wrong
348
try:
349
client.migration_configs.revert(
350
resource_group_name="my-resource-group",
351
namespace_name="my-standard-namespace",
352
config_name="$default"
353
)
354
print("Migration reverted due to error")
355
except:
356
print("Could not revert migration")
357
358
# Run the complete migration lifecycle
359
manage_complete_migration_lifecycle()
360
```
361
362
### Monitoring Service Bus Operations
363
364
```python
365
# List all available Service Bus management operations
366
operations = client.operations.list()
367
368
print("Available Service Bus Management Operations:")
369
for operation in operations:
370
print(f"Operation: {operation.name}")
371
if operation.display:
372
print(f" Provider: {operation.display.provider}")
373
print(f" Resource: {operation.display.resource}")
374
print(f" Operation: {operation.display.operation}")
375
print(f" Description: {operation.display.description}")
376
print()
377
378
# Filter operations by category
379
namespace_operations = [op for op in operations if 'namespace' in op.name.lower()]
380
queue_operations = [op for op in operations if 'queue' in op.name.lower()]
381
topic_operations = [op for op in operations if 'topic' in op.name.lower()]
382
383
print(f"Namespace operations: {len(namespace_operations)}")
384
print(f"Queue operations: {len(queue_operations)}")
385
print(f"Topic operations: {len(topic_operations)}")
386
```
387
388
### Migration Validation and Testing
389
390
```python
391
def validate_migration_readiness(standard_namespace_name, premium_namespace_name):
392
"""Validate that namespaces are ready for migration"""
393
394
validation_results = {
395
"ready_for_migration": True,
396
"issues": [],
397
"recommendations": []
398
}
399
400
try:
401
# Get Standard namespace details
402
standard_ns = client.namespaces.get(
403
resource_group_name="my-resource-group",
404
namespace_name=standard_namespace_name
405
)
406
407
# Get Premium namespace details
408
premium_ns = client.namespaces.get(
409
resource_group_name="my-resource-group",
410
namespace_name=premium_namespace_name
411
)
412
413
# Validate SKU compatibility
414
if standard_ns.sku.name != "Standard":
415
validation_results["ready_for_migration"] = False
416
validation_results["issues"].append(f"Source namespace is {standard_ns.sku.name}, must be Standard")
417
418
if premium_ns.sku.name != "Premium":
419
validation_results["ready_for_migration"] = False
420
validation_results["issues"].append(f"Target namespace is {premium_ns.sku.name}, must be Premium")
421
422
# Validate same region
423
if standard_ns.location != premium_ns.location:
424
validation_results["ready_for_migration"] = False
425
validation_results["issues"].append(f"Namespaces in different regions: {standard_ns.location} vs {premium_ns.location}")
426
427
# Check namespace status
428
if standard_ns.status != "Active":
429
validation_results["ready_for_migration"] = False
430
validation_results["issues"].append(f"Standard namespace status: {standard_ns.status}")
431
432
if premium_ns.status != "Active":
433
validation_results["ready_for_migration"] = False
434
validation_results["issues"].append(f"Premium namespace status: {premium_ns.status}")
435
436
# Add recommendations
437
validation_results["recommendations"].extend([
438
"Backup all authorization rules and access keys",
439
"Test applications with Premium namespace connection strings",
440
"Plan for brief connectivity interruption during completion",
441
"Monitor migration progress and have rollback plan ready"
442
])
443
444
except Exception as e:
445
validation_results["ready_for_migration"] = False
446
validation_results["issues"].append(f"Validation error: {e}")
447
448
return validation_results
449
450
# Validate migration readiness
451
validation = validate_migration_readiness("my-standard-namespace", "my-premium-namespace")
452
453
if validation["ready_for_migration"]:
454
print("✅ Ready for migration!")
455
else:
456
print("❌ Migration issues found:")
457
for issue in validation["issues"]:
458
print(f" - {issue}")
459
460
print("\nRecommendations:")
461
for rec in validation["recommendations"]:
462
print(f" - {rec}")
463
```
464
465
## Types
466
467
```python { .api }
468
class MigrationConfigProperties:
469
def __init__(self, **kwargs): ...
470
471
# Migration configuration
472
id: Optional[str]
473
name: Optional[str]
474
type: Optional[str]
475
476
# Migration properties
477
provisioning_state: Optional[str]
478
pending_replication_operations_count: Optional[int]
479
target_namespace: Optional[str] # ARM resource ID of target Premium namespace
480
post_migration_name: Optional[str] # Name for Standard namespace after migration
481
migration_state: Optional[str]
482
483
class MigrationConfigListResult:
484
def __init__(self, **kwargs): ...
485
486
value: Optional[List[MigrationConfigProperties]]
487
next_link: Optional[str]
488
489
class Operation:
490
def __init__(self, **kwargs): ...
491
492
# Operation details
493
name: Optional[str]
494
is_data_action: Optional[bool]
495
display: Optional[OperationDisplay]
496
origin: Optional[str]
497
properties: Optional[Dict[str, Any]]
498
499
class OperationDisplay:
500
def __init__(self, **kwargs): ...
501
502
provider: Optional[str] # Resource provider name
503
resource: Optional[str] # Resource type
504
operation: Optional[str] # Operation name
505
description: Optional[str] # Operation description
506
507
class OperationListResult:
508
def __init__(self, **kwargs): ...
509
510
value: Optional[List[Operation]]
511
next_link: Optional[str]
512
```
513
514
## Migration Process Overview
515
516
### Migration Phases
517
518
1. **Preparation Phase**
519
- Validate source Standard and target Premium namespaces
520
- Create migration configuration
521
- Start metadata replication to Premium namespace
522
523
2. **Replication Phase**
524
- Entity metadata (queues, topics, subscriptions, rules) replicated
525
- Authorization rules copied to Premium namespace
526
- Applications continue using Standard namespace
527
528
3. **Completion Phase**
529
- Switch DNS alias to point to Premium namespace
530
- Standard namespace renamed with `post_migration_name`
531
- Applications automatically redirected to Premium namespace
532
533
4. **Cleanup Phase**
534
- Remove migration configuration
535
- Optionally delete old Standard namespace
536
537
### Migration Considerations
538
539
**What Gets Migrated:**
540
- Entity configurations (queues, topics, subscriptions)
541
- Message filtering rules
542
- Authorization rules and access keys
543
- Namespace-level settings
544
545
**What Doesn't Get Migrated:**
546
- Message data (messages remain in Standard namespace until consumed)
547
- Private endpoint connections
548
- Network rule sets
549
- Custom DNS configurations
550
551
**Best Practices:**
552
- Perform migration during low-traffic periods
553
- Test applications with Premium namespace before completion
554
- Have rollback plan ready using `revert()` operation
555
- Monitor `pending_replication_operations_count` during migration
556
- Keep Standard namespace temporarily after migration for rollback capability