更新时间:2024-02-19 GMT+08:00
分享

创建迁移任务

功能介绍

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

接口约束

  • 单个租户在过去24小时内最多可创建1500个迁移任务。

  • 单个租户名下处于“等待中”状态的迁移任务达到1500个时不可再创建任务。

调用方法

请参见如何调用API

URI

POST /v2/{project_id}/tasks

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID。

最小长度:1

最大长度:1024

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

IAM鉴权Token。

最小长度:1

最大长度:16384

表3 请求Body参数

参数

是否必选

参数类型

描述

task_type

String

任务类型,默认为object。

list:对象列表迁移 url_list:URL列表迁移 object:文件/文件夹迁移,默认 prefix:对象前缀迁移

缺省值:object

枚举值:

  • list

  • url_list

  • object

  • prefix

src_node

SrcNodeReq object

源端信息。

dst_node

DstNodeReq object

目的端信息。

enable_kms

Boolean

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

缺省值:false

description

String

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

最小长度:0

最大长度:255

migrate_since

Long

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

最小值:0

最大值:9223372036854775807

缺省值:0

bandwidth_policy

Array of BandwidthPolicyDto objects

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

数组长度:0 - 5

source_cdn

SourceCdnReq object

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

smn_config

SmnConfig object

SMN消息发送配置。

enable_metadata_migration

Boolean

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

缺省值:false

enable_restore

Boolean

是否自动解冻归档数据,默认否。

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

缺省值:false

enable_failed_object_recording

Boolean

是否记录失败对象,默认开启。

开启后,如果有迁移失败对象,会在目的端存储失败对象信息。

缺省值:true

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 SrcNodeReq

参数

是否必选

参数类型

描述

cloud_type

String

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

缺省值:Aliyun

region

String

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

最小长度:0

最大长度:100

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

security_token

String

源端桶的临时Token(最大长度16384个字符)

最小长度:0

最大长度:16384

app_id

String

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

最小长度:0

最大长度:255

bucket

String

源端桶的名称,task_type为非url_list时,本参数为必选。

最小长度:0

最大长度:1024

object_key

Array of strings

任务类型为对象迁移任务时,表示待迁移对象名称(以“/”结尾的字符串代表待迁移的文件夹,非“/”结尾的字符串代表待迁移的文件。); 任务类型为前缀迁移任务时,表示待迁移前缀。 整桶迁移时,此参数设置为[""]。

最小长度:0

最大长度:1024

数组长度:0 - 500

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 DstNodeReq

参数

是否必选

参数类型

描述

ak

String

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

最小长度:0

最大长度:100

sk

String

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

最小长度:0

最大长度:100

security_token

String

目的端的临时Token(最大长度16384个字符)。

最小长度:0

最大长度:16384

bucket

String

目的端桶的名称。

最小长度:0

最大长度:1024

save_prefix

String

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

最小长度:0

最大长度:1024

region

String

目的端桶所处的区域。

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

最小长度:0

最大长度:100

表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 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

表9 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": "" }

响应参数

状态码: 200

表10 响应Body参数

参数

参数类型

描述

id

Long

任务ID。

最小值:0

最大值:999999999999999

task_name

String

任务名称。

最小长度:0

最大长度:2048

状态码: 400

表11 响应Body参数

参数

参数类型

描述

error_msg

String

错误信息。

error_code

String

错误码。

