Updated on 2025-11-18 GMT+08:00

Creating a Migration Task

Function

This API is used to create a migration task. Once created, the task will be automatically started.

Constraints

  • A tenant can create a maximum of 1,500 migration tasks within 24 hours.

  • A tenant cannot create more migration tasks if the tenant already has 1,500 migration tasks in the Waiting state.

Calling Method

For details, see Calling APIs.

Authorization

Each account has all of the permissions required to call all APIs, but IAM users must have the required permissions specifically assigned.

  • If you are using role/policy-based authorization, see the required permissions in Permissions and Supported Actions.
  • If you are using identity policy-based authorization, the permission listed below is required.

    Action

    Access Level

    Resource Type (*: required)

    Condition Key

    Alias

    Dependencies

    oms:task:create

    Write

    task *

    -

    -

    -

URI

POST /v2/{project_id}/tasks

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

The project ID.

Minimum length: 1 character

Maximum length: 1,024 characters

Request

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

The token used for IAM authentication.

Minimum length: 1 character

Maximum length: 16,384 characters

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

task_type

No

String

The task type. The default value is object.

list: a list of objects

url_list: a list of URLs.

object (default): files and folder

prefix: objects that match the specified prefixes

Default value: object

Enumerated values:

  • list

  • url_list

  • object

  • prefix

src_node

Yes

SrcNodeReq object

The source information.

dst_node

Yes

DstNodeReq object

The destination information.

enable_kms

No

Boolean

Whether KMS encryption is enabled. This function is disabled by default.

Default value: false

description

No

String

The task description, which cannot exceed 255 characters. The following special characters are not allowed: ^<>&"'

Minimum length: 0 characters

Maximum length: 255 characters

migrate_since

No

Long

A timestamp in seconds. Only source objects that are modified after the specified timestamp will be migrated. No time is specified by default.

Minimum value: 0

Maximum value: 9223372036854775807

Default value: 0

bandwidth_policy

No

Array of BandwidthPolicyDto objects

The traffic limiting rules. Each element in the array corresponds to the maximum bandwidth in a time period. A maximum of five periods are allowed, and the periods cannot overlap.

Array length: 0 to 5

source_cdn

No

SourceCdnReq object

Whether migration from CDN is enabled. If this field is included, migration from CDN is supported. Otherwise, it is not supported. If migration from CDN is enabled, the source objects to be migrated are obtained from the specified CDN domain name during migration.

smn_config

No

SmnConfig object

The configuration of SMN message sending.

enable_metadata_migration

No

Boolean

Whether metadata migration is enabled. This function is disabled by default. Even if this function is disabled, the Content-Type metadata will still be migrated to ensure a successful migration.

Default value: false

enable_restore

No

Boolean

Whether automatic restoration of archived data is enabled. This function is disabled by default.

If this function is enabled, archived data is automatically restored and migrated.

Default value: false

enable_failed_object_recording

No

Boolean

Whether the function of recording failed objects is enabled. This function is enabled by default.

If this function is enabled, information about objects that fail to be migrated will be stored in the destination bucket.

Default value: true

object_overwrite_mode

No

String

How a source object handles its paired destination object, either overwriting the object or skipping the migration. The default value is SIZE_LAST_MODIFIED_COMPARISON_OVERWRITE. NO_OVERWRITE: The system always skips source objects and keeps their paired destination objects. SIZE_LAST_MODIFIED_COMPARISON_OVERWRITE: The system allows overwriting based on the results of size or modification time checks. This is the default value. If a source object has the same name as the paired destination object, the system compares the sizes and last modification time of the source and destination objects to determine whether to overwrite the destination object. The encryption status of the source and destination objects must be the same. If the source object has a different size or was last modified more recently than its paired destination object, the destination object will be overwritten. CRC64_COMPARISON_OVERWRITE: The system allows overwriting if the source and destination objects have different CRC64 checksums. This option is only available for migration within Huawei Cloud or from Alibaba Cloud or Tencent Cloud. If a source object has a CRC64 checksum different from its paired destination object, the destination object will be overwritten. The encryption status of the source and destination objects must be the same. If there are no CRC64 checksums in the metadata, the SIZE_LAST_MODIFIED_COMPARISON_OVERWRITE value is used. FULL_OVERWRITE: The system always allows source objects to overwrite their paired destination objects.

Enumerated values:

  • NO_OVERWRITE

  • SIZE_LAST_MODIFIED_COMPARISON_OVERWRITE

  • CRC64_COMPARISON_OVERWRITE

  • FULL_OVERWRITE

