更新时间:2024-09-12 GMT+08:00

创建迁移任务组

功能介绍

创建迁移任务组,创建成功后,迁移任务组会自动创建迁移任务,不需要额外调用启动任务命令。

调用方法

请参见如何调用API

URI

POST /v2/{project_id}/taskgroups

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目id

最小长度:1

最大长度:1024

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

IAM鉴权Token。

最小长度:1

最大长度:16384

表3 请求Body参数

参数

是否必选

参数类型

描述

src_node

TaskGroupSrcNode object

源端信息

description

String

任务组描述,不能超过255个字符,且不能包含^<>&"'等特殊字符。

最小长度:0

最大长度:255

dst_node

TaskGroupDstNode object

目的端信息。

enable_metadata_migration

Boolean

是否启用元数据迁移,默认否。不启用时,为保证迁移任务正常运行,仍将为您迁移ContentType元数据。

缺省值:false

enable_failed_object_recording

Boolean

是否开启记录失败对象

缺省值:true

enable_restore

Boolean

是否自动解冻归档数据,默认否。 开启后,如果遇到归档类型数据,会自动解冻再进行迁移。

enable_kms

Boolean

是否开启KMS加密,默认不开启。

缺省值:false

task_type

String

任务类型,默认为PREFIX。 LIST:对象列表迁移 URL_LIST:URL列表迁移, PREFIX:对象前缀迁移

枚举值:

  • LIST

  • URL_LIST

  • PREFIX

bandwidth_policy

Array of BandwidthPolicyDto objects

配置流量控制策略。数组中一个元素对应一个时段的最大带宽,最多允许5个时段,且时段不能重叠。

数组长度:0 - 5

smn_config

SmnConfig object

SMN消息发送配置。

source_cdn

SourceCdnReq object

指定是否启用CDN迁移支持,若包含此字段则为支持,否则为不支持,启用CDN迁移支持后,迁移时将从CDN域名获取源端对象。

migrate_since

Long

以时间戳方式表示的迁移指定时间(单位:秒),表示仅迁移在指定时间之后修改的源端待迁移对象。默认不设置迁移指定时间。

最小值:0

最大值:9223372036854775807

缺省值:0

object_overwrite_mode

String

迁移前同名对象覆盖方式,用于迁移前判断源端与目的端有同名对象时,覆盖目的端或跳过迁移。默认SIZE_LAST_MODIFIED_COMPARISON_OVERWRITE。NO_OVERWRITE:不覆盖。迁移前源端对象与目的端对象同名时,不做对比直接跳过迁移。SIZE_LAST_MODIFIED_COMPARISON_OVERWRITE:大小/最后修改时间对比覆盖。默认配置。迁移前源端对象与目的端对象同名时,通过对比源端和目的端对象大小和最后修改时间,判断是否覆盖目的端,需满足源端/目的端对象的加密状态一致。源端与目的端同名对象大小不相同,或目的端对象的最后修改时间晚于源端对象的最后修改时间(源端较新),覆盖目的端。 CRC64_COMPARISON_OVERWRITE:CRC64对比覆盖。目前仅支持华为/阿里/腾讯。迁移前源端对象与目的端对象同名时,通过对比源端和目的端对象元数据中CRC64值是否相同,判断是否覆盖目的端,需满足源端/目的端对象的加密状态一致。如果源端与目的端对象元数据中不存在CRC64值,则系统会默认使用SIZE_LAST_MODIFIED_COMPARISON_OVERWRITE(大小/最后修改时间对比覆盖)来对比进行覆盖判断。FULL_OVERWRITE:全覆盖。迁移前源端对象与目的端对象同名时,不做对比覆盖目的端。

枚举值:

  • NO_OVERWRITE

  • SIZE_LAST_MODIFIED_COMPARISON_OVERWRITE

  • CRC64_COMPARISON_OVERWRITE

  • FULL_OVERWRITE

dst_storage_policy

String

目的端存储类型设置,当且仅当目的端为华为云OBS时需要,默认为标准存储 STANDARD:华为云OBS标准存储 IA:华为云OBS低频存储 ARCHIVE:华为云OBS归档存储 DEEP_ARCHIVE:华为云OBS深度归档存储 SRC_STORAGE_MAPPING:保留源端存储类型,将源端存储类型映射为华为云OBS存储类型