请求示例

  • 使用阿里云A方式进行https CDN方式迁移,开启按时段限速,限速值为50MB/S,将对象列表object_list_file.txt中的对象列表执行迁移,并开启迁移结果通知。

    POST https://{endpoint}/v2/{project_id}/tasks
    
    {
      "task_type" : "list",
      "src_node" : {
        "cloud_type" : "HuaweiCloud",
        "region" : "cn-north-1",
        "bucket" : "src_bucket",
        "ak" : "src_ak",
        "sk" : "src_sk",
        "list_file" : {
          "obs_bucket" : "list_file_bucket",
          "list_file_key" : "object_list_file.txt"
        }
      },
      "dst_node" : {
        "region" : "cn-north-1",
        "ak" : "dst_ak",
        "sk" : "dst_sk",
        "bucket" : "dst_bucket"
      },
      "enable_kms" : false,
      "enable_failed_object_recording" : true,
      "description" : "xxx",
      "migrate_since" : 123456789,
      "bandwidth_policy" : [ {
        "start" : "00:00",
        "end" : "23:59",
        "max_bandwidth" : 50000000
      } ],
      "source_cdn" : {
        "protocol" : "https",
        "domain" : "xxx.xxx.xxx",
        "authentication_type" : "ALIYUN_OSS_A",
        "authentication_key" : "xxx"
      },
      "smn_config" : {
        "topic_urn" : "urn:smn:region:4cf2090802d94440b4cdd72ef26857b2:OMS",
        "trigger_conditions" : [ "SUCCESS", "FAILURE" ],
        "language" : "en-us"
      }
    }
  • 使用阿里云A方式进行https CDN方式迁移,开启按时段限速,限速值为50MB/S,将对象文件/前缀["file1.xxx", "file2.xxx", "path1/"]进行迁移,并开启迁移结果通知

    POST https://{endpoint}/v2/{project_id}/tasks
    
    {
      "task_type" : "object",
      "src_node" : {
        "cloud_type" : "HuaweiCloud",
        "region" : "cn-north-1",
        "bucket" : "src_bucket",
        "ak" : "src_ak",
        "sk" : "src_sk",
        "object_key" : [ "file1.xxx", "file2.xxx", "path1/" ]
      },
      "dst_node" : {
        "region" : "cn-north-1",
        "ak" : "dst_ak",
        "sk" : "dst_sk",
        "bucket" : "dst_bucket"
      },
      "enable_kms" : false,
      "enable_failed_object_recording" : true,
      "description" : "xxx",
      "migrate_since" : 123456789,
      "bandwidth_policy" : [ {
        "start" : "00:00",
        "end" : "23:59",
        "max_bandwidth" : 50000000
      } ],
      "source_cdn" : {
        "protocol" : "https",
        "domain" : "xxx.xxx.xxx",
        "authentication_type" : "ALIYUN_OSS_A",
        "authentication_key" : "xxx"
      },
      "smn_config" : {
        "topic_urn" : "urn:smn:region:4cf2090802d94440b4cdd72ef26857b2:OMS",
        "trigger_conditions" : [ "SUCCESS", "FAILURE" ],
        "language" : "en-us"
      }
    }
  • 创建URL列表迁移任务,将object_list_file.txt中的URL列表执行迁移。

    POST https://{endpoint}/v2/{project_id}/tasks
    
    {
      "task_type" : "url_list",
      "src_node" : {
        "cloud_type" : "URLSource",
        "list_file" : {
          "obs_bucket" : "list_file_bucket",
          "list_file_key" : "object_list_file.txt"
        }
      },
      "dst_node" : {
        "region" : "cn-north-1",
        "ak" : "dst_ak",
        "sk" : "dst_sk",
        "bucket" : "dst_bucket"
      },
      "enable_kms" : false,
      "enable_failed_object_recording" : true,
      "description" : "xxx"
    }
  • 创建前缀迁移任务,将[ "abc", "123", "prefix3", "path/prefix4" ]为前缀的对象文件进行迁移。

    POST https://{endpoint}/v2/{project_id}/tasks
    
    {
      "task_type" : "prefix",
      "src_node" : {
        "cloud_type" : "HuaweiCloud",
        "region" : "cn-north-1",
        "bucket" : "src_bucket",
        "ak" : "src_ak",
        "sk" : "src_sk",
        "object_key" : [ "abc", "123", "prefix3", "path/prefix4" ]
      },
      "dst_node" : {
        "region" : "cn-north-1",
        "ak" : "dst_ak",
        "sk" : "dst_sk",
        "bucket" : "dst_bucket"
      },
      "enable_kms" : false,
      "enable_failed_object_recording" : true,
      "description" : "xxx"
    }

响应示例

状态码: 200

Created

{
  "id" : 200429548242937,
  "task_name" : "task_name"
}

SDK代码示例

