This topic describes how to use the software development kit (SDK) to call job-related methods.
Create a job
This method is used to create a migration task.
After the task is created, you must update its status to start it.
The following sample code shows how to create a job.
package sample;
import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import java.util.List;
public class Demo {
/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
/** Enter the ID of your Alibaba Cloud account.*/
static String userId = "11470***876***55";
public static void main(String[] args) {
// Enter the job name.
String jobName = "examplejob";
// Enter the name of the source data address.
String srcAddress = "examplesrcaddress";
// Enter the name of the destination data address.
String destAddress = "exampledestaddress";
try {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
// This example uses the China (Beijing) region.
config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
config.setAccessKeyId(accessKeyId);
config.setAccessKeySecret(accessKeySecret);
// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
config.setProtocol("http");
Client client = new Client(config);
CreateJobInfo info = new CreateJobInfo();
info.name = jobName;
info.srcAddress = srcAddress;
info.destAddress = destAddress;
/**
overwriteMode and transferMode must be used together. The combinations are as follows:
always,all: Overwrites all files.
always,lastmodified: Overwrites files based on their last modified time.
never,"": Does not overwrite any files.
*/
/* The file overwrite mode. Valid values: 1. never 2. always */
info.overwriteMode = "always";
/* The file transfer mode. Valid values: 1. changed 2. all 3. lastmodified */
info.transferMode = "lastmodified";
// If maxImportTaskQps is set to 0 or left empty, the default value is used. If MaxBandWidth is set to 0 or left empty, the default value is used. The unit of maxBandWidth is bits.
ImportQos importQos = new ImportQos();
// Set maxBandWidth and maxImportTaskQps as needed.
importQos.maxBandWidth = 1073741824L;
importQos.maxImportTaskQps = 1000L;
info.setImportQos(importQos);
// Configure the scheduling rule. For more information about the parameters, see the API documentation.
ScheduleRule scheduleRule = new ScheduleRule();
// Set maxScheduleCount, startCronExpression, and suspendCronExpression as needed.
scheduleRule.maxScheduleCount = 2L;
scheduleRule.startCronExpression = "0 0 10 * * ?";
scheduleRule.suspendCronExpression = "0 0 14 * * ?";
info.setScheduleRule(scheduleRule);
// Configure the filter rule. For more information about the parameters, see the API documentation.
FilterRule filterRule = new FilterRule();
// File filter. Set the value as needed.
KeyFilters keyFilters = new KeyFilters();
KeyFilterItem includekeyFilterItem = new KeyFilterItem();
List<String> includeRegex = new LinkedList<>();
includeRegex.add(".*.jpg");
includeRegex.add(".*.jpeg");
includekeyFilterItem.setRegex(includeRegex);
KeyFilterItem excludekeyFilterItem = new KeyFilterItem();
List<String> excludeRegex = new LinkedList<>();
excludeRegex.add(".*.txt");
excludeRegex.add(".*.js");
excludekeyFilterItem.setRegex(excludeRegex);
keyFilters.setIncludes(includekeyFilterItem);
keyFilters.setExcludes(excludekeyFilterItem);
filterRule.setKeyFilters(keyFilters);
// Time filter. The time must be in UTC format. Set the value as needed.
LastModifiedFilters lastModifiedFilters = new LastModifiedFilters();
LastModifyFilterItem includeLastModifyFilterItem = new LastModifyFilterItem();
List<TimeFilter> includeRegexs = new LinkedList<>();
TimeFilter includeTimeFilter = new TimeFilter();
includeTimeFilter.startTime = "2006-01-01T00:00:00Z";
includeTimeFilter.endTime = "2006-12-31T23:59:59Z";
includeRegexs.add(includeTimeFilter);
includeLastModifyFilterItem.setTimeFilter(includeRegexs);
LastModifyFilterItem excludeLastModifyFilterItem = new LastModifyFilterItem();
List<TimeFilter> excludeRegexs = new LinkedList<>();
TimeFilter excludeTimeFilter = new TimeFilter();
excludeTimeFilter.startTime = "2008-01-01T00:00:00Z";
excludeTimeFilter.endTime = "2008-12-31T23:59:59Z";
excludeRegexs.add(excludeTimeFilter);
excludeLastModifyFilterItem.setTimeFilter(excludeRegexs);
lastModifiedFilters.setIncludes(includeLastModifyFilterItem);
lastModifiedFilters.setExcludes(excludeLastModifyFilterItem);
filterRule.setLastModifiedFilters(lastModifiedFilters);
info.setFilterRule(filterRule);
CreateJobRequest request = new CreateJobRequest();
request.setImportJob(info);
client.createJob(userId, request);
} catch (Exception e) {
e.printStackTrace();
}
}
}Update a job
After you create a task, use this method to start, pause, and close the task. You can also use this method to adjust the task's rate limiting settings.
The following sample code shows how to update the status of a job.
package sample;
import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
public class Demo {
/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
/** Enter the ID of your Alibaba Cloud account.*/
static String userId = "11470***876***55";
public static void main(String[] args) {
// Enter the job name.
String jobName = "examplejob";
try {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
// This example uses the China (Beijing) region.
config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
config.setAccessKeyId(accessKeyId);
config.setAccessKeySecret(accessKeySecret);
// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
config.setProtocol("http");
Client client = new Client(config);
UpdateJobRequest updateJobRequest = new UpdateJobRequest();
UpdateJobInfo updateJobInfo = new UpdateJobInfo();
//Valid status values are IMPORT_JOB_LAUNCHING (start job), IMPORT_JOB_SUSPEND (pause job), and IMPORT_JOB_CLOSING (shut down job).
updateJobInfo.setStatus("IMPORT_JOB_LAUNCHING");
updateJobRequest.setImportJob(updateJobInfo);
client.updateJob(userId, jobName, updateJobRequest);
} catch (Exception e) {
e.printStackTrace();
}
}
}The following sample code shows how to update the rate-limiting settings for a job.
package sample;
import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
public class Demo {
/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
/** Enter the ID of your Alibaba Cloud account.*/
static String userId = "11470***876***55";
public static void main(String[] args) {
// Enter the job name.
String jobName = "examplejob";
try {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
// This example uses the China (Beijing) region.
config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
config.setAccessKeyId(accessKeyId);
config.setAccessKeySecret(accessKeySecret);
// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
config.setProtocol("http");
Client client = new Client(config);
UpdateJobRequest updateJobRequest = new UpdateJobRequest();
UpdateJobInfo updateJobInfo = new UpdateJobInfo();
// Set maxBandWidth and maxImportTaskQps as needed.
long maxBandWidth = 1610612736L;
long maxImportTaskQps = 1500L;
ImportQos qos = new ImportQos();
qos.setMaxBandWidth(maxBandWidth);
updateJobInfo.setImportQos(qos);
qos.setMaxImportTaskQps(maxImportTaskQps);
updateJobRequest.setImportJob(updateJobInfo);
client.updateJob(userId, jobName, updateJobRequest);
} catch (Exception e) {
e.printStackTrace();
}
}
}Get job details
This method is used to get the details of a migration task.
The following sample code shows how to retrieve the details of a specific job by its name.
package sample;
import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import com.google.gson.Gson;
public class Demo {
/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
/** Enter the ID of your Alibaba Cloud account.*/
static String userId = "11470***876***55";
public static void main(String[] args) {
// Enter the job name.
String jobName = "examplejob";
try {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
// This example uses the China (Beijing) region.
config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
config.setAccessKeyId(accessKeyId);
config.setAccessKeySecret(accessKeySecret);
// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
config.setProtocol("http");
Client client = new Client(config);
GetJobRequest request = new GetJobRequest();
GetJobResponse resp = client.getJob(userId, jobName, request);
System.out.println(new Gson().toJson(resp.getBody().getImportJob()));
} catch (Exception e) {
e.printStackTrace();
}
}
}The following sample code shows how to retrieve the details of a specific job by its ID.
package sample;
import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import com.google.gson.Gson;
public class Demo {
/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
/** Enter the ID of your Alibaba Cloud account.*/
static String userId = "11470***876***55";
public static void main(String[] args) {
// Enter the job ID.
String version = "b4155550-****-4371-****-9c73373480211";
try {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
// This example uses the China (Beijing) region.
config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
config.setAccessKeyId(accessKeyId);
config.setAccessKeySecret(accessKeySecret);
// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
config.setProtocol("http");
Client client = new Client(config);
GetJobRequest request = new GetJobRequest();
GetJobResponse resp = client.getJob(userId, version, request);
System.out.println(new Gson().toJson(resp.body.getImportJob()));
} catch (Exception e) {
e.printStackTrace();
}
}
}Sample success 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-31T23:59:59Z"
}
]
},
"Excludes": {
"TimeFilter": [
{
"StartTime": "2006-01-01T00:00:00Z",
"EndTime": "2006-12-31T23:59:59Z"
}
]
}
},
"FileTypeFilters": {
"ExcludeSymlink": true,
"ExcludeDir": true
}
},
"ImportQos": {
"MaxBandWidth": 1073741824,
"MaxImportTaskQps": 1000
},
"ScheduleRule": {
"StartCronExpression": "0 0 * * * ?",
"SuspendCronExpression": "0 0 * * * ?",
"MaxScheduleCount": 1
}
}
}List jobs
This method lists the migration tasks for a user in a region.
The following sample code shows how to list all jobs under an account.
package sample;
import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import com.google.gson.Gson;
public class Demo {
/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
/** Enter the ID of your Alibaba Cloud account.*/
static String userId = "11470***876***55";
public static void main(String[] args) {
try {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
// This example uses the China (Beijing) region.
config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
config.setAccessKeyId(accessKeyId);
config.setAccessKeySecret(accessKeySecret);
// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
config.setProtocol("http");
Client client = new Client(config);
ListJobRequest request = new ListJobRequest();
// Set marker and count as needed.
request.setCount(1);
String marker = "";
request.setMarker(marker);
ListJobResponse resp = client.listJob(userId, request);
System.out.println(new Gson().toJson(resp.getBody().getImportJobList()));
} catch (Exception e) {
e.printStackTrace();
}
}
}Sample success response
{
"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-31T23:59:59Z"
}
]
},
"Excludes": {
"TimeFilter": [
{
"StartTime": "2006-01-01T00:00:00Z",
"EndTime": "2006-12-31T23:59:59Z"
}
]
}
},
"FileTypeFilters": {
"ExcludeSymlink": true,
"ExcludeDir": true
}
},
"ImportQos": {
"MaxBandWidth": 1073741824,
"MaxImportTaskQps": 1000
},
"ScheduleRule": {
"StartCronExpression": "0 0 * * * ?",
"SuspendCronExpression": "0 0 * * * ?",
"MaxScheduleCount": 1
}
}
]
}
}Get job retry information
After a task runs, some files may fail to migrate. Data Online Migration creates a checklist of these failed files. Use the following sample code to retrieve the checklist information for failed files in a specific round. If the response returns Ready, 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 specific job run.
package sample;
import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import com.google.gson.Gson;
public class Demo {
/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
/** Enter the ID of your Alibaba Cloud account.*/
static String userId = "11470***876***55";
public static void main(String[] args) {
// Enter the job name.
String jobName = "examplejob";
// Enter the job run ID.
int runtimeId = 1;
try {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
// This example uses the China (Beijing) region.
config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
config.setAccessKeyId(accessKeyId);
config.setAccessKeySecret(accessKeySecret);
// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
config.setProtocol("http");
Client client = new Client(config);
GetJobResultRequest request = new GetJobResultRequest();
request.runtimeId = runtimeId;
GetJobResultResponse resp = client.getJobResult(userId, jobName, request);
System.out.println(new Gson().toJson(resp.body.importJobResult));
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sample success 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 job history
This method queries the history of a specified task.
The following sample code shows how to list the history of a specific job.
package sample;
import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import com.google.gson.Gson;
public class Demo {
/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
/** Enter the ID of your Alibaba Cloud account.*/
static String userId = "11470***876***55";
public static void main(String[] args) {
// Enter the job name.
String jobName = "examplejob";
// Enter the job run ID. If you do not specify runtimeId, the history of all runs for the specified job is listed.
int runtimeId = 1;
try {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
// This example uses the China (Beijing) region.
config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
config.setAccessKeyId(accessKeyId);
config.setAccessKeySecret(accessKeySecret);
// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
config.setProtocol("http");
Client client = new Client(config);
ListJobHistoryRequest request = new ListJobHistoryRequest();
// Set the following parameter values as needed.
request.runtimeId = runtimeId;
request.count = 1;
request.marker = "";
ListJobHistoryResponse resp = client.listJobHistory(userId, jobName, request);
request.marker = resp.body.jobHistoryList.nextMarker;
resp = client.listJobHistory(userId, jobName, request);
System.out.println(new Gson().toJson(resp.body.jobHistoryList));
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sample success 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": 5368709120,
"CopiedSize": 4294967296,
"SkippedCount": 0,
"SkippedSize": 0,
"RuntimeState": "Normal",
"Message": "test error msg.",
"Operator": "user",
"ListStatus": "Listing"
}
]
}
}Delete a job
This method deletes a migration task.
The following sample code shows how to delete a specific job.
package sample;
import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
public class Demo {
/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
/** Enter the ID of your Alibaba Cloud account.*/
static String userId = "11470***876***55";
public static void main(String[] args) {
// Enter the job name.
String jobName = "examplejob";
try {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
// This example uses the China (Beijing) region.
config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
config.setAccessKeyId(accessKeyId);
config.setAccessKeySecret(accessKeySecret);
// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
config.setProtocol("http");
Client client = new Client(config);
DeleteJobRequest request = new DeleteJobRequest();
client.deleteJob(userId, jobName, request);
} catch (Exception e) {
e.printStackTrace();
}
}
}Create a job 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, retrieve the task migration report.
The following sample code shows how to create a migration report for a specific job.
package sample;
import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
public class Demo {
/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
/** Enter the ID of your Alibaba Cloud account.*/
static String userId = "11470***876***55";
public static void main(String[] args) {
// Enter the job name. This parameter is required.
String jobName = "examplejob";
// Enter the job ID. This parameter is required.
String version = "b4155550-****-4371-****-9c7337348021";
// Enter the job run ID. This parameter is required.
int runtimeId = 1;
try {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
// This example uses the China (Beijing) region.
config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
config.setAccessKeyId(accessKeyId);
config.setAccessKeySecret(accessKeySecret);
// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
config.setProtocol("http");
Client client = new Client(config);
CreateReportRequest request = new CreateReportRequest();
CreateReportInfo info = new CreateReportInfo();
info.jobName = jobName;
info.version = version;
info.runtimeId = runtimeId;
request.setCreateReport(info);
client.createReport(userId, request);
} catch (Exception e) {
e.printStackTrace();
}
}
}Get a job 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.
The following sample code generates a migration report for a specific task.
package sample;
import com.aliyun.hcs_mgw20240626.Client;
import com.aliyun.hcs_mgw20240626.models.*;
import com.google.gson.Gson;
public class Demo {
/** We strongly recommend that you do not save your AccessKey ID and AccessKey secret in your project code. This can lead to an AccessKey pair leak and threaten the security of all resources in your account.*/
static String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
static String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
/** Enter the ID of your Alibaba Cloud account.*/
static String userId = "11470***876***55";
public static void main(String[] args) {
// Enter the job ID. This parameter is required.
String version = "b4155550-****-4371-****-9c7337348021";
// Enter the job run ID. This parameter is required.
int runtimeId = 1;
try {
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
// This example uses the China (Beijing) region.
config.setEndpoint("cn-beijing.mgw.aliyuncs.com");
config.setAccessKeyId(accessKeyId);
config.setAccessKeySecret(accessKeySecret);
// HTTP and HTTPS are supported. If you do not specify a protocol, HTTPS is used by default.
config.setProtocol("http");
Client client = new Client(config);
GetReportRequest request = new GetReportRequest();
request.version = version;
request.runtimeId = runtimeId;
GetReportResponse resp = client.getReport(userId, request);
System.out.println(new Gson().toJson(resp.body.getReportResponse));
} catch (Exception e) {
e.printStackTrace();
}
}
}
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."
}
}