缺省值:STANDARD

最小长度:0

最大长度:128

枚举值:

  • STANDARD

  • IA

  • ARCHIVE

  • DEEP_ARCHIVE

  • SRC_STORAGE_MAPPING

consistency_check

String

一致性校验方式,用于迁移前/后校验对象是否一致,所有校验方式需满足源端/目的端对象的加密状态一致,具体校验方式和校验结果可通过对象列表查看。默认size_last_modified。size_last_modified:默认配置。迁移前后,通过对比源端和目的端对象大小+最后修改时间,判断对象是否已存在或迁移后数据是否完整。源端与目的端同名对象大小相同,且目的端对象的最后修改时间不早于源端对象的最后修改时间,则代表该对象已存在/迁移成功。crc64:目前仅支持华为/阿里/腾讯。迁移前后,通过对比源端和目的端对象元数据中CRC64值是否相同,判断对象是否已存在/迁移完成。如果源端与目的端对象元数据中不存在CRC64值,则系统会默认使用大小/最后修改时间校验方式来校验。no_check:目前仅支持HTTP/HTTPS数据源。当源端对象无法通过标准http协议中content-length字段获取数据大小时,默认数据下载成功即迁移成功,不对数据做额外校验,且迁移时源端对象默认覆盖目的端同名对象。当源端对象能正常通过标准http协议中content-length字段获取数据大小时,则采用大小/最后修改时间校验方式来校验。

缺省值:size_last_modified

枚举值:

  • size_last_modified

  • crc64

  • no_check

enable_requester_pays

Boolean

是否开启请求者付款,在启用后,请求者支付请求和数据传输费用。

缺省值:false

表4 TaskGroupSrcNode

参数

是否必选

参数类型

描述

ak

String

源端桶的AK(最大长度100个字符),task_type为非url_list时,本参数为必选。

最小长度:0

最大长度:100

sk

String

源端桶的SK(最大长度100个字符),task_type为非url_list时,本参数为必选。

最小长度:0

最大长度:100

json_auth_file

String

用于谷歌云Cloud Storage鉴权

最小长度:0

最大长度:65535

app_id

String

当源端为腾讯云时,需要填写此参数。

最小长度:0

最大长度:255

region

String

源端桶所处的区域,task_type为非URL_LIST时,本参数为必选。

最小长度:0

最大长度:100

object_key

Array of strings

任务类型为前缀迁移任务时,表示待迁移前缀。 整桶迁移时,此参数设置为[""]。

最小长度:0

最大长度:1024

数组长度:0 - 500

bucket

String

源端所在桶

最小长度:0

最大长度:1024

cloud_type

String

源端云服务提供商,当task_type为URL_LIST时,本参数为URLSource且必选。可选值有AWS、Azure、Aliyun、Tencent、HuaweiCloud、QingCloud、KingsoftCloud、Baidu、Qiniu、URLSource、Google或者UCloud。默认值为Aliyun。

缺省值:Aliyun

最小长度:0

最大长度:100

list_file

ListFile object

列表文件配置,当task_type为LIST或URL_LIST时,list_file为必选参数。

表5 ListFile

参数

是否必选

参数类型

描述

list_file_key

String

对象列表文件或URL列表文件对象名。

最小长度:1

最大长度:1024

obs_bucket

String

存放对象列表文件的OBS桶名。

请确保与目的端桶处于同一区域,否则将导致任务创建失败。

最小长度:0

最大长度:1024

list_file_num

String

存放对象列表文件的数量

最小长度:0

最大长度:65535

表6 TaskGroupDstNode

参数

是否必选

参数类型

描述

ak

String

目的端桶的AK(最大长度100个字符)。

最小长度:0

最大长度:100

sk

String

目的端桶的SK(最大长度100个字符)。

最小长度:0

最大长度:100

region

String

目的端桶所处的区域。

请与Endpoint对应的区域保持一致。

最小长度:0

最大长度:100

bucket

String

目的端的桶名称

最小长度:0

最大长度:1024

cloud_type

String

华为云目的端信息,默认为HEC

缺省值:HEC

最小长度:0

最大长度:100

save_prefix

String

目的端桶内路径前缀(拼接在对象key前面,组成新的key,拼接后不能超过1024个字符)。

最小长度:0

最大长度:1024

