Example 3: Pausing and Deleting a Migration Task
Scenarios
This section describes how to pause and delete a migration task using an API. For details, see Calling APIs.
Before deleting a migration task, you need to obtain the token. After pausing the migration task, you need to query the task status. The migration task can be deleted only after it is paused.
Involved APIs
- Obtaining a User Token Through Password Authentication: This API is used to obtain the user token for authentication.
- Pausing a Migration Task: used to pause a migration task based on the migration task ID
- Querying a Migration Task: used to query the task details based on the migration task ID to check whether the migration task is successfully paused
- Deleting a Migration Task: used to delete a migration task based on the migration task ID
Procedure
- Obtain the token of the IAM user.
- API
URI format: POST /v3/auth/tokens
For details, see Obtaining a User Token Through Password Authentication.
- Example request
POST: https://{iam_endpoint}/v3/auth/tokens
Obtain {endpoint} from Regions and Endpoints.
Body:{ "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "name": "testname", "domain": { "name": "testname" }, "password": "Password" } } }, "scope": { "project": { "id": "0215ef11e49d4743be23dd97a1561e91" } } } }
In the response header, the value of X-Subject-Token is the token.
X-Subject-Token:MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX...
- API
- Make a call to the API for pausing a migration task to pause a migration task.
- API
URI format: POST /v2/{project_id}/tasks/{task_id}/stop
For details, see Pausing a Migration Task.
- Example request
POST: https://{oms_endpoint}/v2/{project_id}/tasks/{task_id}/stop
Obtain {endpoint} from Regions and Endpoints.
Header:
Content-Type: application/json X-Auth-Token: "Token"
If the response code is 200, the API is successfully called.
- API
- Make a call to the task viewing API to view the task status.
- API
GET /v2/{project_id}/tasks/{task_id}
For details, see Querying a Migration Task.
- Example request
GET: https://{oms_endpoint}/v2/{project_id}/tasks/{task_id}
Obtain {endpoint} from Regions and Endpoints.
Header:
Content-Type: application/json X-Auth-Token: "Token"
- Example response
{ "bandwidth_policy" : [], "complete_size" : 2223728, "description" : "", "dst_node" : { "bucket" : "api-test-outline", "region" : "cn-north-7" }, "enable_failed_object_recording" : true, "enable_kms" : false, "enable_restore" : false, "error_reason" : null, "failed_num" : 0, "failed_object_record" : { "result" : null, "list_file_key" : null, "error_code" : null }, "group_id" : "", "id" : 200477729979132, "is_query_over" : true, "left_time" : 0, "migrate_since" : 0, "migrate_speed" : 71477, "name" : "task_name", "progress" : 1.0, "real_size" : 2223728, "skipped_num" : 0, "src_node" : { "bucket" : "a-test-1", "cloud_type" : "HuaweiCloud", "region" : "cn-north-7", "app_id" : "", "object_key" : ["01.png", "list.txt"], "list_file" : null }, "start_time" : 1589267678170, "status" : 3, "successful_num" : 2, "task_type" : "object", "total_num" : 2, "total_size" : 2223728, "total_time" : 31111, "smn_info" : null, "source_cdn" : null }
status indicates the task execution status. The value 3 indicates that the task is paused.
- API
- Make a call to the API for deleting a migration task to delete a migration task.
- API
URI format: DELETE /v2/{project_id}/tasks/{task_id}
For details, see Deleting a Migration Task.
- Example request
DELETE: https://{oms_endpoint}/v2/{project_id}/tasks/{task_id}
Obtain {endpoint} from Regions and Endpoints.
Header:
Content-Type: application/json X-Auth-Token: "Token"
If the response code is 200, the migration task is deleted successfully.
- API
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.