This topic describes how to use the software development kit (SDK) to call methods related to tasks.
Create a task
This method is used to create a migration task.
After you create a task, you can start it by calling Update A Task.
The following sample code shows how to create a task.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
// Enter the name of the source data address.
srcAddress := "examplesrcaddress"
// Enter the name of the destination data address.
destAddress := "exampledestaddress"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
/**
The overwriteMode and transferMode parameters must be used together. The combinations have the following meanings:
always, all: Overwrites all files.
always, lastmodified: Overwrites files based on their last modified time.
never, "": Does not overwrite files.
*/
/* The file overwrite mode. Valid values: 1. never 2. always */
overwriteMode := "always"
/* The file transfer mode. Valid values: 1. changed 2. all 3. lastmodified */
transferMode := "lastmodified"
// Set maxBandWidth and maxImportTaskQps as needed.
maxImportTaskQps := int64(1000)
maxBandWidth := int64(2147483648)
// If maxImportTaskQps is 0 or not set, the default value is used. If MaxBandWidth is 0 or not set, the default value is used. The unit of maxBandWidth is bits.
importQos := mgwpackage.ImportQos{
MaxImportTaskQps: &maxImportTaskQps,
MaxBandWidth: &maxBandWidth,
}
// Configure filter rules, including file type filters, file filters, and time filters. For more information about the parameters, see the API documentation.
// File type filter, applicable to local file systems (localfs).
excludeSymlink := false
excludeDir := false
fileTypeFilters := &mgwpackage.FileTypeFilters{
&excludeDir, &excludeSymlink,
}
// File filter. Set this filter as needed.
var includeRegex []*string
var excludeRegex []*string
jpgFile := ".*.jpg"
gifFile := ".*.gif"
txtFile := ".*.txt"
jsFile := ".*.js"
includeRegex = append(includeRegex, &jpgFile, &gifFile)
excludeRegex = append(excludeRegex, &txtFile, &jsFile)
KeyFilters := &mgwpackage.KeyFilters{
Excludes: &mgwpackage.KeyFilterItem{
excludeRegex,
}, Includes: &mgwpackage.KeyFilterItem{
includeRegex,
},
}
// Time filter. The time must be in UTC format. Set this filter as needed.
includeStartTime := "2006-01-01T00:00:00Z"
includeEndTime := "2007-01-01T00:00:00Z"
excludeStartTime := "2009-01-01T00:00:00Z"
excludeEndTime := "2010-01-01T00:00:00Z"
includeTimeFilter := []*mgwpackage.TimeFilter{{
&includeStartTime, &includeEndTime,
}}
includeLastModifyFilters := &mgwpackage.LastModifyFilterItem{
includeTimeFilter,
}
excludeTimeFilter := []*mgwpackage.TimeFilter{{
EndTime: &excludeStartTime, StartTime: &excludeEndTime,
}}
excludeLastModifyFilters := &mgwpackage.LastModifyFilterItem{
TimeFilter: excludeTimeFilter,
}
lastModifiedFilters := &mgwpackage.LastModifiedFilters{
Excludes: excludeLastModifyFilters, Includes: includeLastModifyFilters,
}
filterRule := mgwpackage.FilterRule{
LastModifiedFilters: lastModifiedFilters,
KeyFilters: KeyFilters,
FileTypeFilters: fileTypeFilters,
}
// Configure the scheduling rule. For more information about the parameters, see the API documentation.
maxScheduleCount := int64(5)
startCronExpression := "0 0 10 * * ?"
suspendCronExpression := "0 0 14 * * ?"
scheduleRule := mgwpackage.ScheduleRule{
MaxScheduleCount: &maxScheduleCount,
StartCronExpression: &startCronExpression,
SuspendCronExpression: &suspendCronExpression,
}
_, err = client.CreateJob(&userId, &mgwpackage.CreateJobRequest{ImportJob: &mgwpackage.CreateJobInfo{
Name: &jobName,
TransferMode: &transferMode,
OverwriteMode: &overwriteMode,
SrcAddress: &srcAddress,
DestAddress: &destAddress,
ImportQos: &importQos,
FilterRule: &filterRule,
ScheduleRule: &scheduleRule,
}})
if err != nil {
log.Printf("create job failed: %v", err)
return
}
}
Update a task
After you create a task, you can use this method to start, pause, and close the task. You can also use this method to adjust the task's throttling settings.
The following sample code shows how to update the status of a task.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Valid status values are IMPORT_JOB_LAUNCHING (start the task), IMPORT_JOB_SUSPEND (pause the task), and IMPORT_JOB_CLOSING (close the task).
status := "IMPORT_JOB_LAUNCHING"
_, err = client.UpdateJob(&userId, &jobName, &mgwpackage.UpdateJobRequest{
&mgwpackage.UpdateJobInfo{Status: &status},
})
if err != nil {
log.Printf("update job failed, %v", err)
return
}
}
The following sample code shows how to update the throttling settings for a task.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task ID. This is required.
jobName := "examplejob"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set maxBandWidth and maxImportTaskQps as needed.
maxBandWidth := int64(1610612736)
maxImportTaskQps := int64(1500)
_, err = client.UpdateJob(&userId, &jobName, &mgwpackage.UpdateJobRequest{
&mgwpackage.UpdateJobInfo{
ImportQos: &mgwpackage.ImportQos{
MaxBandWidth: &maxBandWidth,
MaxImportTaskQps: &maxImportTaskQps,
},
},
})
if err != nil {
log.Printf("update job failed: %v", err)
return
}
}
Get task details
This method is used to get the details of a migration task.
The following sample code shows how to get the details of a specified task by task name.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
resp, err := client.GetJob(&userId, &jobName, &mgwpackage.GetJobRequest{})
if err != nil {
log.Printf("get job failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("covert failed: %v", err)
return
}
fmt.Println(string(jsonBytes))
}
The following sample code shows how to retrieve the details of a specific task by its task ID.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task ID. This is required.
jobId := "b4155550-****-4371-****-9c7337348021"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
byVersion := ""
resp, err := client.GetJob(&userId, &jobId, &mgwpackage.GetJobRequest{
ByVersion: &byVersion,
})
if err != nil {
log.Printf("get job failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("covert failed: %v", err)
return
}
fmt.Println(string(jsonBytes))
}
Sample successful response
{
"ImportJob": {
"Name": "test_name",
"SrcAddress": "test_src_address",
"DestAddress": "test_dest_address",
"Status": "IMPORT_JOB_DOING",
"EnableMultiVersioning": false,
"CreateTime": "2024-05-01T12:00:00.000Z",
"ModifyTime": "2024-05-01T12:00:00.000Z",
"Version": "test_id",
"Audit": {
"LogMode": "off"
},
"OverwriteMode": "always",
"TransferMode": "all",
"Tags": "K1:V1,K2:V2",
"ParentName": "test_parent_name",
"ParentVersion": "7db93837-a5ee-4e3a-b3c8-800e7947dabc",
"ConvertSymlinkTarget": false,
"CreateReport": false,
"Owner": "test_owner",
"FilterRule": {
"KeyFilters": {
"Includes": {
"Regex": [
".*\\.jpg$"
]
},
"Excludes": {
"Regex": [
".*\\.jpg$"
]
}
},
"LastModifiedFilters": {
"Includes": {
"TimeFilter": [
{
"StartTime": "2006-01-01T00:00:00Z",
"EndTime": "2006-12-31T59:59:59Z"
}
]
},
"Excludes": {
"TimeFilter": [
{
"StartTime": "2006-01-01T00:00:00Z",
"EndTime": "2006-12-31T59:59:59Z"
}
]
}
},
"FileTypeFilters": {
"ExcludeSymlink": true,
"ExcludeDir": true
}
},
"ImportQos": {
"MaxBandWidth": 1073741824,
"MaxImportTaskQps": 1000
},
"ScheduleRule": {
"StartCronExpression": "0 0 * * * ?",
"SuspendCronExpression": "0 0 * * * ?",
"MaxScheduleCount": 1
}
}
}List tasks
This method lists the migration tasks for a user in a region.
The following sample code lists all tasks in an account.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set marker and count as needed.
count := int32(1)
marker := ""
resp, err := client.ListJob(&userId, &mgwpackage.ListJobRequest{
Count: &count,
Marker: &marker,
})
if err != nil {
log.Printf("list job failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("covert failed: %v", err)
return
}
fmt.Println(string(jsonBytes))
}
Successful response example
{
"ImportJobList": {
"NextMarker": "test_nex_marker",
"Truncated": true,
"ImportJob": [
{
"Name": "test_name",
"SrcAddress": "test_src_address",
"DestAddress": "test_dest_address",
"Status": "IMPORT_JOB_DOING",
"EnableMultiVersioning": false,
"CreateTime": "2024-05-01T12:00:00.000Z",
"ModifyTime": "2024-05-01T12:00:00.000Z",
"Version": "test_id",
"Audit": {
"LogMode": "off"
},
"OverwriteMode": "always",
"TransferMode": "all",
"Tags": "K1:V1,K2:V2",
"ParentName": "test_parent_name",
"ParentVersion": "7db93837-a5ee-4e3a-b3c8-800e7947dabc",
"ConvertSymlinkTarget": false,
"CreateReport": false,
"Owner": "test_owner",
"FilterRule": {
"KeyFilters": {
"Includes": {
"Regex": [
".*\\.jpg$"
]
},
"Excludes": {
"Regex": [
".*\\.jpg$"
]
}
},
"LastModifiedFilters": {
"Includes": {
"TimeFilter": [
{
"StartTime": "2006-01-01T00:00:00Z",
"EndTime": "2006-12-31T59:59:59Z"
}
]
},
"Excludes": {
"TimeFilter": [
{
"StartTime": "2006-01-01T00:00:00Z",
"EndTime": "2006-12-31T59:59:59Z"
}
]
}
},
"FileTypeFilters": {
"ExcludeSymlink": true,
"ExcludeDir": true
}
},
"ImportQos": {
"MaxBandWidth": 1073741824,
"MaxImportTaskQps": 1000
},
"ScheduleRule": {
"StartCronExpression": "0 0 * * * ?",
"SuspendCronExpression": "0 0 * * * ?",
"MaxScheduleCount": 1
}
}
]
}
}Get task retry information
After a task runs, some files may fail to migrate. Data Online Migration creates a checklist of these failed files. You can use the following sample code to retrieve the checklist information for failed files in a specific round. If the response returns Ready, you can use the checklist to retry migrating the failed files.
The result of this method is used for the parameter settings of a retry task.
This method is used to determine if failed files from a migration task can be retried.
The following sample code shows how to retrieve the retry information for a task in a specific round.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
// Enter the task round.
runtimeId := int32(1)
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
resp, err := client.GetJobResult(&userId, &jobName, &mgwpackage.GetJobResultRequest{
RuntimeId: &runtimeId,
})
if err != nil {
log.Printf("get job result failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("covert failed: %v", err)
return
}
fmt.Println(string(jsonBytes))
}
Sample successful response
{
"ImportJobResult": {
"ReadyRetry": "Ready",
"InvPath": "mainfest.json",
"InvBucket": "test_sys_bucket",
"InvDomain": "test_domain",
"InvLocation": "oss",
"InvAccessId": "test_access_id",
"InvAccessSecret": "test_secret_key",
"InvRegionId": "test_region_id",
"AddressType": "ossinv",
"TotalObjectCount": 1000,
"CopiedObjectCount": 800,
"FailedObjectCount": 200,
"SkippedObjectCount": 200,
"TotalObjectSize": 1000,
"CopiedObjectSize": 800,
"SkippedObjectSize": 800,
"Version": "test_job_id"
}
}List task history
This method queries the history of a specified task.
The following sample code lists the history of a specified task.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
// Enter the task round. You can leave runtimeId unspecified to list the history of all rounds for the specified task.
runtimeId := int32(1)
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
// Set the following parameter values as needed.
count := int32(1)
marker := ""
resp, err := client.ListJobHistory(&userId, &jobName, &mgwpackage.ListJobHistoryRequest{
Count: &count,
Marker: &marker,
RuntimeId: &runtimeId,
})
if err != nil {
log.Printf("list job history failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("covert failed: %v", err)
return
}
fmt.Println(string(jsonBytes))
}
Sample successful response
{
"JobHistoryList": {
"Truncated": "true",
"NextMarker": "test_next_marker",
"JobHistory": [
{
"Name": "test_name",
"JobVersion": "test_id",
"RuntimeId": "1",
"CommitId": "2",
"StartTime": "2024-05-01T12:00:00.000Z",
"EndTime": "2024-05-01T12:00:00.000Z",
"Status": "IMPORT_JOB_DOING",
"TotalCount": 1000,
"CopiedCount": 900,
"FailedCount": 100,
"TotalSize": 1000,
"CopiedSize": 1000,
"RuntimeState": "Normal",
"Message": "test error msg.",
"Operator": "user",
"ListStatus": "Listing"
}
]
}
}Delete a task
This method deletes a migration task.
You can use the following sample code to delete a specified task.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
_, err = client.DeleteJob(&userId, &jobName, &mgwpackage.DeleteJobRequest{})
if err != nil {
log.Printf("delete job failed: %v", err)
return
}
}
Create a task migration report
This is an asynchronous method call. After you invoke this method, the backend begins to generate the migration report. To check if the report is complete, you can retrieve the task migration report.
The following sample code demonstrates how to create a migration report for a specific task.
package main
import (
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task name.
jobName := "examplejob"
// Enter the task ID. This is required.
version := "b4155550-****-4371-****-9c7337348021"
// Enter the task round. This is required.
runtimeId := int32(1)
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
_, err = client.CreateReport(&userId, &mgwpackage.CreateReportRequest{
CreateReport: &mgwpackage.CreateReportInfo{
JobName: &jobName,
RuntimeId: &runtimeId,
Version: &version,
},
})
if err != nil {
log.Printf("create report failed: %v", err)
return
}
}
Get a task migration report
Call this method to query the migration report for a specified task. The response indicates whether the report has been generated and includes the report if available.
You can use the following sample code to query the migration report for a specified task.
package main
import (
"encoding/json"
"fmt"
"log"
"os"
openapipackage "github.com/alibabacloud-go/darabonba-openapi/v2/client"
mgwpackage "github.com/alibabacloud-go/hcs-mgw-20240626/client"
)
/** Do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and compromise the security of all resources in your account. */
var accessKeyId = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
var accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
/** Enter the ID of your Alibaba Cloud account. */
var userId = "11470***876***55"
func main() {
// This example uses the China (Beijing) region.
endpoint := "cn-beijing.mgw.aliyuncs.com"
// HTTPS and HTTP are supported. If you do not specify a protocol, HTTPS is used by default.
protocol := "http"
// Enter the task ID. This is required.
version := "b4155550-****-4371-****-9c7337348021"
// Enter the task round. This is required.
runtimeId := int32(1)
config := openapipackage.Config{
AccessKeyId: &accessKeyId,
AccessKeySecret: &accessKeySecret,
Endpoint: &endpoint,
Protocol: &protocol,
}
client, err := mgwpackage.NewClient(&config)
if err != nil {
log.Printf("create client failed: %v", err)
return
}
resp, err := client.GetReport(&userId, &mgwpackage.GetReportRequest{
RuntimeId: &runtimeId,
Version: &version,
})
if err != nil {
log.Printf("get report failed: %v", err)
return
}
jsonBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("covert failed: %v", err)
return
}
fmt.Println(string(jsonBytes))
}
Sample success response
{
"GetReportResponse": {
"Status": "Running",
"ReportCreateTime": "2024-05-01T12:00:00.000Z",
"ReportEndTime": "2024-05-01T12:00:00.000Z",
"TotalCount": 1000,
"CopiedCount": 800,
"SkippedCount": 100,
"FailedCount": 100,
"JobCreateTime": "2024-05-01T12:00:00.000Z",
"JobEndTime": "2024-05-01T12:00:00.000Z",
"JobExecuteTime": "1000",
"TotalListPrefix": "test_total_prefix/",
"SkippedListPrefix": "test_skipped_prefix/",
"FailedListPrefix": "test_failed_prefix/",
"ErrorMessage": "test error msg."
}
}