dst_storage_policy

No

String

The destination storage class. This parameter is required only when the destination is Huawei Cloud OBS. The default value is STANDARD.

STANDARD: Huawei Cloud OBS Standard storage

IA: Huawei Cloud OBS Infrequent Access storage

ARCHIVE: Huawei Cloud OBS Archive storage

DEEP_ARCHIVE: Huawei Cloud OBS Deep Archive storage

SRC_STORAGE_MAPPING: The source storage class is retained and mapped to Huawei Cloud OBS storage class.

Default value: STANDARD

Minimum length: 0 characters

Maximum length: 128 characters

Enumerated values:

  • STANDARD

  • IA

  • ARCHIVE

  • DEEP_ARCHIVE

  • SRC_STORAGE_MAPPING

consistency_check

No

String

The method for checking whether objects are consistent before and after migration. The encryption status of the source and destination objects must be the same. The check method and results will be recorded in the object list. The default value is size_last_modified. size_last_modified (default): The system checks object consistency with object size and last modification time. If the source and destination objects have the same size and the destination's last modification time is not earlier than the source's, the system considers the source object does not need to be migrated or has been already migrated successfully. crc64: This value is only available for migration within Huawei Cloud or from Alibaba Cloud or Tencent Cloud. If a source object and its paired destination object have CRC64 checksums in the metadata, the checksums are checked. Otherwise, their sizes and last modification times are checked. no_check: This value is only available for migration of HTTP/HTTPS data. This option takes effect for source objects whose sizes cannot be obtained from the Content-Length field in the standard HTTP protocol. In this case, the migration is considered successful once the data is downloaded successfully, without requiring additional data check. These source objects will overwrite their paired destination objects directly. If the size of a source object can be obtained from the Content-Length field in the standard HTTP protocol, its size and last modification time will be checked.

Default value: size_last_modified

Enumerated values:

  • size_last_modified

  • crc64

  • no_check

enable_requester_pays

No

Boolean

Whether Requester Pays is enabled. If this function is enabled, the requester pays for the request and data transmission.

Default value: false

task_priority

No

String

HIGH: high priority

MEDIUM: medium priority

LOW: low priority

Default value: MEDIUM

Enumerated values:

  • HIGH

  • MEDIUM

  • LOW

Table 4 SrcNodeReq

Parameter

Mandatory

Type

Description

cloud_type

No

String

The source cloud service provider. This parameter is mandatory and must be URLSource if task_type is not url_list. The value can be AWS, Azure, Aliyun, Tencent, HuaweiCloud, QingCloud, KingsoftCloud, Baidu, Qiniu, Google, URLSource, or UCloud. The default value is Aliyun.

Default value: Aliyun

region

No

String

The region where the source bucket is located. This parameter is mandatory when task_type is not url_list.

Minimum length: 0 characters

Maximum length: 100 characters

ak

No

String

The AK for accessing the source bucket. Enter a maximum of 100 characters. This parameter is mandatory when task_type is not url_list.

Minimum length: 0 characters

Maximum length: 100 characters

sk

No

String

The SK for accessing the source bucket. Enter a maximum of 100 characters. This parameter is mandatory when task_type is not url_list.

Minimum length: 0 characters

Maximum length: 100 characters

json_auth_file

No

String

The file used for Google Cloud Storage authentication.

Minimum length: 0 characters

Maximum length: 65,535 characters

security_token

No

String

The temporary token for accessing the source bucket. Enter a maximum of 16,384 characters.

Minimum length: 0 characters

Maximum length: 16,384 characters

app_id

No

String

This parameter is mandatory when cloud_type is Tencent.

Minimum length: 0 characters

Maximum length: 255 characters

bucket

No

String

The name of the source bucket. This parameter is mandatory when task_type is not url_list.

Minimum length: 0 characters

Maximum length: 1,024 characters

object_key

No

Array of strings

If task-type is set to object, this parameter specifies the names of the objects to be migrated. The character strings ending with a slash (/) indicate the folders to be migrated, and the character strings not ending with a slash (/) indicate the files to be migrated.

If task_type is set to prefix, this parameter indicates the name prefixes of objects to be migrated.

If you want to migrate the entire bucket, set this parameter to [""].

Minimum length: 0 characters

Maximum length: 1,024 characters

Array length: 0 to 500

list_file

No

ListFile object

The configurations of the list file. This parameter is mandatory when task_type is set to list or url_list.

Table 5 ListFile

Parameter

Mandatory

Type