表7 BandwidthPolicyDto

参数

是否必选

参数类型

描述

end

String

流量控制结束时间(包含),格式为“hh:mm”。例如“12:03”表示12时03分。

max_bandwidth

Long

时段内允许的最大流量带宽,单位Byte/s,取值范围为>= 1048576Byte/s(相当于1MB/s)且<=209715200Byte/s(相当于200MB/s)。

最小值:1048576

最大值:209715200

start

String

流量控制开始时间(包含),格式为“hh:mm”。例如“12:03”表示12时03分。

表8 SmnConfig

参数

是否必选

参数类型

描述

language

String

当前用户所使用的管理控制台的语言。

可以选择zh-cn或者en-us。

缺省值:en-us

枚举值:

  • zh-cn

  • en-us

topic_urn

String

迁移任务所绑定的SMN消息主题的urn号。

最小长度:0

最大长度:1024

trigger_conditions

Array of strings

SMN消息的触发条件,取决于迁移任务状态。

迁移任务状态的取值范围为SUCCESS或者FAILURE。

  • FAILURE表示任务失败后发送SMN消息。

  • SUCCESS表示任务成功后发送SMN消息。

数组长度:1 - 2

message_template_name

String

如果设置此值,则表示用模板方式发送smn信息。 模板示例: { “Task_Status”: "", "Task_Name" : "", "Start_Time": "", "Total_Time_Used": "", "Transferred_Data": "", "Average_Speed": "", "Source_Bucket": "", "Destination_Bucket": "", "List_File_Bucket": "", "List_File_Key": "", "Success_object_list_path": "", "Skip_object_list_path": "", "Failed_object_list_path": "" }

表9 SourceCdnReq

参数

是否必选

参数类型

描述

authentication_key

String

CDN鉴权秘钥,如果CDN需要进行鉴权,则此选项为必选。

无需授权:无需配置此项。 Qiniu:无需配置此项。 Aliyun:根据authentication_type指定的鉴权方式配置此项。 KingsoftCloud:无需配置此项。

最小长度:0

最大长度:255

authentication_type

String

鉴权类型: NONE, QINIU_PRIVATE_AUTHENTICATION, ALIYUN_OSS_A, ALIYUN_OSS_B, ALIYUN_OSS_C, KSYUN_PRIVATE_AUTHENTICATION, AZURE_SAS_TOKEN,TENCENT_COS_A,TENCENT_COS_B,TENCENT_COS_C,TENCENT_COS_D

缺省值:NONE

枚举值:

  • NONE

  • QINIU_PRIVATE_AUTHENTICATION

  • ALIYUN_OSS_A

  • ALIYUN_OSS_B

  • ALIYUN_OSS_C

  • KSYUN_PRIVATE_AUTHENTICATION

  • AZURE_SAS_TOKEN

  • TENCENT_COS_A

  • TENCENT_COS_B

  • TENCENT_COS_C

  • TENCENT_COS_D

domain

String

从指定域名获取对象。

最小长度:0

最大长度:1024

protocol

String

协议类型,支持http和https协议。

枚举值:

  • http

  • https

响应参数

状态码: 200

表10 响应Body参数

参数

参数类型

描述

group_id

String

创建的迁移任务组id

最小长度:1

最大长度:100

状态码: 400

表11 响应Body参数

参数

参数类型

描述

error_msg

String

错误信息。

error_code

String

错误码。

状态码: 403

表12 响应Body参数

参数

参数类型

描述

error_msg

String

错误信息。

error_code

String

错误码。

状态码: 500

表13 响应Body参数

参数

参数类型

描述

error_msg

String

错误信息。

error_code

String

错误码。

