更新时间:2023-12-27 GMT+08:00

快速入门

场景描述

本节以调用一系列API创建一个对象数据迁移任务为例,介绍使用API的基本流程。

API的调用方法请参见如何调用API

涉及接口

前提条件

创建应用

假设已获取前提条件中的信息为如下值(实际操作中您需要根据实际情况替换):

  • IAM的Endpoint:下面示例中以iam_endpoint代替。
  • OMS的Endpoint:oms.cn-north-1.myhuaweicloud.com 。
  • 项目ID:0215ef11e49d4743be23dd97a156xxxx。
  • 源端桶的区域:cn-beijing。
  • 目的端桶的区域:cn-north-1。
  • 源端AK:下面示例中以source_ak代替。
  • 源端SK:下面示例中以source_sk代替。
  • 目的端AK:下面示例中以destination_ak代替。
  • 目的端SK:下面示例中以destination_sk代替。
  • 源端桶名:下面示例中以source_bucket代替。
  • 目的端桶名:下面示例中以destination_bucket代替。
  • 源端类型:下面示例中以cloud_type代替。

操作步骤

  1. 获取IAM用户Token。

    • 接口相关信息

      URI格式:POST /v3/auth/tokens

      详情请参见获取IAM用户Token(使用密码)

    • 请求示例
      POST: https://{iam_endpoint}/v3/auth/tokens

      {endpoint}信息请从地区和终端节点获取。

      Body:
      {
          "auth": {
              "identity": {
                  "methods": [
                      "password"
                  ],
                  "password": {
                      "user": {
                          "name": "testname",
                          "domain": {
                              "name": "testname"
                          },
                          "password": "Password"
                      }
                  }
              },
              "scope": {
                  "project": {
                      "id": "0215ef11e49d4743be23dd97a156xxxx"
                  }
              }
          }
      }

    响应Header中“X-Subject-Token”的值即为Token:

    X-Subject-Token:MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX...

  2. 调用创建任务接口创建迁移任务。

    • 接口相关信息

      URI格式:POST /v1/{project_id}/objectstorage/task

      详情请参见创建任务

    • 请求示例
      POST: https://oms.cn-north-1.myhuaweicloud.com/v1/0215ef11e49d4743be23dd97a1561e91/objectstorage/task

      {endpoint}信息请从地区和终端节点获取。

      Header:

      Content-Type: application/json
      X-Auth-Token: “Token”

      Body:

      {
          "src_node": {
              "region": "cn-beijing",
              "ak": "source_ak",
              "sk": "source_sk",
              "object_key": {
                  "path": "",
                  "keys": []
              },
              "bucket": "source_bucket",
              "cloud_type": "{cloud_type}"
          },
          "thread_num": 50,
          "enableKMS": false,
          "description": "A migration task.",
          "dst_node": {
              "region": "cn-north-1",
              "ak": "destination_ak",
              "sk": "destination_sk",
              "object_key": "/",
              "bucket": "destination_bucket",
              "cloud_type": "OBS"
          },
          "task_type": "object",
          "enable_failed_object_recording": false
      }
    • 响应示例
      {
              "id" : 180890111968184,
              "task_name" : "task_name"
      }

  3. 调用查看任务接口,查看任务状态。

    • 接口相关信息

      URI格式:

      GET /v1/{project_id}/objectstorage/task/{task_id}

      详情请参见查询指定ID的任务

    • 请求示例
      GET: https://oms.cn-north-1.myhuaweicloud.com/v1/0215ef11e49d4743be23dd97a1561e91/objectstorage/task/{task_id}

      {endpoint}信息请从地区和终端节点获取。

      Header:

      Content-Type: application/json
      X-Auth-Token: “Token”
    • 响应示例
      {
          "id": 180894011968184,
          "name": "task_name",
          "src_node": {
              "region": "cn-beijing",
              "bucket": "source_bucket",
              "object_key": ["/"],
              "list_file": "",
              "cloud_type": "{cloud_type}"
          },
          "dst_node": {
              "region": "cn-north-1",
              "bucket": "destination_bucket",
              "object_key": "/",
              "cloud_type": "OBS"
          },
          "thread_num": 50,
          "is_query_over": true,
          "status": 5,
          "progress": 1,
          "total_num": 1001,
          "success_num": 1001,
          "fail_num": 0,
          "skip_num": 0,
          "description": "A migration task.",
          "enableKMS": false,
          "error_reason": "",
          "total_size": 10240000,
          "real_size": 10240000,
          "complete_size": 10240000,
          "migrate_speed": 577552,
          "start_time": 1534762935868,
          "left_time": 0,
          "total_time": 17730,
          "migrate_since": 0,
          "task_type": "object",
          "failed_object_record": {
              "result": false,
              "list_file_key": "",
              "reson": "S3M.0301"
          }
      }               

      status表示任务执行状态,5代表成功。