Description

list_file_key

Yes

String

The object names in the object or URL list file.

Minimum length: 1 character

Maximum length: 1,024 characters

obs_bucket

Yes

String

The name of the OBS bucket for storing object list files.

Ensure that this bucket is in the same region as the destination bucket, or the task creation will fail.

Minimum length: 0 characters

Maximum length: 1,024 characters

list_file_num

No

String

The number of stored object list files.

Minimum length: 0 characters

Maximum length: 65,535 characters

Table 6 DstNodeReq

Parameter

Mandatory

Type

Description

ak

Yes

String

The AK for accessing the destination bucket. Enter a maximum of 100 characters.

Minimum length: 0 characters

Maximum length: 100 characters

sk

Yes

String

The SK for accessing the destination bucket. Enter a maximum of 100 characters.

Minimum length: 0 characters

Maximum length: 100 characters

security_token

No

String

The temporary token for accessing the destination bucket. Enter a maximum of 16,384 characters.

Minimum length: 0 characters

Maximum length: 16,384 characters

bucket

Yes

String

The name of the destination bucket.

Minimum length: 0 characters

Maximum length: 1,024 characters

save_prefix

No

String

The path prefix used to organize object locations in the destination bucket. The prefix is added before an object key to form a new key. The length of the new key cannot exceed 1,024 characters.

Minimum length: 0 characters

Maximum length: 1,024 characters

region

Yes

String

The region where the destination bucket is located.

The value must be the same as that of the service endpoint.

Minimum length: 0 characters

Maximum length: 100 characters

Table 7 BandwidthPolicyDto

Parameter

Mandatory

Type

Description

end

Yes

String

The time when traffic limiting is ended. The format is hh:mm, for example, 12:03.

max_bandwidth

Yes

Long

The maximum traffic bandwidth allowed in the specified period. The unit is byte/s. The value ranges from 1,048,576 bytes/s (equivalent to 1 MB/s) to 209,715,200 bytes/s (equivalent to 200 MB/s).

Minimum value: 1048576

Maximum value: 209715200

start

Yes

String

The time when traffic limiting is started. The format is hh:mm, for example, 12:03.

Table 8 SourceCdnReq

Parameter

Mandatory

Type

Description

authentication_key

No

String

The CDN authentication key. This parameter is mandatory if CDN authentication is required.

If no authorization is required, do not set this parameter.

Qiniu: You do not need to set this parameter.

Aliyun: Set this parameter based on the value of authentication_type.

KingsoftCloud: You do not need to set this parameter.

Minimum length: 0 characters

Maximum length: 255 characters

authentication_type

Yes

String

The authentication type.

NONE: public access without authentication type

QINIU_PRIVATE_AUTHENTICATION: Qiniu private URL signature

ALIYUN_OSS_A: Alibaba Cloud URL signature, simple and universal

ALIYUN_OSS_B: Alibaba Cloud header signature, used for API calling

ALIYUN_OSS_C: Alibaba Cloud STS temporary security token, the most secure

KSYUN_PRIVATE_AUTHENTICATION: Kingsoft Cloud private URL signature

AZURE_SAS_TOKEN: Microsoft Azure shared access signature, flexible and secure

TENCENT_COS_A: Tencent Cloud multi-signature scenarios (not recommended)

TENCENT_COS_B: Tencent Cloud single-signature scenarios, the most secure

TENCENT_COS_C: Tencent Cloud header signature, used for API calling

TENCENT_COS_D: Tencent Cloud header signature, used for API calling

Default value: NONE

Enumerated values:

  • 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

Yes

String

The domain name used to obtain objects to be migrated.

Minimum length: 0 characters

Maximum length: 1,024 characters

protocol

Yes

String

The protocol type. HTTP and HTTPS are supported.

Enumerated values:

  • http

  • https

Table 9 SmnConfig

Parameter

Mandatory

Type

Description

language

No

String

The management console language you selected.

The value can be zh-cn or en-us.

Default value: en-us

Enumerated values:

  • zh-cn

  • en-us

topic_urn

Yes

String

The URN of the SMN topic associated with the migration task.

Minimum length: 0 characters

Maximum length: 1,024 characters

trigger_conditions

Yes

Array of strings

The trigger conditions of sending messages using SMN. The trigger conditions are based on the migration task states.

The migration task state can be SUCCESS or FAILURE.

  • FAILURE: An SMN message will be sent if the migration task fails.

  • SUCCESS: An SMN message will be sent if the migration task succeeds.

Array length: 1 to 2