请求示例

  • 创建迁移任务组任务,以hw/目录下的txt文件中的对象列表信息作为华为云桶bucket的源端数据,迁移至目的端桶zzww。

    POST https://{endpoint}/v2/{project_id}/taskgroups
    
    {
      "enable_failed_object_recording" : true,
      "src_node" : {
        "bucket" : "hw-src",
        "cloud_type" : "HuaweiCloud",
        "ak" : "******",
        "sk" : "******",
        "region" : "cn-north-7",
        "list_file" : {
          "obs_bucket" : "list-file-bucket",
          "list_file_key" : "hw/"
        }
      },
      "enable_kms" : false,
      "task_type" : "LIST",
      "enable_restore" : false,
      "dst_node" : {
        "bucket" : "zzww",
        "cloud_type" : "HEC",
        "ak" : "******",
        "sk" : "******",
        "region" : "cn-north-7"
      },
      "enable_metadata_migration" : true
    }
  • 创建迁移任务组任务,将前缀为Objectlist的对象从源端桶src-bucket迁移至目的端桶dst-bucket。

    POST https://{endpoint}/v2/{project_id}/taskgroups
    
    {
      "src_node" : {
        "region" : "cn-north-4",
        "ak" : "******",
        "sk" : "******.",
        "bucket" : "src-bucket",
        "cloud_type" : "HuaweiCloud",
        "object_key" : [ "Objectlist" ]
      },
      "dst_node" : {
        "region" : "cn-north-4",
        "ak" : "******",
        "sk" : "******",
        "bucket" : "dst-bucket"
      },
      "task_type" : "PREFIX",
      "enable_failed_object_recording" : true,
      "enable_kms" : false,
      "bandwidth_policy" : [ {
        "max_bandwidth" : 1048576,
        "start" : "00:01",
        "end" : "23:59"
      } ]
    }
  • 创建迁移任务组任务,以test01/路径下的txt文件作为URL列表目录,迁移至目的端桶jjyy。

    POST https://{endpoint}/v2/{project_id}/taskgroups
    
    {
      "src_node" : {
        "cloud_type" : "URLSource",
        "list_file" : {
          "obs_bucket" : "url-file-bucket",
          "list_file_key" : "test01/"
        }
      },
      "description" : "",
      "dst_node" : {
        "region" : "cn-north-4",
        "ak" : "******",
        "sk" : "******.",
        "bucket" : "jjyy",
        "cloud_type" : "HEC"
      },
      "enable_failed_object_recording" : true,
      "enable_restore" : false,
      "enable_metadata_migration" : false,
      "enable_kms" : false,
      "task_type" : "URL_LIST"
    }

响应示例

状态码: 200

Created

{
  "group_id" : "9ad15f51-778f-4684-b47b-4c5109c0e105"
}

SDK代码示例