SDK代码示例如下。

  • 使用阿里云A方式进行https CDN方式迁移,开启按时段限速,限速值为50MB/S,将对象列表object_list_file.txt中的对象列表执行迁移,并开启迁移结果通知。

     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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    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 CreateTaskSolution {
    
        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();
            CreateTaskRequest request = new CreateTaskRequest();
            CreateTaskReq body = new CreateTaskReq();
            List<String> listSmnConfigTriggerConditions = new ArrayList<>();
            listSmnConfigTriggerConditions.add("SUCCESS");
            listSmnConfigTriggerConditions.add("FAILURE");
            SmnConfig smnConfigbody = new SmnConfig();
            smnConfigbody.withLanguage(SmnConfig.LanguageEnum.fromValue("en-us"))
                .withTopicUrn("urn:smn:region:4cf2090802d94440b4cdd72ef26857b2:OMS")
                .withTriggerConditions(listSmnConfigTriggerConditions);
            SourceCdnReq sourceCdnbody = new SourceCdnReq();
            sourceCdnbody.withAuthenticationKey("xxx")
                .withAuthenticationType(SourceCdnReq.AuthenticationTypeEnum.fromValue("ALIYUN_OSS_A"))
                .withDomain("xxx.xxx.xxx")
                .withProtocol(SourceCdnReq.ProtocolEnum.fromValue("https"));
            List<BandwidthPolicyDto> listbodyBandwidthPolicy = new ArrayList<>();
            listbodyBandwidthPolicy.add(
                new BandwidthPolicyDto()
                    .withEnd("23:59")
                    .withMaxBandwidth(50000000L)
                    .withStart("00:00")
            );
            DstNodeReq dstNodebody = new DstNodeReq();
            dstNodebody.withAk("dst_ak")
                .withSk("dst_sk")
                .withBucket("dst_bucket")
                .withRegion("cn-north-1");
            ListFile listFileSrcNode = new ListFile();
            listFileSrcNode.withListFileKey("object_list_file.txt")
                .withObsBucket("list_file_bucket");
            SrcNodeReq srcNodebody = new SrcNodeReq();
            srcNodebody.withCloudType("HuaweiCloud")
                .withRegion("cn-north-1")
                .withAk("src_ak")
                .withSk("src_sk")
                .withBucket("src_bucket")
                .withListFile(listFileSrcNode);
            body.withEnableFailedObjectRecording(true);
            body.withSmnConfig(smnConfigbody);
            body.withSourceCdn(sourceCdnbody);
            body.withBandwidthPolicy(listbodyBandwidthPolicy);
            body.withMigrateSince(123456789L);
            body.withDescription("xxx");
            body.withEnableKms(false);
            body.withDstNode(dstNodebody);
            body.withSrcNode(srcNodebody);
            body.withTaskType(CreateTaskReq.TaskTypeEnum.fromValue("list"));
            request.withBody(body);
            try {
                CreateTaskResponse response = client.createTask(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());
            }
        }
    }
    
  • 使用阿里云A方式进行https CDN方式迁移,开启按时段限速,限速值为50MB/S,将对象文件/前缀["file1.xxx", "file2.xxx", "path1/"]进行迁移,并开启迁移结果通知

     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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    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 CreateTaskSolution {
    
        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();
            CreateTaskRequest request = new CreateTaskRequest();
            CreateTaskReq body = new CreateTaskReq();
            List<String> listSmnConfigTriggerConditions = new ArrayList<>();
            listSmnConfigTriggerConditions.add("SUCCESS");
            listSmnConfigTriggerConditions.add("FAILURE");
            SmnConfig smnConfigbody = new SmnConfig();
            smnConfigbody.withLanguage(SmnConfig.LanguageEnum.fromValue("en-us"))
                .withTopicUrn("urn:smn:region:4cf2090802d94440b4cdd72ef26857b2:OMS")
                .withTriggerConditions(listSmnConfigTriggerConditions);
            SourceCdnReq sourceCdnbody = new SourceCdnReq();
            sourceCdnbody.withAuthenticationKey("xxx")
                .withAuthenticationType(SourceCdnReq.AuthenticationTypeEnum.fromValue("ALIYUN_OSS_A"))
                .withDomain("xxx.xxx.xxx")
                .withProtocol(SourceCdnReq.ProtocolEnum.fromValue("https"));
            List<BandwidthPolicyDto> listbodyBandwidthPolicy = new ArrayList<>();
            listbodyBandwidthPolicy.add(
                new BandwidthPolicyDto()
                    .withEnd("23:59")
                    .withMaxBandwidth(50000000L)
                    .withStart("00:00")
            );
            DstNodeReq dstNodebody = new DstNodeReq();
            dstNodebody.withAk("dst_ak")
                .withSk("dst_sk")
                .withBucket("dst_bucket")
                .withRegion("cn-north-1");
            List<String> listSrcNodeObjectKey = new ArrayList<>();
            listSrcNodeObjectKey.add("file1.xxx");
            listSrcNodeObjectKey.add("file2.xxx");
            listSrcNodeObjectKey.add("path1/");
            SrcNodeReq srcNodebody = new SrcNodeReq();
            srcNodebody.withCloudType("HuaweiCloud")
                .withRegion("cn-north-1")
                .withAk("src_ak")
                .withSk("src_sk")
                .withBucket("src_bucket")
                .withObjectKey(listSrcNodeObjectKey);
            body.withEnableFailedObjectRecording(true);
            body.withSmnConfig(smnConfigbody);
            body.withSourceCdn(sourceCdnbody);
            body.withBandwidthPolicy(listbodyBandwidthPolicy);
            body.withMigrateSince(123456789L);
            body.withDescription("xxx");
            body.withEnableKms(false);
            body.withDstNode(dstNodebody);
            body.withSrcNode(srcNodebody);
            body.withTaskType(CreateTaskReq.TaskTypeEnum.fromValue("object"));
            request.withBody(body);
            try {
                CreateTaskResponse response = client.createTask(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());
            }
        }
    }
    
  • 创建URL列表迁移任务,将object_list_file.txt中的URL列表执行迁移。

     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
    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 CreateTaskSolution {
    
        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();
            CreateTaskRequest request = new CreateTaskRequest();
            CreateTaskReq body = new CreateTaskReq();
            DstNodeReq dstNodebody = new DstNodeReq();
            dstNodebody.withAk("dst_ak")
                .withSk("dst_sk")
                .withBucket("dst_bucket")
                .withRegion("cn-north-1");
            ListFile listFileSrcNode = new ListFile();
            listFileSrcNode.withListFileKey("object_list_file.txt")
                .withObsBucket("list_file_bucket");
            SrcNodeReq srcNodebody = new SrcNodeReq();
            srcNodebody.withCloudType("URLSource")
                .withListFile(listFileSrcNode);
            body.withEnableFailedObjectRecording(true);
            body.withDescription("xxx");
            body.withEnableKms(false);
            body.withDstNode(dstNodebody);
            body.withSrcNode(srcNodebody);
            body.withTaskType(CreateTaskReq.TaskTypeEnum.fromValue("url_list"));
            request.withBody(body);
            try {
                CreateTaskResponse response = client.createTask(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());
            }
        }
    }
    
  • 创建前缀迁移任务,将[ "abc", "123", "prefix3", "path/prefix4" ]为前缀的对象文件进行迁移。

     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
    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 CreateTaskSolution {
    
        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();
            CreateTaskRequest request = new CreateTaskRequest();
            CreateTaskReq body = new CreateTaskReq();
            DstNodeReq dstNodebody = new DstNodeReq();
            dstNodebody.withAk("dst_ak")
                .withSk("dst_sk")
                .withBucket("dst_bucket")
                .withRegion("cn-north-1");
            List<String> listSrcNodeObjectKey = new ArrayList<>();
            listSrcNodeObjectKey.add("abc");
            listSrcNodeObjectKey.add("123");
            listSrcNodeObjectKey.add("prefix3");
            listSrcNodeObjectKey.add("path/prefix4");
            SrcNodeReq srcNodebody = new SrcNodeReq();
            srcNodebody.withCloudType("HuaweiCloud")
                .withRegion("cn-north-1")
                .withAk("src_ak")
                .withSk("src_sk")
                .withBucket("src_bucket")
                .withObjectKey(listSrcNodeObjectKey);
            body.withEnableFailedObjectRecording(true);
            body.withDescription("xxx");
            body.withEnableKms(false);
            body.withDstNode(dstNodebody);
            body.withSrcNode(srcNodebody);
            body.withTaskType(CreateTaskReq.TaskTypeEnum.fromValue("prefix"));
            request.withBody(body);
            try {
                CreateTaskResponse response = client.createTask(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());
            }
        }
    }
    
  • 使用阿里云A方式进行https CDN方式迁移,开启按时段限速,限速值为50MB/S,将对象列表object_list_file.txt中的对象列表执行迁移,并开启迁移结果通知。

     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
    77
    78
    79
    80
    81
    # coding: utf-8
    
    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 = __import__('os').getenv("CLOUD_SDK_AK")
        sk = __import__('os').getenv("CLOUD_SDK_SK")
    
        credentials = BasicCredentials(ak, sk) \
    
        client = OmsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(OmsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateTaskRequest()
            listTriggerConditionsSmnConfig = [
                "SUCCESS",
                "FAILURE"
            ]
            smnConfigbody = SmnConfig(
                language="en-us",
                topic_urn="urn:smn:region:4cf2090802d94440b4cdd72ef26857b2:OMS",
                trigger_conditions=listTriggerConditionsSmnConfig
            )
            sourceCdnbody = SourceCdnReq(
                authentication_key="xxx",
                authentication_type="ALIYUN_OSS_A",
                domain="xxx.xxx.xxx",
                protocol="https"
            )
            listBandwidthPolicybody = [
                BandwidthPolicyDto(
                    end="23:59",
                    max_bandwidth=50000000,
                    start="00:00"
                )
            ]
            dstNodebody = DstNodeReq(
                ak="dst_ak",
                sk="dst_sk",
                bucket="dst_bucket",
                region="cn-north-1"
            )
            listFileSrcNode = ListFile(
                list_file_key="object_list_file.txt",
                obs_bucket="list_file_bucket"
            )
            srcNodebody = SrcNodeReq(
                cloud_type="HuaweiCloud",
                region="cn-north-1",
                ak="src_ak",
                sk="src_sk",
                bucket="src_bucket",
                list_file=listFileSrcNode
            )
            request.body = CreateTaskReq(
                enable_failed_object_recording=True,
                smn_config=smnConfigbody,
                source_cdn=sourceCdnbody,
                bandwidth_policy=listBandwidthPolicybody,
                migrate_since=123456789,
                description="xxx",
                enable_kms=False,
                dst_node=dstNodebody,
                src_node=srcNodebody,
                task_type="list"
            )
            response = client.create_task(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 使用阿里云A方式进行https CDN方式迁移,开启按时段限速,限速值为50MB/S,将对象文件/前缀["file1.xxx", "file2.xxx", "path1/"]进行迁移,并开启迁移结果通知

     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
    77
    78
    79
    80
    81
    82
    # coding: utf-8
    
    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 = __import__('os').getenv("CLOUD_SDK_AK")
        sk = __import__('os').getenv("CLOUD_SDK_SK")
    
        credentials = BasicCredentials(ak, sk) \
    
        client = OmsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(OmsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateTaskRequest()
            listTriggerConditionsSmnConfig = [
                "SUCCESS",
                "FAILURE"
            ]
            smnConfigbody = SmnConfig(
                language="en-us",
                topic_urn="urn:smn:region:4cf2090802d94440b4cdd72ef26857b2:OMS",
                trigger_conditions=listTriggerConditionsSmnConfig
            )
            sourceCdnbody = SourceCdnReq(
                authentication_key="xxx",
                authentication_type="ALIYUN_OSS_A",
                domain="xxx.xxx.xxx",
                protocol="https"
            )
            listBandwidthPolicybody = [
                BandwidthPolicyDto(
                    end="23:59",
                    max_bandwidth=50000000,
                    start="00:00"
                )
            ]
            dstNodebody = DstNodeReq(
                ak="dst_ak",
                sk="dst_sk",
                bucket="dst_bucket",
                region="cn-north-1"
            )
            listObjectKeySrcNode = [
                "file1.xxx",
                "file2.xxx",
                "path1/"
            ]
            srcNodebody = SrcNodeReq(
                cloud_type="HuaweiCloud",
                region="cn-north-1",
                ak="src_ak",
                sk="src_sk",
                bucket="src_bucket",
                object_key=listObjectKeySrcNode
            )
            request.body = CreateTaskReq(
                enable_failed_object_recording=True,
                smn_config=smnConfigbody,
                source_cdn=sourceCdnbody,
                bandwidth_policy=listBandwidthPolicybody,
                migrate_since=123456789,
                description="xxx",
                enable_kms=False,
                dst_node=dstNodebody,
                src_node=srcNodebody,
                task_type="object"
            )
            response = client.create_task(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建URL列表迁移任务,将object_list_file.txt中的URL列表执行迁移。

     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
    # coding: utf-8
    
    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 = __import__('os').getenv("CLOUD_SDK_AK")
        sk = __import__('os').getenv("CLOUD_SDK_SK")
    
        credentials = BasicCredentials(ak, sk) \
    
        client = OmsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(OmsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateTaskRequest()
            dstNodebody = DstNodeReq(
                ak="dst_ak",
                sk="dst_sk",
                bucket="dst_bucket",
                region="cn-north-1"
            )
            listFileSrcNode = ListFile(
                list_file_key="object_list_file.txt",
                obs_bucket="list_file_bucket"
            )
            srcNodebody = SrcNodeReq(
                cloud_type="URLSource",
                list_file=listFileSrcNode
            )
            request.body = CreateTaskReq(
                enable_failed_object_recording=True,
                description="xxx",
                enable_kms=False,
                dst_node=dstNodebody,
                src_node=srcNodebody,
                task_type="url_list"
            )
            response = client.create_task(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 创建前缀迁移任务,将[ "abc", "123", "prefix3", "path/prefix4" ]为前缀的对象文件进行迁移。

     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
    # coding: utf-8
    
    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 = __import__('os').getenv("CLOUD_SDK_AK")
        sk = __import__('os').getenv("CLOUD_SDK_SK")
    
        credentials = BasicCredentials(ak, sk) \
    
        client = OmsClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(OmsRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateTaskRequest()
            dstNodebody = DstNodeReq(
                ak="dst_ak",
                sk="dst_sk",
                bucket="dst_bucket",
                region="cn-north-1"
            )
            listObjectKeySrcNode = [
                "abc",
                "123",
                "prefix3",
                "path/prefix4"
            ]
            srcNodebody = SrcNodeReq(
                cloud_type="HuaweiCloud",
                region="cn-north-1",
                ak="src_ak",
                sk="src_sk",
                bucket="src_bucket",
                object_key=listObjectKeySrcNode
            )
            request.body = CreateTaskReq(
                enable_failed_object_recording=True,
                description="xxx",
                enable_kms=False,
                dst_node=dstNodebody,
                src_node=srcNodebody,
                task_type="prefix"
            )
            response = client.create_task(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • 使用阿里云A方式进行https CDN方式迁移,开启按时段限速,限速值为50MB/S,将对象列表object_list_file.txt中的对象列表执行迁移,并开启迁移结果通知。

     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
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    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.CreateTaskRequest{}
    	var listTriggerConditionsSmnConfig = []string{
            "SUCCESS",
    	    "FAILURE",
        }
    	languageSmnConfig:= model.GetSmnConfigLanguageEnum().EN_US
    	smnConfigbody := &model.SmnConfig{
    		Language: &languageSmnConfig,
    		TopicUrn: "urn:smn:region:4cf2090802d94440b4cdd72ef26857b2:OMS",
    		TriggerConditions: listTriggerConditionsSmnConfig,
    	}
    	authenticationKeySourceCdn:= "xxx"
    	sourceCdnbody := &model.SourceCdnReq{
    		AuthenticationKey: &authenticationKeySourceCdn,
    		AuthenticationType: model.GetSourceCdnReqAuthenticationTypeEnum().ALIYUN_OSS_A,
    		Domain: "xxx.xxx.xxx",
    		Protocol: model.GetSourceCdnReqProtocolEnum().HTTPS,
    	}
    	var listBandwidthPolicybody = []model.BandwidthPolicyDto{
            {
                End: "23:59",
                MaxBandwidth: int64(50000000),
                Start: "00:00",
            },
        }
    	dstNodebody := &model.DstNodeReq{
    		Ak: "dst_ak",
    		Sk: "dst_sk",
    		Bucket: "dst_bucket",
    		Region: "cn-north-1",
    	}
    	listFileSrcNode := &model.ListFile{
    		ListFileKey: "object_list_file.txt",
    		ObsBucket: "list_file_bucket",
    	}
    	cloudTypeSrcNode:= "HuaweiCloud"
    	regionSrcNode:= "cn-north-1"
    	akSrcNode:= "src_ak"
    	skSrcNode:= "src_sk"
    	bucketSrcNode:= "src_bucket"
    	srcNodebody := &model.SrcNodeReq{
    		CloudType: &cloudTypeSrcNode,
    		Region: &regionSrcNode,
    		Ak: &akSrcNode,
    		Sk: &skSrcNode,
    		Bucket: &bucketSrcNode,
    		ListFile: listFileSrcNode,
    	}
    	enableFailedObjectRecordingCreateTaskReq:= true
    	migrateSinceCreateTaskReq:= int64(123456789)
    	descriptionCreateTaskReq:= "xxx"
    	enableKmsCreateTaskReq:= false
    	taskTypeCreateTaskReq:= model.GetCreateTaskReqTaskTypeEnum().LIST
    	request.Body = &model.CreateTaskReq{
    		EnableFailedObjectRecording: &enableFailedObjectRecordingCreateTaskReq,
    		SmnConfig: smnConfigbody,
    		SourceCdn: sourceCdnbody,
    		BandwidthPolicy: &listBandwidthPolicybody,
    		MigrateSince: &migrateSinceCreateTaskReq,
    		Description: &descriptionCreateTaskReq,
    		EnableKms: &enableKmsCreateTaskReq,
    		DstNode: dstNodebody,
    		SrcNode: srcNodebody,
    		TaskType: &taskTypeCreateTaskReq,
    	}
    	response, err := client.CreateTask(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 使用阿里云A方式进行https CDN方式迁移,开启按时段限速,限速值为50MB/S,将对象文件/前缀["file1.xxx", "file2.xxx", "path1/"]进行迁移,并开启迁移结果通知

      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
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    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.CreateTaskRequest{}
    	var listTriggerConditionsSmnConfig = []string{
            "SUCCESS",
    	    "FAILURE",
        }
    	languageSmnConfig:= model.GetSmnConfigLanguageEnum().EN_US
    	smnConfigbody := &model.SmnConfig{
    		Language: &languageSmnConfig,
    		TopicUrn: "urn:smn:region:4cf2090802d94440b4cdd72ef26857b2:OMS",
    		TriggerConditions: listTriggerConditionsSmnConfig,
    	}
    	authenticationKeySourceCdn:= "xxx"
    	sourceCdnbody := &model.SourceCdnReq{
    		AuthenticationKey: &authenticationKeySourceCdn,
    		AuthenticationType: model.GetSourceCdnReqAuthenticationTypeEnum().ALIYUN_OSS_A,
    		Domain: "xxx.xxx.xxx",
    		Protocol: model.GetSourceCdnReqProtocolEnum().HTTPS,
    	}
    	var listBandwidthPolicybody = []model.BandwidthPolicyDto{
            {
                End: "23:59",
                MaxBandwidth: int64(50000000),
                Start: "00:00",
            },
        }
    	dstNodebody := &model.DstNodeReq{
    		Ak: "dst_ak",
    		Sk: "dst_sk",
    		Bucket: "dst_bucket",
    		Region: "cn-north-1",
    	}
    	var listObjectKeySrcNode = []string{
            "file1.xxx",
    	    "file2.xxx",
    	    "path1/",
        }
    	cloudTypeSrcNode:= "HuaweiCloud"
    	regionSrcNode:= "cn-north-1"
    	akSrcNode:= "src_ak"
    	skSrcNode:= "src_sk"
    	bucketSrcNode:= "src_bucket"
    	srcNodebody := &model.SrcNodeReq{
    		CloudType: &cloudTypeSrcNode,
    		Region: &regionSrcNode,
    		Ak: &akSrcNode,
    		Sk: &skSrcNode,
    		Bucket: &bucketSrcNode,
    		ObjectKey: &listObjectKeySrcNode,
    	}
    	enableFailedObjectRecordingCreateTaskReq:= true
    	migrateSinceCreateTaskReq:= int64(123456789)
    	descriptionCreateTaskReq:= "xxx"
    	enableKmsCreateTaskReq:= false
    	taskTypeCreateTaskReq:= model.GetCreateTaskReqTaskTypeEnum().OBJECT
    	request.Body = &model.CreateTaskReq{
    		EnableFailedObjectRecording: &enableFailedObjectRecordingCreateTaskReq,
    		SmnConfig: smnConfigbody,
    		SourceCdn: sourceCdnbody,
    		BandwidthPolicy: &listBandwidthPolicybody,
    		MigrateSince: &migrateSinceCreateTaskReq,
    		Description: &descriptionCreateTaskReq,
    		EnableKms: &enableKmsCreateTaskReq,
    		DstNode: dstNodebody,
    		SrcNode: srcNodebody,
    		TaskType: &taskTypeCreateTaskReq,
    	}
    	response, err := client.CreateTask(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建URL列表迁移任务,将object_list_file.txt中的URL列表执行迁移。

     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
    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.CreateTaskRequest{}
    	dstNodebody := &model.DstNodeReq{
    		Ak: "dst_ak",
    		Sk: "dst_sk",
    		Bucket: "dst_bucket",
    		Region: "cn-north-1",
    	}
    	listFileSrcNode := &model.ListFile{
    		ListFileKey: "object_list_file.txt",
    		ObsBucket: "list_file_bucket",
    	}
    	cloudTypeSrcNode:= "URLSource"
    	srcNodebody := &model.SrcNodeReq{
    		CloudType: &cloudTypeSrcNode,
    		ListFile: listFileSrcNode,
    	}
    	enableFailedObjectRecordingCreateTaskReq:= true
    	descriptionCreateTaskReq:= "xxx"
    	enableKmsCreateTaskReq:= false
    	taskTypeCreateTaskReq:= model.GetCreateTaskReqTaskTypeEnum().URL_LIST
    	request.Body = &model.CreateTaskReq{
    		EnableFailedObjectRecording: &enableFailedObjectRecordingCreateTaskReq,
    		Description: &descriptionCreateTaskReq,
    		EnableKms: &enableKmsCreateTaskReq,
    		DstNode: dstNodebody,
    		SrcNode: srcNodebody,
    		TaskType: &taskTypeCreateTaskReq,
    	}
    	response, err := client.CreateTask(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 创建前缀迁移任务,将[ "abc", "123", "prefix3", "path/prefix4" ]为前缀的对象文件进行迁移。

     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
    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.CreateTaskRequest{}
    	dstNodebody := &model.DstNodeReq{
    		Ak: "dst_ak",
    		Sk: "dst_sk",
    		Bucket: "dst_bucket",
    		Region: "cn-north-1",
    	}
    	var listObjectKeySrcNode = []string{
            "abc",
    	    "123",
    	    "prefix3",
    	    "path/prefix4",
        }
    	cloudTypeSrcNode:= "HuaweiCloud"
    	regionSrcNode:= "cn-north-1"
    	akSrcNode:= "src_ak"
    	skSrcNode:= "src_sk"
    	bucketSrcNode:= "src_bucket"
    	srcNodebody := &model.SrcNodeReq{
    		CloudType: &cloudTypeSrcNode,
    		Region: &regionSrcNode,
    		Ak: &akSrcNode,
    		Sk: &skSrcNode,
    		Bucket: &bucketSrcNode,
    		ObjectKey: &listObjectKeySrcNode,
    	}
    	enableFailedObjectRecordingCreateTaskReq:= true
    	descriptionCreateTaskReq:= "xxx"
    	enableKmsCreateTaskReq:= false
    	taskTypeCreateTaskReq:= model.GetCreateTaskReqTaskTypeEnum().PREFIX
    	request.Body = &model.CreateTaskReq{
    		EnableFailedObjectRecording: &enableFailedObjectRecordingCreateTaskReq,
    		Description: &descriptionCreateTaskReq,
    		EnableKms: &enableKmsCreateTaskReq,
    		DstNode: dstNodebody,
    		SrcNode: srcNodebody,
    		TaskType: &taskTypeCreateTaskReq,
    	}
    	response, err := client.CreateTask(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

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

状态码

状态码

描述

200

Created

400

Bad Request

错误码

请参见错误码

分享:

    相关文档

    相关产品