0
# Task Execution
1
2
Execute and manage various migration and validation tasks including connection testing, schema migration, data migration, and assessment operations. Tasks are the core execution units that perform specific migration operations within projects.
3
4
## Capabilities
5
6
### Create or Update Task
7
8
Creates a new migration task or updates an existing one within a project.
9
10
```python { .api }
11
def create_or_update(
12
group_name: str,
13
service_name: str,
14
project_name: str,
15
task_name: str,
16
parameters: ProjectTask,
17
**kwargs
18
) -> ProjectTask:
19
"""
20
Creates or updates a migration task.
21
22
Parameters:
23
- group_name: Name of the resource group
24
- service_name: Name of the Data Migration Service
25
- project_name: Name of the project
26
- task_name: Name of the task
27
- parameters: Task configuration and properties
28
29
Returns:
30
ProjectTask object with current state and results
31
"""
32
```
33
34
### Get Task
35
36
Retrieves details and status of an existing task.
37
38
```python { .api }
39
def get(
40
group_name: str,
41
service_name: str,
42
project_name: str,
43
task_name: str,
44
expand: str = None,
45
**kwargs
46
) -> ProjectTask:
47
"""
48
Gets a migration task with current status and results.
49
50
Parameters:
51
- group_name: Name of the resource group
52
- service_name: Name of the Data Migration Service
53
- project_name: Name of the project
54
- task_name: Name of the task
55
- expand: Properties to expand (e.g., "output")
56
57
Returns:
58
ProjectTask with current state, progress, and results
59
"""
60
```
61
62
### Cancel Task
63
64
Cancels a running migration task.
65
66
```python { .api }
67
def cancel(
68
group_name: str,
69
service_name: str,
70
project_name: str,
71
task_name: str,
72
**kwargs
73
) -> ProjectTask:
74
"""
75
Cancels a running migration task.
76
77
Parameters:
78
- group_name: Name of the resource group
79
- service_name: Name of the Data Migration Service
80
- project_name: Name of the project
81
- task_name: Name of the task
82
83
Returns:
84
ProjectTask with updated state
85
"""
86
```
87
88
### Execute Task Commands
89
90
Executes commands on running tasks (e.g., complete sync, restart migration).
91
92
```python { .api }
93
def command(
94
group_name: str,
95
service_name: str,
96
project_name: str,
97
task_name: str,
98
parameters: CommandProperties,
99
**kwargs
100
) -> CommandProperties:
101
"""
102
Executes a command on a migration task.
103
104
Parameters:
105
- group_name: Name of the resource group
106
- service_name: Name of the Data Migration Service
107
- project_name: Name of the project
108
- task_name: Name of the task
109
- parameters: Command to execute
110
111
Returns:
112
Command execution results
113
"""
114
```
115
116
### List Tasks
117
118
Lists all tasks within a project.
119
120
```python { .api }
121
def list(
122
group_name: str,
123
service_name: str,
124
project_name: str,
125
task_type: str = None,
126
**kwargs
127
) -> ItemPaged[ProjectTask]:
128
"""
129
Lists migration tasks in a project.
130
131
Parameters:
132
- group_name: Name of the resource group
133
- service_name: Name of the Data Migration Service
134
- project_name: Name of the project
135
- task_type: Filter by task type (optional)
136
137
Returns:
138
Paged collection of ProjectTask objects
139
"""
140
```
141
142
## Common Task Usage Examples
143
144
### Connection Testing Task
145
146
```python
147
from azure.mgmt.datamigration.models import (
148
ProjectTask,
149
ConnectToSourceSqlServerTaskProperties,
150
ConnectToSourceSqlServerTaskInput
151
)
152
153
# Test SQL Server source connection
154
connection_test_properties = ConnectToSourceSqlServerTaskProperties(
155
input=ConnectToSourceSqlServerTaskInput(
156
source_connection_info=source_connection,
157
check_permissions_group="Default"
158
)
159
)
160
161
connection_test_task = ProjectTask(
162
properties=connection_test_properties
163
)
164
165
task = client.tasks.create_or_update(
166
group_name="myResourceGroup",
167
service_name="myMigrationService",
168
project_name="myProject",
169
task_name="connectionTest",
170
parameters=connection_test_task
171
)
172
173
# Check task status
174
task_status = client.tasks.get(
175
group_name="myResourceGroup",
176
service_name="myMigrationService",
177
project_name="myProject",
178
task_name="connectionTest",
179
expand="output"
180
)
181
182
print(f"Task state: {task_status.properties.state}")
183
```
184
185
### Schema Migration Task
186
187
```python
188
from azure.mgmt.datamigration.models import (
189
MigrateSchemaSqlServerSqlDbTaskProperties,
190
MigrateSchemaSqlServerSqlDbTaskInput,
191
MigrateSchemaSqlServerSqlDbDatabaseInput
192
)
193
194
# Schema migration task
195
schema_migration_properties = MigrateSchemaSqlServerSqlDbTaskProperties(
196
input=MigrateSchemaSqlServerSqlDbTaskInput(
197
source_connection_info=source_connection,
198
target_connection_info=target_connection,
199
selected_databases=[
200
MigrateSchemaSqlServerSqlDbDatabaseInput(
201
name="SourceDB",
202
target_database_name="TargetDB"
203
)
204
]
205
)
206
)
207
208
schema_task = ProjectTask(
209
properties=schema_migration_properties
210
)
211
212
task = client.tasks.create_or_update(
213
group_name="myResourceGroup",
214
service_name="myMigrationService",
215
project_name="myProject",
216
task_name="schemaMigration",
217
parameters=schema_task
218
)
219
```
220
221
## Task State Management
222
223
### Task States
224
225
Tasks progress through these states during execution:
226
227
- **Unknown**: Initial state
228
- **Queued**: Task queued for execution
229
- **Running**: Task currently executing
230
- **Canceled**: Task was canceled
231
- **Succeeded**: Task completed successfully
232
- **Failed**: Task failed with errors
233
- **FailedInputValidation**: Task input validation failed
234
- **Faulted**: Task encountered a fault
235
236
### Monitoring Task Progress
237
238
```python
239
import time
240
from azure.mgmt.datamigration.models import TaskState
241
242
def monitor_task(client, group_name, service_name, project_name, task_name):
243
"""Monitor task execution until completion."""
244
245
while True:
246
task = client.tasks.get(
247
group_name=group_name,
248
service_name=service_name,
249
project_name=project_name,
250
task_name=task_name,
251
expand="output"
252
)
253
254
state = task.properties.state
255
print(f"Task state: {state}")
256
257
if state in [TaskState.SUCCEEDED, TaskState.FAILED, TaskState.CANCELED]:
258
break
259
260
time.sleep(30) # Wait 30 seconds before checking again
261
262
return task
263
```
264
265
## Task Types and Properties
266
267
### ProjectTask
268
269
```python { .api }
270
class ProjectTask:
271
"""Migration or validation task."""
272
273
def __init__(self, properties: ProjectTaskProperties, **kwargs):
274
"""
275
Initialize migration task.
276
277
Parameters:
278
- properties: Task-specific properties and configuration
279
"""
280
281
# Properties
282
etag: str # Entity tag for concurrency control
283
properties: ProjectTaskProperties # Task properties and configuration
284
id: str # Resource ID
285
name: str # Resource name
286
type: str # Resource type
287
```
288
289
### ProjectTaskProperties
290
291
```python { .api }
292
class ProjectTaskProperties:
293
"""Base class for task properties."""
294
295
# Properties
296
task_type: str # Task type identifier
297
errors: List[ODataError] # Task execution errors
298
state: str # Current task state
299
commands: List[CommandProperties] # Available commands
300
client_data: Dict[str, Any] # Client-specific data
301
```
302
303
## Command Types
304
305
### MigrateSyncCompleteCommandProperties
306
307
```python { .api }
308
class MigrateSyncCompleteCommandProperties(CommandProperties):
309
"""Complete a sync migration."""
310
311
def __init__(self, input: MigrateSyncCompleteCommandInput, **kwargs):
312
"""
313
Parameters:
314
- input: Command input with database name
315
"""
316
317
# Properties
318
input: MigrateSyncCompleteCommandInput # Command input
319
output: MigrateSyncCompleteCommandOutput # Command output
320
```
321
322
### MongoDB Commands
323
324
```python { .api }
325
class MongoDbCancelCommand(CommandProperties):
326
"""Cancel MongoDB migration."""
327
328
def __init__(self, input: MongoDbCommandInput, **kwargs): ...
329
330
class MongoDbFinishCommand(CommandProperties):
331
"""Finish MongoDB migration."""
332
333
def __init__(self, input: MongoDbFinishCommandInput, **kwargs): ...
334
335
class MongoDbRestartCommand(CommandProperties):
336
"""Restart MongoDB migration."""
337
338
def __init__(self, input: MongoDbCommandInput, **kwargs): ...
339
```
340
341
## Error Handling
342
343
Common task execution errors:
344
345
- **Connection failures**: Source or target database unreachable
346
- **Permission errors**: Insufficient database permissions
347
- **Schema conflicts**: Target schema incompatibilities
348
- **Data validation errors**: Data integrity or constraint violations
349
- **Resource limitations**: Memory, storage, or network constraints
350
351
Monitor task errors through the `errors` property and implement appropriate retry logic for transient failures.