message_template_name

No

String

If this parameter is specified, SMN messages are sent using the specified template.

Example template:

{

"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": ""

}

Response

Status code: 200

Table 10 Response body parameters

Parameter

Type

Description

id

Long

The task ID.

Minimum value: 0

Maximum value: 999999999999999

task_name

String

The task name.

Minimum length: 0 characters

Maximum length: 2,048 characters

Status code: 400

Table 11 Response body parameters

Parameter

Type

Description

error_msg

String

The error message.

error_code

String

The error code.

Example Request

  • This example migrates data from Alibaba Cloud over HTTPS using CDN. It uses the ALIYUN_OSS_A authentication type, enables period–based rate limiting, sets the rate limit to 50 MB/s, migrates the objects in object_list_file.txt, and enables migration result notifications.

    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"
      }
    }
  • This example migrates data from Alibaba Cloud over HTTPS using CDN. It uses the ALIYUN_OSS_A authentication type, enables period–based rate limiting, sets the rate limit to 50 MB/s, migrates object file1.xxx and file2.xxx and objects prefixed with path1/, and enables migration result notifications.

    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"
      }
    }
  • This example creates a URL list-based migration task to migrate the objects listed in the object_list_file.txt file.

    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"
    }
  • This example creates a prefix-based migration task to migrate objects prefixed with abc, 123, prefix3, or 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"
    }

Example Response

Status code: 200

Created

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

SDK Sample Code

The following shows the sample SDK code.

  • This example migrates data from Alibaba Cloud over HTTPS using CDN. It uses the ALIYUN_OSS_A authentication type, enables period–based rate limiting, sets the rate limit to 50 MB/s, migrates the objects in object_list_file.txt, and enables migration result notifications.

     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
    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");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .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());
            }
        }
    }
    
  • This example migrates data from Alibaba Cloud over HTTPS using CDN. It uses the ALIYUN_OSS_A authentication type, enables period–based rate limiting, sets the rate limit to 50 MB/s, migrates object file1.xxx and file2.xxx and objects prefixed with path1/, and enables migration result notifications.

     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
    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");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .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());
            }
        }
    }
    
  • This example creates a URL list-based migration task to migrate the objects listed in the object_list_file.txt file.

     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
    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");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .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());
            }
        }
    }
    
  • This example creates a prefix-based migration task to migrate objects prefixed with abc, 123, prefix3, or 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
    73
    74
    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");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .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());
            }
        }
    }
    
  • This example migrates data from Alibaba Cloud over HTTPS using CDN. It uses the ALIYUN_OSS_A authentication type, enables period–based rate limiting, sets the rate limit to 50 MB/s, migrates the objects in object_list_file.txt, and enables migration result notifications.

     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
    # 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"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        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)
    
  • This example migrates data from Alibaba Cloud over HTTPS using CDN. It uses the ALIYUN_OSS_A authentication type, enables period–based rate limiting, sets the rate limit to 50 MB/s, migrates object file1.xxx and file2.xxx and objects prefixed with path1/, and enables migration result notifications.

     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
    # 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"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        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)
    
  • This example creates a URL list-based migration task to migrate the objects listed in the object_list_file.txt file.

     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
    # 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"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        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)
    
  • This example creates a prefix-based migration task to migrate objects prefixed with abc, 123, prefix3, or 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
    # 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"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        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)
    
  • This example migrates data from Alibaba Cloud over HTTPS using CDN. It uses the ALIYUN_OSS_A authentication type, enables period–based rate limiting, sets the rate limit to 50 MB/s, migrates the objects in object_list_file.txt, and enables migration result notifications.

      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
    101
    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")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            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)
        }
    }
    
  • This example migrates data from Alibaba Cloud over HTTPS using CDN. It uses the ALIYUN_OSS_A authentication type, enables period–based rate limiting, sets the rate limit to 50 MB/s, migrates object file1.xxx and file2.xxx and objects prefixed with path1/, and enables migration result notifications.

      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
    101
    102
    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")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            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)
        }
    }
    
  • This example creates a URL list-based migration task to migrate the objects listed in the object_list_file.txt file.

     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 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")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            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)
        }
    }
    
  • This example creates a prefix-based migration task to migrate objects prefixed with abc, 123, prefix3, or 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
    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")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            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)
        }
    }
    

For SDK code examples in more programming languages, visit API Explorer and click the Sample Code tab. Example code can be automatically generated.

Status Codes

Status Code

Description

200

Created

400

Bad request

Error Codes

For details, see Error Codes.