SDK代码示例如下。

  • 创建迁移任务组任务,以hw/目录下的txt文件中的对象列表信息作为华为云桶bucket的源端数据,迁移至目的端桶zzww。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.oms.v2.region.OmsRegion;
    import com.huaweicloud.sdk.oms.v2.*;
    import com.huaweicloud.sdk.oms.v2.model.*;
    
    
    public class CreateTaskGroupSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            OmsClient client = OmsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(OmsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateTaskGroupRequest request = new CreateTaskGroupRequest();
            CreateTaskGroupReq body = new CreateTaskGroupReq();
            TaskGroupDstNode dstNodebody = new TaskGroupDstNode();
            dstNodebody.withAk("******")
                .withSk("******")
                .withRegion("cn-north-7")
                .withBucket("zzww")
                .withCloudType("HEC");
            ListFile listFileSrcNode = new ListFile();
            listFileSrcNode.withListFileKey("hw/")
                .withObsBucket("list-file-bucket");
            TaskGroupSrcNode srcNodebody = new TaskGroupSrcNode();
            srcNodebody.withAk("******")
                .withSk("******")
                .withRegion("cn-north-7")
                .withBucket("hw-src")
                .withCloudType("HuaweiCloud")
                .withListFile(listFileSrcNode);
            body.withTaskType(CreateTaskGroupReq.TaskTypeEnum.fromValue("LIST"));
            body.withEnableKms(false);
            body.withEnableRestore(false);
            body.withEnableFailedObjectRecording(true);
            body.withEnableMetadataMigration(true);
            body.withDstNode(dstNodebody);
            body.withSrcNode(srcNodebody);
            request.withBody(body);
            try {
                CreateTaskGroupResponse response = client.createTaskGroup(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 创建迁移任务组任务,将前缀为Objectlist的对象从源端桶src-bucket迁移至目的端桶dst-bucket。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.oms.v2.region.OmsRegion;
    import com.huaweicloud.sdk.oms.v2.*;
    import com.huaweicloud.sdk.oms.v2.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateTaskGroupSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            OmsClient client = OmsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(OmsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateTaskGroupRequest request = new CreateTaskGroupRequest();
            CreateTaskGroupReq body = new CreateTaskGroupReq();
            List<BandwidthPolicyDto> listbodyBandwidthPolicy = new ArrayList<>();
            listbodyBandwidthPolicy.add(
                new BandwidthPolicyDto()
                    .withEnd("23:59")
                    .withMaxBandwidth(1048576L)
                    .withStart("00:01")
            );
            TaskGroupDstNode dstNodebody = new TaskGroupDstNode();
            dstNodebody.withAk("******")
                .withSk("******")
                .withRegion("cn-north-4")
                .withBucket("dst-bucket");
            List<String> listSrcNodeObjectKey = new ArrayList<>();
            listSrcNodeObjectKey.add("Objectlist");
            TaskGroupSrcNode srcNodebody = new TaskGroupSrcNode();
            srcNodebody.withAk("******")
                .withSk("******.")
                .withRegion("cn-north-4")
                .withObjectKey(listSrcNodeObjectKey)
                .withBucket("src-bucket")
                .withCloudType("HuaweiCloud");
            body.withBandwidthPolicy(listbodyBandwidthPolicy);
            body.withTaskType(CreateTaskGroupReq.TaskTypeEnum.fromValue("PREFIX"));
            body.withEnableKms(false);
            body.withEnableFailedObjectRecording(true);
            body.withDstNode(dstNodebody);
            body.withSrcNode(srcNodebody);
            request.withBody(body);
            try {
                CreateTaskGroupResponse response = client.createTaskGroup(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 创建迁移任务组任务,以test01/路径下的txt文件作为URL列表目录,迁移至目的端桶jjyy。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.oms.v2.region.OmsRegion;
    import com.huaweicloud.sdk.oms.v2.*;
    import com.huaweicloud.sdk.oms.v2.model.*;
    
    
    public class CreateTaskGroupSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
    
            ICredential auth = new BasicCredentials()
                    .withAk(ak)
                    .withSk(sk);
    
            OmsClient client = OmsClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(OmsRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateTaskGroupRequest request = new CreateTaskGroupRequest();
            CreateTaskGroupReq body = new CreateTaskGroupReq();
            TaskGroupDstNode dstNodebody = new TaskGroupDstNode();
            dstNodebody.withAk("******")
                .withSk("******.")
                .withRegion("cn-north-4")
                .withBucket("jjyy")
                .withCloudType("HEC");
            ListFile listFileSrcNode = new ListFile();
            listFileSrcNode.withListFileKey("test01/")
                .withObsBucket("url-file-bucket");
            TaskGroupSrcNode srcNodebody = new TaskGroupSrcNode();
            srcNodebody.withCloudType("URLSource")
                .withListFile(listFileSrcNode);
            body.withTaskType(CreateTaskGroupReq.TaskTypeEnum.fromValue("URL_LIST"));
            body.withEnableKms(false);
            body.withEnableRestore(false);
            body.withEnableFailedObjectRecording(true);
            body.withEnableMetadataMigration(false);
            body.withDstNode(dstNodebody);
            body.withDescription("");
            body.withSrcNode(srcNodebody);
            request.withBody(body);
            try {
                CreateTaskGroupResponse response = client.createTaskGroup(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • 创建迁移任务组任务,以hw/目录下的txt文件中的对象列表信息作为华为云桶bucket的源端数据,迁移至目的端桶zzww。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkoms.v2.region.oms_region import OmsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkoms.v2 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
    
        credentials = BasicCredentials(ak, sk)
    
        client = OmsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(OmsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateTaskGroupRequest()
            dstNodebody = TaskGroupDstNode(
                ak="******",
                sk="******",
                region="cn-north-7",
                bucket="zzww",
                cloud_type="HEC"
            )
            listFileSrcNode = ListFile(
                list_file_key="hw/",
                obs_bucket="list-file-bucket"
            )
            srcNodebody = TaskGroupSrcNode(
                ak="******",
                sk="******",
                region="cn-north-7",
                bucket="hw-src",
                cloud_type="HuaweiCloud",
                list_file=listFileSrcNode
            )
            request.body = CreateTaskGroupReq(
                task_type="LIST",
                enable_kms=False,
                enable_restore=False,
                enable_failed_object_recording=True,
                enable_metadata_migration=True,
                dst_node=dstNodebody,
                src_node=srcNodebody
            )
            response = client.create_task_group(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建迁移任务组任务,将前缀为Objectlist的对象从源端桶src-bucket迁移至目的端桶dst-bucket。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkoms.v2.region.oms_region import OmsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkoms.v2 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
    
        credentials = BasicCredentials(ak, sk)
    
        client = OmsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(OmsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateTaskGroupRequest()
            listBandwidthPolicybody = [
                BandwidthPolicyDto(
                    end="23:59",
                    max_bandwidth=1048576,
                    start="00:01"
                )
            ]
            dstNodebody = TaskGroupDstNode(
                ak="******",
                sk="******",
                region="cn-north-4",
                bucket="dst-bucket"
            )
            listObjectKeySrcNode = [
                "Objectlist"
            ]
            srcNodebody = TaskGroupSrcNode(
                ak="******",
                sk="******.",
                region="cn-north-4",
                object_key=listObjectKeySrcNode,
                bucket="src-bucket",
                cloud_type="HuaweiCloud"
            )
            request.body = CreateTaskGroupReq(
                bandwidth_policy=listBandwidthPolicybody,
                task_type="PREFIX",
                enable_kms=False,
                enable_failed_object_recording=True,
                dst_node=dstNodebody,
                src_node=srcNodebody
            )
            response = client.create_task_group(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建迁移任务组任务,以test01/路径下的txt文件作为URL列表目录,迁移至目的端桶jjyy。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkoms.v2.region.oms_region import OmsRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkoms.v2 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
    
        credentials = BasicCredentials(ak, sk)
    
        client = OmsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(OmsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateTaskGroupRequest()
            dstNodebody = TaskGroupDstNode(
                ak="******",
                sk="******.",
                region="cn-north-4",
                bucket="jjyy",
                cloud_type="HEC"
            )
            listFileSrcNode = ListFile(
                list_file_key="test01/",
                obs_bucket="url-file-bucket"
            )
            srcNodebody = TaskGroupSrcNode(
                cloud_type="URLSource",
                list_file=listFileSrcNode
            )
            request.body = CreateTaskGroupReq(
                task_type="URL_LIST",
                enable_kms=False,
                enable_restore=False,
                enable_failed_object_recording=True,
                enable_metadata_migration=False,
                dst_node=dstNodebody,
                description="",
                src_node=srcNodebody
            )
            response = client.create_task_group(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建迁移任务组任务,以hw/目录下的txt文件中的对象列表信息作为华为云桶bucket的源端数据,迁移至目的端桶zzww。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        oms "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/oms/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/oms/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/oms/v2/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := oms.NewOmsClient(
            oms.OmsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateTaskGroupRequest{}
    	cloudTypeDstNode:= "HEC"
    	dstNodebody := &model.TaskGroupDstNode{
    		Ak: "******",
    		Sk: "******",
    		Region: "cn-north-7",
    		Bucket: "zzww",
    		CloudType: &cloudTypeDstNode,
    	}
    	listFileSrcNode := &model.ListFile{
    		ListFileKey: "hw/",
    		ObsBucket: "list-file-bucket",
    	}
    	akSrcNode:= "******"
    	skSrcNode:= "******"
    	regionSrcNode:= "cn-north-7"
    	bucketSrcNode:= "hw-src"
    	cloudTypeSrcNode:= "HuaweiCloud"
    	srcNodebody := &model.TaskGroupSrcNode{
    		Ak: &akSrcNode,
    		Sk: &skSrcNode,
    		Region: &regionSrcNode,
    		Bucket: &bucketSrcNode,
    		CloudType: &cloudTypeSrcNode,
    		ListFile: listFileSrcNode,
    	}
    	taskTypeCreateTaskGroupReq:= model.GetCreateTaskGroupReqTaskTypeEnum().LIST
    	enableRestoreCreateTaskGroupReq:= false
    	enableFailedObjectRecordingCreateTaskGroupReq:= true
    	enableMetadataMigrationCreateTaskGroupReq:= true
    	request.Body = &model.CreateTaskGroupReq{
    		TaskType: &taskTypeCreateTaskGroupReq,
    		EnableKms: false,
    		EnableRestore: &enableRestoreCreateTaskGroupReq,
    		EnableFailedObjectRecording: &enableFailedObjectRecordingCreateTaskGroupReq,
    		EnableMetadataMigration: &enableMetadataMigrationCreateTaskGroupReq,
    		DstNode: dstNodebody,
    		SrcNode: srcNodebody,
    	}
    	response, err := client.CreateTaskGroup(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建迁移任务组任务,将前缀为Objectlist的对象从源端桶src-bucket迁移至目的端桶dst-bucket。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        oms "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/oms/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/oms/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/oms/v2/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := oms.NewOmsClient(
            oms.OmsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateTaskGroupRequest{}
    	var listBandwidthPolicybody = []model.BandwidthPolicyDto{
            {
                End: "23:59",
                MaxBandwidth: int64(1048576),
                Start: "00:01",
            },
        }
    	dstNodebody := &model.TaskGroupDstNode{
    		Ak: "******",
    		Sk: "******",
    		Region: "cn-north-4",
    		Bucket: "dst-bucket",
    	}
    	var listObjectKeySrcNode = []string{
            "Objectlist",
        }
    	akSrcNode:= "******"
    	skSrcNode:= "******."
    	regionSrcNode:= "cn-north-4"
    	bucketSrcNode:= "src-bucket"
    	cloudTypeSrcNode:= "HuaweiCloud"
    	srcNodebody := &model.TaskGroupSrcNode{
    		Ak: &akSrcNode,
    		Sk: &skSrcNode,
    		Region: &regionSrcNode,
    		ObjectKey: &listObjectKeySrcNode,
    		Bucket: &bucketSrcNode,
    		CloudType: &cloudTypeSrcNode,
    	}
    	taskTypeCreateTaskGroupReq:= model.GetCreateTaskGroupReqTaskTypeEnum().PREFIX
    	enableFailedObjectRecordingCreateTaskGroupReq:= true
    	request.Body = &model.CreateTaskGroupReq{
    		BandwidthPolicy: &listBandwidthPolicybody,
    		TaskType: &taskTypeCreateTaskGroupReq,
    		EnableKms: false,
    		EnableFailedObjectRecording: &enableFailedObjectRecordingCreateTaskGroupReq,
    		DstNode: dstNodebody,
    		SrcNode: srcNodebody,
    	}
    	response, err := client.CreateTaskGroup(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建迁移任务组任务,以test01/路径下的txt文件作为URL列表目录,迁移至目的端桶jjyy。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        oms "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/oms/v2"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/oms/v2/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/oms/v2/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            Build()
    
        client := oms.NewOmsClient(
            oms.OmsClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateTaskGroupRequest{}
    	cloudTypeDstNode:= "HEC"
    	dstNodebody := &model.TaskGroupDstNode{
    		Ak: "******",
    		Sk: "******.",
    		Region: "cn-north-4",
    		Bucket: "jjyy",
    		CloudType: &cloudTypeDstNode,
    	}
    	listFileSrcNode := &model.ListFile{
    		ListFileKey: "test01/",
    		ObsBucket: "url-file-bucket",
    	}
    	cloudTypeSrcNode:= "URLSource"
    	srcNodebody := &model.TaskGroupSrcNode{
    		CloudType: &cloudTypeSrcNode,
    		ListFile: listFileSrcNode,
    	}
    	taskTypeCreateTaskGroupReq:= model.GetCreateTaskGroupReqTaskTypeEnum().URL_LIST
    	enableRestoreCreateTaskGroupReq:= false
    	enableFailedObjectRecordingCreateTaskGroupReq:= true
    	enableMetadataMigrationCreateTaskGroupReq:= false
    	descriptionCreateTaskGroupReq:= ""
    	request.Body = &model.CreateTaskGroupReq{
    		TaskType: &taskTypeCreateTaskGroupReq,
    		EnableKms: false,
    		EnableRestore: &enableRestoreCreateTaskGroupReq,
    		EnableFailedObjectRecording: &enableFailedObjectRecordingCreateTaskGroupReq,
    		EnableMetadataMigration: &enableMetadataMigrationCreateTaskGroupReq,
    		DstNode: dstNodebody,
    		Description: &descriptionCreateTaskGroupReq,
    		SrcNode: srcNodebody,
    	}
    	response, err := client.CreateTaskGroup(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

Created

400

Bad Request

403

Forbidden

500

Server Error

错误码

请参见错误码